pygsti.extras.drift.probtrajectory
¶
Functions for Fourier analysis of equally spaced timeseries data
Module Contents¶
Classes¶
Encapulates a timedependent probability distribution, as a sum of timedependent basis functions. 

Encapulates a timedependent probability distribution that is actually a constant. 

Encapulates a timedependent probability distribution that is parameterized as a 
Functions¶

Returns x * log(p) where p is bound within (0,1], with adjustments at the boundaries that are useful in 

The negative loglikelihood of a ProbTrajectory, modelling a timedependent probability distribution. 

The negative loglikelihood of varying probabilities probs, evaluated for the data streams 

Implements maximum likelihood estimation over a model for a timeresolved probabilities trajectory, 

Reduces the amplitudes in a CosineProbTrajectory model until the model is valid, i.e., all probabilities 
 class pygsti.extras.drift.probtrajectory.ProbTrajectory(outcomes, hyperparameters, parameters)¶
Bases:
object
Encapulates a timedependent probability distribution, as a sum of timedependent basis functions.
 copy(self)¶
 abstract basisfunction(self, i, times)¶
The ith basis function of the model, evaluated at the times in `times.
* Defined in a derived class *
 Parameters
i (Type specified by derived class.) – The basis function specified by the hyperparameter i. This method should expect all possible hyperparameter values (often ints in some range, or a float) as this input
times (list) – The times to evaluate the basis function at.
 Returns
list – The values of the basis function at the specified times.
 set_hyperparameters(self, hyperparameters, parameters)¶
Sets the hyperparameters – i.e., defines a new parameterized model – and the parameters (see init for details).
 set_parameters(self, parameters)¶
Sets the parameters of the model (see init for details).
 set_parameters_from_list(self, parameterslist)¶
Sets the parameters of the model from a list
 Parameters
parametersaslist (list) – The new parameter values as a list, where the first len(self.hyperparameters) values are the parameter values for the first outcome (the first element of self.outcomes), the second set of len(self.hyperparameters) values are for the second outcome in this list, and so on, up to the second last value of self.outcomes.
 Returns
None
 parameters_as_list(self)¶
Returns the parameters as a list, in the same format as when input to set_parameters_from_list. See the docstring of that method for more info.
 parameters_copy(self)¶
Returns the values of the parameters, in the dictionary form in which it is internally stored.
 probabilities(self, times, trim=True)¶
Returns the probability distribution for each time in times.
 Parameters
times (list) – A list of times, to return the probability distributions for.
time (bool, optional) – Whether or not to set probability > 1 to 1 and probabilities < 0 to 0. If set to True then there is no guarantee that the probabilities will sum to 1 at all times anymore.
 Returns
dict – A dictionary where the keys are the possible outcomes, and the value for a key is a list (of the same lengths as times) containing the probability for that outcome at the times in times.
 class pygsti.extras.drift.probtrajectory.ConstantProbTrajectory(outcomes, probabilities)¶
Bases:
ProbTrajectory
Encapulates a timedependent probability distribution that is actually a constant. Useful when wanting to encode a constant probability distribution in a way that can be used consistently with any other ProbTrajectory object.
 basisfunction(self, i, times)¶
 class pygsti.extras.drift.probtrajectory.CosineProbTrajectory(outcomes, hyperparameters, parameters, starttime, timestep, numtimes)¶
Bases:
ProbTrajectory
Encapulates a timedependent probability distribution that is parameterized as a sum of cosines. Specifically, it is parameterized as the sum of the TypeII DCT basis functions.
 basisfunction(self, i, times)¶
The ith TypeII DCT basis function, evaluated at the specified times, where the DCT basis functions under consideration are defined by the time parameters set in the initialization.
The normalization of the functions is such that the max/min of each function is +1/1.
 Parameters
i (int) – The frequency index of the DCT basis function.
times (list) – The times to evaluate the basis function at
 Returns
array – The value of the basis function at the specified times.
 pygsti.extras.drift.probtrajectory._xlogp_rectified(x, p, minp=0.0001, maxp=0.999999)¶
Returns x * log(p) where p is bound within (0,1], with adjustments at the boundaries that are useful in minimization algorithms.
 pygsti.extras.drift.probtrajectory.negloglikelihood(probtrajectory, clickstreams, times, minp=0.0, maxp=1.0)¶
The negative loglikelihood of a ProbTrajectory, modelling a timedependent probability distribution.
 Parameters
model (ProbTrajectory) – The model to find the loglikelihood of.
data (dict) – The data, consisting of a counts timeseries for each measurement outcome. This is a dictionary whereby the keys are the outcome labels and the values are list (or arrays) giving the number of times that measurement outcome was observed at the corresponding time in the times list.
times (list or array) – The times associated with the data. The probabilities are extracted from the model at these times, using the model.get_probabilites method .
minp (float, optional) – A positive value close to zero. The value of p below which x*log(p) is approximated using a Taylor expansion (used to smooth out the parameter boundaries and obtain better fitting performance). The default value of 0. give the true loglikelihood.
maxp (float, optional) – A positive value close to and <= 1. The value of p above which x*log(p) the boundary on p being <= 1 is enforced using a smooth, quickly growing function. If set to 1. it gives the true loglikelihood.
 Returns
float – The loglikehood of the model given the timeseries data.
 pygsti.extras.drift.probtrajectory.probsdict_negloglikelihood(probs, clickstreams, minp=0.0, maxp=1.0)¶
The negative loglikelihood of varying probabilities probs, evaluated for the data streams in clickstreams.
 Parameters
probs (dict) – A dictionary where the keys are the outcome strings in the clickstream (its keys) and the value for an outcome is the timedependent probability list for that outcome, at the times associated with the data in the clickstreams.
clickstreams (dict) – A dictionary where the keys are the different measurement outcomes, and the values are lists that give counts for that measurement outcome.
 Returns
float – The negative logilikelihood of the probability trajectories given the clickstream data.
 pygsti.extras.drift.probtrajectory.maxlikelihood(probtrajectory, clickstreams, times, minp=0.0001, maxp=0.999999, method='NelderMead', return_opt_output=False, options={}, verbosity=1)¶
Implements maximum likelihood estimation over a model for a timeresolved probabilities trajectory, and returns the maximum likelihood model.
 Parameters
model (ProbTrajectory) – The model for which to maximize the likelihood of the parameters. The value of the parameters in the input model is used as the seed.
clickstreams (dict) – The data, consisting of a counts timeseries for each measurement outcome. This is a dictionary whereby the keys are the outcome labels and the values are list (or arrays) giving the number of times that measurement outcome was observed at the corresponding time in the times list.
times (list or array) – The times associated with the data. The probabilities are extracted from the model at these times (see the model.get_probabilites method), to implement the model parameters optimization.
minp (float, optional) – A positive value close to zero. The value of p below which x*log(p) is approximated using a Taylor expansion (used to smooth out the parameter boundaries and obtain better fitting performance). The default value should be fine.
maxp (float, optional) – A positive value close to and <= 1. The value of p above which x*log(p) the boundary on p being <= 1 is enforced using a smooth, quickly growing function. The default value should be fine.
method (str, optional) – Any value allowed for the method parameter in scipy.optimize.minimize().
verbosity (int, optional) – The amount of print to screen.
return_opt_output (bool, optional) – Whether or not to return the output of the optimizer.
 Returns
ProbTrajectory – The maximum likelihood model returned by the optimizer.
if return_opt_output –
 optout
The output of the optimizer.
 pygsti.extras.drift.probtrajectory.amplitude_compression(probtrajectory, times, epsilon=0.0, verbosity=1)¶
Reduces the amplitudes in a CosineProbTrajectory model until the model is valid, i.e., all probabilities are within [0, 1]. Also rectifies any of the constant components of the probability trajectories that are slightly outside [0, 1].
 Parameters
probtrajectory (CosineProbTrajectory) – The model on which to perform the amplitude reduction
times (list) – The times at which to enforce the validity of the model (this algorithm does not guarantee that the probabilities will be within [0, 1] at all times in the reals).
epsilon (float, optional) – The amplitudes are compressed so that all the probabilities are within [0+epsilon,1epsilon] at all times. Setting this to be larger than 0 can be useful as it guarantees that the resultant probability trajectory has a nonzero likelihood.
 Returns
CosineProbTrajectory – The new model, that may have had the amplitudes reduced
Bool – Whether or not the function did anything nontrivial, i.e, whether any compression was required.