14 #ifndef INCLUDED_protocols_multistate_design_PartitionAggregateFunction_hh
15 #define INCLUDED_protocols_multistate_design_PartitionAggregateFunction_hh
26 #include <utility/pointer/ReferenceCount.hh>
29 #include <utility/vector1.hh>
32 namespace multistate_design {
34 class PartitionAggregateFunction :
public MultiStateAggregateFunction {
78 PartitionAggregateFunction<T>::evaluate(
79 utility::vector1<core::Real> const & single_state_fitnesses,
80 MultiStateFitnessFunction<T> & fitness_function
83 using namespace ObjexxFCL::fmt;
85 utility::vector1<SingleStateCOP> single_states(fitness_function.const_states());
86 runtime_assert(single_state_fitnesses.size() == single_states.size());
92 core::Real const inv_temp( -1.0 / temp_ );
93 core::Real numer(0.), denom(0.);
95 // 'normalize' is just a constant value to subtract from energies of large magnitude, in order to take exponents of
96 // smaller numbers (exact value used should not be important for the calculations)
97 core::Real const normalize( compare_all_to_ground_state_ ? 0 : single_state_fitnesses[ 1 ] );
98 for (core::Size i = 1; i <= single_state_fitnesses.size(); ++i) {
100 core::Real const ground_state_offset( compare_all_to_ground_state_ ? single_states[ i ]->best_score() : 0 );
101 TR(basic::t_trace) << "State fitness " << F(8,2,single_state_fitnesses[i]);
102 TR(basic::t_trace) << "State ground-state offset " << F(8,2,ground_state_offset);
103 core::Real const exp_term( std::exp( ( single_state_fitnesses[i] - ground_state_offset - normalize ) * inv_temp ) );
104 TR(basic::t_trace) << " exp. term " << F(6,2,exp_term);
106 if ( single_states[i]->is_positive_state() ) {
107 TR(basic::t_trace) << " (POSITIVE STATE)";
119 // also add 'affinity anchor(s)' to denominator for each positive state
120 core::Real const anchor_term( std::exp( ( single_states[i]->best_score() - ground_state_offset + anchor_offset_ - normalize ) * inv_temp ) );
121 TR(basic::t_trace) << " anchor exp. term " << F(6,2,anchor_term);
122 denom += anchor_term;
124 TR(basic::t_trace) << std::endl;
126 TR(basic::t_trace) << "numer " << F(5,2,numer) << " / denom " << F(5,2,denom) << std::endl;
127 // flip sign on the Boltzmann probability for proper ranking elsewhere (more negative is better)
128 core::Real const prob_target( numer/denom );
129 TR(basic::t_debug) << "Boltzmann prob. for target state(s) vs. competitor(s): "
130 << ObjexxFCL::fmt::F(5,2,prob_target) << std::endl;
132 return -1.*prob_target; // in genetic algorithm, better fitnesses are more negative
135 template <typename T>
137 PartitionAggregateFunction<T>::TR("protocols.multistate_design.PartitionAggregateFunction");