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

SharedBFactorNetworkMinimizable.cpp

Go to the documentation of this file.
00001 // SharedBFactorNetworkMinimizable.cpp: implementation of the SharedBFactorNetworkMinimizable class.
00002 //
00004 
00005 #include "SharedBFactorNetworkMinimizable.h"
00006 
00008 // Construction/Destruction
00010 
00011 SharedBFactorNetworkMinimizable::SharedBFactorNetworkMinimizable()
00012 {
00013 
00014 }
00015 
00016 SharedBFactorNetworkMinimizable::SharedBFactorNetworkMinimizable(std::vector<Experiment *> experiments,std::vector<CReactionMover *> reactionMovers, bool rateConstantsOptimizable, bool initialChemConcOptimizable, bool logsInObjectiveFunction, double timeSeriesWeight, double rateConstantsWeight, double initialChemConcWeight, int nCells)
00017 {
00018         Initialize(experiments,reactionMovers,nCells,rateConstantsOptimizable,initialChemConcOptimizable,logsInObjectiveFunction,timeSeriesWeight,rateConstantsWeight,initialChemConcWeight);
00019 
00020 }
00021 
00022 SharedBFactorNetworkMinimizable::~SharedBFactorNetworkMinimizable()
00023 {
00024 //      delete [] initialNetworkData;
00025 //      delete [] currentNetworkData;
00026         for (int expCounter=0; expCounter < nExp; expCounter++) {
00027                 this->reactionMovers[expCounter]->Detach(cellObservers[expCounter]);
00028                 delete cellObservers[expCounter];
00029         }
00030         for(int i = 0; i < m_pConversionFactors.size(); i++)
00031         {
00032                 delete m_pConversionFactors[i];
00033         }
00034 }
00035 
00036 void SharedBFactorNetworkMinimizable::Initialize(std::vector<Experiment *> experiments, std::vector<CReactionMover *> reactionMovers, int nCells, bool rateConstantsOptimizable, bool initialChemConcOptimizable, bool logsInObjectiveFunction, double timeSeriesWeight, double rateConstantsWeight, double initialChemConcWeight)
00037 {
00038         this->nExp = experiments.size();
00039         this->experiments = experiments;
00040         this->reactionMovers = reactionMovers;
00041         this->nCells = nCells;
00042         this->rateConstantsOptimizable = rateConstantsOptimizable;
00043         this->initialChemConcOptimizable = initialChemConcOptimizable;
00044         this->logsInObjectiveFunction = logsInObjectiveFunction;
00045 
00046         this->SetTimeSeriesWeight(timeSeriesWeight);
00047         this->SetRateConstantsWeight(rateConstantsWeight);
00048         this->SetInitialChemConcWeight(initialChemConcWeight);
00049 
00050         for (int i=0; i < nExp; i++) {
00051                 // Read in the data
00052                 this->experiments[i]->ReadData();
00053                 // Read in forcing data (if any)
00054                 this->experiments[i]->ReadForcingData();
00055         }
00056 
00057         // Initialize variables dependent on the Experiment class
00058         // Should be safe using nChem and nRateConstants from the first experiment because I don't think this can be changed. -JJW 9-18-03
00059         int nChem = this->experiments[0]->GetReactionNetwork()->GetNumberOfChemicals();
00060         int nRateConstants = this->experiments[0]->GetReactionNetwork()->GetNumberOfRateConstants();
00061 //      int intTime = ((int) this->experiments[0]->GetChemicalTimeSeriesData()->GetLatestDataTime()) + 2;
00062 
00063         for(int expCounter=0; expCounter < nExp; expCounter++) {
00064                 assert(nChem == this->experiments[expCounter]->GetReactionNetwork()->GetNumberOfChemicals());
00065                 assert(nRateConstants == this->experiments[expCounter]->GetReactionNetwork()->GetNumberOfRateConstants() );
00066                 int intTime = ((int) this->experiments[expCounter]->GetChemicalTimeSeriesData()->GetLatestDataTime()) + 2;
00067 
00068                 this->cellObservers.push_back(new CellAverageObserver(nChem,intTime,nCells));
00069                 // attach the observer
00070                 this->reactionMovers[expCounter]->Attach(this->cellObservers[expCounter]);
00071         }
00072 
00073         initialNetworkData.reserve(nExp);
00074         currentNetworkData.reserve(nExp);
00075 
00076         for (int expCounter=0; expCounter<nExp; expCounter++) {
00077                 currentNetworkData.push_back(new std::vector<double *>);
00078                 (*currentNetworkData[expCounter]).reserve(nRateConstants + nChem);
00079                 initialNetworkData.push_back(new std::vector<double *>);
00080                 (*initialNetworkData[expCounter]).reserve(nRateConstants + nChem);
00081         }
00082 
00083 //      initialNetworkData = new double[nExp*(nRateConstants + nChem)];
00084 //      currentNetworkData = new double[nExp*(nRateConstants + nChem)];
00085 
00086         // load up the vector of conversion factors with dummies assuming all data is 
00087         // expressed in terms of number of molecules; if we don't have data we don't 
00088         // need conversion factors
00089         // need one conversion factor for every chemical which has any data on it in any
00090         // of the experiments but need same conversionfactor for same chemical in 
00091         // different experiments
00092         for(int l = 0; l < nChem; l++)
00093         {
00094                 bool needFactorI = false;
00095                 for (int i = 0; i < nExp; i++) {
00096                         if((experiments[i]->GetChemicalTimeSeriesData()->GetTimeSeries(l)).size() > 0 )
00097                         {
00098                                 needFactorI = true;
00099                                 break;
00100                         }
00101                 }
00102                 if (needFactorI) {
00103                         m_pConversionFactors.push_back(new CConversionFactor(true,false,1.0));
00104                 }
00105                 else
00106                 {
00107                         m_pConversionFactors.push_back(new CConversionFactor(false));
00108                 }
00109         }
00110         // I don't know what this is for -JJW 9-12-03
00111         m_iNBFactors = 0;
00112 
00113         // store beginning network data - this allows us to restore the 
00114         // initial state of the network to recover from the beginning
00115         for (int expCounter=0; expCounter < nExp; expCounter++) {
00116                 for(int i = 0; i < nRateConstants; i++)
00117                 {
00118                         (*initialNetworkData[expCounter]).push_back(new double);
00119                         (*(*initialNetworkData[expCounter])[i]) = this->experiments[expCounter]->GetReactionNetwork()->GetRateConstant(i)->GetInitialValue();
00120                         (*currentNetworkData[expCounter]).push_back(new double);
00121                         (*(*currentNetworkData[expCounter])[i]) = (*(*initialNetworkData[expCounter])[i]);
00122                 }
00123                 for(int i = nRateConstants; i < nRateConstants + nChem; i++)
00124                 {
00125                         (*initialNetworkData[expCounter]).push_back(new double);
00126                         (*(*initialNetworkData[expCounter])[i]) = this->experiments[expCounter]->GetReactionNetwork()->GetChemical(i-nRateConstants)->GetInitialAmount();
00127                         (*currentNetworkData[expCounter]).push_back(new double);
00128                         (*(*currentNetworkData[expCounter])[i]) = (*(*initialNetworkData[expCounter])[i]);
00129 
00130                 }
00131         }
00132 
00133         int localResidualsSize = 0;
00134         if(this->timeSeriesWeight > 0.0) {
00135                 for (int expCounter=0; expCounter < nExp; expCounter++) {
00136                         localResidualsSize += this->experiments[expCounter]->GetChemicalTimeSeriesData()->GetNDataPoints();
00137                 }
00138         }
00139         if(this->rateConstantsWeight > 0.0) {localResidualsSize += nExp*nRateConstants;}
00140         if(this->initialChemConcWeight > 0.0) {localResidualsSize       += nExp*nChem;}
00141 
00142         Allocate(localResidualsSize);
00143 
00144 }
00145 
00146 double SharedBFactorNetworkMinimizable::ComputeES(double *parameters, double T)
00147 {
00148         m_dEnergyLastComputed = this->ComputeResiduals(parameters);
00149         double S = this->EntropyShift(T) - 0.5*m_dEntropyLastComputed;
00150         m_dEntropyLastComputed = S;
00151         return m_dEnergyLastComputed;
00152 }
00153 /*
00154 double SharedBFactorNetworkMinimizable::EntropyShift(double T)
00155 {
00156         return 0.5*m_iNBFactors*log(2*3.14159265358979323846*T);
00157 }
00158 */
00159 double SharedBFactorNetworkMinimizable::F(double *parameters, double T)
00160 {
00161         m_dEnergyLastComputed = this->ComputeResiduals(parameters);
00162         double S = -0.5*m_dEntropyLastComputed;
00163         m_dEntropyLastComputed = S;
00164         return (m_dEnergyLastComputed - T*m_dEntropyLastComputed);
00165 }
00166 
00167 double SharedBFactorNetworkMinimizable::F0(double *parameters, double T)
00168 {
00169         m_dEnergyLastComputed = this->ComputeResiduals(parameters);
00170         double S = this->EntropyShift(T) - 0.5*m_dEntropyLastComputed;
00171         m_dEntropyLastComputed = S;
00172         return (m_dEnergyLastComputed - T*m_dEntropyLastComputed);
00173 }
00174 
00175 double SharedBFactorNetworkMinimizable::ComputeResiduals(double *parameters)
00176 {
00177         m_iNBFactors = 0;
00178         m_dEntropyLastComputed = 0.0;
00179         double partialEntropy = 0.0;
00180         
00181         double objFuncVal = 0.0;
00182         //should be safe since all the experiments should have the same number of rateconstants and chemicals (maybe) -JJW
00183         int nRateConstants = experiments[0]->GetReactionNetwork()->GetNumberOfRateConstants();
00184         int nChem = experiments[0]->GetReactionNetwork()->GetNumberOfChemicals();
00185         // put the parameters into the network
00186         // rate constants first, then initial chemical concentrations
00187 //              int base = j*(nRateConstants+nChem);
00188 //              for(int i = base+0; i < base+nRateConstants; i++)
00189 //                      initialNetworkData[i] = this->experiments[j]->GetReactionNetwork()->GetRateConstant(i-base)->GetInitialValue();
00190 //              for(int i = base+nRateConstants; i < base+nRateConstants + nChem; i++)
00191 //                      initialNetworkData[i] = this->experiments[j]->GetReactionNetwork()->GetChemical(i-base-nRateConstants)->GetInitialAmount();
00192 
00193         if(rateConstantsOptimizable && initialChemConcOptimizable)
00194         {
00195                 for (int expCounter = 0; expCounter < nExp; expCounter++) {
00196                         for(int i = 0; i < nRateConstants; i++)
00197                         {
00198                                 experiments[expCounter]->GetReactionNetwork()->GetRateConstant(i)->SetRateConstant(parameters[i]);
00199                                 (*(*currentNetworkData[expCounter])[i]) = parameters[i];
00200                         }
00201                         for(int i = nRateConstants; i < nRateConstants + nChem; i++)
00202                         {
00203                                 experiments[expCounter]->GetReactionNetwork()->GetChemical(i - nRateConstants)->SetAmount(parameters[i]);
00204                                 (*(*currentNetworkData[expCounter])[i]) = parameters[i];
00205                         }
00206                 }
00207         }
00208         else if(rateConstantsOptimizable)
00209         {
00210                 for (int expCounter = 0; expCounter < nExp; expCounter++) {
00211                         for(int i = 0; i < nRateConstants; i++)
00212                         {
00213                                 experiments[expCounter]->GetReactionNetwork()->GetRateConstant(i)->SetRateConstant(parameters[i]);
00214                                 (*(*currentNetworkData[expCounter])[i]) = parameters[i];
00215                         }
00216                         experiments[expCounter]->GetReactionNetwork()->ChemicalReset();
00217                 }
00218         }
00219         else if(initialChemConcOptimizable)
00220         {
00221                 for (int expCounter = 0; expCounter < nExp; expCounter++) {
00222                         for(int i = 0; i < nChem; i++)
00223                         {
00224                                 experiments[expCounter]->GetReactionNetwork()->GetChemical(i)->SetAmount(parameters[i]);
00225                                 (*(*currentNetworkData[expCounter])[i+nRateConstants]) = parameters[i];
00226                         }
00227                         experiments[expCounter]->GetReactionNetwork()->RateConstantReset();
00228                 }
00229         }
00230         else
00231         {
00232                 // do one run at the existing parameter values
00233                 // this ensures that multiple calls with the same parameters
00234                 // give the same cost, but it also ensures that only time
00235                 // series contribute to the cost - this is probably not what
00236                 // we want?
00237                 for (int expCounter = 0; expCounter < nExp; expCounter++) {
00238                         experiments[expCounter]->GetReactionNetwork()->RateConstantReset();
00239                         experiments[expCounter]->GetReactionNetwork()->ChemicalReset();
00240                 }
00241         }
00242 
00243         // zero the observer
00244         for (int expCounter = 0; expCounter < nExp; expCounter++) {
00245                 cellObservers[expCounter]->ZeroConcentrations();
00246         }
00247         for (int expCounter = 0; expCounter < nExp; expCounter++) {
00248 
00249                 for(int cellCounter = 1; cellCounter <= nCells; cellCounter++)
00250                 {
00251                         // make sure the concentration in the network is re-initialized, which
00252                         // is done differently whether you allow initial conc. optimization
00253                         // or not
00254                         //experiment->GetReactionNetwork()->ChemicalReset();
00255                         if(initialChemConcOptimizable)
00256                         {
00257                                 for(int i = nRateConstants; i < nRateConstants + nChem; i++)
00258                                 {
00259                                         experiments[expCounter]->GetReactionNetwork()->GetChemical(i - nRateConstants)->SetAmount(parameters[i]);
00260                                 }
00261                         }
00262                         else
00263                         {
00264                                 experiments[expCounter]->GetReactionNetwork()->ChemicalReset();
00265                         }
00266 
00267                         // if there's no forcing data at all, we can just run from (0,tfinal). 
00268                         // Otherwise we have to stop running in between forcing changes.  This
00269                         // block might be able to be rearranged to be much faster. KSB 4/16/02
00270                         
00271                         // reset step size statistics in either case
00272                         reactionMovers[expCounter]->ResetStepStatistics(experiments[expCounter]->GetChemicalTimeSeriesData()->GetLatestDataTime());
00273 
00274                         // now move through the rest
00275                         if(experiments[expCounter]->GetForcingData()->GetForcingVector().size() == 0)
00276                         {
00277                                 // take data at time 0
00278                                 reactionMovers[expCounter]->Move(0.0,0.0,experiments[expCounter]->GetReactionNetwork());
00279                                 reactionMovers[expCounter]->Move(0.0,experiments[expCounter]->GetChemicalTimeSeriesData()->GetLatestDataTime(),experiments[expCounter]->GetReactionNetwork());
00280                         }
00281                         else
00282                         {
00283                                 int forceCount = 0;
00284                                 double time = 0.0;
00285                                 int lastForce = experiments[expCounter]->GetForcingData()->GetForcingVector().size();
00286                                 double finaltime = experiments[expCounter]->GetChemicalTimeSeriesData()->GetLatestDataTime();
00287                                 double finalForceTime = experiments[expCounter]->GetForcingData()->GetLatestForcingTime();
00288                                 int index;
00289                                 int start,stop;
00290                                 double t1,t2,value;
00291                                 while(time < finalForceTime)
00292                                 {
00293                                         start = forceCount;
00294                                         stop = forceCount;
00295                                         t1 = experiments[expCounter]->GetForcingData()->GetForcingVector()[start]->GetTime();
00296                                         // find the starting and stopping points
00297                                         for(int i = start; i < lastForce; i++)
00298                                         {
00299                                                 t2 = experiments[expCounter]->GetForcingData()->GetForcingVector()[i]->GetTime();
00300                                                 if(t1 == t2)
00301                                                 {
00302                                                 }
00303                                                 else
00304                                                 {
00305                                                         stop = i-1;
00306                                                         for(int k = start; k <= stop; k++)
00307                                                         {
00308                                                                 index = experiments[expCounter]->GetForcingData()->GetForcingVector()[k]->GetChemNumber();
00309                                                                 value = experiments[expCounter]->GetForcingData()->GetForcingVector()[k]->GetValue();
00310                                                                 experiments[expCounter]->GetReactionNetwork()->GetChemical(index)->SetAmount(value);
00311                                                         }
00312                                                         break;
00313                                                 }
00314                                         }
00315                                         forceCount = stop+1;
00316                                         // move for the correct amount of time
00317                                         reactionMovers[expCounter]->Move(time,t1,experiments[expCounter]->GetReactionNetwork());
00318                                         time = t1;
00319                                 }
00320                                 // take care of the last force points
00321                                 // find the starting and stopping points
00322                                 t2 = finalForceTime;
00323                                 stop = lastForce-1;
00324                                 for(int i = lastForce-1; i > 0; i--)
00325                                 {
00326                                         t1 = experiments[expCounter]->GetForcingData()->GetForcingVector()[i]->GetTime();
00327                                         if(t1 == t2)
00328                                         {
00329                                         }
00330                                         else
00331                                         {
00332                                                 start = i+1;
00333                                                 for(int k = start; k <= stop; k++)
00334                                                 {
00335                                                         index = experiments[expCounter]->GetForcingData()->GetForcingVector()[k]->GetChemNumber();
00336                                                         value = experiments[expCounter]->GetForcingData()->GetForcingVector()[k]->GetValue();
00337                                                         experiments[expCounter]->GetReactionNetwork()->GetChemical(index)->SetAmount(value);
00338                                                 }
00339                                                 break;
00340                                         }
00341                                 }
00342                                 // now run to the end, unless we're already there
00343                                 if(finaltime > time)
00344                                 {
00345                                         reactionMovers[expCounter]->Move(time,finaltime,experiments[expCounter]->GetReactionNetwork());
00346                                 }
00347                                 time = finaltime;
00348                         }
00349                 } //end cellCount
00350         } //end nExp
00351 
00352         // compute the scaling factors; successive computation of the cost is somewhat of a
00353         // repeat of this operation, so combining the two calculations in the future may 
00354         // speed things up
00355 
00356         for(int chemCount = 0; chemCount < nChem; chemCount++)
00357         {
00358                 double num = 0.0;
00359                 double den = 0.0;
00360                 //ChemicalTimeSeriesData *cTSD = experiment->GetChemicalTimeSeriesData();
00361                 // do we need a scaling factor AND is it allowed to vary?
00362                 if(m_pConversionFactors[chemCount]->IsFactorNeeded())
00363                 {
00364                         if(m_pConversionFactors[chemCount]->IsFactorFixed())
00365                         {
00366                                 num = m_pConversionFactors[chemCount]->GetFactorValue();
00367                                 den = 1.0;
00368                         }
00369                         else
00370                         {
00371                                 m_iNBFactors++;
00372                                 for (int expCounter=0; expCounter < nExp; expCounter++) {
00373                                         int dataSize = (experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeSeries(chemCount)).size();
00374                                         // loop over the number of data points and compute
00375                                         for(int nData = 0; nData < dataSize; nData++)
00376                                         {
00377                                                 double time = experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeSeries(chemCount)[nData]->GetTime();
00378                                                 double data = experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeSeries(chemCount)[nData]->GetDatum();
00379                                                 double error = experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeSeries(chemCount)[nData]->GetError();
00380                                                 double sim = (cellObservers[expCounter]->GetAverageConcentration())[chemCount][int(time)];
00381                                                 num += ((2*sim)/(error*error))*data;
00382                                                 den += ((2*sim)/(error*error))*sim;
00383                                                 
00384                                                 partialEntropy += ((sim*sim)/(error*error));
00385                                         }
00386                                         m_dEntropyLastComputed += log(partialEntropy);
00387                                 } // end expCounter
00388                         }
00389                 }
00390                 else
00391                 {
00392                         num = 1.0;
00393                         den = 1.0;
00394                 }
00395                 double factor = num/den;
00396 //              cerr << "chemCount " << chemCount << " has B factor " << factor << endl;
00397                 m_pConversionFactors[chemCount]->SetFactorValue(factor);
00398 
00399         }
00400 
00401         // compute the cost
00402         int nextAvailableIndex = 0;
00403         if(timeSeriesWeight > 0.0)
00404         {
00405                 for (int expCounter=0; expCounter<nExp; expCounter++) {
00406                         // load the time series residuals in the master list
00407                         for(int chemIt = 0; chemIt < (experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeVector()).size(); chemIt++)
00408                         {
00409                                 // get the keys
00410                                 double targetTime = (experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeVector())[chemIt]->GetTime();
00411                                 int targetChem = (experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeVector())[chemIt]->GetChemNumber();
00412                                 int vectorIndex = (experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeVector())[chemIt]->GetVectorIndex();
00413                                 // use the keys
00414                                 double data = (experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeSeries(targetChem))[vectorIndex]->GetDatum();
00415                                 double sigma = (experiments[expCounter]->GetChemicalTimeSeriesData()->GetTimeSeries(targetChem))[vectorIndex]->GetError();
00416                                 double sim = (cellObservers[expCounter]->GetAverageConcentration())[targetChem][int(targetTime)];
00417                                 // rescale sim if there is a conversion factor
00418                                 if(m_pConversionFactors[targetChem]->IsFactorNeeded())
00419                                 {
00420                                         sim = sim*(m_pConversionFactors[targetChem]->GetFactorValue());
00421                                 }
00422                                 // compute quantities of interest
00423                                 residuals[nextAvailableIndex] = (sqrt(timeSeriesWeight/2.0))*((data - sim)/sigma);
00424                                 objFuncVal += residuals[nextAvailableIndex]*residuals[nextAvailableIndex];
00425                                 nextAvailableIndex++;
00426                         }
00427                 } // end expCounter
00428         }
00429 
00430         if(rateConstantsWeight > 0.0)
00431         {
00432                 for (int expCounter=0; expCounter<nExp; expCounter++) {
00433                         // load in the rate constants residuals in the master list
00434                         if(logsInObjectiveFunction)
00435                         {
00436                                 for(int i = 0; i < nRateConstants; i++)
00437                                 {
00438                                         double sigma = experiments[expCounter]->GetReactionNetwork()->GetRateConstant(i)->GetErrorInInitialValue();
00439                                         double sigmalog = sigma/(*(*initialNetworkData[expCounter])[i]);
00440                                         residuals[nextAvailableIndex] = (sqrt(rateConstantsWeight/2.0))*(log((*(*initialNetworkData[expCounter])[i])/(*(*currentNetworkData[expCounter])[i]))/sigmalog);
00441                                         objFuncVal += residuals[nextAvailableIndex]*residuals[nextAvailableIndex];
00442                                         nextAvailableIndex++;
00443                                 }
00444                         }
00445                         else
00446                         {
00447                                 for(int i = 0; i < nRateConstants; i++)
00448                                 {
00449                                         double sigma = experiments[expCounter]->GetReactionNetwork()->GetRateConstant(i)->GetErrorInInitialValue();
00450                                         residuals[nextAvailableIndex] = (sqrt(rateConstantsWeight/2.0))*((initialNetworkData[i+expCounter*(nRateConstants+nChem)] - currentNetworkData[i+expCounter*(nRateConstants+nChem)])/sigma);
00451                                         objFuncVal += residuals[nextAvailableIndex]*residuals[nextAvailableIndex];
00452                                         nextAvailableIndex++;
00453                                 }
00454                         }
00455                 } // end expCounter
00456         }
00457 
00458         if(initialChemConcWeight > 0.0)
00459         {
00460                 for (int expCounter=0; expCounter<nExp; expCounter++) {
00461                         // load in the initial chemical concentration residuals in the master list
00462                         for(int i = 0; i < nChem; i++)
00463                         {       
00464                                 double sigma = experiments[expCounter]->GetReactionNetwork()->GetChemical(i)->GetErrorInInitialAmount();
00465                                 residuals[nextAvailableIndex] = (sqrt(initialChemConcWeight/2.0))*((initialNetworkData[i+nRateConstants+expCounter*(nRateConstants+nChem)] - currentNetworkData[i+nRateConstants+expCounter*(nRateConstants+nChem)])/sigma);
00466                                 objFuncVal += residuals[nextAvailableIndex]*residuals[nextAvailableIndex];
00467                                 nextAvailableIndex++;
00468                         }
00469                 } //end expCounter
00470         }
00471 
00472         // notify observers
00473         Notify();
00474 
00475         return objFuncVal;
00476 }
00477 
00478 int SharedBFactorNetworkMinimizable::GetNParameters()
00479 {
00480 //      int nRateConstants = experiment->GetReactionNetwork()->GetNumberOfRateConstants();
00481 //      int nChem = experiment->GetReactionNetwork()->GetNumberOfChemicals();
00482 //      int nParameters;
00483 
00484         int nRateConstants = experiments[0]->GetReactionNetwork()->GetNumberOfRateConstants();
00485         int nChem = experiments[0]->GetReactionNetwork()->GetNumberOfChemicals();
00486         int nParameters;
00487 
00488 
00489         if(rateConstantsOptimizable && initialChemConcOptimizable)
00490         {
00491                 nParameters = nRateConstants + nChem;
00492         }
00493         else if(rateConstantsOptimizable)
00494         {
00495                 nParameters = nRateConstants;
00496         }
00497         else if(initialChemConcOptimizable)
00498         {
00499                 nParameters = nChem;
00500         }
00501         else
00502         {
00503                 nParameters = 0;
00504         }
00505 
00506         return nParameters;
00507 }
00508 
00509 double SharedBFactorNetworkMinimizable::GetParameter(int parIndex)
00510 {
00511         int nP = GetNParameters();
00512         
00513         if(parIndex > nP)
00514         {
00515                 throw std::runtime_error("Parameter index is off parameter list.");
00516         }
00517         else
00518         {
00519                 return (*(*currentNetworkData[0])[parIndex]);
00520         }
00521 
00522         return 0.0;
00523 }

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