Likelihood Functor¶
-
class LikelihoodFunctor¶
A function-like class which acts as a wrapper for the function calls used by the gradient descent algorithm and the necessary message passing for communication with the workers. The overloaded operator () allows the class to be called as a function, but it can store data preventing the need for reloading the data or passing huge numbers of arguments.
Public Functions
-
inline LikelihoodFunctor(const std::vector<std::vector<Star>> &data, int maxBatches)¶
Constructor class initialises L and MaxBatches.
- Parameters
data – The data, arranged according to the minibatching schedule.
maxBatches – the original number of minibatches which are used
-
inline std::vector<double> Initialise(std::string loadPosition, std::string outdir)¶
A separate chunk of almost-constructor, initialising the remaning components + getting the starting position. An argument could be made that this should be part of the constructor, but it is kept separate so that you can re-run the optimisation with a different starting position without destroying the object, you can just reinitialise it.
- Parameters
loadPosition – The place for Efficiency to check for valid starting positions
outdir – The output directory where savefiles are located
- Returns
The EfficiencyVector::RawPosition component of Efficiency, the default starting point for the optimiser
-
void Calculate(const std::vector<double> &x, int batchID, int effectiveBatches)¶
A required function call for templating values of the ADABADAM::Optimizer class, and the main work loop of the class. Sends MPI messages to the workers and instructs them to calculate the next value of their LogLikelihood object. Then uses MPI to collect these objects, call the associated Priors and then populate the Value and Gradient objects for the optimiser to use.
- Parameters
x – The new value of the EfficiencyVector::RawPosition, the current proposed operating efficiency
batchID – The current (randomised) batchID from which to draw the population of stars used to calculate the likelihood. Can be 0 <= batchID < effectiveBatches
effectiveBatches – The current number of minibatches used by the optimiser
- Returns
No explicit return, but populates the Value and Gradient objects
-
void Calculate(const std::vector<double> &x)¶
An overloading alias in case minibatching is ever disabled: calls Calculate(x,0,1)
-
void SavePosition(bool finalSave, int saveStep, bool uniqueSave)¶
A required function call for templating values of the ADABADAM::Optimizer class. Saves the current value of Efficiency to file via the EfficiencyVector::Save() call.
Public Members
-
unsigned int LoopID¶
The total number of calls that have been passed to DistributeCalculations()
-
EfficiencyVector Efficiency¶
The current proposed efficiency vector.
-
double Value¶
A required member for templating values of the ADABADAM::Optimizer class. After Calculate() is called, holds current value of the Functor. Note that we perform an explicit renormalisation of this value, dividing through by the number of stars used to calculate it (hence it is the approximate per-star Value). In addition, as ADABADAM attempts to minimise functions, whilst the Likelihood returns a value we wish to maximise, so this is the negation of that value.
-
std::vector<double> Gradient¶
A required member for templating values of the ADABADAM::Optimizer class. After Calculate() is called, holds current value of the Gradient. Note that we perform an explicit renormalisation of this value, dividing through by the number of stars used to calculate it (hence it is the approximate per-star Value). In addition, as ADABADAM attempts to minimise functions, whilst the Likelihood returns a value we wish to maximise, so this value is equal to the product of -1 and EfficiencyVector::RawGradient.
Private Members
-
LogLikelihoodPrior L¶
Allows the calling process to calculate its own portion of the Likelihood, and as a guaranteed priveleged worker, also can call the associated priors.
-
int MaxBatches¶
The maximum number of minibatches which are used (and which therefore define the structure of LogLikelihoodPrior::Data)
-
inline LikelihoodFunctor(const std::vector<std::vector<Star>> &data, int maxBatches)¶