java.lang.Object
Localiser.algorithms.genericLocaliser.MCMC.MCMC
All Implemented Interfaces:
MinimisationAlgorithm

public class MCMC extends Object implements MinimisationAlgorithm
Markov chain Monte Carlo (MCMC) is a minimisation technique used widely in a variety of field, from finding exo planets, to solving complex intergals.

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
  • Constructor Details

    • MCMC

      public MCMC()
      Constructor for MCMC algorithm.
    • MCMC

      public MCMC(MCMCParams2 mCMCParams)
      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

      public ArrayList<MCMCResult> runMCMCAlgorithm()
      Run the MCMC algorithm.
    • clusterAnalysis

      public ArrayList<MCMCResult> clusterAnalysis(ArrayList<MCMC.ChainResult> meanArray)
      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

      public MCMC.ChainResult analyseChain(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.

      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

      public MCMCResult averageChains(ArrayList<MCMC.ChainResult> data)
      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

      public void setSettings(MCMCParams2 settings)
      Set a new settings class for MCMC.
      Parameters:
      settings - - new MCMCMParams settings class.
    • getSettings

      public MCMCParams2 getSettings()
      Get settings class for MCMC.
      Returns:
    • getChi2Function

      public MinimisationFunction getChi2Function()
      Get the chi2 class for this algorithm.
      Returns:
      the chi2 class for the algortihm
    • setChi2

      public void setChi2(MinimisationFunction chi2)
      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

      public void setMinimisationFunction(MinimisationFunction minFunc)
      Description copied from interface: MinimisationAlgorithm
      Set the minimisation function. This sets up the problem for the algorithm to solve.
      Specified by:
      setMinimisationFunction in interface MinimisationAlgorithm
      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 interface MinimisationAlgorithm
      Returns:
      true if the algorithm competed sucessfully.
    • getMCMCResults

      public ArrayList<MCMCResult> 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 interface MinimisationAlgorithm
      Returns:
      the result
    • getErrors

      public LocaliserError[] 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 interface MinimisationAlgorithm
      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 interface MinimisationAlgorithm
      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 interface MinimisationAlgorithm
      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 interface MinimisationAlgorithm
    • getSettingsPane

      public LocaliserPane<?> getSettingsPane()
      Description copied from interface: MinimisationAlgorithm
      A settings pane for the algorithm if it has user changeable parameters.
      Specified by:
      getSettingsPane in interface MinimisationAlgorithm
      Returns:
      a settings pane.
    • clearResults

      public void clearResults()
      Clear the results from the localiser.