10 #ifndef IMPMULTI_STATE_SAXS_MULTI_COMBINATION_SCORE_H
11 #define IMPMULTI_STATE_SAXS_MULTI_COMBINATION_SCORE_H
22 IMPMULTISTATE_BEGIN_NAMESPACE
25 template <
typename ScoringFunctionT>
37 bool c1_c2_approximate,
38 double min_c1 = 0.99,
double max_c1 = 1.05,
39 double min_c2 = -0.5,
double max_c2 = 2.0,
40 bool use_offset =
false);
55 const std::string fit_file_name)
const override;
57 std::string get_state_name(
unsigned int id)
const override {
58 return profiles_[id]->get_name();
61 std::string get_dataset_name()
const override {
62 return exp_profile_->get_name();
65 double get_average_c1()
const {
return average_c1_; }
66 double get_average_c2()
const {
return average_c2_; }
81 double min_c1_, max_c1_, min_c2_, max_c2_;
82 double average_c1_, average_c2_;
85 bool c1_c2_approximate_;
88 bool c1_c2_no_fitting_;
93 template <
typename ScoringFunctionT>
98 bool c1_c2_approximate,
99 double min_c1,
double max_c1,
100 double min_c2,
double max_c2,
102 profiles_(profiles), main_profile_(main_profile), exp_profile_(exp_profile),
103 min_c1_(min_c1), max_c1_(max_c1), min_c2_(min_c2), max_c2_(max_c2),
104 c1_c2_approximate_(c1_c2_approximate), c1_c2_no_fitting_(false),
105 use_offset_(use_offset) {
107 if(profiles_.size() < 1) {
108 IMP_THROW(
"SAXSMultiCombinationScore - please provide at least one profile"
121 template <
typename ScoringFunctionT>
122 void SAXSMultiCombinationScore<ScoringFunctionT>::set_average_c1_c2(
123 const Vector<saxs::FitParameters>& fps) {
124 if(c1_c2_no_fitting_)
return;
127 for(
unsigned int i=0; i<fps.size(); i++) {
128 c1 += fps[i].get_c1();
129 c2 += fps[i].get_c2();
139 template <
typename ScoringFunctionT>
140 double SAXSMultiCombinationScore<ScoringFunctionT>::get_score(
const MultiStateModel& m)
const {
141 const Vector<unsigned int>& states = m.get_states();
143 IMP_NEW(saxs::Profile, combined_profile,(main_profile_->get_min_q(),
144 main_profile_->get_max_q(),
145 main_profile_->get_delta_q()));
148 combined_profile->add_partial_profiles(main_profile_);
151 for(
unsigned int i=0; i<states.size(); i++) {
152 combined_profile->add_partial_profiles(profiles_[states[i]]);
155 saxs::FitParameters fp =
156 score_->fit_profile(combined_profile, min_c1_, max_c1_, min_c2_, max_c2_, use_offset_);
157 return fp.get_chi_square();
160 template <
typename ScoringFunctionT>
161 saxs::WeightedFitParameters
162 SAXSMultiCombinationScore<ScoringFunctionT>::get_fit_parameters(MultiStateModel& m)
const {
164 if(c1_c2_no_fitting_) {
165 double s = get_score(m);
166 saxs::WeightedFitParameters fp(s, 1.0, 0.0);
169 const Vector<unsigned int>& states = m.get_states();
170 IMP_NEW(saxs::Profile, combined_profile,(main_profile_->get_min_q(),
171 main_profile_->get_max_q(),
172 main_profile_->get_delta_q()));
175 combined_profile->add_partial_profiles(main_profile_);
178 for(
unsigned int i=0; i<states.size(); i++) {
179 combined_profile->add_partial_profiles(profiles_[states[i]]);
182 saxs::WeightedFitParameters fp =
183 score_->fit_profile(combined_profile, min_c1_, max_c1_, min_c2_, max_c2_, use_offset_);
184 Vector<double> weights(states.size(), 1.0/(states.size()+1));
185 fp.set_weights(weights);
186 m.set_score(fp.get_chi_square());
190 template <
typename ScoringFunctionT>
191 saxs::WeightedFitParameters
192 SAXSMultiCombinationScore<ScoringFunctionT>::get_fit_parameters()
const {
194 IMP_NEW(saxs::Profile, combined_profile,(main_profile_->get_min_q(),
195 main_profile_->get_max_q(),
196 main_profile_->get_delta_q()));
199 combined_profile->add_partial_profiles(main_profile_);
202 for(
unsigned int i=0; i<profiles_.size(); i++) {
203 combined_profile->add_partial_profiles(profiles_[i]);
206 if(c1_c2_no_fitting_) {
207 double s = score_->compute_score(combined_profile, use_offset_);
208 saxs::WeightedFitParameters fp(s, 1.0, 0.0);
212 saxs::WeightedFitParameters fp = score_->fit_profile(combined_profile,
214 min_c2_, max_c2_, use_offset_);
218 template <
typename ScoringFunctionT>
219 void SAXSMultiCombinationScore<ScoringFunctionT>::write_fit_file(MultiStateModel& m,
220 const saxs::WeightedFitParameters& fp,
221 const std::string fit_file_name)
const {
224 const Vector<unsigned int>& states = m.get_states();
226 IMP_NEW(saxs::Profile, combined_profile,(main_profile_->get_min_q(),
227 main_profile_->get_max_q(),
228 main_profile_->get_delta_q()));
231 combined_profile->add_partial_profiles(main_profile_);
234 for(
unsigned int i=0; i<states.size(); i++) {
235 combined_profile->add_partial_profiles(profiles_[states[i]]);
238 saxs::WeightedFitParameters fpp = score_->fit_profile(combined_profile,
240 min_c2_, max_c2_, use_offset_, fit_file_name);
243 IMPMULTISTATE_END_NAMESPACE
base class for MultiStateModel scoring classes
Base class for MultiStateModel scoring classes.
a class for fitting two profiles
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.
An input/output exception.
Keep track of multiple states.
#define IMP_UNUSED(variable)
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Parameters of a weighted fit, from WeightedProfileFitter.
A shared base class to help in debugging and things.
Fit two profiles with user-defined scoring function as a template parameter.
Keep track of multiple states.
A class for profile storing and computation.