Class PooledScoreWrapper

java.lang.Object
edu.cmu.tetrad.algcomparison.utils.PooledScoreWrapper
All Implemented Interfaces:
ScoreWrapper, HasParameters, TetradSerializable, Serializable

public final class PooledScoreWrapper extends Object implements ScoreWrapper
A score wrapper that pools several data sets into one IMaGES score built from an inner score wrapper. This is how "IMaGES" becomes a property of the score rather than a separate algorithm: any score-based algorithm that extends AbstractBootstrapAlgorithm, when handed a DataModelList, has its score wrapper replaced by one of these for the duration of the search, so BOSS + SEM-BIC on a list of data sets IS IMaGES-BOSS, and BOSS + BF-BIC is IMaGES with the basis-function score, with no separate wrapper class per combination.

The data model passed to getScore(DataModel, Parameters) is ignored; the pooled score is built over the data sets registered for the calling thread (set by the bootstrap loop for each replicate) or, failing that, the default list given at construction. Inner wrappers implementing MultiDataSetScoreWrapper are asked for a coordinated list of scores so that data-dependent representation choices are shared across data sets; other wrappers are called once per data set.

Instances are transient: they exist only during a search and are never serialized as the algorithm's score.

Author:
josephramsey
See Also:
  • Constructor Details

    • PooledScoreWrapper

      public PooledScoreWrapper(ScoreWrapper inner, List<DataModel> defaultDataSets)
      Constructs a pooled score wrapper.
      Parameters:
      inner - the score wrapper used to build one score per pooled data set; if it implements MultiDataSetScoreWrapper, its coordinated multi-data-set method is used instead.
      defaultDataSets - the data sets pooled when none have been registered for the calling thread via setThreadDataSets(List); a defensive copy is kept. All pooled data sets must have the same variables by name.
      Throws:
      NullPointerException - if inner is null.
      IllegalArgumentException - if defaultDataSets is null or empty.
  • Method Details

    • getScore

      public Score getScore(DataModel ignored, Parameters parameters)
      Builds one score per pooled data set and combines them into an ImagesScore, which sums the local scores across data sets. The data sets used are those registered for the calling thread by setThreadDataSets(List), or the default list given at construction if none are registered.
      Specified by:
      getScore in interface ScoreWrapper
      Parameters:
      ignored - ignored; the pooled data sets are used instead of this argument.
      parameters - the parameters, passed through to the inner wrapper for every data set.
      Returns:
      the pooled IMaGES score.
    • setThreadDataSets

      public void setThreadDataSets(List<DataModel> dataSets)
      Registers the data sets to pool for scores subsequently built on the calling thread, overriding the default list. The registration is thread-local, so concurrent searches (e.g., bootstrap replicates run in parallel) can each pool their own resampled data sets through a single shared wrapper. Pass null to clear the registration and revert to the default list.
      Parameters:
      dataSets - the data sets to pool on this thread, or null to clear.
    • getDataSets

      public List<DataModel> getDataSets()
      The data sets being pooled for the calling thread: those registered by setThreadDataSets(List), or the default list if none are registered. For an algorithm whose search has a stage that works from the data directly rather than through the score, so that it can run that stage over the same data sets.
      Returns:
      the data sets, as an unmodifiable list
    • getInner

      public ScoreWrapper getInner()
      Returns the score wrapper that is built on each pooled data set.
      Returns:
      the inner score wrapper.
    • getDescription

      public String getDescription()
      Returns a description of the pooled score, formed by prefixing the inner wrapper's description with "Pooled (IMaGES)".
      Specified by:
      getDescription in interface ScoreWrapper
      Returns:
      the description.
    • getDataType

      public DataType getDataType()
      Returns the data type the inner score wrapper accepts; pooling does not change it.
      Specified by:
      getDataType in interface ScoreWrapper
      Returns:
      the data type of the inner score wrapper.
    • getParameters

      public List<String> getParameters()
      Returns the names of the parameters the inner score wrapper uses. Pooling itself adds no parameters.
      Specified by:
      getParameters in interface HasParameters
      Specified by:
      getParameters in interface ScoreWrapper
      Returns:
      the parameter names of the inner score wrapper.
    • getVariable

      public Node getVariable(String name)
      Returns the variable with the given name. The inner wrapper is consulted first, since it records the last data set it built a score for; if that yields nothing, the first pooled data set is used, whose variables are shared by name across all pooled data sets.
      Specified by:
      getVariable in interface ScoreWrapper
      Parameters:
      name - the variable name.
      Returns:
      the variable, or null if no pooled data set has a variable of that name.