Class LinearFunctionND

java.lang.Object
edu.cmu.tetrad.search.utils.LinearFunctionND

public class LinearFunctionND extends Object
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

    Constructors
    Constructor
    Description
    LinearFunctionND(int inputDim, double coefLow, double coefHigh, boolean coefSymmetric, long seed)
    Constructor to create a linear function.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    evaluate(double[] x)
    Evaluates the linear function for a given input vector.
    double
    evaluateAdjusted(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.
    double
    Returns the intercept of the linear function.
    static void
    main(String[] args)
    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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static void main(String[] args)
      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.