Class GeneralAdditiveModel

java.lang.Object
edu.cmu.tetrad.sem.GeneralAdditiveModel

public final class GeneralAdditiveModel extends Object

GeneralAdditiveModel

Simulates a genuine generalized additive structural equation model of the form

    X_j = sum_{k in Pa(j)} f_{jk}(X_k) + e_j

where each f_{jk} is a separate randomly initialized univariate neural network (a 1-input MLP), and e_j is an independent noise term drawn from the supplied Sampler.

Root nodes are generated as pure noise. For non-root nodes, each parent contributes through its own random subnet, preserving additivity across parent effects.

NOTE: When input standardization is enabled (the default), each parent column is z-scored using the realized sample's mean and standard deviation before entering its subnet. This couples rows within a dataset: strictly, the effective structural functions depend (weakly, and vanishingly as the sample size grows) on the sampled data, so the simulator is not "SCM-pure." Disable standardization via setInputStandardize(boolean) if this matters.

This class is intended to align with the ANM/GNM simulators while preserving the defining additive structure of a GAM.

  • Constructor Details

    • GeneralAdditiveModel

      public GeneralAdditiveModel(Graph graph, int numSamples, Sampler sampler)
      Constructs a new generalized additive model simulator.
      Parameters:
      graph - DAG over which data are simulated.
      numSamples - Number of rows to simulate.
      sampler - Noise sampler used for the additive errors.
  • Method Details

    • setHiddenDimensions

      public GeneralAdditiveModel setHiddenDimensions(int... hiddenDimensions)
      Sets the hidden dimensions for the model. Hidden dimensions represent the sizes of the hidden layers used within the model. All dimensions must be greater than or equal to 1.
      Parameters:
      hiddenDimensions - the sizes of the hidden layers of the model, each must be >= 1
      Returns:
      the updated GeneralAdditiveModel instance with the specified hidden dimensions
      Throws:
      NullPointerException - if the hiddenDimensions array is null
      IllegalArgumentException - if any dimension in hiddenDimensions is less than 1
    • setInputScale

      public GeneralAdditiveModel setInputScale(double inputScale)
      Sets the input scale for the model. The input scale must be a finite, positive value.
      Parameters:
      inputScale - the scaling factor to be applied to the input data, must be finite and greater than 0
      Returns:
      the updated GeneralAdditiveModel instance with the specified input scale
      Throws:
      IllegalArgumentException - if the input scale is not finite or less than or equal to 0
    • setInputStandardize

      public GeneralAdditiveModel setInputStandardize(boolean inputStandardize)
      Sets whether the input data should be standardized for the model. Standardizing inputs typically involves scaling them to have a mean of zero and a standard deviation of one, which can improve model performance and stability in certain cases. See the class javadoc for the row-coupling caveat this introduces.
      Parameters:
      inputStandardize - a boolean indicating whether input standardization should be applied (true for standardization, false otherwise)
      Returns:
      the updated GeneralAdditiveModel instance with the specified input standardization behavior
    • setActivationFunction

      public GeneralAdditiveModel setActivationFunction(Function<Double,Double> activationFunction)
      Sets the activation function for the generalized additive model. The activation function transforms data through a specified mapping, typically used within neural networks or simulation frameworks. If the specified activation function is exactly the hyperbolic tangent function, an optimization flag is set to use a faster implementation.
      Parameters:
      activationFunction - the function to be used as the activation function, must be non-null
      Returns:
      the updated GeneralAdditiveModel instance with the specified activation function
      Throws:
      NullPointerException - if the activationFunction is null
    • generate

      public DataSet generate()
      Generates a simulated dataset according to the structure of the graph and the specified parameters of the General Additive Model. The dataset is created by sampling noise, combining contributions from parent nodes in the graph using subnet evaluations, and optionally applying input standardization and activation functions.

      Note: the returned dataset's columns are in topological order, not graph.getNodes() order.

      Returns:
      a DataSet object containing the simulated data and associated graph node ordering