28 #ifndef TOMOGRAPHER_DENSEDM_TSPACELLHWALKER_H 29 #define TOMOGRAPHER_DENSEDM_TSPACELLHWALKER_H 36 #include <boost/math/constants/constants.hpp> 71 template<
typename DenseLLH_,
typename Rng,
typename LoggerType>
79 typedef typename DenseLLH::DMTypes
DMTypes;
110 const DenseLLH & _llh;
131 LLHMHWalker(
const MatrixType & startpt,
const DenseLLH & llh, Rng & rng,
135 _normal_distr_rnd(0.0, 1.0),
147 : _llh(
std::move(moveother._llh)),
148 _rng(moveother._rng),
149 _normal_distr_rnd(moveother._normal_distr_rnd),
150 _px(
std::move(moveother._px)),
151 _log(moveother._log),
152 _startpt(moveother._startpt)
168 _log.debug(
"TSpace::LLHMHWalker",
"Starting random walk");
175 if (_startpt.norm() > 1e-3) {
181 MatrixType T(_llh.dmt.initMatrixType());
182 T = Tools::denseRandom<MatrixType>(
183 _rng, _normal_distr_rnd, _llh.dmt.dim(), _llh.dmt.dim()
185 _startpt = T/T.norm();
187 _log.debug(
"TSpace::LLHMHWalker", [&](
std::ostream & str) {
188 str <<
"Chosen random start point T = \n" << _startpt;
212 TOMOGRAPHER_ENABLED_IF(DenseLLH::LLHCalcType ==
LLHCalcTypeX)
213 inline LLHValueType
fnLogVal(const MatrixType & T)
const 215 MatrixType rho(T*T.adjoint());
216 VectorParamType x = _px.
HermToX(rho);
217 LLHValueType llhval = _llh.logLikelihoodX(x);
232 LLHValueType llhval = _llh.logLikelihoodRho(T*T.adjoint());
241 MatrixType DeltaT(Tools::denseRandom<MatrixType>(
242 _rng, _normal_distr_rnd, _llh.dmt.dim(), _llh.dmt.dim()
248 new_T /= new_T.norm();
void init()
Provided for MHRandomWalk. Initializes some fields and prepares for a random walk.
Base namespace for the Tomographer project.
const MatrixType & startPoint()
Return the starting point given in the constructor, or a random start point.
DMTypes::VectorParamType VectorParamType
Type of an X-parameterization of a density operator (see X Parameterization)
C++ types for describing dense density matrices in various parameterizations.
DenseLLH::DMTypes DMTypes
The data types of our problem.
LLHMHWalker(LLHMHWalker &&moveother)
A MHWalker Interface needs to have a move constructor.
LLHMHWalker(const MatrixType &startpt, const DenseLLH &llh, Rng &rng, LoggerType &log_)
Constructor which just initializes the given fields.
DMTypes::RealScalar RealScalar
The real scalar corresponding to our data types. Usually a double.
DenseLLH::LLHValueType LLHValueType
The loglikelihood function value type (see DenseLLH Interface e.g. IndepMeasLLH)
RealScalar StepRealType
The real scalar type for the step size — this is our scalar type (see MHWalker Interface) ...
MatrixType PointType
Provided for MHRandomWalk. A point in our random walk = a density matrix.
Tools for parameterizing hermitian matrices with the X Parameterization.
Some declarations for the DenseLLH type interface.
VectorParamType HermToX(MatrixTypeConstRef Herm) const
Get the X-parameterization corresponding to a given hermitian matrix.
A random walk in the density matrix space of a Hilbert state space of a quantum system.
Provides the logarithm MH function value at each point (see Role of UseFnSyntaxType) ...
void done()
Callback for after random walk is finished. No-op.
DenseLLH_ DenseLLH
The DenseLLH interface object type.
Managing the need for specific overrides to operator new() for some types (especially Eigen types) ...
void thermalizingDone()
Callback for after thermalizing is done. No-op.
LLHValueType FnValueType
Provided for MHRandomWalk. The function value type is the loglikelihood value type.
The DenseLLH-compatible object exposes a method logLikelihoodRho(), taking as argument a (const ref t...
MatrixType jumpFn(const MatrixType &cur_T, RealScalar step_size)
Decides of a new point to jump to for the random walk.
We will calculate the log-likelihood function, which is the logarithm of the Metropolis-Hastings func...
LLHValueType fnLogVal(const MatrixType &T) const
Calculate the logarithm of the Metropolis-Hastings function value.
Routines for performing a Metropolis-Hastings random walk.
DMTypes::MatrixType MatrixType
The matrix type for a density operator on our quantum system.
DMTypes::ComplexScalar ComplexScalar
The complex real scalar corresponding to our data types. Usually a std::complex<double>.
The DenseLLH-compatible object exposes a method logLikelihoodX(), taking as argument a (const ref to ...
Utilities for logging messages.
RealScalar_ RealScalar
Real scalar type, given in template parameter. Usually double is fine.