Class KernelMarginalLikelihoodScore

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

public final class KernelMarginalLikelihoodScore extends Object implements Score, EffectiveSampleSizeSettable

KML: Kernel Marginal Likelihood score for mixed (continuous + discrete) parents

This is the exact-kernel analogue of FfMl. It extends the exact Gaussian-process marginal-likelihood KML score (see KernelMarginalLikelihoodScoreContinuous) to parent sets containing both continuous and discrete variables, using the same modelling recipe as FFML: a product kernel between a continuous RBF kernel and a categorical kernel.

Product-kernel model

For a parent vector Z = (Z_c, Z_d) with continuous part Z_c and discrete part Z_d, the kernel is

  k((z_c, z_d), (z'_c, z'_d)) = k_cont(z_c, z'_c) · k_cat(z_d, z'_d)
  • k_cont is the exact RBF kernel over the continuous parents (median-heuristic bandwidth), reusing KernelMarginalLikelihoodScoreContinuous.rbfGramContinuous(int[], int[], int). Unlike FFML this uses the full n×n Gram matrix rather than a random-feature approximation, so there is no random basis, no seeding, and no bandwidth grid-search.
  • k_cat is the same positive-semidefinite categorical kernel used by FFML: it returns 1 on a level match and ρ on a mismatch (0 ≤ ρ < 1); over several discrete parents it multiplies, giving ρ^(#mismatches).

The two kernels are combined as a Hadamard (elementwise) product K = K_cont ⊙ K_cat, which is positive semidefinite by the Schur product theorem, and the marginal covariance is C = K + σ² I. The local score is the GP log marginal likelihood -0.5·yᵀC⁻¹y - 0.5·log|C|, matching Tetrad's score convention (additive constants omitted).

Routing

  • Continuous target with no discrete parents (including the no-parent case): delegated directly to KernelMarginalLikelihoodScoreContinuous. This is the "KML calls KML-Continuous for continuous variables only" path and reproduces the original continuous KML behaviour exactly.
  • Continuous target with at least one discrete parent: the exact product kernel is built here and scored as a single-output GP marginal likelihood.
  • Discrete target: handled via a Gaussian multi-output surrogate (identical in spirit to FFML). The target is expanded into centered one-hot columns and each column is scored under the same product kernel; because the kernel is independent of the output column, the n×n covariance is Cholesky-factorized once and reused across all one-hot columns. With no parents this reduces to the closed-form C = σ² I sigma-only case.

Notes

  • The discrete-target score is a Gaussian multi-output surrogate, not a true multinomial likelihood, but (as in FFML) it is effective for structure scoring.
  • When there are continuous parents present alongside discrete parents, the RBF bandwidth is estimated on the continuous parents only, over the rows actually used for scoring.
  • Cost is O(n³) from the single Cholesky factorization (small to moderate n), the same regime as the continuous KML.
See Also:
  • Constructor Details

    • KernelMarginalLikelihoodScore

      public KernelMarginalLikelihoodScore(DataSet dataSet)
      Constructs a mixed KML score for the given dataset. Continuous columns are z-scored (NaNs preserved) and discrete columns are read as integer codes, mirroring FFML. A continuous engine is constructed over the same dataset to handle purely continuous local scores.
      Parameters:
      dataSet - the dataset. Must not be null.
      Throws:
      NullPointerException - if the dataset is null.
  • Method Details

    • localScoreDiff

      public double localScoreDiff(int x, int y, int[] z)
      Description copied from interface: Score
      Returns the score difference of the graph.
      Specified by:
      localScoreDiff in interface Score
      Parameters:
      x - A node.
      y - TAhe node.
      z - A set of nodes.
      Returns:
      The score difference.
    • localScore

      public double localScore(int i, int... parents)
      Description copied from interface: Score
      The score of a node given its parents.
      Specified by:
      localScore in interface Score
      Parameters:
      i - The node.
      parents - The parents.
      Returns:
      The score.
    • getVariables

      public List<Node> getVariables()
      Description copied from interface: Score
      The variables of the score.
      Specified by:
      getVariables in interface Score
      Returns:
      This list.
    • getSampleSize

      public int getSampleSize()
      Description copied from interface: Score
      The sample size of the data.
      Specified by:
      getSampleSize in interface Score
      Returns:
      This size.
    • getMaxDegree

      public int getMaxDegree()
      Description copied from interface: Score
      Returns the max degree, by default 1000.
      Specified by:
      getMaxDegree in interface Score
      Returns:
      The max degree.
    • determines

      public boolean determines(List<Node> z, Node y)
      Description copied from interface: Score
      Returns true iff the score determines the edge between x and y.
      Specified by:
      determines in interface Score
      Parameters:
      z - The set of nodes.
      y - The node.
      Returns:
      True iff the score determines the edge between x and y.
    • isEffectEdge

      public boolean isEffectEdge(double bump)
      Description copied from interface: Score
      Returns true iff the edge between x and y is an effect edge.
      Specified by:
      isEffectEdge in interface Score
      Parameters:
      bump - The bump.
      Returns:
      True iff the edge between x and y is an effect edge.
    • getDataModel

      public DataModel getDataModel()
      Retrieves the data model used for scoring.
      Returns:
      the data model.
    • getEffectiveSampleSize

      public int getEffectiveSampleSize()
      Description copied from interface: EffectiveSampleSizeSettable
      Returns the effective sample size.
      Specified by:
      getEffectiveSampleSize in interface EffectiveSampleSizeSettable
      Returns:
      the effective sample size
    • setEffectiveSampleSize

      public void setEffectiveSampleSize(int nEff)
      Description copied from interface: EffectiveSampleSizeSettable
      Sets the effective sample size, or -1 if the actual sample size should be used.
      Specified by:
      setEffectiveSampleSize in interface EffectiveSampleSizeSettable
      Parameters:
      nEff - the effective sample size
    • toString

      public String toString()
      Description copied from interface: Score
      A string representation of the score.
      Specified by:
      toString in interface Score
      Overrides:
      toString in class Object
      Returns:
      This string.
    • setLambda

      public void setLambda(double lambda)
      Sets the lambda (sigma^2) hyperparameter and forwards it to the continuous engine.
      Parameters:
      lambda - the noise variance; must be > 0.
    • setJitter

      public void setJitter(double jitter)
      Sets the Cholesky jitter base and forwards it to the continuous engine.
      Parameters:
      jitter - the jitter base; must be > 0.
    • setBandwidthMultiplier

      public void setBandwidthMultiplier(double bandwidthMultiplier)
      Sets the bandwidth multiplier and forwards it to the continuous engine.
      Parameters:
      bandwidthMultiplier - the multiplier; must be > 0 and finite.
    • setBwMaxRows

      public void setBwMaxRows(int bwMaxRows)
      Sets the maximum number of rows for bandwidth estimation (min 50) and forwards it.
      Parameters:
      bwMaxRows - the maximum number of rows.
    • getCatRho

      public double getCatRho()
      Retrieves the categorical similarity rho.
      Returns:
      catRho in [0, 1).
    • setCatRho

      public void setCatRho(double rho)
      Sets the categorical similarity rho in [0, 1). k_cat(c,c)=1, k_cat(c,c')=rho.
      Parameters:
      rho - the categorical similarity; must be in [0, 1).
    • append

      public int[] append(int[] z, int x)
      Appends an integer to an int array, returning a new array.
      Specified by:
      append in interface Score
      Parameters:
      z - the original array.
      x - the value to append.
      Returns:
      a new array with x appended.