Commit 8987bcff authored by Philipp Frank's avatar Philipp Frank

rename make_adjust_variances in make_adjust_variances_hamiltonian and docs

parent c948dcb5
...@@ -82,7 +82,7 @@ from .library.light_cone_operator import LightConeOperator ...@@ -82,7 +82,7 @@ from .library.light_cone_operator import LightConeOperator
from .library.wiener_filter_curvature import WienerFilterCurvature from .library.wiener_filter_curvature import WienerFilterCurvature
from .library.correlated_fields import CorrelatedField, MfCorrelatedField from .library.correlated_fields import CorrelatedField, MfCorrelatedField
from .library.adjust_variances import (make_adjust_variances, from .library.adjust_variances import (make_adjust_variances_hamiltonian,
do_adjust_variances) do_adjust_variances)
from . import extra from . import extra
......
...@@ -24,7 +24,7 @@ from ..operators.scaling_operator import ScalingOperator ...@@ -24,7 +24,7 @@ from ..operators.scaling_operator import ScalingOperator
from ..operators.simple_linear_operators import ducktape from ..operators.simple_linear_operators import ducktape
def make_adjust_variances(a, def make_adjust_variances_hamiltonian(a,
xi, xi,
position, position,
samples=[], samples=[],
...@@ -35,18 +35,20 @@ def make_adjust_variances(a, ...@@ -35,18 +35,20 @@ def make_adjust_variances(a,
Constructs a Hamiltonian to solve constant likelihood optimizations of the Constructs a Hamiltonian to solve constant likelihood optimizations of the
form phi = a * xi under the constraint that phi remains constant. form phi = a * xi under the constraint that phi remains constant.
FIXME xi is white. xi is desired to be a Gaussian white Field, thus variations that are
more easily represented by a should be absorbed in a.
Parameters Parameters
---------- ----------
a : Operator a : Operator
Gives the amplitude when evaluated at a position. Gives the amplitude when evaluated at position.
xi : Operator xi : Operator
Gives the excitation when evaluated at a position. Field Adapter selecting a part of position.
xi is desired to be a Gaussian white Field.
position : Field, MultiField position : Field, MultiField
Position of the entire problem. Contains the initial values for the operators a and xi, to be adjusted
samples : Field, MultiField samples : Field, MultiField
Residual samples of the whole problem. Residual samples of position.
scaling : Float scaling : Float
Optional rescaling of the Likelihood. Optional rescaling of the Likelihood.
ic_samp : Controller ic_samp : Controller
...@@ -82,16 +84,45 @@ def do_adjust_variances(position, ...@@ -82,16 +84,45 @@ def do_adjust_variances(position,
minimizer, minimizer,
xi_key='xi', xi_key='xi',
samples=[]): samples=[]):
''' """Adjusts the variance of xi_key to be represented by amplitude_operator.
FIXME
''' Solves a constant likelihood optimization of the
form phi = amplitude_operator * position[xi_key] under the constraint that
phi remains constant.
The field indexed by xi_key is desired to be a Gaussian white Field,
thus variations that are more easily represented by amplitude_operator
will be absorbed in amplitude_operator.
Parameters
----------
position : Field, MultiField
Contains the initial values for amplitude_operator and the key xi_key,
to be adjusted.
amplitude_operator : Operator
Gives the amplitude when evaluated at position.
minimizer : Minimizer
Used to solve the optimization problem.
xi_key : String
Key of the Field containing undesired variations. This Field is
contained in position.
samples : Field, MultiField, optional
Residual samples of position. If samples are supplied then phi remains
only approximately constant. Default: [].
Returns
-------
MultiField
The new position after variances were adjusted.
"""
h_space = position[xi_key].domain[0] h_space = position[xi_key].domain[0]
pd = PowerDistributor(h_space, amplitude_operator.target[0]) pd = PowerDistributor(h_space, amplitude_operator.target[0])
a = pd(amplitude_operator) a = pd(amplitude_operator)
xi = ducktape(None, position.domain, xi_key) xi = ducktape(None, position.domain, xi_key)
ham = make_adjust_variances(a, xi, position, samples=samples) ham = make_adjust_variances_hamiltonian(a, xi, position, samples=samples)
# Minimize # Minimize
e = EnergyAdapter( e = EnergyAdapter(
...@@ -106,10 +137,4 @@ def do_adjust_variances(position, ...@@ -106,10 +137,4 @@ def do_adjust_variances(position,
position = MultiField.from_dict(position) position = MultiField.from_dict(position)
position = MultiField.union([position, e.position]) position = MultiField.union([position, e.position])
s_h_new = (a*xi).force(position)
import numpy as np
# TODO Move this into the tests
np.testing.assert_allclose(s_h_new.to_global_data(),
s_h_old.to_global_data())
return position return position
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment