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")
55 py::init<
const std::vector<std::string>&,
const char *,
M3::float_t,
int,
int>(),
56 "Construct a parameters object from a set of yaml files that define the systematic parameters \n\
57 :param yaml_files: The name of the yaml file to initialise from. \n\
58 :param name: the name of this ParameterHandler object. \n\
59 :param threshold: threshold PCA threshold from 0 to 1. Default is -1 and means no PCA. \n\
60 :param first_PCA_par: FirstPCAdpar First PCA parameter that will be decomposed. \n\
61 :param last_PCA_par: LastPCAdpar First PCA parameter that will be decomposed.",
62 py::arg(
"yaml_files"),
64 py::arg(
"threshold") = -1.0,
65 py::arg(
"firs_PCA_par") = -999,
66 py::arg(
"last_PCA_par") = -999
70 "calculate_likelihood",
72 "Calculate penalty term based on inverted covariance matrix."
76 "get_internal_par_name",
81 ret =
self.GetParName(index);
84 "Get the internally used name of this parameter. \n\
85 :param index: The global index of the parameter",
95 ret =
self.GetParFancyName(index);
98 "Get the name of this parameter. \n\
99 :param index: The global index of the parameter",
106 "Get the number of parameters that this ParameterHandler object knows about."
112 "Propose a step based on the covariances. Also feel free to overwrite if you want something more funky."
116 "get_proposal_array",
120 size_t n_pars =
self.GetNParameters();
123 const M3::float_t* data_ptr =
self.GetParPropVec().data();
127 py::array_t<M3::float_t> result(n_pars);
128 auto buf = result.request();
132 std::memcpy(result_ptr, data_ptr, n_pars *
sizeof(
M3::float_t));
136 "Get the parameter proposal values as a numpy array. \n\
137 This returns a copy of the current proposal values. \n\
138 :return: A numpy array containing the proposal values for all parameters."
141 .def(
"set_parameters",
143 if (pars_obj.is_none()) {
144 self.SetParameters();
147 std::vector<double> pars_vec = pars_obj.cast<std::vector<double>>();
148 self.SetParameters(pars_vec);
151 py::arg(
"pars") = py::none(),
153 Set parameter values using array.
157 pars : numpy.ndarray or list of float, optional
158 Array holding new values for every parameter.
159 Must have same size as the number of parameters in the covariance class.
160 If not provided, parameters are set to their pre-fit values.
164 >>> import numpy as np
165 >>> handler.set_parameters(np.array([1.0, 2.0, 3.0]))
166 >>> handler.set_parameters([1.0, 2.0, 3.0])
167 >>> handler.set_parameters()
175 py::init<
const std::vector<std::string>&,
const char *,
M3::float_t,
int,
int>(),
176 "Construct a systematic ParameterHandler object from a set of yaml files that define the systematic parameters \n\
177 :param yaml_files: The name of the yaml file to initialise from. \n\
178 :param name: the name of this ParameterHandler object. \n\
179 :param threshold: threshold PCA threshold from 0 to 1. Default is -1 and means no PCA. \n\
180 :param first_PCA_par: FirstPCAdpar First PCA parameter that will be decomposed. \n\
181 :param last_PCA_par: LastPCAdpar First PCA parameter that will be decomposed.",
182 py::arg(
"yaml_files"),
183 py::arg(
"name") =
"xsec_cov",
184 py::arg(
"threshold") = -1.0,
185 py::arg(
"firs_PCA_par") = -999,
186 py::arg(
"last_PCA_par") = -999
192 "Get what type of systematic this parameters is (see :py:class:`pyMaCh3.m_parameters.SystematicType` for possible types). \n\
193 :param index: The global index of the parameter",
198 "get_par_spline_type",
200 "Get what type of spline this parameter is set to use (assuming that it is a spline type parameter). \n\
201 :param index: The index of the spline parameter",
206 "get_par_spline_name",
208 "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\
209 :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.
int GetNParameters() const
Get number of params which will be different depending if using Eigen decomposition or not.
double CalcLikelihood() const _noexcept_
Calc penalty term based on inverted covariance matrix.
ParameterHandlerBase(const std::vector< std::string > &YAMLFile, std::string name, double threshold=-1, int FirstPCAdpar=-999, int LastPCAdpar=-999)
ETA - constructor for a YAML file.
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)