Fitting a function: constraining a parameter to be 0 or 1?
2 次查看(过去 30 天)
显示 更早的评论
I have two variables of the same length, e.g. x and y. I want to find the parameters for function f such that y = f(x). Functions like lsqcurvefit let me bound the parameters, but is there any way to constrain a parameter to be an integer?
Specifically I have a parameter that I want to constrain to be either 0 or 1. Is there a way to do this? Any help would be lovely.
0 个评论
回答(1 个)
Matt J
2014-12-12
Probably not applicable to (or too complicated for) this problem, but if f(x) has a linear dependence on the unknowns,
y=p1*f1(x)+p2*f2(x)+...+pn*fn(x)
where p1...pn are the unknown parameters, some of which are integers, then instead of doing a least squares fit, you can do a max-norm fit
min r
subject to
-r<=y-( p1*f1(x)+p2*f2(x)+...+pn*fn(x) )<=r
which is a mixed integer linear program in the variables [r,p1,...,p3] and can be solved with intlinprog . An L1-norm fit can be done in a similar way.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!