The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Operation NLFIT Tree Structure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cab0008

25 Posts

Posted - 03/07/2012 :  7:13:58 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello Everyone,

I am hoping someone has a good idea of how to navigate structrues of trees. I know this is probably an easily solved problem, but I'm not much of a great coder, so having a hard time finding the solution.

I am trying to use an operation for fitting a spectrum of many peaks whose parameters may depend on each other. I've been mainly following this pattern: http://ocwiki.originlab.com/index.php?title=OriginC:Fitting_with_Operation but I'm not sure how the parameter values are really stored, i.e. the trOp.GUI.Parameters.FixedValues.Value1.dVal is working fine for me as y0, but I would think for a lorentz that trOp.GUI.Parameters.FixedValues.Value5.dVal would be the baseline for my second dataset, but it is not showing up this way.
I believe there may just be some parameter that I'm not takning into account so it gets me off in the index, but I don't know where to look for this.

To further my example, I'll give a simplified version of my code and my real code I'm using:

simple code:


void function(vector vX, vector vY){
	//number of peaks in xy data
	int nNumPeaks;
	nNumPeaks=10;
	
	//wavelength peak locations in nanometers 
	vector vPeakLocations(nNumPeaks);
	vPeakLocations[0] = 873;
	vPeakLocations[1] = 912;
	vPeakLocations[2] = 952;
	vPeakLocations[3] = 976; 
	vPeakLocations[4] = 992;
	vPeakLocations[5] = 1024;
	vPeakLocations[6] = 1041;
	vPeakLocations[7] = 1053;
	vPeakLocations = 1101;
	vPeakLocations[9] = 1111;
	vPeakLocations[10] = 1120;
	
	
	//create vector for parameters such as whether or not the parameter is fixed, etc.
	//add vPeakLocations as a parameter as well
	//4 is there because it is supposed to be the number of parameters in a lorentzian (y0,xc,w,A)
	vector vParameterNumbers(nNumPeaks*4);   
	vector vParameterFixedBoolean(nNumPeaks*4);
	for(i=0;i<vPeakLocations.GetSize();i++){
		vParameterNumbers[i*4]=0;  //yc
		vParameterNumbers[i*4+1]=1239.87/vSpeciesS11nm[i];  //xc
		vParameterNumbers[i*4+2]=1239.87/10;  //w
		vParameterNumbers[i*4+3]=1;  //A
		vParameterFixedBoolean[i*4]=1;  //fix y0
		vParameterFixedBoolean[i*4+1]=1;  //fix xc
		vParameterFixedBoolean[i*4+2]=0;  //fix w
		vParameterFixedBoolean[i*4+3]=0;  //fix A
	}
	
	//some setup fitting stuff
	bool bInit;
	Operation& op = (Operation&)op_create("FitNL", bInit);  // the operation name of NLFit is FitNL
	Tree trOp;
	op.GetTree(trOp);
	op.OnInitDataFromOCLT(trOp, trOp.GUI.InputData, dr, "Lorentz", "Peak Functions")){
    	trOp.GUI.Replica.Number.nVal = nNumPeaks-1;   




////////////////////////////////////
////This should give the values for all of my lorentz peaks y0=0,  xc=(sequential value from vPeakLocations), w=1239.87/10, A=fitted value
////why is this not working?
    // set fix
    //use foreach loop to set each value in the treenode to the needed value from the vector
    int index=0;
    foreach(TreeNode trNode in trOp.GUI.Parameters.Fixed.Children){
    	if( trNode.Show )//ignore hidden node
            trNode.nVal = vParameterFixedBoolean[index++];  
    }
    index=0;
    foreach(TreeNode trNode1 in trOp.GUI.Parameters.FixedValues.Children){
    	if( trNode1.Show )//ignore hidden node
            trNode1.dVal = vParameterNumbers[index++];  
    }
    


    op.SetTree(trOp);    
    int nAutoUpdate = AU_AUTO;
    op.OnNoEdit(0, nAutoUpdate);
    op.Execute(); 
    op.GetTree(trOp);



real code:

void deconvoluteOA(vector vXeV, vector vYeV){
	int i=0;
	
	int nNumSpecies;
	nNumSpecies=25;
	int nNumPeaks=nNumSpecies;
	vector<string> vSpecies(nNumSpecies);
	vSpecies[0] = "6,4";
	vSpecies[1] = "9,1";
	vSpecies[2] = "8,3";
	vSpecies[3] = "6,5";
	vSpecies[4] = "7,3";
	vSpecies[5] = "7,5";
	vSpecies[6] = "8,1";
	vSpecies[7] = "10,2";
	vSpecies = "9,4";
	vSpecies[9] = "8,4";
	vSpecies[10] = "7,6";
	vSpecies[11] = "9,2";
	vSpecies[12] = "12,1";
	vSpecies[13] = "8,6";
	vSpecies[14] = "11,3";
	vSpecies[15] = "9,5";
	vSpecies[16] = "10,3";
	vSpecies[17] = "10,5";
	vSpecies[18] = "8,7";
	vSpecies[19] = "9,7";
	vSpecies[20] = "11,4";
	vSpecies[21] = "12,2";
	vSpecies[22] = "10,6";
	vSpecies[23] = "11,6";
	vSpecies[24] = "9,8";
	
	vector vSpeciesS11nm(nNumSpecies);
	vSpeciesS11nm[0] = 873; //6,4
	vSpeciesS11nm[1] = 912; //9,1
	vSpeciesS11nm[2] = 952; //8,3
	vSpeciesS11nm[3] = 976; //6,5
	vSpeciesS11nm[4] = 992; //"7,3";
	vSpeciesS11nm[5] = 1024; //"7,5";
	vSpeciesS11nm[6] = 1041; //"8,1";
	vSpeciesS11nm[7] = 1053; //"10,2";
	vSpeciesS11nm = 1101; //"9,4";
	vSpeciesS11nm[9] = 1111; //"8,4";
	vSpeciesS11nm[10] = 1120; //"7,6";
	vSpeciesS11nm[11] = 1138; //"9,2";
	vSpeciesS11nm[12] = 1170; //"12,1";
	vSpeciesS11nm[13] = 1173; //"8,6";
	vSpeciesS11nm[14] = 1197; //"11,3";
	vSpeciesS11nm[15] = 1241; //"9,5";
	vSpeciesS11nm[16] = 1249; //"10,3";
	vSpeciesS11nm[17] = 1249; //"10,5";
	vSpeciesS11nm[18] = 1265; //"8,7";
	vSpeciesS11nm[19] = 1322; //"9,7";
	vSpeciesS11nm[20] = 1371; //"11,4";
	vSpeciesS11nm[21] = 1378; //"12,2";
	vSpeciesS11nm[22] = 1377; //"10,6";
	vSpeciesS11nm[23] = 1397; //"11,6";
	vSpeciesS11nm[24] = 1410; //"9,8";
	
	//create vector for other parameters and add vSpeciesS11nm in
	vector vParameterNumberVector(nNumSpecies*4);
	vector vParameterFixed(nNumSpecies*4);
	for(i=0;i<vSpeciesS11nm.GetSize();i++){
		vParameterNumberVector[i*4]=0;  //yc
		vParameterNumberVector[i*4+1]=1239.87/vSpeciesS11nm[i];  //xc
		vParameterNumberVector[i*4+2]=1239.87/10;  //w
		vParameterNumberVector[i*4+3]=1;  //A
		vParameterFixed[i*4]=1;  //fix y0
		vParameterFixed[i*4+1]=1;  //fix xc
		vParameterFixed[i*4+2]=0;  //fix w
		vParameterFixed[i*4+3]=0;  //fix A
	}
	
	
	//make new worksheet to hold fitting data for P2B deconv
	WorksheetPage FitP2BWksPg("FitByP2B");
	if(!FitP2BWksPg){
		WorksheetPage FitP2BWksPg;
		FitP2BWksPg.Create("ORIGIN", CREATE_VISIBLE);
		if(!FitP2BWksPg)
			return;
		FitP2BWksPg.SetName("FitByP2B");
	}
	string FitP2BWksStr = "[FitByP2B]Sheet1";
	Worksheet FitP2BWks(FitP2BWksStr);
	FitP2BWks.SetSize(-1,nNumSpecies+1);
	
	//make dataset for vectors to be fitted
	DataRange drFitP2B;
	drFitP2B.Add(FitP2BWks, 0, "X");
	drFitP2B.Add(FitP2BWks, 1, "Y");
	drFitP2B.SetData(vXeV, true, 0);
	drFitP2B.SetData(vYeV, true, 1);
	
	
	//fit
	bool bInit;
	Operation& op = (Operation&)op_create("FitNL", bInit);  // the operation name of NLFit is FitNL
	if(!bInit){
		out_str("Error in operation creation");
		return;
	}
	//make tree for this operation
	Tree trOp;
	tree_clear_all_value(trOp);
	op.GetTree(trOp);
	
	
	//init trOp.GUI.InputData tree nodes from datarange and do SetData, SetFunction actions
	string strFunction = "Lorentz";
	string strCategory = "Peak Functions";
	if(OP_NOERROR != op.OnInitDataFromOCLT(trOp, trOp.GUI.InputData, drFitP2B, strFunction, strCategory)){
		out_str("Failed to init data from drFitP2B");
		return;
	}
	// set replica number to 1. Default is 0. 
    trOp.GUI.Replica.Number.nVal = nNumPeaks-1;   
    
    // set fix
    //trOp.GUI.Parameters.AutoParamsInit.nVal=1;
    int index=0;
    foreach(TreeNode trNode in trOp.GUI.Parameters.Fixed.Children){
    	if( trNode.Show )//ignore hidden node
            trNode.nVal = vParameterFixed[index++];  
    }
    index=0;
    foreach(TreeNode trNode1 in trOp.GUI.Parameters.FixedValues.Children){
    	if( trNode1.Show )//ignore hidden node
            trNode1.dVal = vParameterNumberVector[index++];  
    }
    
    // set the changes of trOp back to op object
    op.SetTree(trOp);    
 
    int nAutoUpdate = AU_AUTO;
    op.OnNoEdit(0, nAutoUpdate);  
 
    // do fit and genereate report
    op.Execute(); 
    op.GetTree(trOp);



Thank you for any help with this, I really appreciate it

Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:

easwar

USA
1964 Posts

Posted - 03/12/2012 :  09:56:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cab0008
I am trying to use an operation for fitting a spectrum of many peaks whose parameters may depend on each other....
the trOp.GUI.Parameters.FixedValues.Value1.dVal is working fine for me as y0, but I would think for a lorentz that trOp.GUI.Parameters.FixedValues.Value5.dVal would be the baseline for my second dataset, but it is not showing up this way.



Hi,

When you fit a dataset with multiple peaks/replicas, there is only one y0 (offset) parameter for the entire dataset. In other words there are no separate offsets for each peak.

Easwar
OriginLab
Go to Top of Page

cab0008

25 Posts

Posted - 03/12/2012 :  4:34:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Easwar,

I have modified my code, but I still have a problem with only 6 peaks becoming initialized with parameters.

This is what I essentially have now for the parameter vector loop:

vector vParameterNumbers(nNumPeaks*3+1);   
vector vParameterFixedBoolean(nNumPeaks*3+1);
vector vLowerBoundEnable(nNumSpecies*3+1);
vector vLowerBound(nNumSpecies*3+1);
vParameterNumbers[0]=0;  //yc
vParameterFixedBoolean[0]=1;  //fix y0
vLowerBoundEnable[0]=1;  //y0 has lower bound
vLowerBound[0]=0; //y0 must me greater than 0
for(i=0;i<vPeakLocations.GetSize();i++){
	vParameterNumbers[i*3+1]=1239.87/vPeakLocations[i];  //xc
	vParameterNumbers[i*3+2]=0.1;  //w
	vParameterNumbers[i*3+3]=1.00;  //A
	vParameterFixedBoolean[i*3+1]=1;  //fix xc
	vParameterFixedBoolean[i*3+2]=1;  //fix w
	vParameterFixedBoolean[i*3+3]=0;  //fix A
	vLowerBoundEnable[i*3+1]=1;  //xc has lower bound
	vLowerBound[i*3+1]=0; //xc must me greater than 0
	vLowerBoundEnable[i*3+2]=1;  //w has lower bound
	vLowerBound[i*3+2]=0; //w must me greater than 0
	vLowerBoundEnable[i*3+3]=1;  //A has lower bound
	vLowerBound[i*3+3]=0; //A must me greater than 0
}


Is there a limit on the number of peaks that can be initialized for this fitting operation or am I still setting up something wrong?
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/14/2012 :  12:05:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Could you tell me you how to initialize parameter values? trOp.GUI.Parameters.Values, or auto initialize parameter value with "trOp.GUI.Parameters.AutoParamsInit.nVal=1;"?

If initialized parameters with the 1st way, then how you know the last 4 peaks not be initialized? After do fit to see parameter values?

I tried with 8 peaks in NLFit dialog, and set fix, lower bounds, not got this problem.

Iris
OriginLab
Go to Top of Page

cab0008

25 Posts

Posted - 03/14/2012 :  2:17:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Iris,

As I have in the code above, I am using the following format to initialize my variables:


    int index=0;
    foreach(TreeNode trNode in trOp.GUI.Parameters.Fixed.Children){
    	//if( trNode.Show )//ignore hidden node
            trNode.nVal = vParameterFixed[index++];  
    }
    index=0;
    foreach(TreeNode trNode1 in trOp.GUI.Parameters.FixedValues.Children){
    	//if( trNode1.Show )//ignore hidden node
            trNode1.dVal = vParameterNumberVector[index++];  
    }
    index=0;
    foreach(TreeNode trNode2 in trOp.GUI.Parameters.LowerBoundsEnable.Children){
    	//if( trNode2.Show )//ignore hidden node
            trNode2.nVal = vLowerBoundEnable[index++];  
    }
    index=0;
    foreach(TreeNode trNode3 in trOp.GUI.Parameters.LowerBounds.Children){
    	//if( trNode3.Show )//ignore hidden node
            trNode3.dVal = vLowerBound[index++];  
    }


However, this gives me 6 out of 25 parameters initialized for xc, and 13 out of 25 initialized for A....
Interestingly, using the auto initialize nVal=1 script gives initialization to only the 1st peak. I know this because the report shows "--" for all values except for the first peak.
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/14/2012 :  10:18:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I find out the reason, this becuase the default number of sub nodes (Value1, Value2...Value20) in these nodes like trOp.GUI.Parameters.Fixed, .FixedValues, etc. is 20.

This is a bug, should calculate the number of parameters refer to the number of replica.

Please call the following codes after op.OnInitDataFromOCLT function:

    TreeNode trOpParams = trOp.GUI.Parameters;    
    //int nNumParams = 1 + (nNumPeaks - 1) * 3; // is 31 here
    octree_nlsf_add_params_node_DataID(&trOpParams, 31);

This is a temporary solution, I have submit a jira to fix this problem.

Iris
Go to Top of Page

cab0008

25 Posts

Posted - 03/16/2012 :  5:05:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Iris,

This solution works if I fix all of my parameters. However, when I allow my parameters to not be fixed, the parameters are no longer allowed to be initialized. Upon releasing the "A" parameter from being a fixed value, I end up with only 13 of 25 peaks. In addition, the lower bound of 0 is never respected and I end up with negative peaks for the 13 that show up. It is showing up in the GUI that there is a constraint (0<A) after the fit is done. Is there something I can do to force initialization of these parameters and make sure they are always positive?


void deconvoluteOAOperation(vector vXeV, vector vYeV){
	int i=0;
	
	int nNumSpecies;
	nNumSpecies=25;
	int nNumPeaks=nNumSpecies;
	vector<string> vSpecies(nNumSpecies);
	vSpecies[0] = "6,4";
	vSpecies[1] = "9,1";
	vSpecies[2] = "8,3";
	vSpecies[3] = "6,5";
	vSpecies[4] = "7,3";
	vSpecies[5] = "7,5";
	vSpecies[6] = "8,1";
	vSpecies[7] = "10,2";
	vSpecies = "9,4";
	vSpecies[9] = "8,4";
	vSpecies[10] = "7,6";
	vSpecies[11] = "9,2";
	vSpecies[12] = "12,1";
	vSpecies[13] = "8,6";
	vSpecies[14] = "11,3";
	vSpecies[15] = "9,5";
	vSpecies[16] = "10,3";
	vSpecies[17] = "10,5";
	vSpecies[18] = "8,7";
	vSpecies[19] = "9,7";
	vSpecies[20] = "11,4";
	vSpecies[21] = "12,2";
	vSpecies[22] = "10,6";
	vSpecies[23] = "11,6";
	vSpecies[24] = "9,8";
	
	vector vSpeciesS11nm(nNumSpecies);
	vSpeciesS11nm[0] = 873; //6,4
	vSpeciesS11nm[1] = 912; //9,1
	vSpeciesS11nm[2] = 952; //8,3
	vSpeciesS11nm[3] = 976; //6,5
	vSpeciesS11nm[4] = 992; //"7,3";
	vSpeciesS11nm[5] = 1024; //"7,5";
	vSpeciesS11nm[6] = 1041; //"8,1";
	vSpeciesS11nm[7] = 1053; //"10,2";
	vSpeciesS11nm = 1101; //"9,4";
	vSpeciesS11nm[9] = 1111; //"8,4";
	vSpeciesS11nm[10] = 1120; //"7,6";
	vSpeciesS11nm[11] = 1138; //"9,2";
	vSpeciesS11nm[12] = 1170; //"12,1";
	vSpeciesS11nm[13] = 1173; //"8,6";
	vSpeciesS11nm[14] = 1197; //"11,3";
	vSpeciesS11nm[15] = 1241; //"9,5";
	vSpeciesS11nm[16] = 1249; //"10,3";
	vSpeciesS11nm[17] = 1249; //"10,5";
	vSpeciesS11nm[18] = 1265; //"8,7";
	vSpeciesS11nm[19] = 1322; //"9,7";
	vSpeciesS11nm[20] = 1371; //"11,4";
	vSpeciesS11nm[21] = 1378; //"12,2";
	vSpeciesS11nm[22] = 1377; //"10,6";
	vSpeciesS11nm[23] = 1397; //"11,6";
	vSpeciesS11nm[24] = 1410; //"9,8";
	
	//create vector for other parameters and add vSpeciesS11nm in
	vector vParameterNumberVector(nNumSpecies*3+1);
	vector vParameterFixed(nNumSpecies*3+1);
	vector vLowerBoundEnable(nNumSpecies*3+1);
	vector vLowerBound(nNumSpecies*3+1);
	vParameterNumberVector[0]=0;  //yc
	vParameterFixed[0]=1;  //fix y0
	vLowerBoundEnable[0]=1;  //y0 has lower bound
	vLowerBound[0]=0; //y0 must me greater than 0
	for(i=0;i<vSpeciesS11nm.GetSize();i++){
		vParameterNumberVector[i*3+1]=1239.87/vSpeciesS11nm[i];  //xc
		vParameterNumberVector[i*3+2]=.04;  //w
		vParameterNumberVector[i*3+3]=0.3;  //A
		vParameterFixed[i*3+1]=1;  //fix xc
		vParameterFixed[i*3+2]=0;  //fix w
		vParameterFixed[i*3+3]=0;  //fix A
		vLowerBoundEnable[i*3+1]=0;  //xc has lower bound
		vLowerBound[i*3+1]=0.00; //xc must me greater than 0
		vLowerBoundEnable[i*3+2]=0;  //w has lower bound
		vLowerBound[i*3+2]=0.00; //w must me greater than 0
		vLowerBoundEnable[i*3+3]=1;  //A has lower bound
		vLowerBound[i*3+3]=0.00001; //A must me greater than 0
	}
	
	
	//make new worksheet to hold fitting data for P2B deconv
	WorksheetPage FitP2BWksPg("FitByP2B");
	if(!FitP2BWksPg){
		WorksheetPage FitP2BWksPg;
		FitP2BWksPg.Create("ORIGIN", CREATE_VISIBLE);
		if(!FitP2BWksPg)
			return;
		FitP2BWksPg.SetName("FitByP2B");
	}
	string FitP2BWksStr = "[FitByP2B]Sheet1";
	Worksheet FitP2BWks(FitP2BWksStr);
	FitP2BWks.SetSize(-1,nNumSpecies+1);
	
	//make dataset for vectors to be fitted
	DataRange drFitP2B;
	drFitP2B.Add(FitP2BWks, 0, "X");
	drFitP2B.Add(FitP2BWks, 1, "Y");
	drFitP2B.SetData(&vYeV, &vXeV);
	//drFitP2B.SetData(vXeV, true, 0);
	//drFitP2B.SetData(vYeV, true, 1);
	
	//fit
	bool bInit;
	Operation& op = (Operation&)op_create("FitNL", bInit);  // the operation name of NLFit is FitNL
	if(!bInit){
		out_str("Error in operation creation");
		return;
	}
	//make tree for this operation
	Tree trOp;
	tree_clear_all_value(trOp);
	op.GetTree(trOp);
	
	
	//init trOp.GUI.InputData tree nodes from datarange and do SetData, SetFunction actions
	string strFunction = "Lorentz";
	string strCategory = "Peak Functions";
	if(OP_NOERROR != op.OnInitDataFromOCLT(trOp, trOp.GUI.InputData, drFitP2B, strFunction, strCategory)){
		out_str("Failed to init data from drFitP2B");
		return;
	}
	// set replica number to 1. Default is 0. 
    trOp.GUI.Replica.Number.nVal = nNumPeaks-1;   
    
    int nNumParams = 1 + nNumPeaks * 3; // is 31 here
    TreeNode trOpParams = trOp.GUI.Parameters;    
    octree_nlsf_add_params_node_DataID(&trOpParams, nNumParams);
    
    
    // set fix
    //trOp.GUI.Parameters.AutoParamsInit.nVal=1;
    
    int index=0;
    foreach(TreeNode trNode in trOp.GUI.Parameters.Fixed.Children){
    	//if( trNode.Show )//ignore hidden node
            trNode.nVal = vParameterFixed[index++];  
    }
    index=0;
    foreach(TreeNode trNode1 in trOp.GUI.Parameters.FixedValues.Children){
    	//if( trNode1.Show )//ignore hidden node
            trNode1.dVal = vParameterNumberVector[index++];  
    }
    index=0;
    foreach(TreeNode trNode2 in trOp.GUI.Parameters.LowerBoundsEnable.Children){
    	//if( trNode2.Show )//ignore hidden node
            trNode2.nVal = vLowerBoundEnable[index++];  
    }
    index=0;
    foreach(TreeNode trNode3 in trOp.GUI.Parameters.LowerBoundsExclusive.Children){
    	//if( trNode3.Show )//ignore hidden node
            trNode3.dVal = vLowerBound[index++];  
    }
    
    
    // set the changes of trOp back to op object
    op.SetTree(trOp);    
 
    int nAutoUpdate = AU_AUTO;
    op.OnNoEdit(0, nAutoUpdate);  
 
    // do fit and genereate report
    op.Execute(); 
    op.GetTree(trOp);
}
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/19/2012 :  01:27:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please change the following line:

foreach(TreeNode trNode3 in trOp.GUI.Parameters.LowerBoundsExclusive.Children){


to

foreach(TreeNode trNode3 in trOp.GUI.Parameters.LowerBounds.Children){


The node should be LowerBounds, not LowerBoundsExclusive.


Iris
Go to Top of Page

cab0008

25 Posts

Posted - 03/19/2012 :  1:25:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Iris,

I have changed this and the problem still persists. Here are some images of the output I have received after I made the change.



Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/19/2012 :  10:50:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

From the above output, fit did not converge since parameter w, A not perperly initialized from peak 14.

I checked your function deconvoluteOAOperation, and found in second foreach, assigned values from vParameterNumberVector to trOp.GUI.Parameters.FixedValues, the fixed value only available when fixed is on(1) in Parameter.Fixed node.

So for the not fixed parameters - w, A, we need assign the initialize value to Parameters.Values node, for example,

index=0;
    foreach(TreeNode trNode1 in trOp.GUI.Parameters.Values.Children){
    	//if( trNode1.Show )//ignore hidden node
            trNode1.dVal = vParameterNumberVector[index++];  
    }


And there is more important thing, here need call

trOp.GUI.Parameters.AutoParamsInit.nVal=0;

AutoParamsInit default is on in Lorentz function (we can press F9 to open Fitting Function Organizer dialog to check the option), if not set it as off, will run parameter init code to initialize all not fixed parameters.

Iris

Edited by - Iris_Bai on 03/19/2012 11:09:15 PM
Go to Top of Page

cab0008

25 Posts

Posted - 03/21/2012 :  12:41:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Iris, That worked out very well!
Go to Top of Page

cab0008

25 Posts

Posted - 03/21/2012 :  5:20:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I was also hoping you may help me with another quick question. What is the best way to fix the "A" parameters of certain peaks to depend on the "A" parameter of a corresponding peak? For example, I have a large set of several different components, which each have 2 peaks that correspond to the same component. Therefore, there should be 2*N peaks for N number of components in the spectrum (there are actually 2*N + some additional peaks but I'll add those later).
So far I've tried the following code, but it has been unsuccessful.
Any better ideas of how to fix the amplitudes of half of my peaks to depend on the other half?


 index=0;
    int index2=0;
    foreach(TreeNode trNode1 in trOp.GUI.Parameters.FixedValues.Children){
    	trNode1.dVal = vParameterNumberVector[index];
    	index++;
    }
    
    index=0;
    index2=0;
    foreach(TreeNode trNode1_2 in trOp.GUI.Parameters.FixedValues.Children){
    	if(index>=vSpeciesS11nm.GetSize()*3+1){
    		//for S22 A
    		if(mod(index,3)==0){
    			index2=0;
    			foreach(TreeNode trNodeAS11 in trOp.GUI.Parameters.FixedValues.Children){
    				if(mod(index2,3)==0){
    					trNode1_2.dVal = trNodeAS11.dVal/2; 
    				}
    				index2++;
    			}
    		}
    	}
    	index++;
    }


Any help is greatly appreciated.
Go to Top of Page

Iris_Bai

China
Posts

Posted - 03/26/2012 :  9:42:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Seems there is not better way to set some peaks depend on others. I checked your codes above, not found abvious problem. But in order to check all fixed values you can add the following code to put the values to one worksheet.


    Worksheet wks;
    wks.Create("Origin", CREATE_HIDDEN);
    vector& vTestFixedVals = wks.Columns(0).GetDataObject();
    vTestFixedVals.RemoveAll();
    foreach(TreeNode trNode1_3 in trOp.GUI.Parameters.FixedValues.Children)
    	vTestFixedVals.Add( trNode1_3.dVal );


Iris
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000