forum.alglib.net

ALGLIB forum
It is currently Thu Jul 25, 2024 1:55 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: alglib parameter estimation
PostPosted: Fri Jul 08, 2011 9:47 am 
Offline

Joined: Fri Jul 08, 2011 12:59 am
Posts: 3
Hi I am new to using alglib, and I want to use the following code, but for my own equation of parameter estimation, therefore I have replaced the function and x and y data points with mine, however I cannot get it to successfully compute.

Please can anyone see my mistake?

Thanks

Alex Walker

Code:
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "interpolation.h"

using namespace alglib;
void function_debt_func(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr)
{
    //
    // this callback calculates f(c,x)=c[0]*(1+c[1]*(pow(x[0]-1999,c[2])-1))
    //
    //func = c[0]*(1+c[1]*(pow(x[0]-1999,c[2])-1));
    func = (1/(c[0]*c[1]))*(c[2]-asinh(sinh(c[2])*exp(c[0]*x[0]*2*pi())));
}

int main(int argc, char **argv)
{

    real_2d_array x = "[1,2,3,4,5]";
    real_1d_array y = "[1.9, 1.7, 1.45, 1.3, 1.2]";
    real_1d_array c = "[1, 1, 1]";
    double epsf = 0;
    double epsx = 1.0e-5;
    real_1d_array bndl = "[-inf, -10, 0.1]";
    real_1d_array bndu = "[+inf, +10, 2.0]";
    real_1d_array s = "[1, 1, 1]";
    ae_int_t maxits = 0;
    ae_int_t info;
    lsfitstate state;
    lsfitreport rep;
    double diffstep = 1.0e-5;

    lsfitcreatef(x, y, c, diffstep, state);
    lsfitsetcond(state, epsf, epsx, maxits);
    lsfitsetbc(state, bndl, bndu);
    lsfitsetscale(state, s);
    alglib::lsfitfit(state, function_debt_func);
    lsfitresults(state, info, c, rep);
    printf("%d\n", int(info)); // EXPECTED: 2
    printf("%s\n", c.tostring(-2).c_str()); // EXPECTED: [4.142560E+12, 0.434240, 0.565376]
    return 0;
}


My function is the line func = ...


Top
 Profile  
 
 Post subject: Re: alglib parameter estimation
PostPosted: Fri Jul 08, 2011 1:45 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 921
First error I saw is that you initialize 2D array X with 1-dimensional array [1,2,3,4,5]. It should be [[1],[2],[3],[4],[5]].

Maybe there are other errors, but right now I can't test your code. Try to fix it and compile one more time


Top
 Profile  
 
 Post subject: Re: alglib parameter estimation
PostPosted: Sat Jul 09, 2011 6:14 pm 
Offline

Joined: Fri Jul 08, 2011 12:59 am
Posts: 3
Thanks that did actually get it to compute.
Please can you just help me understand a couple of lines, because I have no real way of checking whether the parameters it estimates are correct, this line:

real_1d_array s = "[1, 1, 1]";

i think scales the starting value of the parameter estimations, is this correct? How do you decide on the scaling factor?


Top
 Profile  
 
 Post subject: Re: alglib parameter estimation
PostPosted: Sat Jul 09, 2011 7:04 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 921
Yes, these coefficients are scaling factors. You can read http://www.alglib.net/optimization/scaling.php which briefly discusses this question. If you still has questions (for example, what will be correct scales for your problem), feel free to ask them.


Top
 Profile  
 
 Post subject: Re: alglib parameter estimation
PostPosted: Sun Jul 10, 2011 12:32 am 
Offline

Joined: Fri Jul 08, 2011 12:59 am
Posts: 3
I think it is solving correcly for the data I am giving it now, thank you. This is part of a bigger 'thing' I am trying to understand, I wandered whether you maybe able to shed some light on it. I am trying to learn parameter estimation, but cant follow through this paper:
I have attached an image of part of a freely available paper I was reading. It shows the equations for least squares minimization of some equations based on empirical data.

I am not completely confident I understand the required steps, and therefore just wanted to talk it through with others, see what you say and see if it sparks any ideas to solve these.

As I understand it, the first equation (eqn 40) is minimizes using levenberg marquardt for a, b and c0. k is 1,2,3,4..... t_k is times stored, the rest of the equation is trying to model the time it will take (whatever that time may be).

Ok so using levenberg marquardt estimate a, b and c0.
But the the next equation (eqn 41) says that he freezes beta to be ab^2, and uses golden section method to 'refine' a and b?

Did the leveneberg marquardt not do a good enough job because I thought we found and ab that way?

the author also give the sub equations for c0. Why? I thought we estimated c0?

Ok so however it has been done, we have a good estimate for a, b and c0.
Eqn 42. Same thing again except now for nu, phi, omega^2.

How is it explaining to solve this?
"robus linear estimation"? "Directly minimizing"? Is that how? Why cant we use levenberg marquardt again?

I just would like discussion, Im not after just the answer, I would like to understand when to use what, and why...

Thanks guys

By the way, that is the whole chapter I havent left anything out except the chapter title


Attachments:
parameter estimation.JPG
parameter estimation.JPG [ 109.49 KiB | Viewed 4274 times ]
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group