gradient descent seems to fail

前端 未结 9 1936
忘掉有多难
忘掉有多难 2020-12-12 15:54

I implemented a gradient descent algorithm to minimize a cost function in order to gain a hypothesis for determining whether an image has a good quality. I did that in Octav

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 16:06

    Using only vectors here is the compact implementation of LR with Gradient Descent in Mathematica:

    Theta = {0, 0}
    alpha = 0.0001;
    iteration = 1500;
    Jhist = Table[0, {i, iteration}];
    Table[  
      Theta = Theta - 
      alpha * Dot[Transpose[X], (Dot[X, Theta] - Y)]/m; 
      Jhist[[k]] = 
      Total[ (Dot[X, Theta] - Y[[All]])^2]/(2*m); Theta, {k, iteration}]
    

    Note: Of course one assumes that X is a n * 2 matrix, with X[[,1]] containing only 1s'

提交回复
热议问题