adjust_variances.py 1.45 KB
Newer Older
1
from ..operators.energy_operators import InverseGammaLikelihood,Hamiltonian
Philipp Frank's avatar
Philipp Frank committed
2
3
from ..operators.scaling_operator import ScalingOperator

4
5
def make_adjust_variances(a,xi,position,samples=[],scaling=None,ic_samp=None):
    """ Creates a Hamiltonian for constant likelihood optimizations.
Philipp Frank's avatar
Philipp Frank committed
6
    
7
    Constructs a Hamiltonian to solve constant likelihood optimizations of the form
Philipp Frank's avatar
Philipp Frank committed
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
23
24
    ic_samp : Controller
        Iteration Controller for Hamiltonian
Philipp Frank's avatar
Philipp Frank committed
25
26
27

    Returns
    -------
28
29
    Hamiltonian
        A Hamiltonian that can be used for further minimization
Philipp Frank's avatar
Philipp Frank committed
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)

47
    return Hamiltonian(InverseGammaLikelihood(x,d_eval),ic_samp=ic_samp)