Class GeneralizedSemPm

java.lang.Object
edu.cmu.tetrad.sem.GeneralizedSemPm
All Implemented Interfaces:
Pm, TetradSerializable, Serializable

public final class GeneralizedSemPm extends Object implements Pm, TetradSerializable
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 Details

    • GeneralizedSemPm

      public GeneralizedSemPm(Graph graph)
      Constructs a BayesPm from the given Graph, which must be convertible first into a ProtoSemGraph and then into a SemGraph.
      Parameters:
      graph - a Graph object
    • GeneralizedSemPm

      public GeneralizedSemPm(SemGraph graph)
      Constructs a new SemPm from the given SemGraph.
      Parameters:
      graph - a SemGraph object
    • GeneralizedSemPm

      public GeneralizedSemPm(SemPm semPm)
      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

      public GeneralizedSemPm(GeneralizedSemPm semPm)
      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

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

      public static List<String> getParameterNames()
      Retrieves the names of the parameters required for a certain operation.
      Returns:
      a list containing the names of the parameters
    • getNodeExpression

      public Expression getNodeExpression(Node node)

      getNodeExpression.

      Parameters:
      node - a Node object
      Returns:
      a Expression object
    • getNodeExpressionString

      public String getNodeExpressionString(Node node)

      getNodeExpressionString.

      Parameters:
      node - a Node object
      Returns:
      a String object
    • setNodeExpression

      public void setNodeExpression(Node node, String expressionString) throws ParseException
      Sets the expression for a given node.
      Parameters:
      node - the node for which to set the expression
      expressionString - the expression string to set
      Throws:
      ParseException - if the expression string cannot be parsed
      NullPointerException - if node is null or expressionString is null
    • setParameterExpression

      public void setParameterExpression(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.
      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 - a String 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 - a String object
      Throws:
      ParseException - If the formula cannot be parsed or contains variable names.
    • getParameters

      public Set<String> getParameters()
      Retrieves the set of parameters.
      Returns:
      a Set of String representing the parameters.
    • getParameterExpression

      public Expression getParameterExpression(String parameter)
      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

      public Expression getParameterEstimationInitializationExpression(String parameter)
      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

      public String getParameterExpressionString(String parameter)
      Returns the expression string associated with the given parameter.
      Parameters:
      parameter - the parameter name
      Returns:
      the expression string associated with the parameter
    • getParameterEstimationInitializationExpressionString

      public String getParameterEstimationInitializationExpressionString(String parameter)
      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

      public SemGraph getGraph()
      Returns the structural model graph this SEM PM is using.
      Returns:
      a SemGraph object
    • getNodes

      public List<Node> getNodes()
      Retrieves a list of nodes.
      Returns:
      A list of nodes.
    • getVariableNodes

      public List<Node> getVariableNodes()
      Returns the list of variable nodes--that is, node that is not error nodes.
      Returns:
      a List object
    • getMeasuredNodes

      public List<Node> getMeasuredNodes()
      Returns a list of measured nodes.
      Returns:
      a list of measured nodes.
    • getErrorNodes

      public List<Node> getErrorNodes()
      Returns the list of exogenous variableNodes.
      Returns:
      a List object
    • getErrorNode

      public Node getErrorNode(Node node)
      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

      public Node getNode(String name)
      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

      public Set<Node> getReferencingNodes(String parameter)
      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

      public Set<String> getReferencedParameters(Node node)
      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

      public Set<Node> getReferencingNodes(Node node)
      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

      public Set<Node> getReferencedNodes(Node node)
      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

      public String 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.
      Parameters:
      base - the base string.
      Returns:
      the first string in the sequence not already being used.
    • getParents

      public List<Node> getParents(Node node)
      Retrieves the list of parent nodes for the given node.
      Parameters:
      node - the specified node
      Returns:
      the list of parent nodes
    • toString

      public String 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.
      Overrides:
      toString in class Object
      Returns:
      a String object
    • getVariablesTemplate

      public String getVariablesTemplate()
      Retrieves the variable template.
      Returns:
      the variable template
    • setVariablesTemplate

      public void setVariablesTemplate(String variablesTemplate) throws ParseException
      Sets the variable template.
      Parameters:
      variablesTemplate - the template for variables
      Throws:
      ParseException - if the variable template fails to parse
      NullPointerException - if the variable template is null
    • getErrorsTemplate

      public String getErrorsTemplate()
      Returns the error template string.
      Returns:
      the error template string
    • setErrorsTemplate

      public void setErrorsTemplate(String errorsTemplate) throws ParseException
      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 successfully
      NullPointerException - if the errorsTemplate parameter is null
    • getParametersTemplate

      public String getParametersTemplate()
      Retrieves the template for the parameters.
      Returns:
      The template for the parameters.
    • setParametersTemplate

      public void setParametersTemplate(String parametersTemplate) throws ParseException
      Sets the parameter template for the object.
      Parameters:
      parametersTemplate - the template string representing the parameters
      Throws:
      ParseException - if the given parameters template is not valid
      NullPointerException - if the parameter template is null
      IllegalArgumentException - if the parameter template contains parameters
      See Also:
    • getParametersEstimationInitializationTemplate

      public String 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 parseable
      NullPointerException - 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 with
      parametersEstimationInitializationTemplate - the template for initializing the parameter estimation
      Throws:
      ParseException - if the template is unable to be parsed
      NullPointerException - if the parametersTemplate is null
      IllegalArgumentException - if the startsWith string contains spaces
    • getStartsWithParameterTemplate

      public String getStartsWithParameterTemplate(String startsWith)

      getStartsWithParameterTemplate.

      Parameters:
      startsWith - a String object
      Returns:
      a String object
    • getStartsWithParameterEstimationInitializationTemplate

      public String getStartsWithParameterEstimationInitializationTemplate(String startsWith)
      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

      public Set<String> startsWithPrefixes()

      startsWithPrefixes.

      Returns:
      a Set object