bfgsmin help

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

bfgsmin help

Dek1024
I tried executing 'bfgsmin' to fit a linear curve to the specified data set.
<http://octave.1599824.n4.nabble.com/file/t372910/trainedmodel.png>  

In the above image the blue line is the curve obtained with gradient
descent.
But when trying to execute the same using bfgsmin to check how it works, it
gives me the following error.

*EXAMPLE 4: Ordinary BFGS, using numeric gradient
error: horizontal dimensions mismatch (1x1 vs 2x1)
warning: __bfgsmin_obj: objective function could not be evaluated - setting
to DBL_MAX
warning: called from
    bfgsmin at line 129 column 35
    BFGS at line 12 column 30
error: horizontal dimensions mismatch (1x1 vs 2x1)
error: called from
    objective2 at line 6 column 23
    bfgsmin at line 129 column 35
    BFGS at line 12 column 30
*

*Here is the code for bfgsmin*

/data = load('ex1data1.txt');
y = data(:,2);
m = length(y);
X = [ ones(m,1), data(:,2)];
dim = 1;
theta = zeros(dim+1,1);  # starting values
location = (0:dim)/dim; # true values
location = location';
printf("EXAMPLE 4: Ordinary BFGS, using numeric gradient\n");
t=cputime();
control = {100;2;1;1};  
[theta, obj_value, convergence] = bfgsmin("objective2",
{theta,location,X,y}, control);
fflush(1);
t4 = cputime() - t;
conv = norm(theta-location, 'inf');
test4 = conv < 1e-5;
printf("EXAMPLE 4: Ordinary BFGS, using numeric gradient\n");
if test4
        printf("Success!! :-)\n");
else
        printf("Failure?! :-(\n");
endif
printf("Elapsed time = %f\n\n\n\n",t4);/

*Here is the code for objective funcion*


