20 #include <basic/options/option.hh>
22 #include <utility/pointer/ReferenceCount.hh>
26 #include <ObjexxFCL/format.hh>
36 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
38 #include <utility/vector1.hh>
44 namespace constraints {
45 using namespace basic::options;
46 using namespace basic::options::OptionKeys;
50 in >> anchor_ >> gaussian_param_ >> exp_param_ >> mixture_param_ >> bg_mean_ >> bg_sd_;
56 if ( bg_mean_ <= 0.001 ) {
70 Real exp_score = 0.5 *
dexponential( local_x, anchor_, exp_param_, mixture_param_ );
71 Real gauss_score =
dgaussian ( local_x, anchor_, gaussian_param_, (1.0 - mixture_param_) );
77 if ( option[ basic::options::OptionKeys::constraints::normalize_mixture_func ]() ) {
79 static const Real upper( 3.8 );
80 static const Real lower( 3.5 );
81 if ( local_x < upper ) {
82 Real factor = std::min( (upper - local_x) / (upper - lower), 1.0 );
83 bg_score = factor * (exp_score + gauss_score);
85 score = -1 * log( (exp_score + gauss_score) / bg_score );
87 score = -1 * log (exp_score + gauss_score);
91 if ( score < 0 ) score = 0;
104 Real score = func_(local_x);
105 if ( local_x < rmax_ ) {
106 score = func_(local_x);
108 score = fmax_ + local_x - rmax_;
113 if ( option[ basic::options::OptionKeys::constraints::penalize_mixture_func ]() ) {
116 return std::min( score, 0.0 );
127 Real df = estimate_dfunc( x );
142 Real gauss_deriv =
gaussian_deriv ( x, anchor_, gaussian_param_, (1 - mixture_param_) );
145 Real gauss_score =
dgaussian ( x, anchor_, gaussian_param_, (1 - mixture_param_) );
149 g = exp_score + gauss_score;
151 g_prime = exp_deriv + gauss_deriv;
153 Real dfunc = g_prime / g - h_prime / h;
159 using namespace ObjexxFCL::fmt;
166 out <<
A( width,
"r" )
167 <<
A( width,
"func" )
168 <<
A( width,
"dfunc" )
171 <<
A( width,
"g_prime" )
172 <<
A( width,
"h_prime" )
173 <<
A( width,
"dfunc_est" )
176 Real g, h, g_prime, h_prime;
177 Real dfunc = dfunc_component( r, g, h, g_prime, h_prime );
180 << F( width, precise, func(r) )
181 << F( width, precise, dfunc )
182 << F( width, precise, g )
183 << F( width, precise, h )
184 << F( width, precise, g_prime )
185 << F( width, precise, h_prime )
186 << F( width, precise, estimate_dfunc(r) )
192 out <<
"MIXTUREFUNC " << anchor_ <<
' ' << gaussian_param_
193 <<
' ' << exp_param_ <<
' ' << mixture_param_ <<
' ' << bg_mean_
194 <<
' ' << bg_sd_ << std::endl;
202 Real kl_divergence = 0;
203 for (
float r = start; r <=
end; r += res ) {
204 Real g, h, g_prime, h_prime;
205 dfunc_component( r, g, h, g_prime, h_prime );
206 kl_divergence += g * ( std::log(g) - std::log(h) );
209 return kl_divergence;