Class ConditionalGaussianScore

java.lang.Object
edu.cmu.tetrad.search.score.ConditionalGaussianScore
All Implemented Interfaces:
Score, EffectiveSampleSizeSettable

public class ConditionalGaussianScore extends Object implements Score, EffectiveSampleSizeSettable
Implements a conditional Gaussian BIC score for FGS, which calculates a BIC score for mixed discrete/Gaussian data using the conditional Gaussian likelihood function.

Reference: Andrews, B., Ramsey, J., & Cooper, G. F. (2018). Scoring Bayesian networks of mixed variables. International Journal of Data Science and Analytics, 6, 3–18.

As for all scores in Tetrad, higher scores mean more dependence, and negative scores indicate independence.

Effective sample size (added 2026-8-25). Rows that are serially dependent, clustered, or interpolated carry less evidence than independent rows. When an effective sample size nEff is set (see setEffectiveSampleSize(int)), the local score is computed as if the data consisted of nEff independent rows: the log-likelihood, which is a sum over rows, is scaled by r = nEff / N, where N is the number of rows in the dataset, and the BIC penalty uses r times the number of rows actually scored. Under testwise deletion the rows actually scored may be fewer than N; the ratio, not the absolute count, is what is preserved, so a family scored on m complete rows behaves as if it had r * m independent rows. With nEff unset (or negative) r = 1 and the score is unchanged from the previous implementation. Cell-size gates in the likelihood (minSampleSizePerCell) are estimability checks on the raw rows and are not affected.

Version:
$Id: $Id
Author:
josephramsey
See Also:
  • Constructor Details

    • ConditionalGaussianScore

      public ConditionalGaussianScore(DataSet dataSet, double penaltyDiscount, boolean discretize)
      Constructs the score.
      Parameters:
      dataSet - mixed (or all-continuous / all-discrete) dataset
      penaltyDiscount - BIC penalty multiplier
      discretize - if true, use shadow discretization of continuous parents for discrete children
    • ConditionalGaussianScore

      public ConditionalGaussianScore(DataSet dataSet, double penaltyDiscount, boolean discretize, MissingDataSpec spec)
      Constructs the score from a dataset with an explicit missing-data specification. If the spec is null and the dataset contains missing values, TESTWISE deletion is used (this score's historical behavior) and a warning is logged; see MissingDataUtils.resolveOrWarn.
      Parameters:
      dataSet - mixed (or all-continuous / all-discrete) dataset
      penaltyDiscount - BIC penalty multiplier
      discretize - if true, use shadow discretization of continuous parents for discrete children
      spec - The missing-data specification, or null for the legacy default.
      Throws:
      IllegalArgumentException - If the policy is FAIL and the dataset has missing values, or if the policy is EM_COVARIANCE (all-continuous data only).
      UnsupportedOperationException - If the policy is MULTIPLE_IMPUTATION (handled by a search wrapper, not by a single score; see Phase 3).
  • Method Details

    • localScore

      public double localScore(int i, int... parents)
      Local BIC score for child i with parents.
      Specified by:
      localScore in interface Score
      Parameters:
      i - child index
      parents - parent indices
      Returns:
      local BIC score for child i with parents
    • localScoreDiff

      public double localScoreDiff(int x, int y, int[] z)
      Score difference localScore(y | z ∪ {x}) - localScore(y | z).
      Specified by:
      localScoreDiff in interface Score
      Parameters:
      x - index of the variable to add to the parents
      y - index of the child variable
      z - array of parent indices
      Returns:
      score difference
    • getSampleSize

      public int getSampleSize()
      Sample size.
      Specified by:
      getSampleSize in interface Score
      Returns:
      sample size
    • isEffectEdge

      public boolean isEffectEdge(double bump)
      FGES “effect edge” convention for this score bump.
      Specified by:
      isEffectEdge in interface Score
      Parameters:
      bump - score bump
      Returns:
      true if the score bump is positive, false otherwise
    • getVariables

      public List<Node> getVariables()
      Returns the list of variables.
      Specified by:
      getVariables in interface Score
      Returns:
      list of variables
    • getMaxDegree

      public int getMaxDegree()
      Recommended max degree (same heuristic used elsewhere).
      Specified by:
      getMaxDegree in interface Score
      Returns:
      the max degree.
    • getPenaltyDiscount

      public double getPenaltyDiscount()
      Retrieves the penalty discount value used in the scoring calculations.
      Returns:
      the penalty discount value as a double.
    • setPenaltyDiscount

      public void setPenaltyDiscount(double penaltyDiscount)
      Updates the penalty discount value used in the scoring calculations.
      Parameters:
      penaltyDiscount - the new penalty discount value as a double
    • setNumCategoriesToDiscretize

      public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize)
      Sets the number of categories to be used for discretizing child variables in order to avoid integration.
      Parameters:
      numCategoriesToDiscretize - the number of categories to discretize child variables
    • setDiscretize

      public void setDiscretize(boolean discretize)
      Sets whether to discretize child variables for shadow discretization. This affects scoring during the learning process to optimize calculations involving mixed data types.
      Parameters:
      discretize - A boolean value indicating whether to enable discretization. If true, enables discretization.
    • setMinSampleSizePerCell

      public void setMinSampleSizePerCell(int n)
      Sets the minimum sample size per cell for scoring calculations during the learning process.
      Parameters:
      n - The minimum number of samples required per cell to guarantee stable computations.
    • setStructurePrior

      public void setStructurePrior(double structurePrior)
      Sets the structure prior value for the scoring process.
      Parameters:
      structurePrior - The value of the structure prior to be used in scoring calculations.
    • getEffectiveSampleSize

      public int getEffectiveSampleSize()
      Returns the effective sample size: the value set via setEffectiveSampleSize(int), or the number of rows in the dataset if none has been set.
      Specified by:
      getEffectiveSampleSize in interface EffectiveSampleSizeSettable
      Returns:
      the effective sample size
    • setEffectiveSampleSize

      public void setEffectiveSampleSize(int nEff)
      Sets the effective sample size, or -1 (any negative value) to use the actual number of rows. A value of 0 is treated as unset, since a zero effective sample size is meaningless. The value is interpreted relative to the full dataset; see the class Javadoc for how it interacts with testwise deletion.

      Configuration mutator: do not call concurrently with running searches.

      Specified by:
      setEffectiveSampleSize in interface EffectiveSampleSizeSettable
      Parameters:
      nEff - the effective sample size, or a nonpositive value to use the actual number of rows
    • toString

      public String toString()
      Returns a string representation of the Conditional Gaussian Score Penalty. The representation includes the penalty discount formatted to two decimal places.
      Specified by:
      toString in interface Score
      Overrides:
      toString in class Object
      Returns:
      a string describing the Conditional Gaussian Score Penalty and its penalty discount value.
    • getMissingValueSupport

      public MissingValueSupport getMissingValueSupport()
      Declares this score's native missing-value support: test-wise deletion.
      Specified by:
      getMissingValueSupport in interface Score
      Returns:
      This support level.