Package edu.cmu.tetrad.sem
Class GeneralizedSemPm
java.lang.Object
edu.cmu.tetrad.sem.GeneralizedSemPm
- All Implemented Interfaces:
Pm
,TetradSerializable
,Serializable
Parametric model for a Generalized SEM model. This contains all the equations of the model with parameters
represented symbolically (i.e., no values for parameters).
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGeneralizedSemPm
(Graph graph) Constructs a BayesPm from the given Graph, which must be convertible first into a ProtoSemGraph and then into a SemGraph.GeneralizedSemPm
(SemGraph graph) Constructs a new SemPm from the given SemGraph.GeneralizedSemPm
(GeneralizedSemPm semPm) Initializes a new instance of the GeneralizedSemPm class by copying the properties of the provided GeneralizedSemPm object.GeneralizedSemPm
(SemPm semPm) Constructs a new GeneralizedSemPm object based on the given SemPm object. -
Method Summary
Modifier and TypeMethodDescriptiongetErrorNode
(Node node) Retrieves the error node associated with the given node.Returns the list of exogenous variableNodes.Returns the error template string.getGraph()
Returns the structural model graph this SEM PM is using.Returns a list of measured nodes.Returns the Node with the given name.getNodeExpression
(Node node) getNodeExpression.getNodeExpressionString
(Node node) getNodeExpressionString.getNodes()
Retrieves a list of nodes.Retrieves the initialization expression for a given parameter used in parameter estimation.Returns the initialization expression string for the given parameter.getParameterExpression
(String parameter) Retrieves the expression associated with the given parameter.getParameterExpressionString
(String parameter) Returns the expression string associated with the given parameter.Retrieves the names of the parameters required for a certain operation.Retrieves the set of parameters.Retrieves the parameter estimation initialization template.Retrieves the template for the parameters.getParents
(Node node) Retrieves the list of parent nodes for the given node.getReferencedNodes
(Node node) Retrieves a set of referenced nodes for the given node.getReferencedParameters
(Node node) Retrieves the set of referenced parameters from a given node.getReferencingNodes
(Node node) Retrieves the set of referencing nodes for a given node.getReferencingNodes
(String parameter) Returns a set of nodes that reference the given parameter.Retrieves the initialization template for parameter estimation based on the provided starting string.getStartsWithParameterTemplate
(String startsWith) getStartsWithParameterTemplate.Returns the list of variable nodes--that is, node that is not error nodes.Retrieves the variable template.nextParameterName
(String base) Given base b (a String), returns the first name in the sequence "b1", "b2", "b3", etc., which is not already the name of a node in the workbench.static GeneralizedSemPm
Generates a simple exemplar of this class to test serialization.void
setErrorsTemplate
(String errorsTemplate) Sets the error template for the software.void
setNodeExpression
(Node node, String expressionString) Sets the expression for a given node.void
setParameterEstimationInitializationExpression
(String parameter, String expressionString) Sets the parameter estimation initialization expression for the given parameter.void
setParameterEstimationInitializationExpression
(String startsWith, String parameter, String expressionString) Sets the expression which should be evaluated when calculating new values for the given parameter.void
setParameterExpression
(String parameter, String expressionString) Sets the expression which should be evaluated when calculating new values for the given parameter.void
setParameterExpression
(String startsWith, String parameter, String expressionString) Sets the expression which should be evaluated when calculating new values for the given parameter.void
setParametersEstimationInitializationTemplate
(String parametersTemplate) Sets the template for parameter estimation initialization.void
setParametersTemplate
(String parametersTemplate) Sets the parameter template for the object.void
setStartsWithParametersEstimationInitializationTemplate
(String startsWith, String parametersEstimationInitializationTemplate) Sets the parameter estimation initialization template for a given startsWith string.void
setStartsWithParametersTemplate
(String startsWith, String parametersTemplate) Sets the parameter template for expressions that start with the specified string.void
setVariablesTemplate
(String variablesTemplate) Sets the variable template.startsWithPrefixes.toString()
Returns a relatively brief String representation of this SEM PM--the equations and distributions of the model.
-
Constructor Details
-
GeneralizedSemPm
Constructs a BayesPm from the given Graph, which must be convertible first into a ProtoSemGraph and then into a SemGraph.- Parameters:
graph
- aGraph
object
-
GeneralizedSemPm
Constructs a new SemPm from the given SemGraph.- Parameters:
graph
- aSemGraph
object
-
GeneralizedSemPm
Constructs a new GeneralizedSemPm object based on the given SemPm object.- Parameters:
semPm
- the SemPm object used to construct the GeneralizedSemPm- Throws:
IllegalStateException
- if there is a parse error in constructing the initial model
-
GeneralizedSemPm
Initializes a new instance of the GeneralizedSemPm class by copying the properties of the provided GeneralizedSemPm object.- Parameters:
semPm
- The GeneralizedSemPm object to copy.
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
GeneralizedSemPm
object
-
getParameterNames
Retrieves the names of the parameters required for a certain operation.- Returns:
- a list containing the names of the parameters
-
getNodeExpression
getNodeExpression.
- Parameters:
node
- aNode
object- Returns:
- a
Expression
object
-
getNodeExpressionString
getNodeExpressionString.
-
setNodeExpression
Sets the expression for a given node.- Parameters:
node
- the node for which to set the expressionexpressionString
- the expression string to set- Throws:
ParseException
- if the expression string cannot be parsedNullPointerException
- if node is null or expressionString is null
-
setParameterExpression
Sets the expression which should be evaluated when calculating new values for the given parameter. These values are used to initialize the freeParameters.- Parameters:
parameter
- The parameter whose initial value needs to be computed.expressionString
- The formula for picking initial values.- Throws:
ParseException
- If the formula cannot be parsed or contains variable names.
-
setParameterEstimationInitializationExpression
public void setParameterEstimationInitializationExpression(String parameter, String expressionString) throws ParseException Sets the parameter estimation initialization expression for the given parameter.- Parameters:
parameter
- The parameter to set the initialization expression for.expressionString
- The expression string to be parsed and stored.- Throws:
NullPointerException
- If either parameter or expressionString is null.ParseException
- If the expressionString is not valid and cannot be parsed.IllegalArgumentException
- If the expressionString contains parameters.
-
setParameterExpression
public void setParameterExpression(String startsWith, String parameter, String expressionString) throws ParseException Sets the expression which should be evaluated when calculating new values for the given parameter. These values are used to initialize the freeParameters.- Parameters:
parameter
- The parameter whose initial value needs to be computed.expressionString
- The formula for picking initial values.startsWith
- aString
object- Throws:
ParseException
- If the formula cannot be parsed or contains variable names.
-
setParameterEstimationInitializationExpression
public void setParameterEstimationInitializationExpression(String startsWith, String parameter, String expressionString) throws ParseException Sets the expression which should be evaluated when calculating new values for the given parameter. These values are used to initialize the freeParameters.- Parameters:
parameter
- The parameter whose initial value needs to be computed.expressionString
- The formula for picking initial values.startsWith
- aString
object- Throws:
ParseException
- If the formula cannot be parsed or contains variable names.
-
getParameters
Retrieves the set of parameters.- Returns:
- a Set of String representing the parameters.
-
getParameterExpression
Retrieves the expression associated with the given parameter.- Parameters:
parameter
- the name of the parameter- Returns:
- the expression associated with the given parameter, or null if not found
-
getParameterEstimationInitializationExpression
Retrieves the initialization expression for a given parameter used in parameter estimation.- Parameters:
parameter
- the parameter for which to retrieve the initialization expression- Returns:
- the initialization expression for the specified parameter, or null if not found
-
getParameterExpressionString
Returns the expression string associated with the given parameter.- Parameters:
parameter
- the parameter name- Returns:
- the expression string associated with the parameter
-
getParameterEstimationInitializationExpressionString
Returns the initialization expression string for the given parameter.- Parameters:
parameter
- the parameter for which the initialization expression string is needed- Returns:
- the initialization expression string for the given parameter, or null if not found
-
getGraph
Returns the structural model graph this SEM PM is using.- Returns:
- a
SemGraph
object
-
getNodes
Retrieves a list of nodes.- Returns:
- A list of nodes.
-
getVariableNodes
Returns the list of variable nodes--that is, node that is not error nodes.- Returns:
- a
List
object
-
getMeasuredNodes
Returns a list of measured nodes.- Returns:
- a list of measured nodes.
-
getErrorNodes
Returns the list of exogenous variableNodes.- Returns:
- a
List
object
-
getErrorNode
Retrieves the error node associated with the given node.- Parameters:
node
- The node to check for error association.- Returns:
- The error node associated with the given node, or null if no error node is found.
-
getNode
Returns the Node with the given name.- Parameters:
name
- the name of the Node to retrieve- Returns:
- the Node with the given name, or null if no Node exists with the specified name
-
getReferencingNodes
Returns a set of nodes that reference the given parameter.- Parameters:
parameter
- the parameter to search for referencing nodes- Returns:
- a set of nodes that reference the given parameter, or an empty set if no nodes are found
-
getReferencedParameters
Retrieves the set of referenced parameters from a given node.- Parameters:
node
- The node for which to retrieve referenced parameters.- Returns:
- The set of referenced parameters found in the given node.
-
getReferencingNodes
Retrieves the set of referencing nodes for a given node.- Parameters:
node
- the node for which to retrieve the referencing nodes- Returns:
- a set of referencing nodes
-
getReferencedNodes
Retrieves a set of referenced nodes for the given node.- Parameters:
node
- the node for which to retrieve the referenced nodes- Returns:
- a set of referenced nodes
-
nextParameterName
Given base b (a String), returns the first name in the sequence "b1", "b2", "b3", etc., which is not already the name of a node in the workbench.- Parameters:
base
- the base string.- Returns:
- the first string in the sequence not already being used.
-
getParents
Retrieves the list of parent nodes for the given node.- Parameters:
node
- the specified node- Returns:
- the list of parent nodes
-
toString
Returns a relatively brief String representation of this SEM PM--the equations and distributions of the model. Initial value distributions for freeParameters are not printed. -
getVariablesTemplate
Retrieves the variable template.- Returns:
- the variable template
-
setVariablesTemplate
Sets the variable template.- Parameters:
variablesTemplate
- the template for variables- Throws:
ParseException
- if the variable template fails to parseNullPointerException
- if the variable template is null
-
getErrorsTemplate
Returns the error template string.- Returns:
- the error template string
-
setErrorsTemplate
Sets the error template for the software.- Parameters:
errorsTemplate
- the string representation of the error template- Throws:
ParseException
- if the error template cannot be parsed successfullyNullPointerException
- if the errorsTemplate parameter is null
-
getParametersTemplate
Retrieves the template for the parameters.- Returns:
- The template for the parameters.
-
setParametersTemplate
Sets the parameter template for the object.- Parameters:
parametersTemplate
- the template string representing the parameters- Throws:
ParseException
- if the given parameters template is not validNullPointerException
- if the parameter template is nullIllegalArgumentException
- if the parameter template contains parameters- See Also:
-
getParametersEstimationInitializationTemplate
Retrieves the parameter estimation initialization template.- Returns:
- The parameter estimation initialization template as a
String
.
-
setParametersEstimationInitializationTemplate
public void setParametersEstimationInitializationTemplate(String parametersTemplate) throws ParseException Sets the template for parameter estimation initialization.- Parameters:
parametersTemplate
- the template string for parameter estimation initialization- Throws:
ParseException
- if the provided parameters template is not parseableNullPointerException
- if the provided parameters template is null
-
setStartsWithParametersTemplate
public void setStartsWithParametersTemplate(String startsWith, String parametersTemplate) throws ParseException Sets the parameter template for expressions that start with the specified string. If the startsWith parameter is null or empty, the method does nothing. If the parametersTemplate parameter is null, a NullPointerException is thrown. The method parses the parametersTemplate to ensure it is a valid expression. If the startsWith string contains spaces, an IllegalArgumentException is thrown.- Parameters:
startsWith
- The starting string for the expressions.parametersTemplate
- The template for the parameters of the expressions.- Throws:
ParseException
- If the parametersTemplate is not a valid expression.NullPointerException
- If the parametersTemplate is null.IllegalArgumentException
- If the startsWith string contains spaces.
-
setStartsWithParametersEstimationInitializationTemplate
public void setStartsWithParametersEstimationInitializationTemplate(String startsWith, String parametersEstimationInitializationTemplate) throws ParseException Sets the parameter estimation initialization template for a given startsWith string.- Parameters:
startsWith
- the string that the template should start withparametersEstimationInitializationTemplate
- the template for initializing the parameter estimation- Throws:
ParseException
- if the template is unable to be parsedNullPointerException
- if the parametersTemplate is nullIllegalArgumentException
- if the startsWith string contains spaces
-
getStartsWithParameterTemplate
getStartsWithParameterTemplate.
-
getStartsWithParameterEstimationInitializationTemplate
Retrieves the initialization template for parameter estimation based on the provided starting string.- Parameters:
startsWith
- The starting string used to find the initialization template.- Returns:
- The initialization template corresponding to the starting string.
-
startsWithPrefixes
startsWithPrefixes.
- Returns:
- a
Set
object
-