lphy.base.function.GeneralLinearFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lphy-base Show documentation
Show all versions of lphy-base Show documentation
The standard library of LPhy, which contains the required generative distributions and basic functions.
The newest version!
package lphy.base.function;
import lphy.core.model.DeterministicFunction;
import lphy.core.model.Value;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.model.annotation.ParameterInfo;
import lphy.core.model.datatype.DoubleValue;
public class GeneralLinearFunction extends DeterministicFunction {
public static final String betaParamName = "beta";
public static final String xParamName = "x";
public GeneralLinearFunction(@ParameterInfo(name = betaParamName, description = "the coefficients of the explanatory variable x.") Value b,
@ParameterInfo(name = xParamName, description = "the explanatory variable x.") Value x) {
setParam(betaParamName, b);
setParam(xParamName, x);
}
@GeneratorInfo(name = "generalLinearFunction", description = "The general linear function: y = \\sum_i b_i*x_i")
public Value apply() {
Value b = getParams().get(betaParamName);
Value x = getParams().get(xParamName);
double y = 0.0;
for (int i = 0; i < b.value().length; i++) {
y += b.value()[i] * x.value()[i];
}
return new DoubleValue(y, this);
}
}