dwave.system.temperatures.maximum_pseudolikelihood#
- maximum_pseudolikelihood(en1: ndarray | None = None, bqms: None | List[BinaryQuadraticModel] = None, sampleset: None | SampleSet | Tuple[ndarray, List] = None, num_bootstrap_samples: int = 0, seed: int | None = None, x0: None | List | ndarray = None, optimize_method: str | None = None, kwargs_opt: dict | None = None, sample_weights: ndarray | None = None, return_optimize_object: bool = False, degenerate_fields: bool | None = None, use_jacobian: bool = True) Tuple [source]#
Maximimum pseudolikelihood estimator for exponential models.
Uses the SciPy optimize method to solve the maximum pseudolikelihood problem of weight estimation for an exponential model with exponent defined by a weighted sum of bqms. Assuming the Probability of states s is given by an exponential model \(P(s)=1/Z exp(- x_i H_i(s))\) for a given list of functions (bqms) estimate x. The exponential model is also called a Boltzmann distribution. Code is designed assuming the bqms are dense (a function of all or most of the variables), although technically operation although sparse bqms like \(H(s)=h_i s_i\) or \(H(s)=J_{ij}s_i s_j\) are technically allowed.
In the case that all samples define local minima or maxima (all energies en1 are same sign) the limit of +/-Inf defines a maximum. In this special case scipy is not called and the limit result is returned. Note that, excitations can be rare in low-temperature samplesets such as those derived from annealing, so that this pathological case can be realized in applications of interest.
Note common reasons for parameter inference failure include: - Too few samples, insufficient to resolve parameters - The samplest is singular or insensitive with respect to some parameter
(e.g. local minima or plateus only).
bqms are too closely related, or weakly dependent on the sampleset variability (e.g. nearly collinear).
- Parameters:
en1 – Effective fields as an np.ndarray (site labels not required). Derived from the
bqms
andsampleset
if not provided. First dimension indexes samples, second dimension indexes sites. Ordering doesn’t matter, but should be consistent with sample_weights.bqms – A list of Binary quadratic models [H_i] describing the sample distribution as \(P(s) ~ exp(sum_i x_i H_i(s))\) for unknown model parameters x.
sampleset – A set of samples, as a dimod Sampleset or samples-like object.
num_bootstrap_samples – Number of bootstrap estimators to calculate. Bootstrapped estimates can be used to reliably estimate variance and bias if samples are uncorrelated. For now, the sampleset must have uniform sample_weights to deploy this option – an aggregated or weighted sampleset must be disaggregated (raw format) with repetitions.
seed – Seeds the bootstrap method (if provided) allowing reproducibility of the estimators.
x0 – Initial guess for the fitting parameters. Should have the same length as bqms when provided.
optimize_method (str, optional, default=None) – Optimize method used by SciPy
root_scalar
method. The default method works well under default operation, ‘bisect’ can be numerically more stable for the scalar case (inverse temperature estimation only).kwargs_opt – Arguments used by the SciPy optimization methods. If using the ‘bisect’ optimization method and for a single bqm, bounds for the fitting parameter can be set using a
tuple[float, float]
forbracket
.sample_weights – A set of weights for the samples. If sampleset is of type
SampleSet
set this is default to sampleset.record.num_occurrences, otherwise uniform weighting is the default.return_optimize_object – When True, and if
sciPy
optimization is invoked, the associated OptimizeResult is returned. Otherwise only the optimal parameter values are returned as floats.degenerate_fields – If effective fields are degenerate owing to sparse connectivity, low precision and/or large number of samples, or low entropy then histogramming (aggregating) of fields is used to accelerate the search stage. A value True is supported (and default) for single parameter esimation
len(bqms)=1
; for multi-parameter estimation only value False is supported.use_jacobian – By default (True) the second derivative of the pseudolikelihood is calculated and used by ScipY root finding methods. The associated complexity of this non-essential calculation is quadratic in len(bqms); use of the second derivative is disabled by setting the value to False.
- Returns:
The optimal parameters and a list of bootstrapped estimates (x_estimate, x_bootstrap_estimates):
x_estimate: parameter estimates
x_bootstrap_estimates: a numpy array of bootstrap estimators
- Return type:
Tuple
Examples
This example builds upon the example for maximum_pseudolikelihood_temperature
Draw samples from a D-Wave Quantum Computer for a large spin-glass problem (random couplers J, zero external field h). Establish a temperature and estimate to the background susceptibility chi which is expected to be a small negative value. Since background susceptiblity is a perturbation, and the problem Hamiltonian and correction Hamiltonian are correlated, a large number of samples can be required for confidence. Other perturbative corrections such as flux noise can also interfere with estimation of small parameters like chi.
>>> import dimod >>> from dwave.system.temperatures import maximum_pseudolikelihood >>> from dwave.system.temperatures import background_susceptibility_bqm >>> from dwave.system import DWaveSampler >>> from random import random >>> sampler = DWaveSampler() >>> bqm1 = dimod.BinaryQuadraticModel.from_ising({}, {e : 1-2*random() for e in sampler.edgelist}) >>> bqm2 = background_susceptibility_bqm(bqm1) >>> sampleset = sampler.sample(bqm1, num_reads=1000, auto_scale=False) >>> params, _ = maximum_pseudolikelihood(bqms=[bqm1, bqm2], sampleset=sampleset) >>> print('Effective temperature ', -1/params[0], 'Background susceptibliity', params[1]/params[0]) Effective temperature 0.22298662677716122 Background susceptibliity -0.009343961890466117