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>
117 :
dmt(dmt_), _Exn(VectorParamListType::Zero(0,
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, dmt.dim2());
216 bool check_validity =
true)
225 if (check_validity) {
231 IndexType newi = _Exn.rows();
235 _Exn.
row(newi) = E_x.transpose();
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(), dmt.dim2());
284 _Nx.
resize(Nx_.rows(), 1);
289 for (IndexType i = 0; i < Exn_.rows(); ++i) {
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 double mineigval = slv.
eigenvalues().minCoeff();
335 if ( ! (mineigval >= -1e-12) ) {
339 if ( ! (
double(E_m.norm()) > 1e-6) ) {
351 TOMOGRAPHER_ENABLED_IF(UseNMeasAmplifyFactor)
379 return _mult_by_nmeasfactor(
380 (_Nx.template cast<LLHValueType>() * (_Exn * x).template cast<LLHValueType>().array().
log()).sum()
385 template<
typename Expr, TOMOGRAPHER_ENABLED_IF_TMPL(UseNMeasAmplifyFactor)>
386 inline auto _mult_by_nmeasfactor(Expr&& expr)
const -> decltype(
LLHValueType(1) * expr)
388 return _NMeasAmplifyFactor.value * expr;
390 template<
typename Expr, TOMOGRAPHER_ENABLED_IF_TMPL(!UseNMeasAmplifyFactor)>
391 inline auto _mult_by_nmeasfactor(Expr&& expr)
const -> decltype(std::forward<Expr>(expr))
393 return std::forward<Expr>(expr);
406 template<
typename DMTypes_,
typename LLHValueType_,
407 typename IntFreqType_,
int FixedMaxParamList_,
408 bool UseNMeasAmplifyFactor_>
411 template<
typename DMTypes_,
typename LLHValueType_,
412 typename IntFreqType_,
int FixedMaxParamList_,
413 bool UseNMeasAmplifyFactor_>
416 template<
typename DMTypes_,
typename LLHValueType_,
417 typename IntFreqType_,
int FixedMaxParamList_,
418 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.
static constexpr bool IsDynamicMaxParamList
Whether the dimension is specified dynamically at run-time or statically at compile-time.
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)
static constexpr int FixedMaxParamList
Maximum number of POVM effects, fixed at compile-time or Eigen::Dynamic.
void conservativeResize(Index nbRows, Index nbCols)
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.
static constexpr bool UseNMeasAmplifyFactor
Whether we allow NMeasAmplifyFactor to be set.
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 NMeasAmplifyFactor() const
Factor by which to artificially amplify the number of measurements.
LLHValueType logLikelihoodX(typename DMTypes::VectorParamTypeConstRef x) const
Calculates the log-likelihood function, in X parameterization.
Declare that this DenseLLH object exposes a logLikelihoodX() method.
void setNMeasAmplifyFactor(LLHValueType val)
Set the factor by which to artificially multiply all frequency counts.
const IndexType numEffects() const
The number of POVM effects in the list.
const CwiseUnaryOp< internal::scalar_log_op< Scalar >, const Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > > log() const
void resize(Index nbRows, Index nbCols)
#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.