Philipp Frank committed Aug 31, 2018 1 ``````from ..operators.energy_operators import InverseGammaLikelihood,Hamiltonian `````` Philipp Frank committed Aug 31, 2018 2 3 ``````from ..operators.scaling_operator import ScalingOperator `````` Philipp Frank committed Aug 31, 2018 4 5 ``````def make_adjust_variances(a,xi,position,samples=[],scaling=None,ic_samp=None): """ Creates a Hamiltonian for constant likelihood optimizations. `````` Philipp Frank committed Aug 31, 2018 6 `````` `````` Philipp Frank committed Aug 31, 2018 7 `````` Constructs a Hamiltonian to solve constant likelihood optimizations of the form `````` Philipp Frank committed Aug 31, 2018 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 `````` phi = a * xi under the constraint that phi remains constant. Parameters ---------- a : Operator Operator which gives the amplitude when evaluated at a position xi : Operator Operator which gives the excitation when evaluated at a position postion : Field, MultiField Position of the whole problem res_samples : Field, MultiField Residual samples of the whole Problem scaling : Float Optional rescaling of the Likelihood `````` Philipp Frank committed Aug 31, 2018 23 24 `````` ic_samp : Controller Iteration Controller for Hamiltonian `````` Philipp Frank committed Aug 31, 2018 25 26 27 `````` Returns ------- `````` Philipp Frank committed Aug 31, 2018 28 29 `````` Hamiltonian A Hamiltonian that can be used for further minimization `````` Philipp Frank committed Aug 31, 2018 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 `````` """ d = a * xi d = (d.conjugate()*d).real n = len(samples) if n>0: d_eval = 0. for i in range(n): d_eval = d_eval + d(position+samples[i]) d_eval = d_eval / n else: d_eval = d(position) x = (a.conjugate()*a).real if scaling is not None: x = ScalingOperator(scaling,x.target)(x) `````` Philipp Frank committed Aug 31, 2018 47 `` return Hamiltonian(InverseGammaLikelihood(x,d_eval),ic_samp=ic_samp)``