Question

I have a set of data points pair (y,x). I want to fit a function using the form

y = c * x * log2(x)

I want to find the value of c. Matlab lsqcurvefit is not working for this. It seems to be stuck in local optima.

Any suggestions on how to do it?

Thanks!

Was it helpful?

Solution

As cdbitesky wrote, the simplest way to estimate c is to compute pointwise ratios and take the mean:

c_est = mean(y ./ (x .* log2(x)));

Another would be to use Matlab's matrix division, which performs a least squares fit:

c_est = y / (x .* log2(x));

The optimal way to estimate c can only be derived if you have an idea how (if at all) your data deviate from the ideal equation y = c * x * log2(x). Are your data corrupted by additive noise or multiplicative? Where does this noise come from? etc.

OTHER TIPS

Using some weights w[k], compute the sums

yxlx over w[k]*y[k]*x[k]*log2(x[k]) and

xlx2 over w[k]*sqr(x[k]*log2(x[k])), where sqr(u)=u*u.

Then the estimate for c is yxlx/xlx2.

One can chose the standard weights w[k]=1 or adapting weights

w[k]=1/( 1+sqr( x[k]*log2(x[k]) ) )

or even more adapting

w[k]=1/( 1+sqr( x[k]*log2(x[k]) ) +sqr( y[k] ) ) 

so that large values for x,y do not excessively influence the estimate. For some middle strategy take the square root of those expressions as weights.


Mathematics: These formulas result from the formulation of the estimation problem as a weighted least square problem

sum[ w(x,y)*(y-c*f(x))^2 ]        over (x,y) in Data 

which expands as

sum[ w(x,y)*y^2 ] 
     -2*c* sum[ w(x,y)*y*f(x) ] 
          + c^2 * sum[ w(x,y)*f(x)^2 ]      over (x,y) in Data 

where the minimum is located at

c = sum[ w(x,y)*y*f(x) ] / sum[ w(x,y)*f(x)^2 ]

w(x,y) should be approximately inverse to the variance of the error at (x,y), so if you expect a uniform size of the error, then w(x,y)=1, if the error grows proportional to x and y, then w(x,y)=1/(1+x^2+y^2) or similar is a sensible choice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top