/function [obj_value, gradient] = objective2(theta,location,X,y)
  m = length(y);
  x = theta - location + ones(rows(theta),1); # move minimizer to "location"
  [obj_value, gradient] = [((1/(2*m)) * sum(((X * x) - y).^2)),
((1/m)*((((X*theta)-y)'*X)'))]
endfunction/

*I tried executing the same without analytical gradient, but obtained a
similar error.(Given Below)*

/obj_value =  26.734
warning: __bfgsmin_obj: objective function could not be evaluated - setting
to DBL_MAX
warning: called from
    bfgsmin at line 129 column 35
    BFGS at line 12 column 30
obj_value =  26.734
obj_value =  26.734
warning: __bfgsmin_obj: objective function could not be evaluated - setting
to DBL_MAX
warning: called from
    bfgsmin at line 129 column 35
    BFGS at line 12 column 30
error: __numgradient: objective function failed, can't compute numeric
gradient
error: called from
    bfgsmin at line 129 column 35
    BFGS at line 12 column 30/

The dataset is a textfile(ex1data1.txt) consisting of a 97 * 2 matrix with
the first row containing *population* and second row containing *profit *.

I took help from  this page
<https://sourceforge.net/p/octave/optim/ci/03e17f135cbe8a154dd01a341b72f454636f507f/tree/inst/bfgsmin_example.m#l155>  
for executing the code.

I am unable to debug the code.(Don't know why the objective function
implementation fails)

Here is the text file  ex1data1.txt
<http://octave.1599824.n4.nabble.com/file/t372910/ex1data1.txt>  .








--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: bfgsmin help

Dek1024
Dek1024 wrote

> I tried executing 'bfgsmin' to fit a linear curve to the specified data
> set.
> &lt;http://octave.1599824.n4.nabble.com/file/t372910/trainedmodel.png&gt; 
>
> In the above image the blue line is the curve obtained with gradient
> descent.
> But when trying to execute the same using bfgsmin to check how it works,
> it
> gives me the following error.
>
> *EXAMPLE 4: Ordinary BFGS, using numeric gradient
> error: horizontal dimensions mismatch (1x1 vs 2x1)
> warning: __bfgsmin_obj: objective function could not be evaluated -
> setting
> to DBL_MAX
> warning: called from
>     bfgsmin at line 129 column 35
>     BFGS at line 12 column 30
> error: horizontal dimensions mismatch (1x1 vs 2x1)
> error: called from
>     objective2 at line 6 column 23
>     bfgsmin at line 129 column 35
>     BFGS at line 12 column 30
> *
>
> *Here is the code for bfgsmin*
>
> /data = load('ex1data1.txt');
> y = data(:,2);
> m = length(y);
> X = [ ones(m,1), data(:,2)];
> dim = 1;
> theta = zeros(dim+1,1);  # starting values
> location = (0:dim)/dim; # true values
> location = location';
> printf("EXAMPLE 4: Ordinary BFGS, using numeric gradient\n");
> t=cputime();
> control = {100;2;1;1};  
> [theta, obj_value, convergence] = bfgsmin("objective2",
> {theta,location,X,y}, control);
> fflush(1);
> t4 = cputime() - t;
> conv = norm(theta-location, 'inf');
> test4 = conv < 1e-5;
> printf("EXAMPLE 4: Ordinary BFGS, using numeric gradient\n");
> if test4
> printf("Success!! :-)\n");
> else
> printf("Failure?! :-(\n");
> endif
> printf("Elapsed time = %f\n\n\n\n",t4);/
>
> *Here is the code for objective funcion*
>
>
> /function [obj_value, gradient] = objective2(theta,location,X,y)
>   m = length(y);
>   x = theta - location + ones(rows(theta),1); # move minimizer to
> "location"
>   [obj_value, gradient] = [((1/(2*m)) * sum(((X * x) - y).^2)),
> ((1/m)*((((X*theta)-y)'*X)'))]
> endfunction/
>
> *I tried executing the same without analytical gradient, but obtained a
> similar error.(Given Below)*
>
> /obj_value =  26.734
> warning: __bfgsmin_obj: objective function could not be evaluated -
> setting
> to DBL_MAX
> warning: called from
>     bfgsmin at line 129 column 35
>     BFGS at line 12 column 30
> obj_value =  26.734
> obj_value =  26.734
> warning: __bfgsmin_obj: objective function could not be evaluated -
> setting
> to DBL_MAX
> warning: called from
>     bfgsmin at line 129 column 35
>     BFGS at line 12 column 30
> error: __numgradient: objective function failed, can't compute numeric
> gradient
> error: called from
>     bfgsmin at line 129 column 35
>     BFGS at line 12 column 30/
>
> The dataset is a textfile(ex1data1.txt) consisting of a 97 * 2 matrix with
> the first row containing *population* and second row containing *profit *.
>
> I took help from  this page
> &lt;https://sourceforge.net/p/octave/optim/ci/03e17f135cbe8a154dd01a341b72f454636f507f/tree/inst/bfgsmin_example.m#l155&gt; 
> for executing the code.
>
> I am unable to debug the code.(Don't know why the objective function
> implementation fails)
>
> Here is the text file  ex1data1.txt
> &lt;http://octave.1599824.n4.nabble.com/file/t372910/ex1data1.txt&gt;  .
>
>
>
>
>
>
>
>
> --
> Sent from:
> http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

Here is the trimmed version of the same problem:

That post was very exhaustive.


*I tried executing 'bfgsmin' to fit a linear curve to a data set, the
following error occured:*


/warning: __bfgsmin_obj: objective function could not be evaluated - setting
to DBL_MAX
error: horizontal dimensions mismatch (1x1 vs 2x1)
/

*I tried executing the same without analytical gradient, but obtained a
similar error.(Given Below)
*

/warning: __bfgsmin_obj: objective function could not be evaluated - setting
to DBL_MAX

warning: __bfgsmin_obj: objective function could not be evaluated - setting
to DBL_MAX
warning: called from
 
error: __numgradient: objective function failed, can't compute numeric
gradient/



*I am unable to debug the code.(Don't know why the objective function
implementation fails)*
.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html