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

java.lang.Object
  extended by org.hd.d.pg2k.ai.scorer.AbstractScorer
All Implemented Interfaces:
ScorerIF
Direct Known Subclasses:
AbstractImgScorer, AbstractNonParamScorer, FixedScore

public abstract class AbstractScorer
extends java.lang.Object
implements ScorerIF

Class to implement some common Scorer features in one place.

Author:
dhd

Field Summary
private static java.lang.String DOUBLE_SEP
          Double separator, not permitted in Scorer name-and-parameters.
protected  java.lang.String nameAndParameters
          Name and parameters of this scorer always starting with our default name and syntactically valid; never null.
static java.util.regex.Pattern parameterNameRegex
          Regex pattern to match for Scorer parameter-name validity; never null.
static java.util.regex.Pattern parameterSepRegex
          Regex pattern to separate parameters; never null.
static java.util.regex.Pattern scorerNameRegex
          Regex pattern to match for Scorer name validity; never null.
static char SEPARATOR
          The character used to tokenise the scorer name-plus-parameters form ScorerName{:name=value}*.
 
Constructor Summary
protected AbstractScorer()
          Default constructor uses class-based name and allows no parameterisation.
protected AbstractScorer(java.lang.String nameAndParameters)
          Construct instance with name and optional parameters.
protected AbstractScorer(java.lang.String baseName, java.util.List<ScorerParam> parameters)
           
 
Method Summary
static java.lang.String canonicalise(ScorerIF scorer)
          Create canonical form of Scorer (and any parameters); never null.
 ScorerIF createPerturbedVariant()
          Create perturbed (gently mutated) variant.
 java.lang.String getBaseName()
          Return the base name (the last component of the class name unless overridden); never null.
protected  java.lang.String getDefaultName()
          Get default name for this Scorer; always a valid ScorerName.
 java.lang.String getNameAndParameters()
          Return the name with any parameters for this instance; never null.
 java.util.List<ScorerParam> getParameterDefsAndValues()
          Get (immutable, ordered) parameter definitions and current values (immutable) for this Scorer, empty by default; never null.
 java.util.List<ScorerParam> getPerturbedDefsAndValues()
          Computes randomly-perturbed parameters (if any); never null.
static boolean isValidParameterName(java.lang.String name)
          Returns true iff the parameter name supplied is non-null and is valid.
static boolean isValidScorerName(java.lang.String name)
          Returns true iff the Scorer name supplied is non-null and is valid.
static java.util.Map<java.lang.String,ScorerParam> paramListAsMap(java.util.List<ScorerParam> params)
          Create parameter Map from parameter values; never null but may be empty.
static java.lang.String paramListAsString(java.util.List<ScorerParam> params)
          Create parameter String from in-order catenation of parameter values; never null but may be empty.
static Tuple.Pair<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseNameAndParameters(java.lang.String nameAndParameters)
          Parse name-and-parameters into name and name-value immutable Map; never null.
static boolean similarNParams(ScorerIF scorerInstance1, ScorerIF scorerInstance2, int minSimilarParams)
          Returns true if the two supplied Scorer instances are 'genetically'/'genotypically' similar.
static boolean verySimilar(ScorerIF scorerInstance1, ScorerIF scorerInstance2)
          Returns true if the two supplied Scorer instances are 'genetically'/'genotypically' very similar.
 
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.ScorerIF
computeScoreAndConfidence, createVariant, createVariant
 

Field Detail

nameAndParameters

protected final java.lang.String nameAndParameters
Name and parameters of this scorer always starting with our default name and syntactically valid; never null. By default this has no parameters, and is based on the implementing class' name.


parameterNameRegex

public static final java.util.regex.Pattern parameterNameRegex
Regex pattern to match for Scorer parameter-name validity; never null.


scorerNameRegex

public static final java.util.regex.Pattern scorerNameRegex
Regex pattern to match for Scorer name validity; never null. Currently the same as the parameter name regex for simplicity.


SEPARATOR

public static final char SEPARATOR
The character used to tokenise the scorer name-plus-parameters form ScorerName{:name=value}*. A printable non-whitespace 7-bit ASCII character.

See Also:
Constant Field Values

DOUBLE_SEP

private static final java.lang.String DOUBLE_SEP
Double separator, not permitted in Scorer name-and-parameters.

See Also:
Constant Field Values

parameterSepRegex

public static final java.util.regex.Pattern parameterSepRegex
Regex pattern to separate parameters; never null.

Constructor Detail

AbstractScorer

protected AbstractScorer()
Default constructor uses class-based name and allows no parameterisation.


AbstractScorer

protected AbstractScorer(java.lang.String nameAndParameters)
                  throws java.lang.IllegalArgumentException
