Ejemplo n.º 1
0
double nmWorker::getChi(const Properties& parameters)
{
    Log(lDebug)<<"Getting chisquare using parameters: "<<parameters;
    //Reset RoadRunner
    mHost.mRRI->reset();

    for(int i = 0; i < parameters.count(); i++)
    {
        Property<double> *para = (Property<double>*) (parameters[i]);
        mHost.mRRI->setValue(para->getName(), para->getValue());
    }

    TelluriumData* expData = (TelluriumData*) mHost.mExperimentalData.getValueHandle();
    rr::SimulateOptions options;
    options.start       = expData->getTimeStart();
    options.duration    = expData->getTimeEnd() - expData->getTimeStart();
    options.steps       = expData->rSize() - 1;

    options.flags = options.flags | rr::SimulateOptions::RESET_MODEL;

    rr::RoadRunnerData *modelData = NULL;
    if(mHost.mRRI->simulate(&options))
    {
        modelData = mHost.mRRI->getSimulationResult();
    }

    TelluriumData& obsData      = *(TelluriumData*) mHost.mExperimentalData.getValuePointer();
    Plugin* chi                 = mHost.mPM->getPlugin("tel_chisquare");

    Property<TelluriumData>* para =  dynamic_cast<Property<TelluriumData>*>(chi->getProperty("ExperimentalData"));
    para->setValue(obsData);

    para =  dynamic_cast<Property<TelluriumData>*>(chi->getProperty("ModelData"));
    para->setValue(TelluriumData(*(modelData)));

    Property<int>* intPara =  dynamic_cast< Property<int>* >(chi->getProperty("NrOfModelParameters"));
    intPara->setValue(getNumberOfParameters());

    //Calculate Chi square
    chi->execute();
    Property<double>* chiSquare =  dynamic_cast< Property<double>* >(chi->getProperty("ChiSquare"));
    return chiSquare->getValue();
}
Ejemplo n.º 2
0
double lmWorker::getChi(const Properties& parameters)
{
    RRPLOG(lDebug)<<"Getting chisquare using parameters: "<<parameters;
    //Reset RoadRunner
    mRRI->reset();

    for(int i = 0; i < parameters.count(); i++)
    {
        Property<double> *para = (Property<double>*) (parameters[i]);
        mRRI->setValue(para->getName(), para->getValue());
    }

    rr::SimulateOptions options;
    options.start = mLMData.timeStart;
    options.duration = mLMData.timeEnd - mLMData.timeStart;
    options.steps = mLMData.nrOfTimePoints - 1;
    mRRI->reset();

    const DoubleMatrix* modelData = NULL;
    if(mRRI->simulate(&options))
    {
        modelData = mRRI->getSimulationData();
    }

    TelluriumData& obsData      = *(TelluriumData*) mTheHost.mExperimentalData.getValuePointer();
    Plugin* chi                 = mTheHost.mPM->getPlugin("tel_chisquare");

    Property<TelluriumData>* para =  dynamic_cast<Property<TelluriumData>*>(chi->getProperty("ExperimentalData"));
    para->setValue(obsData);

    para =  dynamic_cast<Property<TelluriumData>*>(chi->getProperty("ModelData"));
    TelluriumData td;
    td.setData(*modelData);
    para->setValue(td);

    Property<int>* intPara =  dynamic_cast< Property<int>* >(chi->getProperty("NrOfModelParameters"));
    intPara->setValue(mLMData.nrOfParameters);

    //Calculate Chi square
    chi->execute();
    Property<double>* chiSquare =  dynamic_cast< Property<double>* >(chi->getProperty("ChiSquare"));
    return chiSquare->getValue();
}
Ejemplo n.º 3
0
void nmWorker::createModelData(TelluriumData* _data)
{
    TelluriumData& data = *(_data);
    TelluriumData* expData = (TelluriumData*) mHost.mExperimentalData.getValueHandle();

    Properties& outParas =  * (Properties*) mHost.mOutputParameterList.getValueHandle();
    int nrOfParameters = outParas.count();

    //We now have the parameters
    StringList selList("time");
    selList.append(mHost.mModelDataSelectionList.getValue());

    data.reSize(expData->rSize(), selList.count());
    mHost.mRRI->reset();
    mHost.mRRI->setSelections(selList);

    for(int i = 0; i < nrOfParameters; i++)
    {
        mHost.mRRI->setValue(outParas[i]->getName(),  * (double*) outParas[i]->getValueHandle());
    }

    rr::SimulateOptions options;
    options.start       = expData->getTimeStart();
    options.duration    = expData->getTimeEnd() - expData->getTimeStart();
    options.steps       = expData->rSize() - 1;

    options.flags = options.flags | rr::SimulateOptions::RESET_MODEL;

    if(mHost.mRRI->simulate(&options))
    {
        data = * (mHost.mRRI->getSimulationResult());
    }
}
Ejemplo n.º 4
0
bool TelluriumData::append(const TelluriumData& dataToAppend)
{
    //When appending data, the number of rows have to match with current data
    if(mTheData.RSize() > 0)
    {
        if(dataToAppend.rSize() != rSize())
        {
            return false;
        }
    }
    else
    {
        //Starting with an empty data object. Simple assignment
        (*this) = dataToAppend;
        return true;
    }

    int originalColSize = cSize();

    //Copy our data to temp data object
    TelluriumData temp;
    temp = (*this);

    int newCSize = originalColSize + dataToAppend.cSize();

    //Check if first column is 'time'.. if so, ignore
    bool isFirstColTime = dataToAppend.isFirstColumnTime();

    if(isFirstColTime)
    {
        newCSize -= 1;
    }

    mTheData.resize(dataToAppend.rSize(), newCSize);

    //First, copy back 'original' data
    for(int row = 0; row < temp.rSize(); row++)
    {
        for( int col = 0; col < temp.cSize(); col++)
        {
            mTheData(row, col) = temp(row, col);
        }
    }

    //Append the data
    for(int col = isFirstColTime ? 1 : 0, colNr = 0; col < dataToAppend.cSize(); col++, colNr++)
    {
        for(int row = 0; row < mTheData.RSize(); row++)
        {
            int destCol = originalColSize  + colNr;
            mTheData(row, destCol) = dataToAppend(row, col);
        }
    }

    //Add column names
    for(int col = isFirstColTime ? 1 : 0; col < dataToAppend.cSize(); col++)
    {
        mColumnNames.add(dataToAppend.getColumnName(col));
    }
    return true;
}