Example #1
0
//------------------------------------------------------------------------
Parameter* ParameterContainer::addParameter (const TChar* title, const TChar* units,
											 int32 stepCount, ParamValue defaultNormalizedValue,
											 int32 flags, int32 tag, UnitID unitID)
{
	if (!title)
	{
		return 0;
	}

	ParameterInfo info = {0};

	UString (info.title, tStrBufferSize(String128)).assign (title);

	UString uUnits (info.units, tStrBufferSize(String128));
	if (units)
	{
		uUnits.assign (units);
	}

	info.stepCount = stepCount;
	info.defaultNormalizedValue = defaultNormalizedValue;
	info.flags = flags;
	info.id = (tag >= 0) ? tag : getParameterCount ();
	info.unitId = unitID;
	
	return addParameter (info);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IMPLEMENT THE FIT MODEL, THE FIT AND ALL THE PARAMETERS REQUIRED FOR THOSE
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void QFFCSMaxEntEvaluationItem::evaluateModel(QFRawDataRecord *record, int index, int model, double *taus, double *modelEval, uint32_t N, double* distTaus, double* dist, uint32_t Ndist) const {
    if (!taus || !modelEval) return;
    //qDebug()<<"evalModel(N="<<N<<"  distributionN="<<distributionN<<")";

    QVector<double> param_vector(getParameterCount(model));
    switch(model)
        {
            case 0:
                    param_vector[0]=getFitValue(record,index,model,"trip_tau")*1e-6;
                    param_vector[1]=getFitValue(record,index,model,"trip_theta");
                    param_vector[2]=getFitValue(record,index,model,"focus_struct_fac");
                    param_vector[3]=getFitValue(record,index,model,"offset");
                    break;
            case 1: param_vector[0]=getFitValue(record,index,model,"trip_tau")*1e-6;
                    param_vector[1]=getFitValue(record,index,model,"trip_theta");
                    param_vector[2]=getFitValue(record,index,model,"focus_struct_fac");
                    param_vector[3]=getFitValue(record,index,model,"dark_tau")*1e-6;
                    param_vector[4]=getFitValue(record,index,model,"dark_theta");
                    param_vector[5]=getFitValue(record,index,model,"offset");
                    break;
            case 2: param_vector[0]=getFitValue(record,index,model,"trip_tau")*1e-6;
                    param_vector[1]=getFitValue(record,index,model,"trip_theta");
                    param_vector[2]=getFitValue(record,index,model,"dark_tau")*1e-6;
                    param_vector[3]=getFitValue(record,index,model,"dark_theta");
                    param_vector[4]=getFitValue(record,index,model,"offset");
                    break;
            case 3: param_vector[0]=getFitValue(record,index,model,"A");
                    break;
            case 4: param_vector[0]=getFitValue(record,index,model,"tau_1")*1e-6;
                    param_vector[1]=getFitValue(record,index,model,"tau_2")*1e-6;
                    param_vector[2]=getFitValue(record,index,model,"focus_struct_fac");
                    param_vector[3]=getFitValue(record,index,model,"fraction");
                    param_vector[4]=getFitValue(record,index,model,"particle_number");
                    param_vector[5]=getFitValue(record,index,model,"offset");
                    break;

            case 5: //param_vector[0]=getFitValue(record,index,model,"maxent_wxy")*1e-3;
                    param_vector[0]=getFitValue(record,index,model,"focus_height")*1e-3;
                    param_vector[1]=getFitValue(record,index,model,"pixel_size")*1e-3;
                    param_vector[2]=getFitValue(record,index,model,"offset");
                    break;
            case 6: param_vector[0]=getFitValue(record,index,model,"pixel_size")*1e-3;
                    param_vector[1]=getFitValue(record,index,model,"offset");
                    break;

         }
    double* params=param_vector.data();

    MaxEntB040 mem_eval;
    mem_eval.evaluateModel(taus,modelEval,N,distTaus,dist,Ndist,params,model,getFitValue(record,index,model,"maxent_wxy")*1e-3);


}
Example #3
0
/**
 * @brief This function prints out a list of all available commands
 */
void helpCommand(void) {
#if EFI_PROD_CODE
	if (isBoardTestMode()) {
		printBoardTestState();
		return;
	}
#endif /* EFI_PROD_CODE */

#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
	scheduleMsg(logging, "%d actions available", consoleActionCount);
	for (int i = 0; i < consoleActionCount; i++) {
		TokenCallback *current = &consoleActions[i];
		scheduleMsg(logging, "  %s: %d parameters", current->token, getParameterCount(current->parameterType));
	}
#endif
	scheduleMsg(logging, "For more visit http://rusefi.com/wiki/index.php?title=Manual:Software:dev_console_commands");
}
emb_size_type getOptModelParameterCount(emb_optimizer optim)
{
	return getParameterCount(myModel);
}
Example #5
0
void
RemotePluginServer::dispatchControlEvents()
{    
    RemotePluginOpcode opcode = RemotePluginNoOpcode;
    static float *parameterBuffer = 0;

    tryRead(m_controlRequestFd, &opcode, sizeof(RemotePluginOpcode));

    switch (opcode) {

    case RemotePluginGetVersion:
	writeFloat(m_controlResponseFd, getVersion());
	break;

    case RemotePluginGetName:
	writeString(m_controlResponseFd, getName());
	break;

    case RemotePluginGetMaker:
	writeString(m_controlResponseFd, getMaker());
	break;
    
    case RemotePluginTerminate:
	terminate();
	break;
    
    case RemotePluginGetInputCount:
	m_numInputs = getInputCount();
	writeInt(m_controlResponseFd, m_numInputs);
	break;

    case RemotePluginGetOutputCount:
	m_numOutputs = getOutputCount();
	writeInt(m_controlResponseFd, m_numOutputs);
	break;

    case RemotePluginGetParameterCount:
	writeInt(m_controlResponseFd, getParameterCount());
	break;
	
    case RemotePluginGetParameterName:
	writeString(m_controlResponseFd, getParameterName(readInt(m_controlRequestFd)));
	break;
    
    case RemotePluginGetParameter:
	writeFloat(m_controlResponseFd, getParameter(readInt(m_controlRequestFd)));
	break;
    
    case RemotePluginGetParameterDefault:
	writeFloat(m_controlResponseFd, getParameterDefault(readInt(m_controlRequestFd)));
	break;

    case RemotePluginGetParameters:
    {
	if (!parameterBuffer) {
	    parameterBuffer = new float[getParameterCount()];
	}
	int p0 = readInt(m_controlRequestFd);
	int pn = readInt(m_controlRequestFd);
	getParameters(p0, pn, parameterBuffer);
	tryWrite(m_controlResponseFd, parameterBuffer, (pn - p0 + 1) * sizeof(float));
	break;
    }

    case RemotePluginHasMIDIInput:
    {
	bool m = hasMIDIInput();
	tryWrite(m_controlResponseFd, &m, sizeof(bool));
	break;
    }
       
    case RemotePluginGetProgramCount:
	writeInt(m_controlResponseFd, getProgramCount());
	break;

    case RemotePluginGetProgramName:
	writeString(m_controlResponseFd, getProgramName(readInt(m_controlRequestFd)));
	break;

    case RemotePluginIsReady:
    {
	if (!m_shm) sizeShm();
	bool b(isReady());
	std::cerr << "isReady: returning " << b << std::endl;
	tryWrite(m_controlResponseFd, &b, sizeof(bool));
    }

    case RemotePluginSetDebugLevel:
    {
	RemotePluginDebugLevel newLevel = m_debugLevel;
	tryRead(m_controlRequestFd, &newLevel, sizeof(RemotePluginDebugLevel));
	setDebugLevel(newLevel);
	m_debugLevel = newLevel;
	break;
    }

    case RemotePluginWarn:
    {
	bool b = warn(readString(m_controlRequestFd));
	tryWrite(m_controlResponseFd, &b, sizeof(bool));
	break;
    }

    case RemotePluginShowGUI:
    {
	showGUI(readString(m_controlRequestFd));
	break;
    }

    case RemotePluginHideGUI:
    {
	hideGUI();
	break;
    }

    //Deryabin Andrew: vst chunks support
    case RemotePluginGetVSTChunk:
    {
        std::vector<char> chunk = getVSTChunk();
        writeRaw(m_controlResponseFd, chunk);
        break;
    }

    case RemotePluginSetVSTChunk:
    {
        std::vector<char> chunk = readRaw(m_controlRequestFd);
        setVSTChunk(chunk);
        break;
    }
    //Deryabin Andrew: vst chunks support: end code

    case RemotePluginNoOpcode:
	break;

    case RemotePluginReset:
	reset();
	break;

    default:
	std::cerr << "WARNING: RemotePluginServer::dispatchControlEvents: unexpected opcode "
		  << opcode << std::endl;
    }
}
void QFFCSMaxEntEvaluationItem::doFit(QFRawDataRecord* record, int index, int model, int defaultMinDatarange, int defaultMaxDatarange, int runAvgWidth, int residualHistogramBins) {
    bool doEmit=record->isEmitResultsChangedEnabled();
    bool thisDoEmitResults=get_doEmitResultsChanged();
    bool thisDoEmitProps=get_doEmitResultsChanged();
    set_doEmitResultsChanged(false);
    set_doEmitPropertiesChanged(false);
    record->disableEmitResultsChanged();

    //qDebug() << "START DEBUGGING 0: We enter the do fit Method with MODEL = " << model;



    /* IMPLEMENT THIS

      Ergebnisse koennen einfach mit einer der setFitResult... Methoden gespeichert werden:

        //                                          PARAMETERNAME           WERT
        setFitResultValueBool(record, index, model, "evaluation_completed", true);
        //                                      PARAMETERNAME   WERT   FEHLER und EINHEIT (z.B. "ms") dazu
        setFitResultValue(record, index, model, "my_parameter", value, error, unit);

    */

    // HERE IS A DUMMY IMPLEMENTATION THAT OUTPUTS A SIMPLE GAUSSIAN
    QFRDRFCSDataInterface* data=qobject_cast<QFRDRFCSDataInterface*>(record);
    if (data) {
        getProject()->getServices()->log_text(tr("running MaxEnt fit with model '%1' on raw data record '%2', run %3 ... \n").arg(getModelName(model)).arg(record->getName()).arg(index));
        // which datapoints should we actually use?
        int rangeMinDatarange=0;
        int rangeMaxDatarange=data->getCorrelationN();
        if (defaultMinDatarange>=0) rangeMinDatarange=defaultMinDatarange;
        if (defaultMaxDatarange>=0) rangeMaxDatarange=defaultMaxDatarange;
        getProject()->getServices()->log_text(tr("   - fit data range: %1...%2 (%3 datapoints)\n").arg(defaultMinDatarange).arg(defaultMaxDatarange).arg(defaultMaxDatarange-defaultMinDatarange));




        uint32_t N=data->getCorrelationN();
        double* taus=data->getCorrelationT();
        double* distTaus=NULL;//(double*)qfCalloc(Ndist,sizeof(double));
        double* distDs=NULL;//(double*)qfCalloc(Ndist,sizeof(double));
        double* dist=NULL;//(double*)qfCalloc(Ndist,sizeof(double));
        double* modelEval=(double*)qfMalloc(N*sizeof(double));
        bool weightsOK=false;
        double* corrdata=data->getCorrelationMean();
        if (index>=0) corrdata=data->getCorrelationRun(index);
        double* weights=allocWeights(&weightsOK, record, index);
        if (!weightsOK) getProject()->getServices()->log_warning(tr("   - weights have invalid values => setting all weights to 1\n"));

        //////////Load Algorithm Parameters ////////////////////////////////////////////////
        double alpha=getFitValue(record,index,model,"maxent_alpha");
        int NumIter=getFitValue(record,index,model,"maxent_numiter");
        uint32_t Ndist=getFitValue(record,index,model,"maxent_Ndist");
        ////////////////////////////////////////////////////////////////////////////////////
        bool fitSuccess=false;


        //qDebug() << "DEBUG #1: alpha = " << alpha << " NumIter = " << NumIter << "Ndist =" << Ndist ;

        //////////Load Model Parameters//////////////////////////////////////////////////////
        //int parameter_count=getParameterCount(model);
        QVector<double> param_vector(getParameterCount(model));
        switch(model)
            {
                // FCS 3D diffusion with triplet
                case 0: param_vector[0]=getFitValue(record,index,model,"trip_tau")*1e-6;
                        param_vector[1]=getFitValue(record,index,model,"trip_theta");
                        param_vector[2]=getFitValue(record,index,model,"focus_struct_fac");
                        param_vector[3]=getFitValue(record,index,model,"offset");
                        break;
                // FCS 3D diffusion with 2 blinking components
                case 1:
                        param_vector[0]=getFitValue(record,index,model,"trip_tau")*1e-6;
                        param_vector[1]=getFitValue(record,index,model,"trip_theta");
                        param_vector[2]=getFitValue(record,index,model,"focus_struct_fac");
                        param_vector[3]=getFitValue(record,index,model,"dark_tau")*1e-6;
                        param_vector[4]=getFitValue(record,index,model,"dark_theta");
                        param_vector[5]=getFitValue(record,index,model,"offset");
                        break;
                // FCS 2D diffusion with 2 blinking components
                case 2:
                        param_vector[0]=getFitValue(record,index,model,"trip_tau")*1e-6;
                        param_vector[1]=getFitValue(record,index,model,"trip_theta");
                        param_vector[2]=getFitValue(record,index,model,"dark_tau")*1e-6;
                        param_vector[3]=getFitValue(record,index,model,"dark_theta");
                        param_vector[4]=getFitValue(record,index,model,"offset");
                        break;
                case 3: param_vector[0]=getFitValue(record,index,model,"A");
                        break;
                case 4: param_vector[0]=getFitValue(record,index,model,"tau_1")*1e-6;
                        param_vector[1]=getFitValue(record,index,model,"tau_2")*1e-6;
                        param_vector[2]=getFitValue(record,index,model,"focus_struct_fac");
                        param_vector[3]=getFitValue(record,index,model,"fraction");
                        param_vector[4]=getFitValue(record,index,model,"particle_number");
                        param_vector[5]=getFitValue(record,index,model,"offset");
                        break;
                case 5: //param_vector[0]=getFitValue(record,index,model,"maxent_wxy")*1e-3;
                        param_vector[0]=getFitValue(record,index,model,"focus_height")*1e-3;
                        param_vector[1]=getFitValue(record,index,model,"pixel_size")*1e-3;
                        param_vector[2]=getFitValue(record,index,model,"offset");
                        break;
                case 6: param_vector[0]=getFitValue(record,index,model,"pixel_size")*1e-3;
                        param_vector[1]=getFitValue(record,index,model,"offset");
                        break;



             }

        double *param_list=param_vector.data();
        //////////////////////////////////////////////////////////////////////////////////////////////////

        /*
        double kappa=getFitValue(record,index,model,"focus_struct_fac");
        double tripTau=getFitValue(record,index,model,"trip_tau")*1e-6;
        double tripTheta=getFitValue(record,index,model,"trip_theta");
        */

        QVector<double> init_tau=getFitValueNumberArray(record, index, model, "maxent_tau");
        QVector<double> init_dist=getFitValueNumberArray(record, index, model, "maxent_distribution");

        //qDebug()<<init_tau;

        bool old_distribution=false; // default value
        if (init_tau.size()>0 && init_dist.size()>0)
            {
                Ndist=qMin(init_tau.size(), init_dist.size());
                distTaus=(double*)qfCalloc(Ndist,sizeof(double));
                dist=(double*)qfCalloc(Ndist,sizeof(double));
                for (uint32_t i=0; i<Ndist; i++)
                    {
                        distTaus[i]=init_tau[i];
                        dist[i]=init_dist[i];
                    }
                old_distribution=true;
                //qDebug()<< "OLDDIST TRUE";
            }
        else
            {
                distTaus=NULL;
                dist=NULL;
                old_distribution=false;
                //qDebug()<< "OLDDIST FALSE";
                if (int64_t(Ndist)>(rangeMaxDatarange-rangeMinDatarange))
                    {
                        Ndist=(rangeMaxDatarange-rangeMinDatarange);
                    }

            }



        QElapsedTimer time;
        time.start();

        /////////////////////////////////////////////////////////
        /// MaxEnt Implementation ///////////////////////////////
        /////////////////////////////////////////////////////////
        double tau_min=getFitValue(record,index,model,"maxent_taumin");
        double tau_max=getFitValue(record,index,model,"maxent_taumax");
        MaxEntB040::TauMode tau_mode= (MaxEntB040::TauMode)getFitValue(record,index,model,"maxent_taumode");

        MaxEntB040 mem;
        mem.setData(taus,corrdata,weights,N,rangeMinDatarange,rangeMaxDatarange,Ndist,dist,distTaus, model,getParameterCount(model),param_list, getFitValue(record,index,model,"maxent_wxy")*1e-3, tau_mode, tau_min, tau_max);
        mem.run(alpha,NumIter,param_list,model,getParameterCount(model));
        fitSuccess=true;
        if (old_distribution==false)
            {
                distTaus=(double*)qfCalloc(Ndist,sizeof(double));
                dist=(double*)qfCalloc(Ndist,sizeof(double));
            }
        mem.writeDistTaus(distTaus);
        mem.writeDistribution(dist);
        /////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////


        // reset all NAN to 0
        for (unsigned int i=0; i<Ndist; i++) {
            double d=dist[i];
            if (!QFFloatIsOK(dist[i])) dist[i]=0;
            //qDebug()<<distTaus[i]<<" ,\t"<<d<<" ,\t"<<dist[i];
        }

        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
/*
        // REPLACE THIS WITH THE ACTUAL MAXENT FIT!!!
        double T0=1e-4;
        double sigma=2e-5;
        double dSum=0;
        for (int i=rangeMinDatarange; i<rangeMaxDatarange; i++) {
            const double t=taus[i];
            dist[i]=exp(-0.5*sqr(t-T0)/sqr(sigma));
            dSum=dSum+dist[i];
        }
        for (int i=rangeMinDatarange; i<rangeMaxDatarange; i++) {
            dist[i]=dist[i]/dSum;
        }
        fitSuccess=true;
        // FIT CODE COMPLETE
*/

        // duration measurement
        double duration=double(time.elapsed())/1000.0;

        getProject()->getServices()->log_text(tr("   - fit completed after %1 msecs with result %2\n").arg(duration).arg(fitSuccess?tr("success"):tr("no convergence")));

        distDs=(double*)qfCalloc(Ndist, sizeof(double));
        if (model!=3) {
            const double wxy=getWXY();
            for (uint32_t i=0; i<Ndist; i++) {
                distDs[i]=wxy*wxy/1000000.0/(4.0*distTaus[i]);
            }
        } else if (model==3) {
            const double q2=qfSqr(getDLSQ());
            //qDebug()<<"q2="<<q2;
            for (uint32_t i=0; i<Ndist; i++) {
                distDs[i]=1.0/(q2*distTaus[i]);
            }
        }

        // now store the results:
        QString param,paramtau,paramD,parammem;
        setFitResultValueNumberArray(record, index, model, paramtau=param="maxent_tau", distTaus, Ndist, QString("seconds"));
        setFitResultGroup(record, index, model, param, tr("fit results"));
        setFitResultLabel(record, index, model, param, tr("MaxEnt distribution: lag times"), QString("MaxEnt distribution: lag times <i>&tau;</i>"));
        setFitResultSortPriority(record, index, model, param, true);

        setFitResultValueNumberArray(record, index, model, paramD=param="maxent_D", distDs, Ndist, QString("seconds"));
        setFitResultGroup(record, index, model, param, tr("fit results"));
        setFitResultLabel(record, index, model, param, tr("MaxEnt distribution: diffusion coefficients"), QString("MaxEnt distribution: diffusion coefficients <i>D</i>"));
        setFitResultSortPriority(record, index, model, param, true);

        setFitResultValueNumberArray(record, index, model, parammem=param="maxent_distribution", dist, Ndist);
        setFitResultGroup(record, index, model, param, tr("fit results"));
        setFitResultLabel(record, index, model, param, tr("MaxEnt distribution"), QString("MaxEnt distribution: <i>p(&tau;)</i>"));
        setFitResultSortPriority(record, index, model, param, true);

        setFitResultValueInt(record, index, model, param="maxent_taumode", tau_mode);
        setFitResultGroup(record, index, model, param, tr("fit results"));
        setFitResultLabel(record, index, model, param, tr("MaxEnt distribution: tau mode"), tr("MaxEnt distribution: tau mode"));
        setFitResultSortPriority(record, index, model, param, true);

        QFRawDataRecord::evaluationCompoundResult comp;
        comp.type=QFRawDataRecord::qfrdrctGraph1D;
        comp.metadata["logX"]=true;
        comp.metadata["logY"]=false;
        comp.metadata["labelX"]=tr("correlation time \\tau_D [s]");
        comp.metadata["labelY"]=tr("MaxEnt distribution");
        comp.label=tr("MaxEnt(tauD)");
        comp.referencedResults<<paramtau<<parammem;
        record->resultsCompoundSet(getEvaluationResultID(index, model), "maxent_tau_curve", comp);

        comp.metadata["labelX"]=tr("diffusion coefficient D [{\\mu}m^2/s]");
        comp.label=tr("MaxEnt(D)");
        comp.referencedResults.clear();
        comp.referencedResults<<paramD<<parammem;
        record->resultsCompoundSet(getEvaluationResultID(index, model), "maxent_d_curve", comp);

        if (tau_mode>2) {

            double wxy=getFitValue(record,index,model,"maxent_wxy")*1e-3;

            setFitResultValue(record, index, model, param="maxent_taumax", wxy*wxy/(4.0*distTaus[0]), QString("seconds"));
            setFitResultGroup(record, index, model, param, tr("fit results"));
            setFitResultLabel(record, index, model, param, tr("MaxEnt distribution: minimum distribution times"), QString("MaxEnt distribution: minimum distribution times <i>&tau;<sub>min</sub></i>"));
            setFitResultSortPriority(record, index, model, param, true);

            setFitResultValue(record, index, model, param="maxent_taumin", wxy*wxy/(4.0*distTaus[Ndist-1]), QString("seconds"));
            setFitResultGroup(record, index, model, param, tr("fit results"));
            setFitResultLabel(record, index, model, param, tr("MaxEnt distribution: maximum distribution times"), QString("MaxEnt distribution: maximum distribution times <i>&tau;<sub>max</sub></i>"));
            setFitResultSortPriority(record, index, model, param, true);
        } else {
            setFitResultValue(record, index, model, param="maxent_taumin", distTaus[0], QString("seconds"));
            setFitResultGroup(record, index, model, param, tr("fit results"));
            setFitResultLabel(record, index, model, param, tr("MaxEnt distribution: minimum distribution times"), QString("MaxEnt distribution: minimum distribution times <i>&tau;<sub>min</sub></i>"));
            setFitResultSortPriority(record, index, model, param, true);

            setFitResultValue(record, index, model, param="maxent_taumax", distTaus[Ndist-1], QString("seconds"));
            setFitResultGroup(record, index, model, param, tr("fit results"));
            setFitResultLabel(record, index, model, param, tr("MaxEnt distribution: maximum distribution times"), QString("MaxEnt distribution: maximum distribution times <i>&tau;<sub>max</sub></i>"));
            setFitResultSortPriority(record, index, model, param, true);

        }


        // save all the default values for all fit parameters as results.
        for (int i=0; i<getParameterCount(model); i++) {
            param=getParameterID(model, i);
            double value=getFitValue(record, index, model, param);
            //qDebug()<<"model param "<<i<<": "<<param<<" = "<<value;
            setFitResultValue(record, index, model, param, value, getParameterUnit(model, i, false));
            setFitResultGroup(record, index, model, param, tr("fit results"));
            setFitResultLabel(record, index, model, param, getParameterName(model, i, false), getParameterName(model, i, true));
            setFitResultSortPriority(record, index, model, param, true);
            //qDebug()<<"model param "<<i<<": "<<param<<" = "<< getFitValue(record, index, model, param)<<getParameterUnit(model, i, false);
        }

        // you can overwrite certain of these parameters using code like this:
        /*setFitResultValue(record, index, model, param="focus_struct_fac", getFitValue(record, index, model, param));
        setFitResultGroup(record, index, model, param, tr("fit results"));
        setFitResultLabel(record, index, model, param, tr("focus structure factor"), QString("focus structure factor <i>&gamma;</i>"));
        setFitResultSortPriority(record, index, model, param, true);*/




        // store number of iterations ... you may also store more fit algorithm properties like this
        setFitResultValue(record, index, model, param="maxent_alpha", alpha);
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("MaxEnt scaling parameter alpha"), tr("scaling parameter &alpha;"));

        setFitResultValueInt(record, index, model, param="maxent_iterations", ceil(getFitValue(record, index, model, param)+NumIter));
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("number of MaxEnt iterations"), tr("number of MaxEnt iterations"));

        setFitResultValueInt(record, index, model, param="maxent_numiter", NumIter);
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("number of MaxEnt iterations in last run of algorithm"), tr("last MaxEnt iterations"));

        setFitResultValueString(record, index, model, param="used_model", getModelName(model));
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("used model name"), tr("used model name"));

        setFitResultValueInt(record, index, model, param="maxent_Ndist",Ndist);
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("MaxEnt number of distribution points"), tr("MaxEnt number of distribution points"));

        setFitResultValueInt(record, index, model, param="used_model_id", model);
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("used model id"), tr("used model id"));

        setFitResultValueInt(record, index, model, param="used_run", index);
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("used run"), tr("used run"));

        setFitResultValue(record, index, model, param="runtime", duration, tr("seconds"));
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("fit runtime"), tr("fit runtime"));

        setFitResultValueString(record, index, model, param="fitalg_message", tr("MaxEnt finished successfully after %1 iterations with alpha=%2").arg(NumIter).arg(alpha));
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("MaxEnt message"), tr("MaxEnt message"));

        setFitResultValueString(record, index, model, param="fitalg_messageHTML", tr("<b>MaxEnt finished successfully</b><br>after %1 iterations with &alpha;=%2").arg(NumIter).arg(alpha));
        setFitResultGroup(record, index, model, param, tr("fit properties"));
        setFitResultLabel(record, index, model, param, tr("MaxEnt message"), tr("MaxEnt message"));

        // CALCULATE FIT STATISTICS
        //   now we evaluate the model for the given distribution
        /////////////////////////
        /////////////////////////
        // I changed the 7th argument in the evaluateModel call from &(taus[rangeMindatarange]) to &(distTaus[rangeMinDatarange])
        // this is what the 7th and 8th argument used to be like: &(distTaus[rangeMinDatarange]), &(dist[rangeMinDatarange])
        // this was the last argument:  rangeMaxDatarange-rangeMinDatarange, now changed to Ndist
        ////////////////////////

        evaluateModel(record, index, model, taus, modelEval, N, distTaus,dist,Ndist);
        //   then we can call calcFitStatistics()
        QFFitStatistics fit_stat=calcFitStatistics(record, index, model, taus, corrdata, N,Ndist, rangeMinDatarange, rangeMaxDatarange, runAvgWidth, residualHistogramBins);
        //   finally we have to free the memory allocated in the calcFitStatistics() result.
        fit_stat.free();

        qfFree(dist);
        qfFree(weights);
        qfFree(modelEval);
        qfFree(distTaus);
        qfFree(distDs);


    }

    if (doEmit) record->enableEmitResultsChanged(true);
    set_doEmitResultsChanged(thisDoEmitResults);
    set_doEmitPropertiesChanged(thisDoEmitProps);
}
int MidiMessage::getArgCount(void) const {
   return getParameterCount();
}