Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
ParamOptimizer.h
Go to the documentation of this file.
1#ifndef PARAM_OPTIMIZER_H
2#define PARAM_OPTIMIZER_H
3
4#include <vector>
5#include <unordered_map>
6#include <unordered_set>
7#include <variant>
8#include <memory>
9#include <stdexcept>
10#include <string>
11#include <algorithm>
12
13#include "BlockAccessor.h"
14#include "Block.h"
15#include "Parameter.h"
16
40struct BAKeyHash {
46 std::size_t operator()(const std::pair<std::string,std::string>& k) const noexcept {
47 std::size_t h1 = std::hash<std::string>()(k.first);
48 std::size_t h2 = std::hash<std::string>()(k.second);
49 return h1 ^ (h2 + 0x9e3779b97f4a7c15ULL + (h1<<6) + (h1>>2));
50 }
51};
52
76public:
81 explicit ParamOptimizer(std::shared_ptr<BlockAccessor> scope);
82
93 explicit ParamOptimizer(std::vector<std::shared_ptr<BlockAccessor>> scopes);
94
105 void set_value(const BlockName& block, const LhaID& id, scalar_t v);
106
117 void set_param(const BlockName& block, const LhaID& id, std::shared_ptr<Parameter> p);
118
127 void remove(const BlockName& block, const LhaID& id);
128
146 void commit(bool coalesce = true);
147
151 void clear();
152
153private:
155 struct OpSetValue { BlockName block; LhaID id; scalar_t value; };
156
158 struct OpSetParam { BlockName block; LhaID id; std::shared_ptr<Parameter> param; };
159
161 struct OpRemove { BlockName block; LhaID id; };
162
164 using Op = std::variant<OpSetValue, OpSetParam, OpRemove>;
165
174 std::vector<Op> coalesce_ops_() const;
175
188 std::shared_ptr<Block> find_block_(const BlockName& name) const;
189
195 void freeze_all_();
196
202 void unfreeze_all_();
203
211 std::vector<std::shared_ptr<BlockAccessor>> scopes_;
212
216 std::vector<Op> ops_;
217};
218
219#endif
Alias-aware façade for accessing and manipulating multiple parameter blocks.
Defines classes used to store parameters and to build derived/dependent parameter blocks.
Defines the Parameter class used to store individual physical/model parameters.
Block identifier with alias support.
Definition BlockName.h:59
Helper class to batch parameter updates on one or several BlockAccessor scopes.
void commit(bool coalesce=true)
Applies all queued operations.
void remove(const BlockName &block, const LhaID &id)
Queue a removal operation for a parameter.
void set_value(const BlockName &block, const LhaID &id, scalar_t v)
Queue a simple numerical value assignment for a parameter.
void clear()
Clears the pending operation queue without applying changes.
void set_param(const BlockName &block, const LhaID &id, std::shared_ptr< Parameter > p)
Queue a full Parameter object assignment.
double h1(double x)
Wilson special function h1 depending on x.
Hash functor for (block name, parameter id string) pairs.
std::size_t operator()(const std::pair< std::string, std::string > &k) const noexcept
Computes the hash of a pair of strings.
Represents an identifier of a LHA element, possibly containing several sub-ids.
Definition LhaID.h:56