28 #ifndef TOMOGRAPHER_DENSEDM_INDEPMEASLLH_H 29 #define TOMOGRAPHER_DENSEDM_INDEPMEASLLH_H 35 #include <Eigen/Eigen> 61 template<
typename DMTypes_,
typename LLHValueType_ =
typename DMTypes_::RealScalar,
62 typename IntFreqType_ = int,
int FixedMaxParamList_ = Eigen::Dynamic,
63 bool UseNMeasAmplifyFactor_ =
false>
75 static constexpr
int FixedMaxParamList = FixedMaxParamList_;
77 static constexpr
bool IsDynamicMaxParamList = (FixedMaxParamList_ == Eigen::Dynamic);
79 static constexpr
bool UseNMeasAmplifyFactor = UseNMeasAmplifyFactor_;
117 : dmt(dmt_), _Exn(VectorParamListType::Zero(0, (
Eigen::Index)dmt.dim2())), _Nx(FreqListType::Zero(0)),
118 _NMeasAmplifyFactor(1)
126 inline IndepMeasLLH(DMTypes dmt_, VectorParamListTypeConstRef Exn_, FreqListTypeConstRef Nx_)
127 : dmt(dmt_), _Exn(VectorParamListType::Zero(0, dmt.dim2())), _Nx(FreqListType::Zero(0)), _NMeasAmplifyFactor(1)
141 inline const IndexType
numEffects()
const {
return _Exn.rows(); }
153 inline const VectorParamListType &
Exn()
const {
return _Exn; }
163 return _Exn.row(i).transpose();
178 inline const FreqListType &
Nx()
const {
return _Nx; }
187 inline const IntFreqType
Nx(IndexType i)
const {
return _Nx(i); }
196 _Exn.resize(0, (Eigen::Index)dmt.dim2());
216 bool check_validity =
true)
225 if (check_validity) {
231 IndexType newi = _Exn.rows();
234 _Exn.conservativeResize(newi + 1, Eigen::NoChange);
235 _Exn.row(newi) = E_x.transpose();
236 _Nx.conservativeResize(newi + 1, Eigen::NoChange);
252 bool check_validity =
true)
262 if (check_validity) {
274 inline void setMeas(VectorParamListTypeConstRef Exn_, FreqListTypeConstRef Nx_,
bool check_validity =
true)
280 if ((Nx_ > 0).all()) {
282 _Exn.resize(Exn_.rows(), (Eigen::Index)dmt.dim2());
284 _Nx.resize(Nx_.rows(), 1);
289 for (IndexType i = 0; i < Exn_.rows(); ++i) {
290 addMeasEffect(Exn_.row(i), Nx_(i),
false);
293 if (check_validity) {
298 inline void checkAllMeas()
const 304 for (IndexType i = 0; i < _Exn.rows(); ++i) {
313 inline void checkEffect(IndexType i)
const 329 if ( ! (
double( (E_m - E_m.adjoint()).norm() ) < 1e-8) ) {
334 const typename DMTypes::RealScalar mineigval = slv.
eigenvalues().minCoeff();
338 << mineigval <<
") : E_m =\n" 341 if ( ! (
double(E_m.norm()) > 1e-6) ) {
353 TOMOGRAPHER_ENABLED_IF(UseNMeasAmplifyFactor)
354 inline LLHValueType NMeasAmplifyFactor()
const {
return _NMeasAmplifyFactor.value; }
357 TOMOGRAPHER_ENABLED_IF(!UseNMeasAmplifyFactor)
366 TOMOGRAPHER_ENABLED_IF(UseNMeasAmplifyFactor)
367 inline
void setNMeasAmplifyFactor(
LLHValueType val) { _NMeasAmplifyFactor.value = val; }
381 return _mult_by_nmeasfactor(
382 (_Nx.template cast<LLHValueType>() * (_Exn * x).template cast<LLHValueType>().array().log()).sum()
387 template<
typename Expr, TOMOGRAPHER_ENABLED_IF_TMPL(UseNMeasAmplifyFactor)>
388 inline auto _mult_by_nmeasfactor(Expr&& expr)
const -> decltype(
LLHValueType(1) * expr)
390 return _NMeasAmplifyFactor.value * expr;
392 template<
typename Expr, TOMOGRAPHER_ENABLED_IF_TMPL(!UseNMeasAmplifyFactor)>
393 inline auto _mult_by_nmeasfactor(Expr&& expr)
const -> decltype(std::forward<Expr>(expr))
395 return std::forward<Expr>(expr);
408 template<
typename DMTypes_,
typename LLHValueType_,
409 typename IntFreqType_,
int FixedMaxParamList_,
410 bool UseNMeasAmplifyFactor_>
413 template<
typename DMTypes_,
typename LLHValueType_,
414 typename IntFreqType_,
int FixedMaxParamList_,
415 bool UseNMeasAmplifyFactor_>
418 template<
typename DMTypes_,
typename LLHValueType_,
419 typename IntFreqType_,
int FixedMaxParamList_,
420 bool UseNMeasAmplifyFactor_>
Utilities for formatting strings.
const Eigen::Ref< const VectorParamListType > & VectorParamListTypeConstRef
Const ref to a VectorParamListType.
const Eigen::Ref< const FreqListType > & FreqListTypeConstRef
Const ref to a FreqListType.
Base namespace for the Tomographer project.
const RealVectorType & eigenvalues() const
C++ types for describing dense density matrices in various parameterizations.
internal::traits< Matrix< typename DMTypes::RealScalar, Eigen::Dynamic, DMTypes::FixedDim2, Eigen::RowMajor, FixedMaxParamList, DMTypes::FixedDim2 > >::Index Index
IndepMeasLLH(DMTypes dmt_, VectorParamListTypeConstRef Exn_, FreqListTypeConstRef Nx_)
Constructor with full measurement data.
const DMTypes dmt
The DMTypes object, storing e.g. the dimension of the problem.
void setMeas(VectorParamListTypeConstRef Exn_, FreqListTypeConstRef Nx_, bool check_validity=true)
Specify the full measurement data at once.
void addMeasEffect(typename DMTypes::VectorParamTypeConstRef E_x, IntFreqType n, bool check_validity=true)
Store a measurement POVM effect along with a frequency count.
const IntFreqType Nx(IndexType i) const
The number of counts stored for the i-th POVM effect.
C++ types and functions for calculating the log-likelihood for POVM effects which can be written as a...
static constexpr int FixedDim2
The square of the dimension of the quantum system, or Eigen::Dynamic.
LLHValueType_ LLHValueType
Type used to calculate the log-likelihood function (see DenseLLH Interface)
Tools for parameterizing hermitian matrices with the X Parameterization.
Exception class notifying of invalid measurement data.
DMTypes_ DMTypes
The DMTypes in use here.
Some declarations for the DenseLLH type interface.
VectorParamListType::Index IndexType
Type used to index entries in VectorParamListType (and also used for indexing entries in FreqListType...
IntFreqType_ IntFreqType
Type used to store integer measurement counts.
const VectorParamListType & Exn() const
The stored individual POVM effects, in X Parameterization.
Some C++ utilities, with a tad of C++11 tricks.
Eigen::Matrix< typename DMTypes::RealScalar, Eigen::Dynamic, DMTypes::FixedDim2, Eigen::RowMajor, FixedMaxParamList, DMTypes::FixedDim2 > VectorParamListType
dynamic Matrix with rows = dim*dim Vectors (row-major) [maximum FixedMaxParamList rows...
Managing the need for specific overrides to operator new() for some types (especially Eigen types) ...
Eigen::Array< IntFreqType, Eigen::Dynamic, 1, 0, FixedMaxParamList, 1 > FreqListType
dynamic Array of integers [maximum FixedMaxParamList entries or Dynamic]
LLHValueType logLikelihoodX(typename DMTypes::VectorParamTypeConstRef x) const
Calculates the log-likelihood function, in X parameterization.
const IndexType numEffects() const
The number of POVM effects in the list.
#define streamstr(tokens)
Utility macro to format stream tokens to a std::string.
T setprecision(T... args)
void resetMeas()
Reset the measurement vectors and frequency counts.
IndepMeasLLH(DMTypes dmt_)
Simple constructor.
#define tomographer_assert(...)
Assertion test macro.
The DenseLLH-compatible object exposes a method logLikelihoodX(), taking as argument a (const ref to ...
const FreqListType & Nx() const
The stored frequency counts for each individual POVM effect.
RealScalar_ RealScalar
Real scalar type, given in template parameter. Usually double is fine.
void addMeasEffect(typename DMTypes::MatrixTypeConstRef E_m, IntFreqType n, bool check_validity=true)
Store a POVM measurement effect with frequency count.
Eigen::Ref< const typename DMTypes::VectorParamType > Exn(IndexType i) const
The i-th stored POVM effect, in X Parameterization.