pygsti.objectivefns.objectivefns.TimeDependentPoissonPicLogLFunction#
- class TimeDependentPoissonPicLogLFunction(mdc_store, regularization=None, penalties=None, name=None, description=None, verbosity=0)#
Bases:
TimeDependentMDCObjectiveFunctionPoisson-picture delta log-likelihood function that can handle time-dependent circuits and data.
This objective function can handle time-dependent circuits - that is, circuits are treated as potentially time-dependent and mdl as well. This function currently doesn’t support much regularization or penalization.
Create a new MDCObjectiveFunction.
mdc_store is thought to be a normal MDC store, but could also be an evaluated one, in which case should we take enable_hessian from it?
Methods
__init__(mdc_store[, regularization, ...])Create a new MDCObjectiveFunction.
add_count_vectors([force])Ensure this store contains count and total-count vectors.
add_omitted_freqs([printer, force])Detect omitted frequencies (assumed to be 0) so we can compute objective fn correctly
approximate_hessian([paramvec])Compute an approximate Hessian of this objective function.
chi2k_distributed_qty(objective_function_value)Convert a value of this objective function to one that is expected to be chi2_k distributed.
compute_array_types(method_names, fsim)create_from(model, dataset, circuits[, ...])dlsvec([paramvec])The derivative (jacobian) of the least-squares vector.
dlsvec_percircuit([paramvec])Compute the jacobian of the sqrt(per-circuit) values given by
lsvec_percircuit().dpercircuit([paramvec])Compute the jacobian of the per-circuit contributions of this objective function.
dterms([paramvec])Compute the jacobian of the terms of the objective function.
fn([paramvec, stateless])Evaluate the value of this objective function.
fn_from_model(model)Evaluate this objective function when self.model is replaced by model, and then restore self.model before returning.
fn_local([paramvec, stateless])Evaluate the local value of this objective function.
hessian([paramvec])Compute the Hessian of this objective function.
jacobian([paramvec])Compute the Jacobian of this objective function.
lsvec([paramvec])Compute the least-squares vector of the objective function.
lsvec_percircuit([paramvec])Compute the square root of per-circuit contributions to this objective function.
The number of degrees of freedom in the data used by this objective function.
percircuit([paramvec])Compute the per-circuit contributions to this objective function.
set_penalties([cptp_penalty_factor, ...])Set penalties.
set_regularization([min_prob_clip, radius])Set regularization values.
terms([paramvec])Compute the terms of the objective function.
Attributes
A description of this objective function.
Name of this objective function.
opBasis- add_count_vectors(force=False)#
Ensure this store contains count and total-count vectors.
- add_omitted_freqs(printer=None, force=False)#
Detect omitted frequencies (assumed to be 0) so we can compute objective fn correctly
- approximate_hessian(paramvec=None)#
Compute an approximate Hessian of this objective function.
This is typically much less expensive than
hessian()and does not require that enable_hessian=True was set upon initialization. It computes an approximation to the Hessian that only utilizes the information in the Jacobian. Derivatives are takes with respect to model parameters.- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nParams, nParams) where nParams is the number of model parameters.
- Return type:
numpy.ndarray
- chi2k_distributed_qty(objective_function_value)#
Convert a value of this objective function to one that is expected to be chi2_k distributed.
- Parameters:
objective_function_value (float) – A value of this objective function, i.e. one returned from self.fn(…).
- Return type:
float
- dlsvec(paramvec=None)#
The derivative (jacobian) of the least-squares vector.
Derivatives are taken with respect to model parameters.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nElements,nParams) where nElements is the number of circuit outcomes and nParams is the number of model parameters.
- Return type:
numpy.ndarray
- dlsvec_percircuit(paramvec=None)#
Compute the jacobian of the sqrt(per-circuit) values given by
lsvec_percircuit().This jacobian is primarily useful for interfacing with a least-squares optimizer.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nCircuits, nParams) where nCircuits is the number of circuits and nParams is the number of model parameters (the circuits and model were specified when this objective function was constructed).
- Return type:
numpy.ndarray
- dpercircuit(paramvec=None)#
Compute the jacobian of the per-circuit contributions of this objective function.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nCircuits, nParams) where nCircuits is the number of circuits and nParams is the number of model parameters (the circuits and model were specified when this objective function was constructed).
- Return type:
numpy.ndarray
- dterms(paramvec=None)#
Compute the jacobian of the terms of the objective function.
The “terms” are the per-circuit-outcome values that get summed together to result in the objective function value. Differentiation is with respect to model parameters.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nElements,nParams) where nElements is the number of circuit outcomes and nParams is the number of model parameters.
- Return type:
numpy.ndarray
- fn(paramvec=None, stateless=False)#
Evaluate the value of this objective function.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
stateless (bool) – The callsequence triggered by this function can modify self.model. If stateless=True, then we restore self.model’s state before returning.
- Return type:
float
- fn_from_model(model)#
Evaluate this objective function when self.model is replaced by model, and then restore self.model before returning.
- Return type:
float
- fn_local(paramvec=None, stateless=False)#
Evaluate the local value of this objective function.
When the objective function’s layout is distributed, each processor only holds a portion of the objective function terms, and this function returns only the sum of these local terms. See
fn()for the global objective function value.- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
stateless (bool) – The callsequence triggered by this function can modify self.model. If stateless=True, then we restore self.model’s state before returning.
- Return type:
float
- hessian(paramvec=None)#
Compute the Hessian of this objective function.
Derivatives are takes with respect to model parameters.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nParams, nParams) where nParams is the number of model parameters.
- Return type:
numpy.ndarray
- jacobian(paramvec=None)#
Compute the Jacobian of this objective function.
Derivatives are takes with respect to model parameters.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nParams,) where nParams is the number of model parameters.
- Return type:
numpy.ndarray
- lsvec(paramvec=None)#
Compute the least-squares vector of the objective function.
This is the square-root of the terms-vector returned from
terms(). This vector is the objective function value used by a least-squares optimizer when optimizing this objective function. Note that the existence of this quantity requires that the terms be non-negative. If this is not the case, an error is raised.- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nElements,) where nElements is the number of circuit outcomes.
- Return type:
numpy.ndarray
- lsvec_percircuit(paramvec=None)#
Compute the square root of per-circuit contributions to this objective function.
These values are primarily useful for interfacing with a least-squares optimizer.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nCircuits,) where nCircuits is the number of circuits (specified when this objective function was constructed).
- Return type:
numpy.ndarray
- num_data_params()#
The number of degrees of freedom in the data used by this objective function.
- Return type:
int
- percircuit(paramvec=None)#
Compute the per-circuit contributions to this objective function.
These values collect (sum) together the contributions of the outcomes of a single circuit.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nCircuits,) where nCircuits is the number of circuits (specified when this objective function was constructed).
- Return type:
numpy.ndarray
- set_penalties(cptp_penalty_factor=0, spam_penalty_factor=0, errorgen_penalty_factor=0, forcefn_grad=None, shift_fctr=100, prob_clip_interval=(-10000, 10000))#
Set penalties.
- Parameters:
cptp_penalty_factor (float, optional) – The prefactor of a term that penalizes non-CPTP operations. Specifically, adds a cptp_penalty_factor * sqrt(tracenorm(choi_matrix)) penalty utilizing each operation’s (gate’s) Choi matrix.
spam_penalty_factor (float, optional) – The prefactor of a term that penalizes invalid SPAM operations. Specifically, adds a spam_penalty_factor * sqrt(tracenorm(spam_op)) penalty where spam_op runs over each state preparation’s density matrix and each effect vector’s matrix.
errorgen_penalty_factor (float, optional) – The prefactor of a term that penalizes nonzero error generators. Specifically, adds a errorgen_penalty_factor * sqrt(sum_i(|errorgen_coeff_i|)) penalty where the sum ranges over all the error generator coefficients of each model operation.
forcefn_grad (numpy.ndarray, optional) – The gradient of a “forcing function” that is added to the objective function. This is used in the calculation of linear-response error bars.
shift_fctr (float, optional) – An adjustment prefactor for computing the “shift” that serves as a constant offset of the forcing function, i.e. the forcing function (added to the objective function) is essentially ForceFn = force_shift + dot(forcefn_grad, parameter_vector), and force_shift = shift_fctr * ||forcefn_grad|| * (||forcefn_grad|| + ||parameter_vector||). Here || indicates a frobenius norm. The idea behind all this is that ForceFn as given above must remain positive (for least-squares optimization), and so shift_fctr must be large enough to ensure this is the case. Usually you don’t need to alter the default value.
prob_clip_interval (tuple, optional) – A (min, max) tuple that specifies the minimum (possibly negative) and maximum values allowed for probabilities generated by the model. If the model gives probabilities outside this range they are clipped to min or max. These values can be quite generous, as the optimizers are quite tolerant of badly behaved probabilities.
- Returns:
The number of penalty terms.
- Return type:
int
- set_regularization(min_prob_clip=0.0001, radius=0.0001)#
Set regularization values.
- Parameters:
min_prob_clip (float, optional) – The probability below which the objective function is replaced with its second order Taylor expansion.
radius (float, optional) – Affects sharpness of the regularization of zero-frequency terms.
- Return type:
None
- terms(paramvec=None)#
Compute the terms of the objective function.
The “terms” are the per-circuit-outcome values that get summed together to result in the objective function value.
- Parameters:
paramvec (numpy.ndarray, optional) – The vector of (model) parameters to evaluate the objective function at. If None, then the model’s current parameter vector is used (held internally).
- Returns:
An array of shape (nElements,) where nElements is the number of circuit outcomes.
- Return type:
numpy.ndarray
- property description#
A description of this objective function.
- property name#
Name of this objective function.