Package edu.cmu.tetrad.search.utils
Class LinearFunctionND
java.lang.Object
edu.cmu.tetrad.search.utils.LinearFunctionND
Represents a linear function in an n-dimensional space (R^n -> R). The function is defined as f(x) = c1*x1 + c2*x2 +
... + cn*xn + intercept, where c1, c2, ..., cn are the coefficients, and intercept is a constant.
-
Constructor Summary
ConstructorsConstructorDescriptionLinearFunctionND(int inputDim, double coefLow, double coefHigh, boolean coefSymmetric, long seed) Constructor to create a linear function. -
Method Summary
Modifier and TypeMethodDescriptiondoubleevaluate(double[] x) Evaluates the linear function for a given input vector.doubleevaluateAdjusted(double[] x) Evaluates the linear function with the given input vector and calculates the resulting adjusted value for intercept == 0.0.double[]Returns the coefficients of the linear function.doubleReturns the intercept of the linear function.static voidThe main method demonstrates the creation of a linear function with specified parameters, prints its coefficients and intercept, and evaluates the function for a set of sample inputs.
-
Constructor Details
-
LinearFunctionND
public LinearFunctionND(int inputDim, double coefLow, double coefHigh, boolean coefSymmetric, long seed) Constructor to create a linear function.- Parameters:
inputDim- Number of input dimensions (R^n).coefLow- Lower bound for the coefficients.coefHigh- Upper bound for the coefficients.coefSymmetric- If true, coefficients may randomly switch sign.seed- Random seed for reproducibility.
-
-
Method Details
-
main
The main method demonstrates the creation of a linear function with specified parameters, prints its coefficients and intercept, and evaluates the function for a set of sample inputs.- Parameters:
args- Command-line arguments (not used in this demonstration).
-
evaluate
public double evaluate(double[] x) Evaluates the linear function for a given input vector.- Parameters:
x- Input vector in R^n.- Returns:
- Output value in R.
-
evaluateAdjusted
public double evaluateAdjusted(double[] x) Evaluates the linear function with the given input vector and calculates the resulting adjusted value for intercept == 0.0.- Parameters:
x- Input vector in R^n, where n is the number of dimensions. The length of this array must match the number of coefficients.- Returns:
- The computed value after evaluating the linear function using the input vector and coefficients.
- Throws:
IllegalArgumentException- If the dimension of the input vector does not match the expected number of coefficients.
-
getCoefficients
public double[] getCoefficients()Returns the coefficients of the linear function.- Returns:
- Array of coefficients.
-
getIntercept
public double getIntercept()Returns the intercept of the linear function.- Returns:
- Intercept value.
-