小编how*_*rdh的帖子

梯度下降算法不会收敛

我正在尝试为斯坦福机器学习讲座(讲座2大约25:00)中解释的梯度下降算法编写一些代码.下面是我最初使用的实现,我认为它已经从讲座中正确复制了,但是当我>8向训练集添加大数字()时它并没有收敛.

我正在输入一个数字X,并且point (X,X)被添加到训练集中,所以此刻,我只是想让它收敛到y=ax+b哪里a=1=theta\[1\]b=0=theta\[0\].训练集是数组xy,其中(x[i],y[i])是一个点.

void train()
{
    double delta;
    for (int i = 0; i < x.size(); i++)
    {
        delta = y[i]-hypothesis(x[i]);
        theta[1] += alpha*delta*x[i];
        theta[0] += alpha*delta*1;
    }
}

void C_Approx::display()
{
    std::cout<<theta[1]<<"x + "<<theta[0]<<" \t "<<"f(x)="<<hypothesis(1)<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)

我得到的一些结果:我输入一个数字,然后运行train()几次display()

1
0.33616x + 0.33616   f(x)=0.67232
1
0.482408x + 0.482408     f(x)=0.964816
1
0.499381x + 0.499381     f(x)=0.998762
1
0.499993x + …
Run Code Online (Sandbox Code Playgroud)

c++ machine-learning linear-regression

8
推荐指数
1
解决办法
8171
查看次数

与缩进对齐

我的文本必须是正确对齐的,当这个文本占用多行并换行时,新行必须与之后的行区分开,所以我试图让它在右侧缩进,但我找不到有效的解决方案.

我已经尝试了[htmlhelp论坛帖子#8327]和[codingforums线程#58451]的建议,以及两者的组合无济于事(无法发布链接.抱歉.).还有其他方法可以实现吗?

我的尝试:

div.poem li:after
{
 content: " ";
 display: inline-block;
 width: 10px; 
}
Run Code Online (Sandbox Code Playgroud)

有什么,但我不希望它缩进,如果文本只占用一行.

div.poem li::first-line::after
{
 content: "asdf";
}
Run Code Online (Sandbox Code Playgroud)

什么也没做

div.poem li:first-line
{
 color: red;
 margin-right: 200px;
 padding-right: 200px;
}
Run Code Online (Sandbox Code Playgroud)

第一行的文字变为红色(这样我就知道发生了什么)但是边距和填充没有做任何事情.

HTML:

<div class='poem'>
    <ul class='poem'>
        <li>Here's one line of the poem</li>
        <li>This is the second line of the same stanza, which is long and will wrap around</li>
        <li>Part of the line above is now on line 3, and looks like it's supposed to be a line of …
Run Code Online (Sandbox Code Playgroud)

css

7
推荐指数
1
解决办法
1万
查看次数

将对象映射为关键字

我想创建一个具有某个类作为键的映射.我遇到的问题是,由于这个类包含指针,如果我使用HashMap,则在散列时使用此地址(请参阅下面的代码).我怎样才能比较实际值而不是地址,或者我可以使用其他容器来实现相同的结果吗?

import java.util.*;
public class Main {
    public static void main(String args[]) {
        class Foo {
            public Foo(String a) {s = a;}
            public String s;
        }

        HashMap<Foo,Integer> a = new HashMap<Foo,Integer>();
        a.put(new Foo("test"), 1);
        System.out.println(a.get(new Foo("test")));
    }
}
Run Code Online (Sandbox Code Playgroud)

这输出 null

java map

2
推荐指数
1
解决办法
161
查看次数

标签 统计

c++ ×1

css ×1

java ×1

linear-regression ×1

machine-learning ×1

map ×1