Class MCMC
- All Implemented Interfaces:
MinimisationAlgorithm
This is a highly computationally intensive localisation algorithm based on MCMC methods. For a good description see; The Transit Light Curve (TLC) Project.I. Four Consecutive Transits of the Exoplanet XO-1b Matthew J. Holman1
A chi2 function is required to define the minimisation problem.
Multiple MCMC chains can and should be run. These are executed on different threads to take advantage of multi-core processing if possible. Even so, a large number of chains or large observation set can result in significant processing times.
Results are analysed for convergence and final locations packed into an MCMCTDResults class.
- Author:
- Jamie Macaulay
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Class to hold the results of a single Markov chain. -
Field Summary
Fields inherited from interface Localiser.algorithms.genericLocaliser.MinimisationAlgorithm
ALGORITHM_FINISHED, ALGORITHM_FINISHED_ERR, ALGORITHM_RUNNING, PREPARING_ALGORTIHM
-
Constructor Summary
ConstructorDescriptionMCMC()
Constructor for MCMC algorithm.MCMC
(MCMCParams2 mCMCParams) Constructor for the MCMC algorithm -
Method Summary
Modifier and TypeMethodDescriptionanalyseChain
(MCMC.ChainResult chainResult) Take an ArrayList of the Markov chain jumps and chi-squared values of each jump and calculate average values and the standard deviation for all dimensions.Take different MCMC chains and average the results.void
Clear the results from the localiser.clusterAnalysis
(ArrayList<MCMC.ChainResult> meanArray) Perform a cluster analysis of results.double[][]
Used in testing the localiser error.double[]
getChi2()
The chi2 value for each resultGet the chi2 class for this algorithm.Get the errors.Get MCMC results.double[]
getNewJumpPoint
(double[] chainPos) Calculates a random new Co-Ordinate, 3D Cartesian or Cylindrical space;double[][]
Get the result.Get settings class for MCMC.A settings pane for the algorithm if it has user changeable parameters.boolean
A progress function which can be used to update different threads.ArrayList<double[]>
kMeansAnalysis
(ArrayList<MCMC.ChainResult> mcmcChains, int attempts, int iterations) Sometimes multiple chains will converge to different final distributions.mCMC
(MinimisationFunction chi2) Run MCMC algortihm.void
notifyStatus
(int status, double progress) A progress function which can be used to update different threads.double
randNGenerator
(double[] limits) Get a random number betwene two limits.double
Generate a random number from a Gaussian distribution.boolean
Run the algorithm to find a solution to the set minimisation function.Run the MCMC algorithm.void
setChi2
(MinimisationFunction chi2) Set the chi2 value for the MCMC algortihm.void
Set the minimisation function.void
setSettings
(MCMCParams2 settings) Set a new settings class for MCMC.
-
Constructor Details
-
MCMC
public MCMC()Constructor for MCMC algorithm. -
MCMC
Constructor for the MCMC algorithm- Parameters:
mCMCParams
- - the MCMC settings to use.
-
-
Method Details
-
mCMC
Run MCMC algortihm. This starts a single Markov chain at a random location.- Parameters:
chi2
- - the chi2 function to compare simulation data to observed data.- Returns:
- the results from the chain.
-
getNewJumpPoint
public double[] getNewJumpPoint(double[] chainPos) Calculates a random new Co-Ordinate, 3D Cartesian or Cylindrical space;- Parameters:
chainPos
- - the position of the chain in ndimensional space.- Returns:
- the new jump point to tests
-
runMCMCAlgorithm
Run the MCMC algorithm. -
clusterAnalysis
Perform a cluster analysis of results. The clustering algorithm used is determined by the MCMC localiser params. -
kMeansAnalysis
public ArrayList<double[]> kMeansAnalysis(ArrayList<MCMC.ChainResult> mcmcChains, int attempts, int iterations) Sometimes multiple chains will converge to different final distributions. If this is the case the results must be clustered, otherwise the final answer will simply be the mean of the two different distributions. Here a 3D k-means clustering algorithm is used in x, y and z . First, nk random points are assigned in space based on the start dispersion. Next, all chains are clusters corresponding to their euclidian distance from these two random points. The random points then move to the centroid of their corresponding clusters. The process repeats 'int iterations' times by which time it is likely convergence will have occurred. Clustering is attempted 'attempts' times from different random positions.See: https://en.wikipedia.org/wiki/K-means_clustering
- Parameters:
attempts
- - the number of clustering attempts. Each attempt starts at a random location for each cluster. All attempts are averaged.iterations
- - the number of iterations for each attempt. Should be high enough for each kmeans cluster to converge to a result.chains
- - an array of single Markov chains with summary results (mean position, standard deviation etc.)- Returns:
- a list of cluster locations. i.e. where the clusters are centred. This is not a list of average positions of the chains within each cluster.
-
analyseChain
Take an ArrayList of the Markov chain jumps and chi-squared values of each jump and calculate average values and the standard deviation for all dimensions.The main task of this function are to 1) get rid of the burn in phase and 2) calculate the mean and standard deviation of where the chain has converged for all dimensions.
- Parameters:
chainResult
- : the result from a single Markov chain. The summary results are added to this class and this class is also returned by the function.- Returns:
- ChainResult with added summary of chain result added.
-
averageChains
Take different MCMC chains and average the results.- Parameters:
data
- - a list of MCMC results from a single Markov chain.- Returns:
- the average of all results packaged in a MCMCResult class.
-
createErrorData
public double[][] createErrorData()Used in testing the localiser error.- Returns:
- a set of random points centered on (0,0,0);
-
randomNGenerator
public double randomNGenerator()Generate a random number from a Gaussian distribution.- Returns:
- a random number from Gaussian distribution with a mean of zero and standard deviation of 1.
-
randNGenerator
public double randNGenerator(double[] limits) Get a random number betwene two limits. So for example a number between 5 and 20 would have standard deviation of 15. The random number generated form this standard deviation would then have 5 add to it.- Parameters:
limits
- - the min std and max std values the number should be between- Returns:
- the random number;
-
setSettings
Set a new settings class for MCMC.- Parameters:
settings
- - new MCMCMParams settings class.
-
getSettings
Get settings class for MCMC.- Returns:
-
getChi2Function
Get the chi2 class for this algorithm.- Returns:
- the chi2 class for the algortihm
-
setChi2
Set the chi2 value for the MCMC algortihm. This must be set before the algorithm is run.- Parameters:
chi2
- - the chi2 class to set. Compares simulation to obsetrved data.
-
setMinimisationFunction
Description copied from interface:MinimisationAlgorithm
Set the minimisation function. This sets up the problem for the algorithm to solve.- Specified by:
setMinimisationFunction
in interfaceMinimisationAlgorithm
- Parameters:
minFunc
- - the minimisation function specific to the problem whihc needs solved
-
runAlgorithm
public boolean runAlgorithm()Description copied from interface:MinimisationAlgorithm
Run the algorithm to find a solution to the set minimisation function. This- Specified by:
runAlgorithm
in interfaceMinimisationAlgorithm
- Returns:
- true if the algorithm competed sucessfully.
-
getMCMCResults
Get MCMC results. -
getResult
public double[][] getResult()Description copied from interface:MinimisationAlgorithm
Get the result. There maybe multiple results if ambiguities exist. The number of dimensions is defined in the minimisation function.- Specified by:
getResult
in interfaceMinimisationAlgorithm
- Returns:
- the result
-
getErrors
Description copied from interface:MinimisationAlgorithm
Get the errors. Should be the same number of dimensions as the result. If errors have not been calculated leave as null The number of dimensions is defined in the minimisation function.- Specified by:
getErrors
in interfaceMinimisationAlgorithm
- Returns:
- the errors in the result
-
notifyStatus
public void notifyStatus(int status, double progress) Description copied from interface:MinimisationAlgorithm
A progress function which can be used to update different threads.- Specified by:
notifyStatus
in interfaceMinimisationAlgorithm
- Parameters:
status
- - the current status flag.progress
- - the progress of the algorithm from 0 to 1.0.
-
getChi2
public double[] getChi2()Description copied from interface:MinimisationAlgorithm
The chi2 value for each result- Specified by:
getChi2
in interfaceMinimisationAlgorithm
- Returns:
- the chi2 value for each result.
-
hasParams
public boolean hasParams()Description copied from interface:MinimisationAlgorithm
A progress function which can be used to update different threads.- Specified by:
hasParams
in interfaceMinimisationAlgorithm
-
getSettingsPane
Description copied from interface:MinimisationAlgorithm
A settings pane for the algorithm if it has user changeable parameters.- Specified by:
getSettingsPane
in interfaceMinimisationAlgorithm
- Returns:
- a settings pane.
-
clearResults
public void clearResults()Clear the results from the localiser.
-