Fitting a function: constraining a parameter to be 0 or 1?

3 views (last 30 days)
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.

Answers (1)

Matt J
Matt J on 12 Dec 2014
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!