Package edu.cmu.tetrad.sem
Class GeneralizedSemIm
java.lang.Object
edu.cmu.tetrad.sem.GeneralizedSemIm
- All Implemented Interfaces:
Simulator
,Im
,TetradSerializable
,Serializable
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 Summary
ConstructorsConstructorDescriptionConstructs a new GeneralizedSemIm from the given GeneralizedSemPm by picking values for each of the freeParameters from their initial distributions.GeneralizedSemIm
(GeneralizedSemPm pm, SemIm semIm) Initializes a GeneralizedSemIm object by applying values to free parameters from the given GeneralizedSemPm and SemIm. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the GeneralizedSemPm object associated with this GeneralizedSemIm.getNodeSubstitutedString
(Node node) Retrieves the substituted string representation of a given Node.getNodeSubstitutedString
(Node node, Map<String, Double> substitutedValues) Retrieves the substituted string representation of a given Node.double
getParameterValue
(String parameter) Retrieves the value of a parameter in the model.getSemPm()
getSemPm.static GeneralizedSemIm
Generates a simple exemplar of this class to test serialization.void
setGuaranteeIid
(boolean guaranteeIid) Setter for the fieldguaranteeIid
.void
setParameterValue
(String parameter, double value) setParameterValue.void
setSubstitutions
(Map<String, Double> parameterValues) setSubstitutions.simulateData
(int sampleSize, boolean latentDataSaved) Simulates data based on the given parameters.simulateDataAvoidInfinity
(int sampleSize, boolean latentDataSaved) Simulates data avoiding infinity values.simulateDataFisher
(int sampleSize) Simulates data using the model of R.simulateDataFisher
(int sampleSize, int intervalBetweenShocks, double epsilon) Simulates data using the model of R.simulateDataMinimizeSurface
(int sampleSize, boolean latentDataSaved) Simulates data by minimizing the surface defined by the given sample size and whether latent data is saved.simulateDataNSteps
(int sampleSize, boolean latentDataSaved) Simulates data for a given number of steps.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.simulateOneRecord.toString()
Returns a string representation of the object.
-
Constructor Details
-
GeneralizedSemIm
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
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
Generates a simple exemplar of this class to test serialization.- Returns:
- a
GeneralizedSemIm
object
-
getGeneralizedSemPm
Retrieves the GeneralizedSemPm object associated with this GeneralizedSemIm.- Returns:
- The GeneralizedSemPm object.
-
setParameterValue
setParameterValue.
- Parameters:
parameter
- The parameter whose values are to be set.value
- The double value thatparam
is to be set to.
-
getParameterValue
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
-
getNodeSubstitutedString
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
-
simulateData
Simulates data based on the given parameters.- Specified by:
simulateData
in interfaceSimulator
- 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
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
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
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
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
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
-
simulateDataNSteps
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
-
setSubstitutions
-
setGuaranteeIid
public void setGuaranteeIid(boolean guaranteeIid) Setter for the field
guaranteeIid
.- Parameters:
guaranteeIid
- a boolean
-