![]() ![]() Additionally, the result is dependent on the penalty function. ![]() Note that it is using a term pen to penalize the violation of the derivative check, thus the result is not a true least square error solution. The idea: convert the problem to an unconstrained optimization by using a penalty term. Below is a solution to alleviate this problem. The issue pointed out in the comments is due to that the derivative checks are enforced only in the data points. Legend('data', 'lsq-pseudo-inv', 'lsq-polyfit', 'lsq-constrained', 'Location', 'southoutside')įor the specified input the fitted curves:Īctually this code is more general than what you requested, since the degree of polynomial can be changed as well.ĮDIT: enforce derivative constrain in additional points % limit on derivative - in each data point % Following lsqlin's notationsĭ = rand(n_data,1) + linspace(0,1,n_data).' Two coefficient matrices are needed, one ( C) for least square error calculation and one ( A) for derivatives in the data points. The derivative constrain is enforced in each data point, this could be easily modified if needed. ![]() Is lsqcurvefit best? How can I use it to produce a best fitting monotonic curve? Would a random number be enough for a "start guess". I must have a monotonic curve but I'm not sure how to do it, even with all of this information. X^3 %derivative f(x), probability density f(x)>=0 %Erfi(x)=erf(i*x) (look mathematica) but the function %looks much like But it isĪ nice analytic expression to give as a semi-empirical formula in a Lsqcurvefit but it require a start guess on the parameters. Also, I think in my case I need a curve so I should use lsqcurvefit but I don't know how to constrain it to produce monotonic curves.įurther research turned up this post recommending lsqcurvefit but I can't figure out how to use the important part: I don't know how to constrain the first derivative to be non-negative as he said. I'm coming from a programming rather than math background so this is a little beyond me. Constrain the first derivative to be non-negative at both I did some research and found a possible solution in this post: The polyfit for data in this dataset was non-monotonic. I originally had been polyfitting my results and this had been working great until I found a particular dataset. the curve can only go upward or stay flat. The curve must be monotonic (never decreasing in value) i.e. I have a set of points I want to fit a curve to. Edit: Some time after I asked this question, an R package called MonoPoly (available here) came out that does exactly what I want. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |