00001 // main.cpp : Defines the entry point for the console application. 00002 // 00003 00004 #ifdef _WINDOWS 00005 //#include "stdafx.h" 00006 //#include <crtdbg.h> 00007 #endif 00008 00009 #include "OneGeneMaster.h" 00010 #include "InfrastructureMaster.h" 00011 /* 00012 // debugging only 00013 //#define _CRT_DEBUG_MAP_ALLOC 00014 #include <stdlib.h> 00015 //#include <crtdbg.h> 00016 */ 00017 00018 main(int argc, char* argv[]) 00019 { 00020 00021 // MICROSOFT DEBUGGING STUFF 00022 //_crtBreakAlloc = 55; // Breaks at memory allocation failure no. ? 00023 // global variable 00024 //_CrtSetBreakAlloc(22584); 00025 00026 //int tmpFlag = _CRTDBG_REPORT_FLAG; 00027 //tmpFlag |= _CRTDBG_DELAY_FREE_MEM_DF; 00028 //tmpFlag |= _CRTDBG_ALLOC_MEM_DF; // use any checking at all. 00029 //tmpFlag |= _CRTDBG_LEAK_CHECK_DF; // at end of program. 00030 //tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF; // end of program 00031 //tmpFlag &= ~_CRTDBG_DELAY_FREE_MEM_DF; // turn it off 00032 00033 //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF); 00034 //_CrtMemState s1,s2,s3; 00035 //_CrtMemCheckpoint( &s1 ); 00036 00037 //ReactionNetwork *rN = new CEGFRTraffickingNetwork(); 00038 //rN->DumpPetriNetDotFile("PetriPC12.dot"); 00039 //rN->DumpTeXForm("traffic.tex"); 00040 //delete rN; 00041 00042 00043 // CRunDirector *rD = new COneGeneStochasticNetworkRunDirector(); 00044 //CRunDirector *rD = new COneGeneInhibitoryNetworkRunDirector(); 00045 //CRunDirector *rD = new COneGeneInhibitoryAveragingDirector(); 00046 //CRunDirector *rD = new CPC12EGFNGFRunDirector(); 00047 //CRunDirector *rD = new CEGFRTraffickingRunDirector(); 00048 //CEnsembleCombinationDirector *rD = new COneGeneEnsembleDirector(500); 00049 //CEnsembleCombinationDirector *rD = new CPC12EGFNGFEnsembleDirector(704); 00050 //CEnsembleCombinationDirector *rD = new CPC12AlternateEnsembleDirector(50); 00051 //CEnsembleCombinationDirector *rD = new CLaubLoomisDictyNetworkEnsembleDirector(60); 00052 //CEnsembleCombinationDirector *rD = new CPC12RapMinusEnsembleDirector(320); 00053 //CEnsembleCombinationDirector *rD = new CEGFRTraffickingEnsembleDirector(200); 00054 00055 /* 00056 rD->Execute(); 00057 cin.get(); 00058 delete rD; 00059 */ 00060 00061 /* 00062 NetworkMinimizableDirector *pS1 = new CPC12AlternateMinimizableDirector(); 00063 NetworkMinimizableDirector *pS0 = new PC12EGFNGFMinimizableDirector(); 00064 CParameterTranslator *pT = new CPC12ParameterTranslator(); 00065 CAcceptanceRatioFreeEnergyEstimator *pDeltaF = new CAcceptanceRatioFreeEnergyEstimator(pS0,686,pS1,1000,pT); 00066 pDeltaF->LoadEnsemble("ensemble0.par","ensemble1.par"); 00067 pDeltaF->ComputeHistograms(); 00068 00069 delete pS0; 00070 delete pS1; 00071 delete pT; 00072 delete pDeltaF; 00073 */ 00074 00075 // define an uber-minimizable 00076 //NetworkMinimizableDirector *nM = new CPC12AlternateMinimizableDirector(); 00077 00078 //NetworkMinimizableDirector *nM = new PC12EGFNGFMinimizableDirector(); 00079 00080 //NetworkMinimizableDirector *nM = new CPC12RapMinusMinimizableDirector(); 00081 00082 //NetworkMinimizableDirector *nM = new CCoupledPC12NetworksMinimizableDirector(0.01,0.0); 00083 00084 NetworkMinimizableDirector *nM = new COneGeneInhibitoryNetworkMinimizableDirector(); 00085 00086 // NetworkMinimizableDirector *nM = new COneGeneStochasticNetworkMinimizableDirector(); 00087 00088 //NetworkMinimizableDirector *nM = new CAlternateOneGeneInhibitoryNetworkMinimizableDirector(); 00089 00090 //NetworkMinimizableDirector *nM = new CExampleNetworkMinimizableDirector(); 00091 00092 //NetworkMinimizableDirector *nM = new CCoupledOneGeneNetworksMinimizableDirector(0.01,0.0); 00093 00094 //NetworkMinimizableDirector *nM = new CEGFRTraffickingIdealCellMinimizableDirector(); 00095 00096 //NetworkMinimizableDirector *nM = new CEGFRTraffickingCoupledMinimizableDirector(1.0,0.0); 00097 00098 //NetworkMinimizableDirector *nM = new CEGFRTraffickingNIH3T3MinimizableDirector(); 00099 00100 //NetworkMinimizableDirector *nM = new CEGFRTraffickingCHOMinimizableDirector(); 00101 00102 //NetworkMinimizableDirector *nM = new CLaubLoomisDictyNetworkMinimizableDirector(); 00103 00104 //NetworkMinimizableDirector *nM = new CMartielGoldbeterDictyNetworkMinimizableDirector(); 00105 00106 // NLLSMinimizable *nM = new TranslationModelMinimizable("../../folddata.dat",12); 00107 //NLLSMinimizable *nM = new TranslationModelMinimizable("folddata.dat",12); 00108 00109 00110 /* 00111 // read in two sets of parameters 00112 ParameterReader *pR1 = new ParameterReader("min2_cg_woPI3K.par"); 00113 double *p1 = new double[nM->GetNParameters()]; 00114 for(int i = 0; i < nM->GetNParameters(); i++) 00115 { 00116 p1[i] = pR1->ReadParameter(); 00117 } 00118 delete pR1; 00119 ParameterReader *pR2 = new ParameterReader("min3_cg_woPI3K.par"); 00120 double *p2 = new double[nM->GetNParameters()]; 00121 for(i = 0; i < nM->GetNParameters(); i++) 00122 { 00123 p2[i] = pR2->ReadParameter(); 00124 } 00125 delete pR2; 00126 ParameterReader *pR3 = new ParameterReader("min4_cg_woPI3K.par"); 00127 double *p3 = new double[nM->GetNParameters()]; 00128 for(i = 0; i < nM->GetNParameters(); i++) 00129 { 00130 p3[i] = pR3->ReadParameter(); 00131 } 00132 delete pR3; 00133 00134 // create the mapper and filter 00135 CLowDimensionalCostFunctionMapper *pMap = new CLowDimensionalCostFunctionMapper(); 00136 CParameterFilter *pFilter = new CLogParameterFilter(); 00137 // do the mapping 00138 pMap->Map(nM,pFilter,p1,p2,p3,-1,1,-1,1,961); 00139 00140 delete pMap; 00141 delete pFilter; 00142 delete nM; 00143 delete [] p1; 00144 delete [] p2; 00145 delete [] p3; 00146 */ 00147 00148 // use default parameters 00149 double *parameters = new double[nM->GetNParameters()]; 00150 for(int i = 0; i < nM->GetNParameters(); i++) 00151 { 00152 parameters[i] = nM->GetParameter(i); 00153 } 00154 00155 /* 00156 // read parameters from previous optimization pass 00157 // ParameterReader *pReader = new ParameterReader("../../translation_default.par"); 00158 ParameterReader *pReader = new ParameterReader("translation_default.par"); 00159 double *parameters = new double[nM->GetNParameters()]; 00160 cout << "Total number of parameters is " << nM->GetNParameters() << endl; 00161 for(i = 0; i < nM->GetNParameters(); i++) 00162 { 00163 parameters[i] = pReader->ReadParameter(); 00164 } 00165 delete pReader; 00166 */ 00167 /* 00168 // randomize parameters 00169 CParameterRandomizer *pR = new CParameterRandomizer(776157); 00170 pR->Randomize(parameters,nM->GetNParameters(),0.5,1); 00171 delete pR; 00172 */ 00173 00174 //cin.get(); 00175 //clock_t start,finish; 00176 //start = clock(); 00177 //double cost = nM->ObjectiveFunction(parameters); 00178 //cout << "Ground state cost is " << cost << endl; 00179 //finish = clock(); 00180 //for(i = 0; i < nM->GetNExperiments(); i++) 00181 //{ 00182 // cout << "Steps: " << nM->GetMover(i)->GetTotalStepsTaken() << endl; 00183 //} 00184 //cout << "Clock Duration: " << (double)(finish - start)/CLOCKS_PER_SEC; 00185 //cin.get(); 00186 00187 00188 /* 00189 // STEPSIZE TESTER - FOR USE WITH STOCHASTIC SENSITIVITY 00190 // evaluate the objective function at the minimum to determine what size step 00191 // to give to fixed stepsize mover 00192 double cost = nM->ObjectiveFunction(parameters); 00193 cout << "Cost of parameter set is " << cost << endl; 00194 for(int nEx = 0; nEx < nM->GetNExperiments(); nEx++) 00195 { 00196 cout << "Experiment " << nEx << ":" << endl; 00197 cout << "\tSmallest stepsize was " << nM->GetMover(nEx)->GetMinStepSize() << endl; 00198 cout << "\tLargest stepsize was " << nM->GetMover(nEx)->GetMaxStepSize() << endl; 00199 cout << "\tTotal number of steps was " << nM->GetMover(nEx)->GetTotalStepsTaken() << endl; 00200 } 00201 // just a dummy so I don't have to keep commenting out delete statement at bottom 00202 Minimizer *minimizer = new CBasicQuenchMinimizer(1,10,1.0,1); 00203 */ 00204 /* 00205 CParameterFilter *pFilter = new CLogParameterFilter(); 00206 CStochasticSensitivityAnalysis *minimizer = new CStochasticSensitivityAnalysis(false,false,0,9801,pFilter,1.0e-6,1.0); 00207 cout << "Performing Stochastic Sensitivity Analysis" << endl; 00208 00209 minimizer->DoAnalysis(parameters,nM); 00210 00211 cout << "RW Variance : " << minimizer->GetRWValue() << endl; 00212 delete pFilter; 00213 */ 00214 /* 00215 cout << "(mu/rho,lambda)-ES One Selected" << endl; 00216 CParameterFilter *filter = new CLogParameterFilter(); 00217 Minimizer *minimizer = new CCommaStrategyOne(filter,1.0,15,2,50,100,887); 00218 double cost = minimizer->Minimize(parameters,nM); 00219 cout << "Average cost of final population " << cost << endl; 00220 delete filter; 00221 */ 00222 /* 00223 cout << "(mu,lambda)-ES Selected" << endl; 00224 CParameterFilter *filter = new CLogParameterFilter(); 00225 Minimizer *minimizer = new CClonalCommaES(filter,0.0,15,100,1109); 00226 double cost = minimizer->Minimize(parameters,nM); 00227 cout << "Average cost of final population " << cost << endl; 00228 delete filter; 00229 */ 00230 00231 00232 // BE CAREFUL WITH THE ERROR TOLERANCE, PARTICULARLY IF YOU USE A LOW ORDER 00233 // INTEGRATOR 00234 /* 00235 cout << "Nelder-Mead Simplex Selected" << endl; 00236 CParameterFilter *filter = new CLogParameterFilter(); 00237 Minimizer *minimizer = new CNelderMeadSimplexMinimizer(filter,1000,2.0); 00238 double cost = minimizer->Minimize(parameters,nM); 00239 cout << "Final cost of " << cost << endl; 00240 delete filter; 00241 */ 00242 /* 00243 cout << "Levenberg-Marquardt Selected" << endl; 00244 CParameterFilter *filter = new CLogParameterFilter(); 00245 Minimizer *minimizer = new CImprovedLevenbergMarquardtMinimizer(filter,false,1.0e-06,false,1.0e-08,true,1.0e-06,true,1.0e-06,1,1.0e-06); 00246 Observer *LSObs = new CLeastSquaresObserver(); 00247 minimizer->Attach(LSObs); 00248 double cost = minimizer->Minimize(parameters,nM); 00249 cout << "Final cost of " << cost << endl; 00250 minimizer->Detach(LSObs); 00251 delete filter; 00252 delete LSObs; 00253 */ 00254 00255 /* 00256 cout << "Scale-Invariant Levenberg-Marquardt Selected" << endl; 00257 CParameterFilter *filter = new CLogParameterFilter(); 00258 Minimizer *minimizer = new CScaleInvariantMarquardtMinimizer(filter,false,1.0e-2,true,1.0e-08,true,1.0e-06,true,1.0e-06,1000,1.0e-06); 00259 double cost = minimizer->Minimize(parameters,nM); 00260 cout << "Final cost of " << cost << endl; 00261 delete filter; 00262 */ 00263 00264 cout << "Conjugate Gradient Selected" << endl; 00265 CParameterFilter *filter = new CLogParameterFilter(); 00266 Minimizer *minimizer = new CConjugateGradientMinimizer(false,filter,500,1.0e-06); 00267 //Observer *CGObs = new CConjugateGradientObserver(); 00268 //minimizer->Attach(CGObs); 00269 double cost = minimizer->Minimize(parameters,nM); 00270 //minimizer->Detach(CGObs); 00271 //delete CGObs; 00272 delete filter; 00273 00274 /* 00275 cout << "Basic Quench Selected" << endl; 00276 int nEquilibrationSteps = 25; 00277 double stepScale = 0.0; 00278 CParameterFilter *filter = new CLogParameterFilter(); 00279 Minimizer *minimizer = new CBasicQuenchMinimizer(nEquilibrationSteps,10,stepScale,99449,filter); 00280 double cost = minimizer->Minimize(parameters,nM); 00281 */ 00282 00283 /* 00284 cout << "Variable Stepsize SA Selected" << endl; 00285 CParameterFilter *filter = new CLogParameterFilter(); 00286 Minimizer *minimizer = new CVariableStepsizeAnnealMinimizer(4040440,filter,10,0.7,0.15,10); 00287 //GnuPlotter *plotter = new GnuPlotterSimulatedAnnealingObserver(); 00288 //minimizer->Attach(plotter); 00289 double cost = minimizer->Minimize(parameters,nM); 00290 //minimizer->Detach(plotter); 00291 //delete plotter; 00292 delete filter; 00293 */ 00294 /* 00295 cout << "Periodic Quench Selected" << endl; 00296 CParameterFilter *filter = new CLogParameterFilter(); 00297 Minimizer *minimizer = new CPeriodicQuenchMinimizer(5587,filter,true,10,200,1.0e-02,10,0.5,2.0); 00298 double cost = minimizer->Minimize(parameters,nM); 00299 delete filter; 00300 */ 00301 00302 cout << "Best cost for this minimization is " << cost << endl; 00303 // write the best parameters to a file and stdout 00304 fstream *pfbest = new fstream("onegene_cg.par",ios::out); 00305 *pfbest << "##################################################################" << endl; 00306 *pfbest << "# BEST PARAMETERS" << endl; 00307 *pfbest << "# COST : " << cost << endl; 00308 *pfbest << "##################################################################" << endl; 00309 for(int i = 0; i < nM->GetNParameters(); i++) 00310 { 00311 *pfbest << parameters[i] << endl; 00312 } 00313 delete pfbest; 00314 cout << "done?\n"; 00315 00316 // cin.get(); 00317 delete minimizer; 00318 delete [] parameters; 00319 00320 //delete nM causes a seg fault for some unknown reason 00321 // JJW 9/4/03 00322 //delete nM; 00323 00324 //_CrtDumpMemoryLeaks(); 00325 00326 //_CrtMemCheckpoint( &s2 ); 00327 00328 /* 00329 if ( _CrtMemDifference( &s3, &s1, &s2) ) 00330 _CrtMemDumpStatistics( &s3 ); 00331 */ 00332 00333 return 0; 00334 }