LogLikelihood

class LogLikelihood

This class holds the data and functions necessary to calculate log p(data | x), where x is the provided EfficiencyVector. The majority of the guts + internal workings of the class are hidden away in the LikelihoodData.

Subclassed by LogLikelihoodPrior

Public Functions

LogLikelihood(const std::vector<std::vector<Star>> &data)

Constructor function.

Parameters

data – A vector of Star objects arranged according to the minibatching schedule.

void Calculate(const EfficiencyVector &position, int batchID, int effectiveBatches, int maxBatches)

The key function: executes a single minibatch calculation of the loglikelihood. Loops over each star and calls PerStarContribution()

Parameters
  • position – The current EfficiencyVector

  • batchID – The minibatch to be executed

  • effectiveBatches – The current number of active minibatches

  • maxBatches – The original number of active minibatches

Returns

Assigns the value of L to Value, and the associated gradient to Gradient

Public Members

double Value

The last-calculated value of the Calculate() function.

std::vector<double> Gradient

The last-calculated gradient of the Calculate() function with respect to the associated position this is eventually summed into EfficiencyVector::TransformedGradient.

int StarsUsed

The number of stars within the last-called minibatch.

Protected Functions

void Reset()

Cleans the Value and Gradient to make way for a new loop.

void PerStarContribution(int batchId, int starID, const EfficiencyVector &position)

Calculates the likelihood contribution of an individual star, given the proposed efficiency vector. The results are accumulated into Value and Gradient.

Parameters
  • batchId – the current id of the minibatch loop

  • starId – the id of the star within the minibatch

  • position – the proposed effiency vector

void GeneratePs(const Star *candidate, const EfficiencyVector &position)

Given a star, calculate the temporal and spatial probabilities associated with it, following our probability model .

Parameters
  • candidate – A pointer to the star being evaluated

  • position, the – current proposed efficency vector

void GenerateContribution(const Star *candidate)

After GeneratePs() has produced probabilities, call either the PoissonBinomial function or the NormalApproximation

Parameters

candidate – A pointer to the star being evaluated

void AssignGradients(const Star *candidate)

Translates the temporary gradients stored in Data, via the chain rule, into results appropriate for summing into Gradient

void NormalContribution(const Star *candidate)

Calculates the p(k = K | {p_i}) for the NormalApproximation to the PoissonBinomial. Here {p_i} is the set of probabilities generated by GeneratePs() and K is Star::nMeasure for the candidate.

Parameters

candidate – A pointer to the star being evaluated

void PoissonContribution(const Star *candidate)

Calculates the p(k = K | {p_i}) for the PoissonBinomial, with a small truncation to the calculation. Here {p_i} is the set of probabilities generated by GeneratePs() and K is Star::nMeasure for the candidate.

Parameters

candidate – A pointer to the star being evaluated

void ExactPoissonContribution(const Star *candidate)

Calculates the p(k = K | {p_i}) for the PoissonBinomial, without the truncation of PoissonContribution(). This is only called if one of the {p_i}s is close to zero or one, or the approximation otherwise results in a divergence.

Parameters

candidate – A pointer to the star being evaluated

Protected Attributes

LikelihoodData Data

The storage for most of the Gnarly bits of this function, hides a lot of nasty stuff away in here.