Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

AcceptanceRatioFreeEnergyEstimator.cpp

Go to the documentation of this file.
00001 // AcceptanceRatioFreeEnergyEstimator.cpp: implementation of the CAcceptanceRatioFreeEnergyEstimator class.
00002 //
00004 
00005 #include "AcceptanceRatioFreeEnergyEstimator.h"
00006 
00008 // Construction/Destruction
00010 
00011 CAcceptanceRatioFreeEnergyEstimator::CAcceptanceRatioFreeEnergyEstimator()
00012 {
00013 
00014 }
00015 
00016 CAcceptanceRatioFreeEnergyEstimator::CAcceptanceRatioFreeEnergyEstimator(Minimizable *pS0, int n0, Minimizable *pS1, int n1, CParameterTranslator *pTrans)
00017 {
00018         m_pSystem0 = pS0;
00019         m_pSystem1 = pS1;
00020         m_iN0 = n0;
00021         m_iN1 = n1;
00022         m_pTranslator = pTrans;
00023 }
00024 
00025 
00026 CAcceptanceRatioFreeEnergyEstimator::~CAcceptanceRatioFreeEnergyEstimator()
00027 {
00028         int i;
00029         for(i = 0; i < m_vpdEnsemble0.size(); i++)
00030         {
00031                 delete [] m_vpdEnsemble0[i];
00032         }
00033         for(i = 0; i < m_vpdEnsemble1.size(); i++)
00034         {
00035                 delete [] m_vpdEnsemble1[i];
00036         }
00037 
00038         m_vdHistogram0.clear();
00039         m_vdHistogram1.clear();
00040 
00041 }
00042 
00043 void CAcceptanceRatioFreeEnergyEstimator::ComputeHistograms()
00044 {
00045         int i,count;
00046         int nP0 = m_pSystem0->GetNParameters();
00047         int nP1 = m_pSystem1->GetNParameters();
00048         double *temp0 = new double[nP0];
00049         double *temp1 = new double[nP1];
00050 
00051         
00052         // get the h0 histogram - i.e., run both minimizables with the zero parameters
00053         for(i = 0; i < m_iN0; i++)
00054         {
00055                 // zero system takes its own parameters freely
00056                 double cost0in0 = m_pSystem0->ObjectiveFunction(m_vpdEnsemble0[i]);
00057                 // transform the zero parameters to run in the one system
00058                 m_pTranslator->ZeroToOne(m_vpdEnsemble0[i],nP0,temp1,nP1);
00059                 double cost0in1 = m_pSystem1->ObjectiveFunction(temp1);
00060                 // now get the difference
00061                 m_vdHistogram0.push_back(cost0in1 - cost0in0);
00062                 // write a message to the screen
00063                 cout << "Set " << i << " run in system 0" << endl;
00064         }
00065         /*
00066         // get the h1 histogram - i.e., run both minimizables with the one parameters
00067         for(i = 0; i < m_iN1; i++)
00068         {
00069                 // one system takes its own parameters freely
00070                 double cost1in1 = m_pSystem1->ObjectiveFunction(m_vpdEnsemble1[i]);
00071                 // transform the one parameters to run in the zero system
00072                 m_pTranslator->OneToZero(m_vpdEnsemble1[i],nP1,temp0,nP0);
00073                 double cost1in0 = m_pSystem0->ObjectiveFunction(temp0);
00074                 // now get the difference
00075                 m_vdHistogram1.push_back(cost1in0 - cost1in1);
00076                 // write a message to the screen
00077                 cout << "Set " << i << " run in system 1" << endl;
00078         }
00079         */
00080         
00081         // write the histograms to files
00082         fstream *pfHist0 = new fstream("histogram0.par",ios::out);
00083         fstream *pfHist1 = new fstream("histogram1.par",ios::out);
00084         *pfHist0 << "##################################################################" << endl;
00085         *pfHist1 << "##################################################################" << endl;
00086         *pfHist0 << "# POTENTIAL DIFFERENCES IN 0 SYSTEM - " << m_iN0 << " SAMPLES" << endl;
00087         *pfHist1 << "# POTENTIAL DIFFERENCES IN 1 SYSTEM - " << m_iN1 << " SAMPLES" << endl;
00088         *pfHist0 << "##################################################################" << endl;
00089         *pfHist1 << "##################################################################" << endl;
00090 
00091         for(count = 0; count < m_vdHistogram0.size(); count++)
00092         {
00093                 *pfHist0 << setprecision(10) << m_vdHistogram0[count] << endl;
00094         }
00095         for(count = 0; count < m_vdHistogram1.size(); count++)
00096         {
00097                 *pfHist1 << setprecision(10) << m_vdHistogram1[count] << endl;
00098         }
00099 
00100         cout << "Histograms writtten." << endl;
00101 
00102         delete pfHist0;
00103         delete pfHist1;
00104         delete [] temp0;
00105         delete [] temp1;
00106 }
00107 
00108 void CAcceptanceRatioFreeEnergyEstimator::LoadEnsemble(std::string f0name, std::string f1name)
00109 {
00110         int i,j;
00111         // read in two vectors of rate constants
00112         int nRC0 = m_pSystem0->GetNParameters();
00113         int nRC1 = m_pSystem1->GetNParameters();
00114 
00115         // two parameter readers scan the files
00116         ParameterReader *pEns0Reader = new ParameterReader(f0name.c_str());
00117         ParameterReader *pEns1Reader = new ParameterReader(f1name.c_str());
00118 
00119         for(i = 0; i < m_iN0; i++)
00120         {
00121                 m_vpdEnsemble0.push_back(new double[nRC0]);
00122                 for(j = 0; j < nRC0; j++)
00123                 {
00124                         double parameter = pEns0Reader->ReadParameter();
00125                         m_vpdEnsemble0[i][j] = parameter;
00126                 }
00127         }
00128 
00129         for(i = 0; i < m_iN1; i++)
00130         {
00131                 m_vpdEnsemble1.push_back(new double[nRC1]);
00132                 for(j = 0; j < nRC1; j++)
00133                 {
00134                         double parameter = pEns1Reader->ReadParameter();
00135                         m_vpdEnsemble1[i][j] = parameter;
00136                 }
00137         }
00138         
00139         delete pEns0Reader;
00140         delete pEns1Reader;
00141 
00142         return;
00143 }

Generated on Mon Nov 3 09:37:37 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002