org.hd.d.pg2k.ai.scorer
Class MiniScorerCacheImpl

java.lang.Object
  extended by org.hd.d.pg2k.ai.scorer.AbstractScorerCache
      extended by org.hd.d.pg2k.ai.scorer.MiniScorerCacheImpl
All Implemented Interfaces:
ScorerCacheIF

public final class MiniScorerCacheImpl
extends AbstractScorerCache
implements ScorerCacheIF

"Lite" implementation to compute (and cache) the score and confidence for exhibits. Used were access to the full data pipeline is not available or too expensive, and where memory and CPU resources are potentially scarce, for example in an applet or JWS app run by a user to donate CPU time.

This caps its use of resources, population size, etc, at smaller levels than a "full" implementation might.

This only handles the most promising sub-set of "real" parameterised Scorers.


Field Summary
(package private)  java.util.Map<Name.ExhibitShort,ScoreAndConf> calibrationData
          Immutable map from short exhibit name to calibration data; never null but may be empty.
static java.util.Map<java.lang.String,ScorerIF> fixedSimpleScorers
          The (small) immutable current fixed set of parameterless base Scorer instances.
static int MAX_MINI_SCORER_SCORES_RETAINED
          Maximum number of Scorers retained in the population; strictly positive.
 
Fields inherited from class org.hd.d.pg2k.ai.scorer.AbstractScorerCache
dataSource, log, population
 
Fields inherited from interface org.hd.d.pg2k.ai.scorer.ScorerCacheIF
TRIVIAL
 
Constructor Summary
MiniScorerCacheImpl(SimpleExhibitPipelineIF dataSource, SimpleLoggerIF log, ScorerPopulation.NewBestCallbackIF callback)
          Construct an instance attached to the supplied data source and logger.
 
Method Summary
 ScoreAndConf computeCompositeScoreAndConfidence(Name.ExhibitFull exhibitName, boolean allowStale)
          Computes a weighted composite score [-1,+1] and confidence [0,+1] for the specified exhibit with the best available scorers/parameters; never null but may be (0,0).
 ScoreAndConf computeScorerWeighting(ScorerIF scorer, boolean allowStale, java.lang.String source)
          ScoreAndConfidence for the given scorer itself over all exhibit types; never null but may be (0,0) where the scorer is unknown or untested.
 java.util.Map<Name.ExhibitShort,ScoreAndConf> extractCalibrationSet(java.lang.String basename, int maxSamples, java.lang.Boolean difficult, boolean allowStale)
          Compute exemplar exhibit sub-set to calibrate against; never null but may be empty.
 ScorerIF getBaseScorerByName(java.lang.String baseName)
          Get base non-parameterised Scorer by name; null if no such base Scorer supported.
 java.util.Set<java.lang.String> getBaseScorersWithoutParameters()
          Base set of available Scorers' names (no parameters); never null but may be empty.
 ScoreAndConf getCachedCompositeScoreAndConfidence(Name.ExhibitFull exhibitName, boolean allowStale)
          Not available.
 java.util.Map<Name.ExhibitShort,ScoreAndConf> getCalibrationExhibitsAndScores()
          Get the set of exhibits (short names) to calibrate against and their score/confidence values; never null.
 void setCalibrationExhibitsAndScores(java.util.Map<Name.ExhibitShort,ScoreAndConf> calibrationData)
          Indicate the set of exhibits (short names) to calibrate against and their score/confidence values.
 
Methods inherited from class org.hd.d.pg2k.ai.scorer.AbstractScorerCache
canAcceptMoreExternalScorers, computeScorerWeighting, computeUnweightedScoreAndConfidence, destroy, getCurrentScorersWithParameters, getDataSource, getPopulation, getScorerInstance, hasQueuedExternalScorer, offerExternalScorer, poll, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hd.d.pg2k.ai.scorer.ScorerCacheIF
canAcceptMoreExternalScorers, computeScorerWeighting, computeUnweightedScoreAndConfidence, destroy, getCurrentScorersWithParameters, getScorerInstance, hasQueuedExternalScorer, offerExternalScorer, poll, size
 

Field Detail

MAX_MINI_SCORER_SCORES_RETAINED

public static final int MAX_MINI_SCORER_SCORES_RETAINED
Maximum number of Scorers retained in the population; strictly positive. Small enough not to be too burdensome in memory for an applet, for example.

Much more than 1000 may cause out-of-memory difficulties.

See Also:
Constant Field Values

calibrationData

volatile java.util.Map<Name.ExhibitShort,ScoreAndConf> calibrationData
Immutable map from short exhibit name to calibration data; never null but may be empty. Marked as volatile to allow atomic replacement of the entire map, but each map instance is immutable.

Initially empty.


fixedSimpleScorers

public static final java.util.Map<java.lang.String,ScorerIF> fixedSimpleScorers
The (small) immutable current fixed set of parameterless base Scorer instances. Note that since these are fixed and immutable and have no parameters, we can safely create and store instances here.

These include only the live Scorers that we want end-users to help search for. It is possible that we might allow this to be updated remotely

Constructor Detail

MiniScorerCacheImpl

public MiniScorerCacheImpl(SimpleExhibitPipelineIF dataSource,
                           SimpleLoggerIF log,
                           ScorerPopulation.NewBestCallbackIF callback)
Construct an instance attached to the supplied data source and logger.

Parameters:
dataSource - (probably-restricted) live data source; must not be null
Method Detail

setCalibrationExhibitsAndScores

public void setCalibrationExhibitsAndScores(java.util.Map<Name.ExhibitShort,ScoreAndConf> calibrationData)
Indicate the set of exhibits (short names) to calibrate against and their score/confidence values. Used by computeScorerWeighting() and thus computeScorerWeighting() to calibrate the Scorers.

This restricts the work that has to be done for calibration (and the data that need be fetched, which may be important for some users), and supplies calibration data that may not be available over a restricted pipeline.

Any exhibit data and metadata required will be fetched from the pipeline.

Parameters:
calibrationData - map from full valid exhibit names to non-null calibration data; never null, though may be empty

getCalibrationExhibitsAndScores

public java.util.Map<Name.ExhibitShort,ScoreAndConf> getCalibrationExhibitsAndScores()
Get the set of exhibits (short names) to calibrate against and their score/confidence values; never null.


computeCompositeScoreAndConfidence

public ScoreAndConf computeCompositeScoreAndConfidence(Name.ExhibitFull exhibitName,
                                                       boolean allowStale)
                                                throws java.io.IOException
Computes a weighted composite score [-1,+1] and confidence [0,+1] for the specified exhibit with the best available scorers/parameters; never null but may be (0,0). Always throws UnsupportedOperationException in this implementation.

Specified by:
computeCompositeScoreAndConfidence in interface ScorerCacheIF
Parameters:
exhibitName - valid full exhibit name
allowStale - if true then allow a stale value from cache, else throw an exception if nothing is currently available
Returns:
(0,0) if named scorer is not available, cannot be used with the specified parameters, or cannot be applied to the indicated exhibit (eg because of the exhibit type or the exhibit does not exist); else returns a non-null ScoreAndConf value
Throws:
java.io.IOException

getCachedCompositeScoreAndConfidence

public ScoreAndConf getCachedCompositeScoreAndConfidence(Name.ExhibitFull exhibitName,
                                                         boolean allowStale)
Not available. Always throws UnsupportedOperationException in this implementation.

Specified by:
getCachedCompositeScoreAndConfidence in interface ScorerCacheIF
Overrides:
getCachedCompositeScoreAndConfidence in class AbstractScorerCache
Parameters:
exhibitName - valid full exhibit name
allowStale - if true then allow a stale value from cache, else throw an exception if nothing is currently available
Returns:
null if nothing already available in cache, else (0,0) if named scorer is not available, cannot be used with the specified parameters, or cannot be applied to the indicated exhibit (eg because of the exhibit type or the exhibit does not exist); else returns a non-null ScoreAndConf value

getBaseScorersWithoutParameters

public java.util.Set<java.lang.String> getBaseScorersWithoutParameters()
Base set of available Scorers' names (no parameters); never null but may be empty. The values returned are of the form ScorerName.

Specified by:
getBaseScorersWithoutParameters in interface ScorerCacheIF

getBaseScorerByName

public ScorerIF getBaseScorerByName(java.lang.String baseName)
Get base non-parameterised Scorer by name; null if no such base Scorer supported.

Specified by:
getBaseScorerByName in interface ScorerCacheIF
Parameters:
baseName - base (no parameters) name of Scorer; must not be null

extractCalibrationSet

public java.util.Map<Name.ExhibitShort,ScoreAndConf> extractCalibrationSet(java.lang.String basename,
                                                                           int maxSamples,
                                                                           java.lang.Boolean difficult,
                                                                           boolean allowStale)
Compute exemplar exhibit sub-set to calibrate against; never null but may be empty. This implementation returns its input calibration data.

Specified by:
extractCalibrationSet in interface ScorerCacheIF
Parameters:
basename - base name of Scorer to extract calibration set for, or null for a generic all-Scorers calibration set
maxSamples - the maximum number of samples to return; strictly positive
difficult - if TRUE the return the difficult cases that we do not predict well, if FALSE then return the easy cases that we predict well, else return a mixure of good, bad, and other random cases
allowStale - if true then allow slightly older data for speed and robustness
Returns:
map of zero-or-more exhibits (short names) to calibration-data values; non-null

computeScorerWeighting

public ScoreAndConf computeScorerWeighting(ScorerIF scorer,
                                           boolean allowStale,
                                           java.lang.String source)
                                    throws java.io.IOException
ScoreAndConfidence for the given scorer itself over all exhibit types; never null but may be (0,0) where the scorer is unknown or untested. Essentially the result of this should be multiplied by the result for each exhibit (for the same scorer and parameters) to normalise the predicted score and confidence for the exhibit.

Some results will be cached (typically those from the base/current Scorer lists) while other may have to be computed each time, which may be slow.

Specified by:
computeScorerWeighting in interface ScorerCacheIF
Parameters:
allowStale - if true then allow a stale or low-confidence value from cache, else throw an exception if nothing is currently available and we cannot quickly compute enough points to increase our confidence
source - the name of the mechanism used to generate this Scorer value, or null if none
scorer - instance of the Scorer; never null
Returns:
the score represents the correlation with the underlying votes (and whatever the scoring is measured against) with MAX meaning perfect correlation, 0 meaning no correlation, and -MAX meaning perfectly wrong answers all the time, and the confidence 0 if we have no (or very/too few) data points and approaching MAX as we have a large (enough) number of data points
Throws:
java.io.IOException

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.