I am getting a stack over flow error when using the optimize function from Optim package

71 views
Skip to first unread message

SajeelBongale

unread,
Oct 21, 2016, 9:50:13 AM10/21/16
to julia-users
Hello, i am new to julia. 
I am trying to implement logistic regression as per some course on Machine learning. I am using the Atom editor for running Julia. 
However i am unable to find the right arguments for using the optimize function. 
I am sending my differentiable function which is the costFunction and initial_theta as the initial parameters. What other arguments are needed? 
Which optimizer function should be used? 

I am attaching my code here.

This is my cost function:
"This function calculates the cost and gradient at a given theta"
function costFunction( initial_theta,X, y)
  m = length(y);
  J = 0;
  grad = zeros(size(initial_theta));
  z = X * initial_theta;
  h_theta = sigmoid(z);
  J = (-1/m) * ( y .* log(h_theta) + (1-y) .* log(1 - h_theta) );
  grad = (1/m) * X' * ( h_theta - y );
  return J, grad;
end


This is the snippet from my main function:
l() = Optim.DifferentiableFunction(costFunction(initial_theta,X,y))
methodToUse = Optim.GradientDescent()
options = Optim.OptimizationOptions(iterations = 400)

optimize(l,initial_theta)                  #########          when i do this, i get a stack over flow error
optimize(l,initial_theta, methodToUse,options)            ########         with this i get a Method error : no method matching finite_difference

Let me know if any additional information is needed. 
Thanks!

Páll Haraldsson

unread,
Oct 21, 2016, 7:25:24 PM10/21/16
to julia-users
On Friday, October 21, 2016 at 1:50:13 PM UTC, SajeelBongale wrote:

This is my cost function:
"This function calculates the cost and gradient at a given theta"
function costFunction( initial_theta,X, y)

I find it likely, this should go to julia-opt.

See: http://julialang.org/community/

I can't see anything obviously wring with the function, like recursively calling itself (I guess Optim, may do that to it..).

Reply all
Reply to author
Forward
0 new messages