leaspy.algo.others.constant_prediction_algo.ConstantPredictionAlgorithm

class ConstantPredictionAlgorithm(settings)

Bases: AbstractAlgo

ConstantPredictionAlgorithm is the algorithm that outputs a constant prediction

It is associated to ConstantModel

TODO: it should be a child of AbstractPersonalizeAlgorithm (refactoring needed)

Parameters:
settingsAlgorithmSettings

The settings of constant prediction algorithm. It may define prediction_type (str):

  • 'last': last value seen during calibration (even if NaN) [default],

  • 'last_known': last non NaN value seen during calibration*§,

  • 'max': maximum (=worst) value seen during calibration*§,

  • 'mean': average of values seen during calibration§.

\* <!> depending on features, the last_known / max value may correspond to different visits.
§ <!> for a given feature, value will be NaN if and only if all values for this feature were NaN.
Raises:
LeaspyAlgoInputError

If any invalid setting for the algorithm

Methods

load_parameters(parameters)

Update the algorithm's parameters by the ones in the given dictionary.

run(model, *args[, return_loss])

Main method, run the algorithm.

run_impl(model, dataset)

Main method, refer to abstract definition in run().

set_output_manager(output_settings)

Not implemented.

load_parameters(parameters: dict)

Update the algorithm’s parameters by the ones in the given dictionary. The keys in the io which does not belong to the algorithm’s parameters keys are ignored.

Parameters:
parametersdict

Contains the pairs (key, value) of the wanted parameters

Examples

>>> settings = leaspy.io.settings.algorithm_settings.AlgorithmSettings("mcmc_saem")
>>> my_algo = leaspy.algo.fit.tensor_mcmcsaem.TensorMCMCSAEM(settings)
>>> my_algo.algo_parameters
{'n_iter': 10000,
 'n_burn_in_iter': 9000,
 'eps': 0.001,
 'L': 10,
 'sampler_ind': 'Gibbs',
 'sampler_pop': 'Gibbs',
 'annealing': {'do_annealing': False,
  'initial_temperature': 10,
  'n_plateau': 10,
  'n_iter': 200}}
>>> parameters = {'n_iter': 5000, 'n_burn_in_iter': 4000}
>>> my_algo.load_parameters(parameters)
>>> my_algo.algo_parameters
{'n_iter': 5000,
 'n_burn_in_iter': 4000,
 'eps': 0.001,
 'L': 10,
 'sampler_ind': 'Gibbs',
 'sampler_pop': 'Gibbs',
 'annealing': {'do_annealing': False,
  'initial_temperature': 10,
  'n_plateau': 10,
  'n_iter': 200}}
run(model: AbstractModel, *args, return_loss: bool = False, **extra_kwargs) Any

Main method, run the algorithm.

TODO fix proper abstract class method: input depends on algorithm… (esp. simulate != from others…)

Parameters:
modelAbstractModel

The used model.

datasetDataset

Contains all the subjects’ observations with corresponding timepoints, in torch format to speed up computations.

return_lossbool (default False), keyword only

Should the algorithm return main output and optional loss output as a 2-tuple?

Returns:
Depends on algorithm class: TODO change?
run_impl(model: ConstantModel, dataset: Dataset)

Main method, refer to abstract definition in run().

Parameters:
modelConstantModel

A subclass object of leaspy ConstantModel.

datasetDataset

Dataset object build with leaspy class objects Data, algo & model

Returns:
individual_parametersIndividualParameters

Contains individual parameters.

noise_stdfloat

TODO: always 0 for now

set_output_manager(output_settings)

Not implemented.