Class GeneralizedSemIm

java.lang.Object
edu.cmu.tetrad.sem.GeneralizedSemIm
All Implemented Interfaces:
Simulator, Im, TetradSerializable, Serializable

public class GeneralizedSemIm extends Object implements Im, Simulator
Represents a generalized SEM-instantiated model. The parametric form of this model allows arbitrary equations for variables. This instantiated model gives values for all the parameters of the parameterized model.
Version:
$Id: $Id
Author:
josephramsey
See Also:
  • Constructor Details

    • GeneralizedSemIm

      public GeneralizedSemIm(GeneralizedSemPm pm)
      Constructs a new GeneralizedSemIm from the given GeneralizedSemPm by picking values for each of the freeParameters from their initial distributions.
      Parameters:
      pm - the GeneralizedSemPm. Includes all the equations and distributions of the model.
    • GeneralizedSemIm

      public GeneralizedSemIm(GeneralizedSemPm pm, SemIm semIm)
      Initializes a GeneralizedSemIm object by applying values to free parameters from the given GeneralizedSemPm and SemIm.
      Parameters:
      pm - The GeneralizedSemPm object that contains the equations and distributions of the model.
      semIm - The SemIm object to apply values from.
  • Method Details

    • serializableInstance

      public static GeneralizedSemIm serializableInstance()
      Generates a simple exemplar of this class to test serialization.
      Returns:
      a GeneralizedSemIm object
    • getGeneralizedSemPm

      public GeneralizedSemPm getGeneralizedSemPm()
      Retrieves the GeneralizedSemPm object associated with this GeneralizedSemIm.
      Returns:
      The GeneralizedSemPm object.
    • setParameterValue

      public void setParameterValue(String parameter, double value)

      setParameterValue.

      Parameters:
      parameter - The parameter whose values are to be set.
      value - The double value that param is to be set to.
    • getParameterValue

      public double getParameterValue(String parameter)
      Retrieves the value of a parameter in the model.
      Parameters:
      parameter - The name of the parameter to retrieve.
      Returns:
      The value of the parameter.
      Throws:
      NullPointerException - If the parameter name is null.
      IllegalArgumentException - If the parameter name is not present in the model.
    • getNodeSubstitutedString

      public String getNodeSubstitutedString(Node node)
      Retrieves the substituted string representation of a given Node.
      Parameters:
      node - The Node whose expression is being evaluated.
      Returns:
      The substituted expression string for the Node, or null if the expression is null.
    • getNodeSubstitutedString

      public String getNodeSubstitutedString(Node node, Map<String,Double> substitutedValues)
      Retrieves the substituted string representation of a given Node.
      Parameters:
      node - The Node whose expression is being evaluated.
      substitutedValues - A map of substituted values for parameters.
      Returns:
      The substituted expression string for the Node.
      Throws:
      NullPointerException - if the node or substitutedValues is null.
    • toString

      public String toString()
      Returns a string representation of the object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the object.
    • simulateData

      public DataSet simulateData(int sampleSize, boolean latentDataSaved)
      Simulates data based on the given parameters.
      Specified by:
      simulateData in interface Simulator
      Parameters:
      sampleSize - The number of rows to simulate.
      latentDataSaved - If true, latent variables are saved in the data set.
      Returns:
      A DataSet object representing the simulated data.
    • simulateDataRecursive

      public DataSet simulateDataRecursive(int sampleSize, boolean latentDataSaved)
      This simulates data by picking random values for the exogenous terms and percolating this information down through the SEM, assuming it is acyclic. Fast for large simulations but hangs for cyclic models.
      Parameters:
      sampleSize - > 0.
      latentDataSaved - a boolean
      Returns:
      the simulated data set.
    • simulateDataMinimizeSurface

      public DataSet simulateDataMinimizeSurface(int sampleSize, boolean latentDataSaved)
      Simulates data by minimizing the surface defined by the given sample size and whether latent data is saved.
      Parameters:
      sampleSize - The size of the sample to simulate.
      latentDataSaved - Specifies whether the latent data should be saved.
      Returns:
      The simulated data set.
    • simulateDataAvoidInfinity

      public DataSet simulateDataAvoidInfinity(int sampleSize, boolean latentDataSaved)
      Simulates data avoiding infinity values.
      Parameters:
      sampleSize - The number of data samples to simulate.
      latentDataSaved - Indicates whether the latent (unmeasured) data is saved in the result.
      Returns:
      The simulated data as a DataSet object.
      Throws:
      IllegalArgumentException - if undefined value is encountered during simulation.
      NullPointerException - if error node is null for any variable node.
    • simulateDataFisher

      public DataSet simulateDataFisher(int sampleSize)
      Simulates data using the model of R. A. Fisher, for a linear model. Shocks are applied every so many steps. A data point is recorded before each shock is administered. If convergence happens before that number of steps has been reached, a data point is recorded and a new shock immediately applied. The model may be cyclic. If cyclic, all eigenvalues for the coefficient matrix must be less than 1, though this is not checked. Uses an interval between shocks of 50 and a convergence threshold of 1e-5. Uncorrelated Gaussian shocks are used.
      Parameters:
      sampleSize - The number of samples to be drawn. Must be a positive integer.
      Returns:
      a DataSet object
    • simulateDataFisher

      public DataSet simulateDataFisher(int sampleSize, int intervalBetweenShocks, double epsilon)
      Simulates data using the model of R. A. Fisher, for a linear model. Shocks are applied every so many steps. A data point is recorded before each shock is administered. If convergence happens before that number of steps has been reached, a data point is recorded and a new shock immediately applied. The model may be cyclic. If cyclic, all eigenvalues for the coefficient matrix must be less than 1, though this is not checked.
      Parameters:
      sampleSize - The number of samples to be drawn.
      intervalBetweenShocks - External shock is applied every this many steps. Must be positive integer.
      epsilon - The convergence criterion; |xi.t - xi.t-1| < epsilon.
      Returns:
      a DataSet object
    • simulateOneRecord

      public Vector simulateOneRecord(Vector e)

      simulateOneRecord.

      Parameters:
      e - a Vector object
      Returns:
      a Vector object
    • simulateDataNSteps

      public DataSet simulateDataNSteps(int sampleSize, boolean latentDataSaved)
      Simulates data for a given number of steps.
      Parameters:
      sampleSize - The number of samples to generate.
      latentDataSaved - Flag indicating whether to save latent data.
      Returns:
      The generated dataset.
      Throws:
      NullPointerException - If an error node is null.
      IllegalArgumentException - If an expression evaluates to NaN or is undefined.
    • getSemPm

      public GeneralizedSemPm getSemPm()

      getSemPm.

      Returns:
      a GeneralizedSemPm object
    • setSubstitutions

      public void setSubstitutions(Map<String,Double> parameterValues)

      setSubstitutions.

      Parameters:
      parameterValues - a Map object
    • setGuaranteeIid

      public void setGuaranteeIid(boolean guaranteeIid)

      Setter for the field guaranteeIid.

      Parameters:
      guaranteeIid - a boolean