Class BasisFunctionBicScore
- All Implemented Interfaces:
Score
This version uses covariance matrices to calculate likelihoods.
- Author:
- bryanandrews, josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBasisFunctionBicScore(DataSet dataSet, int truncationLimit, double lambda) Constructs a BasisFunctionBicScore object with the specified parameters.BasisFunctionBicScore(DataSet dataSet, int truncationLimit, double lambda, boolean adaptiveBasisSelection) Constructs a BasisFunctionBicScore object with the specified parameters.BasisFunctionBicScore(DataSet dataSet, int truncationLimit, double lambda, boolean adaptiveBasisSelection, boolean rankTransform) AsBasisFunctionBicScore(DataSet, int, double, boolean), with the option to rank-transform continuous variables to [-1, 1] before the Legendre embedding.BasisFunctionBicScore(DataSet dataSet, int truncationLimit, double lambda, boolean adaptiveBasisSelection, boolean rankTransform, MissingDataSpec spec) AsBasisFunctionBicScore(DataSet, int, double, boolean, boolean), with an explicit missing-data specification.BasisFunctionBicScore(DataSet dataSet, int truncationLimit, double lambda, Map<Integer, List<Integer>> embedding, boolean rankTransform) Constructs a BasisFunctionBicScore that scores against an externally supplied embedding - a map from variable index to the embedded columns to use for that variable. -
Method Summary
Modifier and TypeMethodDescriptionadaptivePrunedEmbedding(DataSet dataSet, int truncationLimit) Computes the adaptive basis-column decision for a single data set: the embedding thatnew BasisFunctionBicScore(dataSet, truncationLimit, lambda, true)would score against.int[]The number of embedded components per variable, in variable order: the basis-function count for a continuous variable, the number of categories minus one for a discrete one (after any adaptive pruning).fitNullsByPermutation(DataSet rawData, int samplesPerClass, long seed) Estimates, by permutation on the raw data, the null distribution of this score's gain for adding one parent, per degrees-of-freedom class.fullEmbedding(DataSet dataSet, int truncationLimit) Computes the unpruned embedding layout for a single data set, for callers that need to combine or validate basis-column decisions across data sets.Returns a copy of the embedding this score is scoring against (variable index to embedded columns).intRetrieves the maximum degree from the underlying BIC score component.Declares what this score can do, natively, with data containing missing values.doubleThe penalty discount in use, which may have been set automatically by the algcomparison wrapper.intRetrieves the sample size from the underlying BIC score component.Retrieves the list of nodes representing the variables in the basis function score.booleanisEffectEdge(double bump) Determines if the given bump value represents an effect edge.booleanWhether continuous variables were rank-transformed before embedding.doublelocalScore(int i, int... parents) Calculates the local score for a given node and its parent nodes.doublelocalScoreDiff(int x, int y, int[] z) Returns the score difference of the graph.voidsetDoOneEquationOnly(boolean doOneEquationOnly) When calculation the score for X = <X1 = X, X2, X3,..., Xp> use the equation for X1 only, if true; otherwise, use equations for all of X1, X2,...,Xp.voidsetPenaltyDiscount(double penaltyDiscount) Sets the penalty discount value, which is used to adjust the penalty term in the BIC score calculation.toString()Returns a string representation of the BasisFunctionBicScore object.Methods inherited from interface Score
append, determines, getVariable, localScore, localScore, localScoreDiff
-
Constructor Details
-
BasisFunctionBicScore
Constructs a BasisFunctionBicScore object with the specified parameters.- Parameters:
dataSet- the data set on which the score is to be calculated.truncationLimit- the truncation limit of the basis.lambda- Singularity lambda- See Also:
-
BasisFunctionBicScore
public BasisFunctionBicScore(DataSet dataSet, int truncationLimit, double lambda, boolean adaptiveBasisSelection) Constructs a BasisFunctionBicScore object with the specified parameters.- Parameters:
dataSet- the data set on which the score is to be calculated.truncationLimit- the truncation limit of the basis.lambda- Singularity lambdaadaptiveBasisSelection- if true, basis columns beyond the linear term that fail a BIC-crossing screen against every other variable's embedded block are dropped from the embedding before scoring, so that the effective truncation is chosen by the data and the score converges as the truncation limit is raised past the data-supported order. The screen is computed once from the full-sample embedded correlation matrix, independently of any graph, so the pruned embedding is a single fixed embedding and score equivalence is preserved.- See Also:
-
BasisFunctionBicScore
public BasisFunctionBicScore(DataSet dataSet, int truncationLimit, double lambda, boolean adaptiveBasisSelection, boolean rankTransform) AsBasisFunctionBicScore(DataSet, int, double, boolean), with the option to rank-transform continuous variables to [-1, 1] before the Legendre embedding. SeeEmbedding.RANK_TRANSFORMfor why this is recommended: it gives the score's LRT an exact chi-square null and removes leverage-driven spurious edges, at the cost of modeling the copula rather than the joint distribution with its marginals.- Parameters:
dataSet- the datatruncationLimit- the truncation limit of the basislambda- the singularity lambdaadaptiveBasisSelection- see the four-argument constructorrankTransform- if true, rank-transform continuous variables before embedding
-
BasisFunctionBicScore
public BasisFunctionBicScore(DataSet dataSet, int truncationLimit, double lambda, boolean adaptiveBasisSelection, boolean rankTransform, MissingDataSpec spec) AsBasisFunctionBicScore(DataSet, int, double, boolean, boolean), with an explicit missing-data specification. On a data set with missing values the supported policies are LISTWISE and TESTWISE. Under TESTWISE the embedding carries NaN in every derived column of a variable wherever that variable is missing, and the underlyingSemBicScorecomputes each family's covariance over the rows complete on that family's embedded columns (from the raw embedded columns rather than the correlation matrix; the two differ only by a per-column scale, which contributes the same constant to every parent set of a node and so leaves all score comparisons unchanged). With adaptive basis selection, the screen is computed from pairwise-deletion correlations. A null spec on missing data is treated as FAIL.- Parameters:
dataSet- the datatruncationLimit- the truncation limit of the basislambda- the singularity lambdaadaptiveBasisSelection- see the four-argument constructorrankTransform- if true, rank-transform continuous variables before embeddingspec- the missing-data specification, or null
-
BasisFunctionBicScore
public BasisFunctionBicScore(DataSet dataSet, int truncationLimit, double lambda, Map<Integer, List<Integer>> embedding, boolean rankTransform) Constructs a BasisFunctionBicScore that scores against an externally supplied embedding - a map from variable index to the embedded columns to use for that variable. The correlation matrix and the underlying SemBicScore are built at full size from this data set's own embedding, exactly as in the other constructors; the supplied map only controls which columns are referenced. This is how a multi-data-set algorithm aiming at a single common model (e.g. IMaGES) shares one basis-column decision across all of its data sets, so that every data set scores the identical parameterization: with per-data-set adaptive selection, different data sets can keep different columns, and the summed score then compares models whose effective embeddings differ across data sets.The supplied embedding must be consistent with this data set's own (unpruned) embedding layout: same variable keys, and for each variable a subsequence of its unpruned columns. This holds automatically when the map is derived (e.g. by union) from per-data-set decisions over data sets with the same variables, types, and categories, as
Embedding.getEmbeddedDatalays such data sets out identically.- Parameters:
dataSet- the data set on which the score is to be calculated. Must not be null.truncationLimit- the truncation limit of the basis. Must be a positive integer.lambda- Singularity lambda. Must be non-negative.embedding- the embedding (variable index to embedded columns) to score against. Must not be null.rankTransform- whether to apply a rank t ransformation to the unit interval.
-
-
Method Details
-
adaptivePrunedEmbedding
public static Map<Integer, List<Integer>> adaptivePrunedEmbedding(DataSet dataSet, int truncationLimit) Computes the adaptive basis-column decision for a single data set: the embedding thatnew BasisFunctionBicScore(dataSet, truncationLimit, lambda, true)would score against. Exposed so that multi-data-set callers can combine per-data-set decisions (e.g. by union) into one common embedding.- Parameters:
dataSet- the data set.truncationLimit- the truncation limit of the basis.- Returns:
- the pruned embedding for this data set.
-
fullEmbedding
Computes the unpruned embedding layout for a single data set, for callers that need to combine or validate basis-column decisions across data sets.- Parameters:
dataSet- the data set.truncationLimit- the truncation limit of the basis.- Returns:
- the full (unpruned) embedding for this data set.
-
getEmbedding
-
localScore
public double localScore(int i, int... parents) Calculates the local score for a given node and its parent nodes.- Specified by:
localScorein interfaceScore- Parameters:
i- The index of the node whose score is being calculated.parents- The indices for the parent nodes of the given node.- Returns:
- The calculated local score as a double value.
-
localScoreDiff
public double localScoreDiff(int x, int y, int[] z) Description copied from interface:ScoreReturns the score difference of the graph.- Specified by:
localScoreDiffin interfaceScore- Parameters:
x- A node.y- TAhe node.z- A set of nodes.- Returns:
- The score difference.
-
getVariables
Retrieves the list of nodes representing the variables in the basis function score.- Specified by:
getVariablesin interfaceScore- Returns:
- a list containing the nodes that represent the variables in the basis function score.
-
isEffectEdge
public boolean isEffectEdge(double bump) Determines if the given bump value represents an effect edge.- Specified by:
isEffectEdgein interfaceScore- Parameters:
bump- the bump value to be evaluated.- Returns:
- true if the bump is an effect edge, false otherwise.
-
getSampleSize
public int getSampleSize()Retrieves the sample size from the underlying BIC score component.- Specified by:
getSampleSizein interfaceScore- Returns:
- the sample size as an integer
-
embeddingBlockSizes
public int[] embeddingBlockSizes()The number of embedded components per variable, in variable order: the basis-function count for a continuous variable, the number of categories minus one for a discrete one (after any adaptive pruning). Adding a parent x to y costs size[y] * size[x] degrees of freedom, so this is the inputPenaltyDiscountCalibration.pairDofHistogram(int[])needs to calibrate the penalty discount for this score.- Returns:
- One entry per variable.
-
fitNullsByPermutation
public Map<Integer, PenaltyDiscountCalibration.NullFit> fitNullsByPermutation(DataSet rawData, int samplesPerClass, long seed) Estimates, by permutation on the raw data, the null distribution of this score's gain for adding one parent, per degrees-of-freedom class. Re-embeds the data with this score's truncation limit and restricts to the columns this score actually uses (after any adaptive pruning), so the statistic is the one the search sees.Use the result with
PenaltyDiscountCalibration.penaltyDiscountForFalseDiscoveryRateFitted(Map, int, int, double, double)rather than the exact chi-square version: the embedded components of a variable are not jointly Gaussian, so the LRT's null has the chi-square mean but roughly double the variance, and a chi-square calibration sets the penalty discount far too low for this score.- Parameters:
rawData- The data this score was built from.samplesPerClass- Null draws per df class; a few hundred is plenty.seed- Seed for reproducible calibration.- Returns:
- Map from df to fitted null.
-
getMaxDegree
public int getMaxDegree()Retrieves the maximum degree from the underlying BIC score component.- Specified by:
getMaxDegreein interfaceScore- Returns:
- the maximum degree as an integer.
-
toString
-
getPenaltyDiscount
public double getPenaltyDiscount()The penalty discount in use, which may have been set automatically by the algcomparison wrapper.- Returns:
- c.
-
setPenaltyDiscount
public void setPenaltyDiscount(double penaltyDiscount) Sets the penalty discount value, which is used to adjust the penalty term in the BIC score calculation.- Parameters:
penaltyDiscount- The multiplier on the penalty term for this score.
-
isRankTransform
public boolean isRankTransform()Whether continuous variables were rank-transformed before embedding.- Returns:
- true if so.
-
setDoOneEquationOnly
public void setDoOneEquationOnly(boolean doOneEquationOnly) When calculation the score for X = <X1 = X, X2, X3,..., Xp> use the equation for X1 only, if true; otherwise, use equations for all of X1, X2,...,Xp.- Parameters:
doOneEquationOnly- True if only the equation for X1 is to be used for X = X1,...,Xp. *
-
getMissingValueSupport
Declares what this score can do, natively, with data containing missing values. The default isMissingValueSupport.NONE, meaning that missingness must be handled upstream (e.g., by imputation, or by supplying an EM-estimated covariance matrix if the score consumes one); scores that handle missing values themselves should override this.TESTWISE: constructed with
MissingDataSpec.testwise(), each family is scored on the rows complete on that family's embedded columns.- Specified by:
getMissingValueSupportin interfaceScore- Returns:
- This support level.
-