NLFitSession::ParamsInitValues
ParamsInitValues
Description
Initialize parameters by parameter initialization code in FDF file.
Syntax
bool ParamsInitValues(bool bRunParamInit = true, DWORD dwInitCtrl = 0, int nFunc = -1)
Parameters
- bRunParamInit
- [input] if true will run parameter initializetion code, else the parameter value will be the default value defined in FDF file.
- dwInitCtrl
- [input] can be 0 to specify nothing. The enum like NLF_FUNC_CHANGE, NLF_RESET_SHARE_FIX, NLF_KEEP_OLD_DATASET.
- nFunc
- [input] the index of function, -1 for all functions. To specify initialize the parameters of which function.
Return
return ture if set function successfully.
Examples
EX1
- Prior to running the following example, the nlsf_utils.c file need to be loaded and compiled. This can be done from script with the command run.LoadOC(Originlab\nlsf_utils.c) or just add this file to your workspace.
- New a worksheet and import \Samples\Curve Fitting\Gaussian.dat.
- Copy and compile the following codes, and run "NLFitSession_ParamsInitValues_ex" in Command window.
#include <..\originlab\NLFitSession.h>
void NLFitSession_ParamsInitValues_ex()
{
Worksheet wks = Project.ActiveLayer();
if( !wks )
return;
XYRange dr;
dr.Add(wks, 0, "X");
dr.Add(wks, 1, "Y");
dr.Add();
dr.Add(wks, 0, "X");
dr.Add(wks, 2, "Y");
vector vX1, vY1, vX2, vY2;
dr.GetData(vY1, vX1, NULL, 0);
dr.GetData(vY2, vX2, NULL, 1);
int nNumDataset = dr.GetNumData(DRR_GET_DEPENDENT);
NLFitSession FitSession;
if( !FitSession.SetFunction("Gauss")) // set function as Gauss, category name can be ignore
{
out_str("invalid fit function");
return;
}
// set first dataset
if( !FitSession.SetData(vY1, vX1, NULL, 0, nNumDataset))
{
out_str("fail to set data");
return;
}
// set second dataset
if( !FitSession.SetData(vY2, vX2, NULL, 1, nNumDataset))
{
out_str("fail to set data");
return;
}
if( !FitSession.ParamsInitValues())
{
out_str("fail to initialize parameters");
return;
}
out_str("Parameter initialized successfully!");
// get parameter values after initialization
vector vParamValues;
vector<int> vnParamsOffsets; // the begin index of one group of parameters, normally one group for one dataset
FitSession.GetParamValuesAndOffsets(vParamValues, vnParamsOffsets);
// output parameter values with names
vector<string> vsParamNames;
FitSession.GetParamNamesInFunction(vsParamNames);
for(int nDataset = 0; nDataset < nNumDataset; nDataset++)
{
printf("---The parameters of data %d---\n", nDataset+1);
for( int nParam = vnParamsOffsets[nDataset], ii = 0; nParam < vnParamsOffsets[nDataset+1]; nParam++, ii++ )
{
printf("%s = %f\n", vsParamNames[ii], vParamValues[nParam]);
}
}
}
Remark
See Also
SetData, SetFunction, Fit
header to Include
Originlab\NLFitSession.h
|