7 #include <pybind11/pybind11.h>
8 #include <pybind11/stl.h>
9 #include <pybind11/numpy.h>
14 namespace py = pybind11;
24 PYBIND11_OVERRIDE_NAME(
33 PYBIND11_OVERRIDE_NAME(
46 py::enum_<SystType>(m_parameters,
"SystematicType")
54 py::init<std::string &, std::string, M3::float_t, int, int>(),
55 "Construct a parameters object from a set of yaml files that define the systematic parameters \n\
56 :param name: the name of this ParameterHandler object. \n\
57 :param file: The name of the yaml file to initialise from. \n\
58 :param threshold: threshold PCA threshold from 0 to 1. Default is -1 and means no PCA. \n\
59 :param first_PCA_par: FirstPCAdpar First PCA parameter that will be decomposed. \n\
60 :param last_PCA_par: LastPCAdpar First PCA parameter that will be decomposed.",
63 py::arg(
"threshold") = -1.0,
64 py::arg(
"firs_PCA_par") = -999,
65 py::arg(
"last_PCA_par") = -999)
68 "calculate_likelihood",
70 "Calculate penalty term based on inverted covariance matrix.")
73 "get_internal_par_name",
78 ret =
self.GetParName(index);
81 "Get the internally used name of this parameter. \n\
82 :param index: The global index of the parameter",
91 ret =
self.GetParFancyName(index);
94 "Get the name of this parameter. \n\
95 :param index: The global index of the parameter",
101 "Get the number of parameters that this ParameterHandler object knows about.")
106 "Propose a step based on the covariances. Also feel free to overwrite if you want something more funky.")
109 "get_proposal_array",
113 size_t n_pars =
self.GetNParameters();
116 const M3::float_t* data_ptr =
self.GetParPropVec().data();
120 py::array_t<M3::float_t> result(n_pars);
121 auto buf = result.request();
125 std::memcpy(result_ptr, data_ptr, n_pars *
sizeof(
M3::float_t));
129 "Get the parameter proposal values as a numpy array. \n\
130 This returns a copy of the current proposal values. \n\
131 :return: A numpy array containing the proposal values for all parameters.")
135 if (pars_obj.is_none()) {
136 self.SetParameters();
139 std::vector<double> pars_vec = pars_obj.cast<std::vector<double>>();
140 self.SetParameters(pars_vec);
141 } }, py::arg(
"pars") = py::none(),
143 Set parameter values using array.
147 pars : numpy.ndarray or list of float, optional
148 Array holding new values for every parameter.
149 Must have same size as the number of parameters in the covariance class.
150 If not provided, parameters are set to their pre-fit values.
154 >>> import numpy as np
155 >>> handler.set_parameters(np.array([1.0, 2.0, 3.0]))
156 >>> handler.set_parameters([1.0, 2.0, 3.0])
157 >>> handler.set_parameters()
162 "Get initial value of parameter at index i\n\
163 :param index: index of the parameter")
166 "Get the lower bound of parameter at index i. \n\
167 :param index: index of the parameter")
170 "Get the upper bound of parameter at index i. \n\
171 :param index: index of the parameter")
174 "Is the parameter at index i flat?. \n\
175 :param index: index of the parameter")
178 "The prior error on parameter at index i \n\
179 :param index: index of the parameter")
182 "Is the parameter at index i fixed \n\
183 :param index: index of the parameter")
187 auto mat =
self.GetCovMatrix();
189 throw std::runtime_error(
"TMatrixDSym pointer is null");
191 int n = mat->GetNrows();
192 const double *data = mat->GetMatrixArray();
193 py::array_t<float> result({n, n});
195 std::transform(data, data + n * n,
196 result.mutable_data(),
198 { return static_cast<float>(v); });
201 "Get the prior covariance")
207 py::init<
const std::vector<std::string>&,
const char *,
M3::float_t,
int,
int>(),
208 "Construct a systematic ParameterHandler object from a set of yaml files that define the systematic parameters \n\
209 :param yaml_files: The name of the yaml file to initialise from. \n\
210 :param name: the name of this ParameterHandler object. \n\
211 :param threshold: threshold PCA threshold from 0 to 1. Default is -1 and means no PCA. \n\
212 :param first_PCA_par: FirstPCAdpar First PCA parameter that will be decomposed. \n\
213 :param last_PCA_par: LastPCAdpar First PCA parameter that will be decomposed.",
214 py::arg(
"yaml_files"),
215 py::arg(
"name") =
"xsec_cov",
216 py::arg(
"threshold") = -1.0,
217 py::arg(
"firs_PCA_par") = -999,
218 py::arg(
"last_PCA_par") = -999
224 "Get what type of systematic this parameters is (see :py:class:`pyMaCh3.m_parameters.SystematicType` for possible types). \n\
225 :param index: The global index of the parameter",
230 "get_par_spline_type",
232 "Get what type of spline this parameter is set to use (assuming that it is a spline type parameter). \n\
233 :param index: The index of the spline parameter",
238 "get_par_spline_name",
240 "Get the name of the spline associated with a spline parameter. This is generally what it is called in input spline files and can in principle be different to the parameters name. \n\
241 :param index: The index of the spline parameter",
@ kNorm
For normalisation parameters.
@ kSpline
For splined parameters (1D)
@ kSystTypes
This only enumerates.
@ kFunc
For functional parameters.
Base class responsible for handling of systematic error parameters. Capable of using PCA or using ada...
virtual void ProposeStep()
Generate a new proposed state.
double GetUpperBound(const int i) const
Get upper parameter bound in which it is physically valid.
int GetNParameters() const
Get number of params which will be different depending if using Eigen decomposition or not.
bool IsParameterFixed(const int i) const
Is parameter fixed or not.
double GetLowerBound(const int i) const
Get lower parameter bound in which it is physically valid.
double CalcLikelihood() const _noexcept_
Calc penalty term based on inverted covariance matrix.
bool GetFlatPrior(const int i) const
Get if param has flat prior or not.
double GetParInit(const int i) const
Get prior parameter value.
double GetDiagonalError(const int i) const
Get diagonal error for ith parameter.
ParameterHandlerBase()=default
Class responsible for handling of systematic error parameters with different types defined in the con...
SystType GetParamType(const int i) const
Returns enum describing our param type.
std::string GetParSplineName(const int i) const
Get the name of the spline associated with the spline at index i.
SplineInterpolation GetParSplineInterpolation(const int i) const
Get interpolation type for a given parameter.
EW: As ParameterHandlerBase is an abstract base class we have to do some gymnastics to get it to get ...
double GetLikelihood() override
Return CalcLikelihood if some params were thrown out of boundary return LARGE_LOGL
void ProposeStep() override
Generate a new proposed state.
void initParametersModule(py::module &m_parameters)