Construct instance with name and optional parameters. The name-and-parameters value must be synactically valid (or at least the name must be), and the Scorer name must match the "default" name (at least for now), but the parameters are not interpreted here.

Throws:
java.lang.IllegalArgumentException - if parameter syntax or Scorer bad name is wrong

AbstractScorer

protected AbstractScorer(java.lang.String baseName,
                         java.util.List<ScorerParam> parameters)
                  throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException
Method Detail

getDefaultName

protected final java.lang.String getDefaultName()
Get default name for this Scorer; always a valid ScorerName. Must not be overrideable else it will not be safe to use in constructors.


paramListAsString

public static java.lang.String paramListAsString(java.util.List<ScorerParam> params)
Create parameter String from in-order catenation of parameter values; never null but may be empty. The result is directly suitable to append to a base Scorer name.

Parameters:
params - parameter list may be empty but is never null
Returns:
in-order non-null parameter list (each parameter being preceded by the separator); "" in the case of empty parameter list

paramListAsMap

public static java.util.Map<java.lang.String,ScorerParam> paramListAsMap(java.util.List<ScorerParam> params)
Create parameter Map from parameter values; never null but may be empty. The this will discard early parameters whose names are re-used later in the list.

Parameters:
params - parameter list may be empty but is never null
Returns:
in-order non-null parameter list (each parameter being preceded by the separator); "" in the case of empty parameter list

getBaseName

public java.lang.String getBaseName()
Return the base name (the last component of the class name unless overridden); never null.

Specified by:
getBaseName in interface ScorerIF

getNameAndParameters

public java.lang.String getNameAndParameters()
Return the name with any parameters for this instance; never null.

Specified by:
getNameAndParameters in interface ScorerIF

getPerturbedDefsAndValues

public java.util.List<ScorerParam> getPerturbedDefsAndValues()
Description copied from interface: ScorerIF
Computes randomly-perturbed parameters (if any); never null. This returns with zero or more of any parameters of the current Scorer usually altered by a small amount and guaranteed to be valid (in range).

The net effect is that most changes should be small and verging on insignificant, but some changes should be large enough to help escape from local minima/maxima.

Specified by:
getPerturbedDefsAndValues in interface ScorerIF

createPerturbedVariant

public ScorerIF createPerturbedVariant()
Create perturbed (gently mutated) variant.

Specified by:
createPerturbedVariant in interface ScorerIF

canonicalise

public static java.lang.String canonicalise(ScorerIF scorer)
Create canonical form of Scorer (and any parameters); never null.


getParameterDefsAndValues

public java.util.List<ScorerParam> getParameterDefsAndValues()
Get (immutable, ordered) parameter definitions and current values (immutable) for this Scorer, empty by default; never null.

Specified by:
getParameterDefsAndValues in interface ScorerIF

isValidParameterName

public static boolean isValidParameterName(java.lang.String name)
Returns true iff the parameter name supplied is non-null and is valid.


isValidScorerName

public static boolean isValidScorerName(java.lang.String name)
Returns true iff the Scorer name supplied is non-null and is valid.


parseNameAndParameters

public static Tuple.Pair<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseNameAndParameters(java.lang.String nameAndParameters)
                                                                                                            throws java.lang.IllegalArgumentException
Parse name-and-parameters into name and name-value immutable Map; never null.

Parameters:
nameAndParameters - Scorer name-and-parameters; never null
Returns:
non-null non-empty Scorer base name and non-null possibly empty parameter set
Throws:
IllegalArgmentException - for null/invalid argument
java.lang.IllegalArgumentException

verySimilar

public static boolean verySimilar(ScorerIF scorerInstance1,
                                  ScorerIF scorerInstance2)
Returns true if the two supplied Scorer instances are 'genetically'/'genotypically' very similar. Always returns true for identical Scorers.

Always returns false for Scorers with different base names.

Parameters:
scorerInstance1 - non-null instance
scorerInstance2 - non-null instance
Returns:
false if a different base name or at least one parameter value significantly different

similarNParams

public static boolean similarNParams(ScorerIF scorerInstance1,
                                     ScorerIF scorerInstance2,
                                     int minSimilarParams)
Returns true if the two supplied Scorer instances are 'genetically'/'genotypically' similar. Always returns true for identical Scorers.

Always returns false for Scorers with different base names.

Parameters:
scorerInstance1 - non-null instance
scorerInstance2 - non-null instance
minSimilarParams - minimum number of parameters that must be similar for the two Scorers must be for this routine to return true; non-negative (the result is always true for same-base-name Scorers if zero)
Returns:
true if the Scorers are as similar as specified, false otherwise

DHD Multimedia Gallery V1.50.55

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