Class KernelMarginalLikelihoodScoreContinuous
- All Implemented Interfaces:
Score, EffectiveSampleSizeSettable
This score implements the exact Gaussian Process (GP) marginal likelihood
for evaluating candidate parent sets in score-based causal discovery.
For a target variable Y and parent set Z, the model is
Y = f(Z) + ε, ε ~ N(0, σ² I) f ~ GP(0, k(·,·))
where k is a positive-definite kernel (typically an RBF kernel).
The marginal covariance of Y is
C = K_Z + σ² I
with K_Z the kernel Gram matrix over the parent variables.
The score (up to an additive constant) is the GP marginal log-likelihood
S = -0.5 · Yᵀ C⁻¹ Y - 0.5 · log |C|.
This class is the continuous engine used by KernelMarginalLikelihoodScore,
which handles the mixed (continuous + discrete) case and delegates purely
continuous local scores here. It also exposes the exact RBF Gram construction
(rbfGramContinuous(int[], int[], int)) and the GP marginal-likelihood
solvers (gpLogMarginalLikelihood(double[], DMatrixRMaj, double) and
gpLogMarginalLikelihoodMulti(double[][], DMatrixRMaj, double)) so the
mixed score can compose the RBF kernel with a categorical kernel without
re-implementing the linear algebra.
Computational considerations
Computing the KML score requires forming and factorizing an
n × n kernel covariance matrix, which has
O(n³) time and O(n²) memory complexity.
As a result, this score is best suited for small to moderate
sample sizes.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an instance of KernelMarginalLikelihoodScoreContinuous using the provided data set. -
Method Summary
Modifier and TypeMethodDescriptionint[]append(int[] z, int x) Appends an integer to an int array, returning a new array.booleandetermines(List<Node> z, Node y) Determines if a node is determined by a set of nodes.Retrieves the data model used for scoring.intRetrieves the effective sample size used for scoring.doubleRetrieves the jitter parameter.intRetrieves the maximum degree allowed for scoring.intRetrieves the sample size used for scoring.Retrieves the list of variables associated with this score object.static doublegpLogMarginalLikelihood(double[] y, org.ejml.data.DMatrixRMaj C, double jitter) Computes the single-output GP log marginal likelihood-0.5*yᵀ C⁻¹ y - 0.5*log|C|using Cholesky with jitter escalation.static doublegpLogMarginalLikelihoodMulti(double[][] Ycentered, org.ejml.data.DMatrixRMaj C, double jitter) Multi-output GP log marginal likelihood for a shared covarianceC.booleanisEffectEdge(double bump) Determines if an edge is an effect edge based on a given bump value.doublelocalScore(int i, int... parents) The score of a node given its parents.doublelocalScoreDiff(int x, int y, int[] z) Computes the difference in local scores when adding a variable to the conditioning set.org.ejml.data.DMatrixRMajrbfGramContinuous(int[] contParents, int[] rows, int n) Public accessor for the exact RBF Gram matrix over the given (continuous) parents, so composite scores can build product kernels without re-implementing the kernel.voidsetBandwidthMultiplier(double bandwidthMultiplier) Sets the bandwidth multiplier parameter for the Kernel Marginal Likelihood Score.voidsetBwMaxRows(int bwMaxRows) Sets the maximum number of rows to be used in bandwidth calculations.voidsetEffectiveSampleSize(int nEff) Sets the effective sample size used for scoring.voidsetJitter(double jitter) Sets the jitter parameter for the Kernel Marginal Likelihood Score.voidsetLambda(double lambda) Sets the lambda hyperparameter for the Kernel Marginal Likelihood Score.toString()Retrieves the name of the score.Methods inherited from interface Score
getMissingValueSupport, getVariable, localScore, localScore, localScoreDiff
-
Constructor Details
-
KernelMarginalLikelihoodScoreContinuous
Constructs an instance of KernelMarginalLikelihoodScoreContinuous using the provided data set. This constructor initializes internal variables, processes the input data, and applies z-scoring to standardize the columns while preserving NaN values.- Parameters:
dataSet- The data set to be used for computing the Kernel Marginal Likelihood Score. Must not be null. Throws aNullPointerExceptionif the data set is null.
-
-
Method Details
-
localScoreDiff
public double localScoreDiff(int x, int y, int[] z) Computes the difference in local scores when adding a variable to the conditioning set.- Specified by:
localScoreDiffin interfaceScore- Parameters:
x- The variable to be added to the conditioning set.y- The target variable for which the score is being computed.z- The original conditioning set of variables.- Returns:
- The difference in local scores between the modified and original conditioning sets.
-
localScore
public double localScore(int i, int... parents) Description copied from interface:ScoreThe score of a node given its parents.- Specified by:
localScorein interfaceScore- Parameters:
i- The node.parents- The parents.- Returns:
- The score.
-
getVariables
Retrieves the list of variables associated with this score object.- Specified by:
getVariablesin interfaceScore- Returns:
- A list of Node objects representing the variables.
-
getSampleSize
public int getSampleSize()Retrieves the sample size used for scoring.- Specified by:
getSampleSizein interfaceScore- Returns:
- The sample size as an integer.
-
getMaxDegree
public int getMaxDegree()Retrieves the maximum degree allowed for scoring.- Specified by:
getMaxDegreein interfaceScore- Returns:
- The maximum degree as an integer.
-
determines
Determines if a node is determined by a set of nodes.- Specified by:
determinesin interfaceScore- Parameters:
z- The set of nodes.y- The node.- Returns:
- True if the node is determined by the set of nodes, false otherwise.
-
isEffectEdge
public boolean isEffectEdge(double bump) Determines if an edge is an effect edge based on a given bump value.- Specified by:
isEffectEdgein interfaceScore- Parameters:
bump- The bump value.- Returns:
- True if the edge is an effect edge, false otherwise.
-
getDataModel
-
getEffectiveSampleSize
public int getEffectiveSampleSize()Retrieves the effective sample size used for scoring.- Specified by:
getEffectiveSampleSizein interfaceEffectiveSampleSizeSettable- Returns:
- The effective sample size as an integer.
-
setEffectiveSampleSize
public void setEffectiveSampleSize(int nEff) Sets the effective sample size used for scoring.- Specified by:
setEffectiveSampleSizein interfaceEffectiveSampleSizeSettable- Parameters:
nEff- the effective sample size
-
toString
-
setLambda
public void setLambda(double lambda) Sets the lambda hyperparameter for the Kernel Marginal Likelihood Score.- Parameters:
lambda- The new value for the lambda hyperparameter. Must be greater than 0.
-
setJitter
public void setJitter(double jitter) Sets the jitter parameter for the Kernel Marginal Likelihood Score.- Parameters:
jitter- The new value for the jitter parameter. Must be greater than 0.
-
getJitter
public double getJitter()Retrieves the jitter parameter.- Returns:
- the jitter value.
-
setBandwidthMultiplier
public void setBandwidthMultiplier(double bandwidthMultiplier) Sets the bandwidth multiplier parameter for the Kernel Marginal Likelihood Score.- Parameters:
bandwidthMultiplier- The new value for the bandwidth multiplier. Must be greater than 0 and finite.
-
setBwMaxRows
public void setBwMaxRows(int bwMaxRows) Sets the maximum number of rows to be used in bandwidth calculations. Minimum 50.- Parameters:
bwMaxRows- The new maximum number of rows for bandwidth calculations.
-
gpLogMarginalLikelihood
public static double gpLogMarginalLikelihood(double[] y, org.ejml.data.DMatrixRMaj C, double jitter) Computes the single-output GP log marginal likelihood-0.5*yᵀ C⁻¹ y - 0.5*log|C|using Cholesky with jitter escalation.Cis expected to already include theσ² Iridge.- Parameters:
y- centered target vector (length n).C- then×nmarginal covariance (kernel + ridge).jitter- jitter base for Cholesky stabilization.- Returns:
- the GP log marginal likelihood, or
NaNif factorization fails.
-
gpLogMarginalLikelihoodMulti
public static double gpLogMarginalLikelihoodMulti(double[][] Ycentered, org.ejml.data.DMatrixRMaj C, double jitter) Multi-output GP log marginal likelihood for a shared covarianceC.Each column of
Ycenteredis treated as an independent output with the same covarianceC = K + σ² I, so the score is the sum of the per-output single-output log marginal likelihoods:Σ_c [ -0.5 · y_cᵀ C⁻¹ y_c ] - 0.5 · L · log|C|.
Because
Cdoes not depend on the output column, it is factorized once and reused for every column (thelog|C|term is shared), which is substantially cheaper than re-factorizing per output.- Parameters:
Ycentered-n×Lmatrix of centered outputs (e.g. centered one-hot columns).C- the sharedn×nmarginal covariance (kernel + ridge).jitter- jitter base for Cholesky stabilization.- Returns:
- the summed multi-output GP log marginal likelihood, or
NaNon failure.
-
rbfGramContinuous
public org.ejml.data.DMatrixRMaj rbfGramContinuous(int[] contParents, int[] rows, int n) Public accessor for the exact RBF Gram matrix over the given (continuous) parents, so composite scores can build product kernels without re-implementing the kernel.Note: with an empty parent list this returns the all-ones matrix (the RBF kernel over zero dimensions is identically 1), which is exactly the multiplicative identity for a Hadamard product with a categorical kernel.
- Parameters:
contParents- continuous parent indices (may be empty).rows- active absolute row indices, ornullto use the firstnrows.n- number of active rows.- Returns:
- the
n×nRBF Gram matrix.
-
append
-