📄 potential.cc.svn-base
字号:
#include <utility>#include <iostream>#include <cmath>#include <Potential.h>#include <RandomVariable.h>using namespace std; // **************** Potential Implementation ***********//Potential::~Potential(){}/*void Potential::modify_potential_value(unsigned int, double){ cout << "ERROR (CRITICAL): Changing a Potential value is not possible for this kind of potential (modify_potential_value() called on the base Potential class)" << endl;}*/Potential * Potential::clone(){ cout << "ERROR (CRITICAL): Cloning this kind of potential is not possible (clone() called on the base Potential class)" << endl; return NULL;}#ifndef NDEBUGvoid Potential::debug_display_state(){ cout << "ERROR (CRITICAL): We are calling debug_display_information() on the base Potential class)" << endl;}#endif/*void Potential::add_potential(Potential *){ cout << "ERROR (CRITICAL): Adding to this kind of potential is not possible (add_potential(Potential *) called on the base Potential class)" << endl;}*/ // **************** End of Potential Implementation ***********//ContinuousPotential::ContinuousPotential(){}ContinuousPotential::~ContinuousPotential(){}// ******************* GaussianPotential Implementation **************//// ConstructorsGaussianPotential::GaussianPotential (double a): variance(a){}GaussianPotential::GaussianPotential (double a, RandomVariable & var_1, RandomVariable & var_2): variance(a), variable_1_index(var_1.get_index()), variable_2_index(var_2.get_index()), value_1(0.0), value_2(0.0){ }// Methodsdouble GaussianPotential::get_potential_value() const { //cout << endl; //cout << "[Gaussian values: " << value_1 << " ( " << variable_1_index << " ) " << " , " << value_2 << " ( " << variable_2_index << " ) " << " , " << exp( - ((value_1 - value_2)*(value_1 - value_2)) / (2*variance) ) << "]" << endl; //cout << endl; return exp( - ((value_1 - value_2)*(value_1 - value_2)) / (2*variance) );}// Watch out: this doesn't return the value of the variable corresponding to index a, but on the contrary, the value of the *OTHER* variable// This is in effect the mean for this variabledouble GaussianPotential::get_variable_mean(unsigned int a) const{ if (a == variable_1_index) { return value_2; } else { return value_1; }}void GaussianPotential::set_variable_value (const RandomVariable & rv){ unsigned int a = rv.get_index(); double b = static_cast< const ContinuousRandomVariable & > (rv).last_sampled_value; if (a == variable_1_index) { value_1 = b; } else { value_2 = b; }}// Debug methods#ifndef NDEBUGvoid GaussianPotential::debug_display_state(){ cout << "Gaussian values: " << value_1 << " ( " << variable_1_index << " ) " << " , " << value_2 << " ( " << variable_2_index << " ) " << " , " << exp( - ((value_1 - value_2)*(value_1 - value_2)) / (2*variance) ) << "]" << endl; cout << "Variance: " << variance << endl;}#endif// Deprecated methodsvoid GaussianPotential::set_variable_value (unsigned int a, double b){ if (a == variable_1_index) { value_1 = b; } else { value_2 = b; }}// ******************* End of GaussianPotential Implementation **************//// ******************* BernouilliPotential Implementation **************//// Initializing with a parameter of 1 in the default caseBernouilliPotential::BernouilliPotential (const RandomVariable & var_discrete, const RandomVariable & var_continuous): parameter(2.0), threshold(0.0), discrete_variable_index(var_discrete.get_index()), continuous_variable_index(var_continuous.get_index()){ }// Inherited virtual functionsvoid BernouilliPotential::set_variable_value(const RandomVariable & rv){ unsigned int a = rv.get_index(); if (a == discrete_variable_index) { value_discrete = static_cast< const DiscreteRandomVariable & > (rv).last_sampled_value; //cout << "prout" << endl; } else { value_continuous = static_cast< const ContinuousRandomVariable & > (rv).last_sampled_value; }}double BernouilliPotential::get_potential_value() const{ double a = 1/(1+exp(-parameter*(value_continuous-threshold))); if (0 == value_discrete ) { return a; } else { a = 1 - a; //cout << "using value 1: " << value_discrete << endl; return a; }}// Debug methods#ifndef NDEBUGvoid BernouilliPotential::debug_display_state(){ cout << "Bernouilli Potential: " << value_continuous << " ( continuous: " << continuous_variable_index << " ) " << " , " << value_discrete << " ( discrete: " << discrete_variable_index << " ) " << endl;}#endif// ******************* End of BernouilliPotential Implementation **************//// **************** ChainedSinglePotential Implementation ***********//ChainedSinglePotential::~ChainedSinglePotential(){}ChainedSinglePotential::ChainedSinglePotential(const unsigned int a): variable_index(a){}double ChainedSinglePotential::get_potential_value() const{ double a (1.0); for (list < Potential * >::const_iterator it = potential_lst.begin(); it != potential_lst.end(); ++it) { a = a * (*it)->get_potential_value(); } return a;}void ChainedSinglePotential::set_variable_value(const RandomVariable & rv){ for (list < Potential * >::iterator it = potential_lst.begin(); it != potential_lst.end(); ++it) { (*it)->set_variable_value(rv); }}/*void ChainedSinglePotential::set_variable_value(const unsigned int, const double a){ //cout << "chained potentials: " << potential_lst.size() << endl; for (list < Potential * >::iterator it = potential_lst.begin(); it != potential_lst.end(); ++it) { (*it)->set_variable_value(variable_index, a); }}*/void ChainedSinglePotential::add_potential(Potential * p){ potential_lst.push_back( p);}// **************** End of ChainedSinglePotential Implementation ***********//// **************** ConstantPotential Implementation ***********//ConstantPotential::~ConstantPotential(){}// **************** End of ConstantPotential Implementation ***********//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -