KevinCoble / AIToolbox

A toolbox of AI modules written in Swift: Graphs/Trees, Support Vector Machines, Neural Networks, PCA, K-Means, Genetic Algorithms
Apache License 2.0
793 stars 87 forks source link

How can I restrict the result vector to be positive using LinearRegression? #18

Closed RealHacker closed 6 years ago

RealHacker commented 7 years ago

Sorry, this is not a bug. I just want to ask a question regarding Linear Regression Model.

I need to solve a linear equation Ax=B, with no bias. But I need to restrict x to be all positive. Is this possible with LinearRegressionModel? Or maybe using LAPACK directly?

Thanks!

KevinCoble commented 6 years ago

Sorry I didn't see this before today.

Restricting x to be positive makes it a constrained optimization problem, rather than a linear regression. Linear regression finds parameters for a hypothesis equation that matches the data closest. You don't want to match the data closest, if the data will give a negative answer. Therefore, constrained optimization is what you are looking for. The AIToolbox library does not have a general constrained optimizer.