public abstract class PhaseDiagramStatistics
extends java.lang.Object
implements java.io.Serializable
Practical Guide:
Disregarding actually informing you what is being computed. Use this class by:
Theory Behind this Method:
The simple goal of this method is to calculate correlations between two events, like a phase diagram having a B2 compound and one of its constituents being Fe. This is accomplished by representing each phase diagram by the following variable vector:
With this description, one can calculate the probability of some condition being true for a compound in a certain phase diagram by calculating:
In order make this computable, Fisher et al used the following approximation (known as the Morita cumulant expansion):
Applied to the above condition probability formula, this allows the following simplification:
All of the probabilities necessary to calculate are relatively straightforward to compute. The only other important thing to note is a slight adjustment to the calculated probabilities that ensures that P(x ∩ y) is always non-zero, but is always some small positive value. This (very clever) modification allows for P(condition | ...) to be non-zero when the condition and only one of the variables have not yet been observed to exist together before. Otherwise, the corresponding g(x,y) will be zero and the calculated probability would be zero - even if all other variables have favorable correlations.
Implementation Guide:
Every operation necessary for this class except three are implemented in the base class. In order to make a functioning version, one needs to implement:
Modifier and Type | Field and Description |
---|---|
protected java.util.List<org.apache.commons.lang3.tuple.Pair<double[],java.util.List<java.lang.String>>> |
CommonCompositions
List of common compositions and the names of prototypes found at that composition.
|
protected java.util.Comparator<org.apache.commons.lang3.tuple.Pair<double[],java.util.List<java.lang.String>>> |
CompositionComparator
Used to sort CommonCompositions.
|
protected double |
ElementProbability
Probability that each element appears in a phase diagram
|
protected double |
MinDistance
Minimum Manhattan distance between compositions to be considered equal
|
protected int |
NComponents
Order of phase diagram
|
protected int |
NCompounds
Number compounds stored by this object
|
protected double[][] |
StructureProbability
For each composition, probability of each structure existing in a phase diagram.
|
Modifier | Constructor and Description |
---|---|
protected |
PhaseDiagramStatistics()
Create a blank instance of this class.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addCompositionBin(double[] x,
java.util.List<java.lang.String> Prototypes)
Adds all permutations (i.e.
|
protected void |
calculateProbabilities()
Calculate the probability of each compound and element being in a phase
diagram.
|
protected abstract void |
calculateStructureProbabilities()
Calculate the probability of each prototype appearing in a phase diagram.
|
protected boolean |
compositionsAreEqual(double[] a,
double[] b)
Determine whether two compositions are equal (within MinDistance).
|
double[] |
createLookupKey(double[] frac)
Extend the length of a composition by padding the end with zeros.
|
double |
evaluateProbability(PrototypeEntry entry,
double[][] cumulant,
double conditionProb)
Given a prototype entry, generate its probability of having a certain condition.
|
int |
getClosestBin(double[] key)
Find the composition bin in CommonCompositions) that has the same number of elements
and is the closest
|
protected void |
getCommonCompositions(java.util.Map<CompositionEntry,java.lang.String> Compounds,
int[] DesiredNBins)
Determine most common compositions from all structures.
|
protected abstract int[] |
getCompoundVector(int[] sites)
Given a list of elements on each site of a structure, determine which prototypes
exist on each site of the corresponding phase diagram.
|
double[][] |
getCumulants(PrototypeDataset trainingData,
boolean[] hasCondition)
For a certain training set, calculate the cumulant function between a condition
being true and each variable being any allowed condition.
|
java.util.List<java.lang.String> |
getPrototypeNames(double[] fracs)
Get list of all known prototype structures at a composition.
|
int[] |
getVariableVector(PrototypeEntry compound)
For a certain prototype, get a vector that describes the characteristics of its phase diagram.
|
protected java.util.Map<CompositionEntry,java.lang.String> |
importCompoundDataset(java.lang.String filename)
Load in file containing composition and prototypes of all known compounds.
|
void |
importKnownCompounds(java.util.Map<CompositionEntry,java.lang.String> compounds,
int DiagramOrder,
int[] DesiredNBins)
Import list of known compounds into phase diagram object
|
void |
importKnownCompounds(java.lang.String Filename,
int DiagramOrder,
int[] DesiredNBins)
Import all known compounds into phase diagram object
|
int |
NComponents()
Get the order of the phase diagram (number of elements).
|
int |
NCompositions() |
int |
NCompounds()
Get number of compounds stored by this object.
|
static void |
orderComposition(int[] elems,
double[] frac)
Ensure that a composition is sorted such that elements are listed in
ascending order by atomic fraction
|
java.lang.String |
printCumulants(double[][] cumulants,
int toPrint)
Print out values of each cumulant and their names.
|
protected abstract void |
processCompounds(java.util.Map<CompositionEntry,java.lang.String> compounds)
Given a list of compounds, mark which phase diagrams they appear in.
|
int |
roundComposition(double[] frac)
Round a compound such that it's composition exactly equals that of a common
composition, and return the index of that composition
|
protected final double MinDistance
protected int NComponents
protected double ElementProbability
protected java.util.List<org.apache.commons.lang3.tuple.Pair<double[],java.util.List<java.lang.String>>> CommonCompositions
protected double[][] StructureProbability
protected final java.util.Comparator<org.apache.commons.lang3.tuple.Pair<double[],java.util.List<java.lang.String>>> CompositionComparator
protected int NCompounds
protected PhaseDiagramStatistics()
public static void orderComposition(int[] elems, double[] frac)
elems
- Elements present in samplefrac
- Fractions of each element presentpublic int NCompounds()
public int NComponents()
protected boolean compositionsAreEqual(double[] a, double[] b)
a
- Composition #1b
- Composition #2public int[] getVariableVector(PrototypeEntry compound)
compound
- Compound of interestprotected void calculateProbabilities()
public void importKnownCompounds(java.lang.String Filename, int DiagramOrder, int[] DesiredNBins)
Filename
- Path to a file containing all known compoundsDiagramOrder
- Number of constituents in phase diagram (2 for binary, etc)DesiredNBins
- Number of composition bins for each number of compounds. Should
be an array where x[i] is the number of desired composition bins for compositions
with i+1 components.public void importKnownCompounds(java.util.Map<CompositionEntry,java.lang.String> compounds, int DiagramOrder, int[] DesiredNBins)
compounds
- Map of composition to prototype nameDiagramOrder
- Number of constituents in phase diagram (2 for binary, etc)DesiredNBins
- Number of composition bins for each number of compounds. Should
be an array where x[i] is the number of desired composition bins for compositions
with i+1 components.protected abstract void calculateStructureProbabilities()
protected java.util.Map<CompositionEntry,java.lang.String> importCompoundDataset(java.lang.String filename)
filename
- Path to data filepublic int NCompositions()
protected void getCommonCompositions(java.util.Map<CompositionEntry,java.lang.String> Compounds, int[] DesiredNBins)
Compounds
- Map of compound compositions and prototype namesDesiredNBins
- Number of composition bins to have for each number of constituents.
x[0] is for binaries, x[1] for ternaries, and so on...protected void addCompositionBin(double[] x, java.util.List<java.lang.String> Prototypes)
x
- Stoichiometry to be added (must be sorted in ascending order)Prototypes
- List that holds names of all prototypes with this stoichiometry (does not have to contain anything yet)public double[][] getCumulants(PrototypeDataset trainingData, boolean[] hasCondition)
trainingData
- Data containing examples on which to train cumulant functionshasCondition
- For each entry in the training set, whether whatever condition is truepublic double evaluateProbability(PrototypeEntry entry, double[][] cumulant, double conditionProb)
entry
- Entry to evaluatecumulant
- Cumulant function values generated by getCumulants(PrototypeDataset, boolean[])conditionProb
- Probability that a random entry has the conditionprotected abstract int[] getCompoundVector(int[] sites)
sites
- Which elements are on each siteprotected abstract void processCompounds(java.util.Map<CompositionEntry,java.lang.String> compounds)
compounds
- Map of phase diagrams to be addedpublic int getClosestBin(double[] key)
key
- Composition of a compound. Defined by the fraction of each element present, first element is the
number of elements, the remainder is the fraction of each elementpublic double[] createLookupKey(double[] frac)
frac
- Fraction to be extendpublic java.lang.String printCumulants(double[][] cumulants, int toPrint)
cumulants
- Cumulants to be printedtoPrint
- Number of the strongest cumulants to print. -1 for all of thempublic int roundComposition(double[] frac)
frac
- Atomic fractions of elements in the compound (will be rounded
to match that of the closest bin)public java.util.List<java.lang.String> getPrototypeNames(double[] fracs)
fracs
- Fraction of elements in