8 #ifndef IMPKERNEL_OPTIMIZER_H
9 #define IMPKERNEL_OPTIMIZER_H
11 #include "kernel_config.h"
13 #include "VersionInfo.h"
61 double optimize(
unsigned int max_steps);
70 void set_score_threshold(
double s) {min_score_=s;}
71 double get_score_threshold()
const {
return min_score_;}
77 void set_stop_on_good_score(
bool tf) {
78 stop_on_good_score_=tf;
80 bool get_stop_on_good_score()
const {
81 return stop_on_good_score_;
84 double get_last_score()
const {
85 return cache_->get_last_score();
94 Model *get_model()
const {
105 void set_model(Model *m);
109 virtual void show(std::ostream &out= std::cout)
const {
110 out <<
"Some optimizer" << std::endl;
121 optimizer_state, optimizer_states, OptimizerState*,
124 Optimizer::set_optimizer_state_optimizer(obj,
this);
125 obj->set_was_used(
true);
127 {Optimizer::set_optimizer_state_optimizer(obj,
nullptr);});
133 virtual void set_scoring_function(ScoringFunctionInput sf);
136 void set_restraints(
const RestraintsTemp &rs);
143 virtual double do_optimize(
unsigned int ns) =0;
145 void update_states()
const ;
157 typedef Model::FloatIndex FloatIndex;
158 typedef base::Vector<FloatIndex> FloatIndexes;
159 base::Vector<Model::FloatIndex> get_optimized_attributes()
const {
160 return get_model()->get_optimized_attributes();
162 void set_value(Model::FloatIndex fi,
double v)
const {
163 get_model()->set_attribute(fi.k_, fi.p_, v);
166 Float get_value(Model::FloatIndex fi)
const {
167 return get_model()->get_attribute(fi.k_, fi.p_);
170 Float get_derivative(Model::FloatIndex fi)
const {
171 return get_model()->get_derivative(fi.k_, fi.p_);
177 if (widths_.size() <=k.get_index() || widths_[k.get_index()]==0) {
179 double wid=
static_cast<double>(w.second)- w.first;
180 widths_.resize(std::max(widths_.size(), size_t(k.get_index()+1)), 0.0);
183 widths_[k.get_index()]= wid;
185 widths_[k.get_index()]= 1.0;
188 return widths_[k.get_index()];
199 void set_scaled_value(Model::FloatIndex fi,
Float v)
const {
200 double wid = width(fi.k_);
201 set_value(fi, v*wid);
204 double get_scaled_value(Model::FloatIndex fi)
const {
205 double uv= get_value(fi);
206 double wid = width(fi.k_);
210 double get_scaled_derivative(Model::FloatIndex fi)
const {
211 double uv=get_derivative(fi);
212 double wid= width(fi.k_);
217 void clear_range_cache() {
225 Restraints get_restraints()
const;
228 void set_is_optimizing_states(
bool tf)
const;
229 static void set_optimizer_state_optimizer(OptimizerState *os, Optimizer *o);
230 mutable Floats widths_;
231 Pointer<Model> model_;
233 bool stop_on_good_score_;
234 Pointer<ScoringFunction> cache_;