Class LikelihoodCalculator
java.lang.Object
_global.tri.oxidationstates.calculator.OxidationStateCalculator
_global.tri.oxidationstates.calculator.likelihood.LikelihoodCalculator
This is the main class for calculating likelihood scores
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThis class is used to idnetify the electronic chemical potential that maximizes the likelihood score -
Constructor Summary
ConstructorsConstructorDescriptionLikelihoodCalculator(String paramFileName) Initialize a likelihood calculator from a parameters file.LikelihoodCalculator(String inputFileName, boolean isJSONBoundaryFile) Initialize a likelihood calculator from a parameters file.LikelihoodCalculator(HashMap<String, int[]> oxidationStateMap) Initialized the likelihood calculator from a map of molecule types to allowed oxidation states -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]boundariesToParameters(double[] boundaries) Converts a set of oxidation state boundaries for an ion type into parametersgetAllOxidationStates(Composition composition, double minAllowedLikelihood, int minNumberToReturn) Returns an array possible oxidation state assignments for the given composition, subject to the given constraints.getAllOxidationStates(String composition, double minAllowedLikelihood, int minNumberToReturn) Get all possible oxidation state assignments for the given composition, subject to the given constraints.double[]getBoundaries(int ionTypeIndex) Return all of the midpoint boundary values for the given ion typedouble[]Get the midpoint boundaries (lower and upper) for the given ionintgetIonTypeIndex(String ionTypeSymbol) Returns the ion type index (used by this class) for ion types with the given symbol.getIonTypeSymbol(int ionTypeIndex) Get the ion type symbol corresponding to the given indexGet a an array of all ions known to this calculatordoublegetLikelihood(double fermiLevel, IonFactory.Ion ion) Return the likelihood score for a given ion at a give electronic chemical potential (fermiLevel)doublegetLikelihood(double fermiLevel, IonFactory.Ion[] allIons) Calculates the likelihood score for a given set of ions at a given electronic chemical potentialgetLikelyOxidationStates(String[] ionTypeIDs, double[] weights) Calculate the most likely oxidation states for the given ion types with the given composition.double[]Returns the minimum and maximum boundary values across all ion typesintReturn the index of the state set with the minimum likelihood score from the given listintgetOxidationState(int ionTypeIndex, int stateNum) Returns the stateNum'th oxidation state for the ion type with the given indexint[]getOxidationStates(String ionTypeSymbol) Returns the oxidation states known to this calculator for the ion type with the given symboldoublegetParameter(int ionTypeIndex, int paramNumForIonType) Return the paramNumForMolecule'th parameter for the ion type with the given indexdouble[]getParameters(double[] template) Returns the parameters for this calculatordouble[]getParameters(int ionTypeIndex) Returns the parameters for the ion type with the given indexdoubleSum of the maximum boundaries for all ion types, subtract the sum of the minimum boundaries, and report the difference.booleanhasParamsForElement(matsci.Element element) Whether this calculator has parameters for the given elementbooleanWhether this calculator has parameters for the given ionbooleanhasParamsForIonType(String symbol) Whether this calculator has parameters for the given ion typeintReturns the number of ion types known to this calculatorintnumOxidationStates(int ionTypeIndex) Returns the number of oxidation states known to this calculator for the ion type with the given indexintReturns the total number of parameters used by this calculatorDetermine the electronic chemical potential that maximizes the likelihood score for the given entryoptimizeLikelihood(IonFactory.Ion[] ions) Finds the electronic chemical potential that maximizes the likelihood score for the given set of ionsoptimizeLikelihood(IonFactory.Ion[] ions, double initialFermiLevel) Finds the electronic chemical potential that maximizes the likelihood score for the given set of ionsoptimizeLikelihood(String[] ionTypeIDs, double[] weights) Determine the electronic chemical potential that maximizes the likelihood score for the given ion type IDS, where weights indicate the composition of each ion type.optimizeLikelihood(matsci.Species[] allSpecies) Finds the electronic chemical potential that maximizes the likelihood score for the given set of speciesstatic double[]parametersToBoundaries(double[] parameters) Converts a set of parameters for an ion type into oxidation state boundariesdouble[]readParameters(String fileName) Read the parameters from a parameters file (the old format, not the JSON format).double[]readParametersFromBoundaryJSON(String fileName) Read parameters from a JSON-formatted boundaries filesetParameters(double[] parameters) Returns a new calculator copied with this one, with parameters given by the provided parameters.voidwriteBoundaries(OutputStream stream) Write the boundaries to an output stream in a simple (non-JSON) formatvoidwriteBoundaries(String fileName) Write the boundaries to a simple text file.voidwriteBoundaryJSON(OutputStream stream) Write the boundaries in JSON format to an output stream.voidwriteBoundaryJSON(String fileName) Write the boundaries to a JSON-formatted file.voidwriteDataFile(String ionType, String fileName, boolean smoothCutoff) Write a file that can be used to visualize the boundaries for a particular ion typevoidwriteDataFile(String ionType, String fileName, double lowerBound, double upperBound, double increment, boolean smoothCutoff) Write a file that can be used to visualize the boundaries for a particular ion typevoidwriteDataFiles(String directoryName, boolean smoothCutoff) Write files that can be used to visualize the boundariesvoidwriteDataFiles(String directoryName, double lowerBound, double upperBound, double increment, boolean smoothCutoff) Write files that can be used to visualize the boundariesvoidwriteParameters(OutputStream stream) Write the parameters to an output stream (not JSON formatted).voidwriteParameters(String fileName) Write the parameters to a text file (not JSON formatted).Methods inherited from class _global.tri.oxidationstates.calculator.OxidationStateCalculator
getLikelyOxidationStates, getLikelyOxidationStates, getLikelyOxidationStates
-
Constructor Details
-
LikelihoodCalculator
Initialize a likelihood calculator from a parameters file. This is an older constructor; to initialize from a JSON file, use theLikelihoodCalculator(String, boolean)constructor.- Parameters:
paramFileName- The name of the parameter file to read
-
LikelihoodCalculator
Initialize a likelihood calculator from a parameters file.- Parameters:
inputFileName- The name of the parameter fileisJSONBoundaryFile- True if the parameter file is a JSON-formated boundaries file, false if it's a parameters file
-
LikelihoodCalculator
Initialized the likelihood calculator from a map of molecule types to allowed oxidation states- Parameters:
oxidationStateMap- The map, in which keys are molecule type ids and the values are the allowed oxidation states
-
-
Method Details
-
hasParamsForIon
Whether this calculator has parameters for the given ion- Parameters:
ion- The given ion- Returns:
- True if this calculator has parameters for the ion, and false otherwise.
-
hasParamsForIonType
Whether this calculator has parameters for the given ion type- Parameters:
symbol- The symbol for the given ion type- Returns:
- True if this calculator has parameters for the given ion type, and false otherwise
-
hasParamsForElement
public boolean hasParamsForElement(matsci.Element element) Whether this calculator has parameters for the given element- Parameters:
element- The given element- Returns:
- True if the calculator has parameters for the given element, false otherwise
-
numParameters
public int numParameters()Returns the total number of parameters used by this calculator- Returns:
- The total number of parameters used by this calculator
-
getParameters
public double[] getParameters(double[] template) Returns the parameters for this calculator- Parameters:
template- If this array is provided, the parameters will be copied into it. Otherwise a new array is created.- Returns:
- The parameters for this calculator.
-
setParameters
Returns a new calculator copied with this one, with parameters given by the provided parameters.- Parameters:
parameters- The parameters for the new calculator- Returns:
- A copy of this calculator with the parameters changed to the given parameters.
-
readParameters
Read the parameters from a parameters file (the old format, not the JSON format).- Parameters:
fileName- The name of the file to be read- Returns:
- An array of parameters
-
readParametersFromBoundaryJSON
Read parameters from a JSON-formatted boundaries file- Parameters:
fileName- The name of the JSON-formatted file- Returns:
- And array of the read parameters
-
getMinAndMaxBoundary
public double[] getMinAndMaxBoundary()Returns the minimum and maximum boundary values across all ion types- Returns:
- the minimum and maximum boundary values across all ion types
-
getBoundaries
Get the midpoint boundaries (lower and upper) for the given ion- Parameters:
ion- The ion for which we want boundaries- Returns:
- the midpoint boundaries (lower and upper) for the given ion
-
getBoundaries
public double[] getBoundaries(int ionTypeIndex) Return all of the midpoint boundary values for the given ion type- Parameters:
ionTypeIndex- The index of the ion type- Returns:
- all of the midpoint boundary values for the given ion type
-
parametersToBoundaries
public static double[] parametersToBoundaries(double[] parameters) Converts a set of parameters for an ion type into oxidation state boundaries- Parameters:
parameters- The parameters for the model- Returns:
- The oxidation state boundaries for that ion type, ordered from lowest to highest
-
boundariesToParameters
public static double[] boundariesToParameters(double[] boundaries) Converts a set of oxidation state boundaries for an ion type into parameters- Parameters:
boundaries- The oxidation state boundaries- Returns:
- The parameters representing those boundaries, suitable for use in the conjugate gradient optimizer
-
writeBoundaries
Write the boundaries to a simple text file. This will not be the JSON-formatted file.- Parameters:
fileName- The name of the file to be written.
-
writeBoundaries
Write the boundaries to an output stream in a simple (non-JSON) format- Parameters:
stream- The output stream to which boundaries should be written.
-
writeBoundaryJSON
Write the boundaries to a JSON-formatted file.- Parameters:
fileName- The name of the file to be written.
-
writeBoundaryJSON
Write the boundaries in JSON format to an output stream.- Parameters:
stream- The output stream to which the bouandaries should be written.
-
writeDataFiles
Write files that can be used to visualize the boundaries- Parameters:
directoryName- The name of the directory in which the files should be written.smoothCutoff- True if the plots should have smooth boundaries, reflecting the logistic functions, false if the plots should have sharp boundaries.
-
writeDataFiles
public void writeDataFiles(String directoryName, double lowerBound, double upperBound, double increment, boolean smoothCutoff) Write files that can be used to visualize the boundaries- Parameters:
directoryName- The name of the directory in which the files should be written.lowerBound- The lower electronic chemical potential bound for the plotsupperBound- The upper electronic chemical potential bound for the plotsincrement- The width of the electronic chemical potential bins used to generate the plotssmoothCutoff- True if the plots should have smooth boundaries, reflecting the logistic functions, false if the plots should have sharp boundaries.
-
writeDataFile
Write a file that can be used to visualize the boundaries for a particular ion type- Parameters:
ionType- The ion typefileName- The name of the file to be writtensmoothCutoff- True if the plots should have smooth boundaries, reflecting the logistic functions, false if the plots should have sharp boundaries.
-
writeDataFile
public void writeDataFile(String ionType, String fileName, double lowerBound, double upperBound, double increment, boolean smoothCutoff) Write a file that can be used to visualize the boundaries for a particular ion type- Parameters:
ionType- The ion typefileName- The name of the file to be writtenlowerBound- The lower electronic chemical potential bound for the plotsupperBound- The upper electronic chemical potential bound for the plotsincrement- The width of the electronic chemical potential bins used to generate the plotssmoothCutoff- True if the plots should have smooth boundaries, reflecting the logistic functions, false if the plots should have sharp boundaries.
-
writeParameters
Write the parameters to a text file (not JSON formatted).- Parameters:
fileName- The name of the file to be written.
-
writeParameters
Write the parameters to an output stream (not JSON formatted).- Parameters:
stream- The output stream to which the parameters should be written.
-
getSumOfSpreads
public double getSumOfSpreads()Sum of the maximum boundaries for all ion types, subtract the sum of the minimum boundaries, and report the difference.- Returns:
- The difference between the sum of the maximum boundaries and the sum of the minimum boundaries.
-
getLikelihood
Return the likelihood score for a given ion at a give electronic chemical potential (fermiLevel)- Parameters:
fermiLevel- The electronic chemical potential at which to calculate the likelihood scoreion- The ion for which the likelihood score should be calculated- Returns:
- the likelihood score for a given ion at a give electronic chemical potential (fermiLevel)
-
optimizeLikelihood
Finds the electronic chemical potential that maximizes the likelihood score for the given set of species- Parameters:
allSpecies- The distinct species for which we want to optimize the likelihood score- Returns:
- the electronic chemical potential that maximizes the likelihood score for the given set of species
-
optimizeLikelihood
Finds the electronic chemical potential that maximizes the likelihood score for the given set of ions- Parameters:
ions- The distinct ions for which we want to optimize the likelihood score- Returns:
- the PotentialOptimizer containing the electronic chemical potential that maximizes the likelihood score for the given set of ions
-
optimizeLikelihood
public LikelihoodCalculator.PotentialOptimizer optimizeLikelihood(IonFactory.Ion[] ions, double initialFermiLevel) Finds the electronic chemical potential that maximizes the likelihood score for the given set of ions- Parameters:
ions- The distinct ions for which we want to optimize the likelihood scoreinitialFermiLevel- The chemical potential at which we should start the optimization process- Returns:
- the electronic chemical potential that maximizes the likelihood score for the given set of ions
-
getIonTypeIndex
Returns the ion type index (used by this class) for ion types with the given symbol.- Parameters:
ionTypeSymbol- The symbol for the ion type- Returns:
- the ion type index (used by this class) for ion types with the given symbol.
-
getLikelihood
Calculates the likelihood score for a given set of ions at a given electronic chemical potential- Parameters:
fermiLevel- The given electronic chemical potentialallIons- The ions for which we are calculating the likelihood score- Returns:
- the likelihood score for a given set of ions at a given electronic chemical potential
-
optimizeLikelihood
Determine the electronic chemical potential that maximizes the likelihood score for the given entry- Parameters:
entry- The entry for which we will maximize the likelihood score- Returns:
- the electronic chemical potential that maximizes the likelihood score for the given entry
-
optimizeLikelihood
public LikelihoodCalculator.PotentialOptimizer optimizeLikelihood(String[] ionTypeIDs, double[] weights) Determine the electronic chemical potential that maximizes the likelihood score for the given ion type IDS, where weights indicate the composition of each ion type.- Parameters:
ionTypeIDs- The ion type IDs for which we are maximizing the likelihood score.weights- The compositions of each of the ion type ids, in the same order.- Returns:
- the electronic chemical potential that maximizes the likelihood score for the given ion type IDS, where weights indicate the composition of each ion type.
-
getAllOxidationStates
public LikelihoodStateSet[] getAllOxidationStates(String composition, double minAllowedLikelihood, int minNumberToReturn) Get all possible oxidation state assignments for the given composition, subject to the given constraints.- Parameters:
composition- The composition for which we want oxidation statesminAllowedLikelihood- The minimum allowed likelihood score for the returned states. Set this to something non-zero to improve performance.minNumberToReturn- The minimum number of states to return, even if some of those states have a likelihood score below minAllowedLikelihood- Returns:
- all possible oxidation state assignments for the given composition, subject to the given constraints.
-
getAllOxidationStates
public LikelihoodStateSet[] getAllOxidationStates(Composition composition, double minAllowedLikelihood, int minNumberToReturn) Returns an array possible oxidation state assignments for the given composition, subject to the given constraints.- Parameters:
composition- The composition for which we want oxidation statesminAllowedLikelihood- The minimum allowed likelihood score for the returned states. Set this to something non-zero to improve performance.minNumberToReturn- The minimum number of states to return, even if some of those states have a likelihood score below minAllowedLikelihood- Returns:
- an array possible oxidation state assignments for the given composition, subject to the given constraints.
-
getMinLikelihoodIndex
Return the index of the state set with the minimum likelihood score from the given list- Parameters:
list- The given list- Returns:
- the index of the state set with the minimum likelihood score from the given list
-
getLikelyOxidationStates
Description copied from class:OxidationStateCalculatorCalculate the most likely oxidation states for the given ion types with the given composition.- Specified by:
getLikelyOxidationStatesin classOxidationStateCalculator- Parameters:
ionTypeIDs- The IDS of the ion types.weights- The composition of each ion type, ordered in the way that corresponds to the ordering of ionTypeIDs.- Returns:
- the most likely oxidation states for the given ion types with the given composition.
-
getKnownOxidationStates
Get a an array of all ions known to this calculator- Returns:
- a an array of all ions known to this calculator
-
getIonTypeSymbol
Get the ion type symbol corresponding to the given index- Parameters:
ionTypeIndex- The given ion type index- Returns:
- the ion type symbol corresponding to the given index
-
numIonTypes
public int numIonTypes()Returns the number of ion types known to this calculator- Returns:
- the number of ion types known to this calculator
-
numOxidationStates
public int numOxidationStates(int ionTypeIndex) Returns the number of oxidation states known to this calculator for the ion type with the given index- Parameters:
ionTypeIndex- The given ion type index- Returns:
- the number of oxidation states known to this calculator for the ion type with the given index
-
getOxidationStates
Returns the oxidation states known to this calculator for the ion type with the given symbol- Parameters:
ionTypeSymbol- The given symbol- Returns:
- the oxidation states known to this calculator for the ion type with the given symbol
-
getOxidationState
public int getOxidationState(int ionTypeIndex, int stateNum) Returns the stateNum'th oxidation state for the ion type with the given index- Parameters:
ionTypeIndex- The given ion type indexstateNum- The number of the oxidation state to return- Returns:
- the stateNum'th oxidation state for the ion type with the given index
-
getParameter
public double getParameter(int ionTypeIndex, int paramNumForIonType) Return the paramNumForMolecule'th parameter for the ion type with the given index- Parameters:
ionTypeIndex- The given ion type indexparamNumForIonType- The parameter number for this ion type- Returns:
- the paramNumForMolecule'th parameter for the ion type with the given index
-
getParameters
public double[] getParameters(int ionTypeIndex) Returns the parameters for the ion type with the given index- Parameters:
ionTypeIndex- The given ion type index- Returns:
- the parameters for the ion type with the given index
-