Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0d33ba9806+3d1aa5cd78,g0fba68d861+6c07529581,g1e78f5e6d3+aa4d1c21f1,g1ec0fe41b4+f536777771,g1fd858c14a+c6963eae98,g35bb328faa+fcb1d3bbc8,g4af146b050+58cb980876,g4d2262a081+bfae794ebc,g53246c7159+fcb1d3bbc8,g5a012ec0e7+b20b785ecb,g60b5630c4e+3d1aa5cd78,g67b6fd64d1+4086c0989b,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+a8b896a16a,g8852436030+75f93ca278,g89139ef638+4086c0989b,g9125e01d80+fcb1d3bbc8,g94187f82dc+3d1aa5cd78,g989de1cb63+4086c0989b,g9f33ca652e+94dd9a85be,g9f7030ddb1+3f50642ad9,ga2b97cdc51+3d1aa5cd78,ga44b1db4f6+7d2d5e68ea,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+96cb2ddcf2,gb58c049af0+f03b321e39,gb89ab40317+4086c0989b,gcf25f946ba+75f93ca278,gd6cbbdb0b4+af3c3595f5,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+ed90e8109d,ge278dab8ac+d65b3c2b70,ge410e46f29+4086c0989b,gf67bdafdda+4086c0989b,gfe06eef73a+e2ab3e8e4f,v29.0.0.rc5
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
prior.cc
Go to the documentation of this file.
1/*
2 * This file is part of gauss2d_fit.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include <string>
25
28
32
33namespace lsst::gauss2d::fit {
34
36 bool python_style = true) {
37 std::string str = "{";
38 const std::string prefix = python_style ? "" : "{ ";
39 const std::string separator = python_style ? ": " : ", ";
40 for (const auto& [obj, value] : jacobians) {
41 str += obj.get().str() + separator + to_string_float_iter(value) + ", ";
42 }
43 return str.substr(0, str.size() - 2 * (jacobians.size() > 0)) + "}";
44}
45
47 PriorEvaluation::Jacobians jacobians_, bool check_size)
48 : loglike(loglike_), residuals(residuals_), jacobians(jacobians_) {
49 const auto n_resid = residuals.size();
50 if (!((n_resid > 0) || (jacobians.size() == 0))) {
51 throw std::invalid_argument("residuals cannot be empty unless jacobians are too");
52 }
53 if (check_size) {
54 for (const auto& [paramref, values] : jacobians) {
55 if (values.size() != n_resid) {
56 throw std::invalid_argument(paramref.get().str()
57 + " jacobian size=" + std::to_string(values.size())
58 + " != n_resid=" + std::to_string(n_resid));
59 }
60 }
61 } else {
62 }
63}
64
66
67double PriorEvaluation::compute_dloglike_dx(const ParamBase& param, bool transformed) const {
68 double dll_dx = 0;
69 auto jacobian = this->jacobians.find(param);
70 if (jacobian != this->jacobians.end()) {
71 // jacobian is dresidual/dx
72 // loglike is -residual^2/2
73 // dloglike/dx = -residual*dresidual/dx
74 const auto& jacobian_values = (*jacobian).second;
75 for (size_t idx = 0; idx < jacobian_values.size(); ++idx) {
76 dll_dx -= jacobian_values[idx] * residuals.at(idx);
77 }
78 }
79 if (!transformed) dll_dx /= param.get_transform_derivative();
80 return dll_dx;
81}
82
83std::string PriorEvaluation::repr(bool name_keywords, std::string_view namespace_separator) const {
84 return type_name_str<PriorEvaluation>(false, namespace_separator) + "("
85 + (name_keywords ? "loglike=" : "") + to_string_float(loglike) + ", "
86 + (name_keywords ? "residuals=" : "") + to_string_float_iter(residuals) + ", "
87 + (name_keywords ? "jacobians=" : "") + str_jacobians(jacobians) + ")";
88}
89
91 return type_name_str<PriorEvaluation>(true) + "(loglike=" + to_string_float(loglike) + ", residuals="
92 + to_string_float_iter(residuals) + ", jacobians=" + str_jacobians(jacobians) + ")";
93}
94
95} // namespace lsst::gauss2d::fit
double compute_dloglike_dx(const ParamBase &param, bool transformed=true) const
Definition prior.cc:67
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
Definition prior.cc:83
std::string str() const override
Return a brief, human-readable string representation of this.
Definition prior.cc:90
std::map< ParamBaseCRef, std::vector< double > > Jacobians
Definition prior.h:18
std::vector< double > residuals
Definition prior.h:21
PriorEvaluation(double loglike, std::vector< double > residuals={}, Jacobians jacobians={}, bool check_size=true)
Definition prior.cc:46
virtual T get_transform_derivative() const =0
Return the derivative of the transform for this parameter instance.
std::string str_jacobians(const std::map< ParamBaseCRef, std::vector< double > > &jacobians, bool python_style=true)
Definition prior.cc:35
@ jacobian
Compute the model Jacobian.
Definition model.h:37
std::reference_wrapper< const ParamBase > ParamBaseCRef
Definition param_defs.h:10
lsst::modelfit::parameters::ParameterBase< double > ParamBase
Definition param_defs.h:9
std::string type_name_str(bool strip_namespace=false, std::string_view namespace_str=detail::NAMESPACE_SEPARATOR)
Get a string representation of an arbitrary C++ type, potentially modifying its namespace prefix.
Definition type_name.h:104
std::string to_string_float_iter(const Container< Value > &container, const int precision=6, const bool scientific=true)
Definition to_string.h:28
std::string to_string_float(const T value, const int precision=6, const bool scientific=true)
Definition to_string.h:15
T substr(T... args)
T to_string(T... args)