コード例 #1
0
ファイル: nmWorker.cpp プロジェクト: alexdarling/telPlugins
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());
    }
}
コード例 #2
0
ファイル: nmWorker.cpp プロジェクト: alexdarling/telPlugins
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();
}
コード例 #3
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;
}