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

First off, can you explain your thoughts behind "I() = ..." ? You are defining a function that takes no arguments and returns a DifferentiableFunction type instance. You should just write "df = Optim.DifferentiableFunction(costFunction(initial_theta,X,y))" and then pass "df" instead of "I".

On Monday, October 24, 2016 at 9:07:46 AM UTC+2, SajeelBongale wrote:

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

First off, can you explain your thoughts behind "I() = ..." ? You are defining a function that takes no arguments and returns a DifferentiableFunction type instance. You should just write "df = Optim.DifferentiableFunction(costFunction(initial_theta,X,y))" and then pass "df" instead of "I".

On Monday, October 24, 2016 at 9:07:46 AM UTC+2, SajeelBongale wrote:

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