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
 All Forums
 Origin Forum
 Origin Forum
 User Defined Fitting function

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
nithinsudersanan Posted - 02/28/2017 : 02:19:59 AM
I am new to coding and I am finding difficult to run successfully a fitting curve need for my data. The current code is as follows. Please help me to resolve the issue

#pragma numlittype(push, TRUE)
#pragma numlittype(push, TRUE)
#pragma warning(error : 15618)
//
void _nlsfNewFunction(
// Fit Parameter(s):
double a, double m,
// Independent Variable(s):
double t,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
vector t_data;
// Dependent Dataset(s):
vector y_data;
// Curve(s):
Curve t_y_curve;
// Auxilary error code:
int nErr();
vector y0, y1;
//sort(t_y_curve);
int N = y_data.GetSize();
for(int i = 0; i < N; i++)
{
y0[i] = y_data[i-1];
y1[i] = y_data[i-2];
}
y=(2*(y0[i]^(1-(a+m*t))-(y1[i]^(1-(a+m*t)))))^(1/(1-(a+m*t)));
// End of editable part
}
5   L A T E S T    R E P L I E S    (Newest First)
yuki_wu Posted - 03/02/2017 : 9:44:03 PM
Hi Nithin S,

To define the initial values of y data, I think there are two ways:
1. Define two fit parameters at the beginning, and then assign those values to variable vydata[0] and vydata[1].

void _nlsfPDEM(
// Fit Parameter(s):
double a, double m, double y0, double y1,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	…
	vector  vydata;
	vydata[0] = y0;
	vydata[1] = y1;
	…
}

2.Declare a variable vydata and assign its initial value directly inside the function.

void _nlsfPDEM(
// Fit Parameter(s):
double a, double m,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	…
	vector  vydata;	
	vydata[0] = 1;
	vydata[1] = 2;
	…
}

Though you should learn how to use the methods of NLFitContext class from that tutorial, your fitting model is still not totally the same with that example.

For instance,
1. Your fitting model doesn't include convolution
2. The equation vdeformation = (vcycles[1]-vcycles[0])*vdeformation doesn’t come from your model.
3. … and etc.

Perhaps you need to take more time to go through the pages and then try to rewrite your own fitting function.

Regards,
Yuki
OriginLab
nithinsudersanan Posted - 03/02/2017 : 04:10:40 AM
Dear Yuki,

Thanks for the examples. It really help to understand the way in which the origin does the fitting. Still I couldn't resolve the issue completely. I would be glad if you could go through the current code so that i can make the corrections.

void _nlsfPDEM(
// Fit Parameter(s):
double a, double m,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	// Beginning of editable part
		NLFitContext *pCtxt = Project.GetNLFitContext();
	        Worksheet wks;
	        DataRange dr;
	        int c1,c2;
	        dr = pCtxt->GetSourceDataRange(); //Get the source data range
	        dr.GetRange(wks, c1, c2);  //Get the source data worksheet
	        if ( pCtxt )
		{	
			// Vector for the output signal in each iteration.
			static vector vdeformation;
			// If parameters were updated, we will recalculate the convolution result.
			BOOL bIsNewParamValues = pCtxt->IsNewParamValues();
			if ( bIsNewParamValues )
			{
				// Read sampling and response data from worksheet.
				Dataset dscycles(wks, 0);
				Dataset dsdeformation(wks, 1);
				int iSize = dscycles.GetSize();
	 
				vector vcycles, vdeformation, vC;
	 
				vcycles = dscycles;
				vdeformation = dsdeformation;
	 
				vcycles.SetSize(iSize);
				vdeformation.SetSize(iSize);
				vC.SetSize(iSize);
				// Compute the PDEM
				vC=a+(m*vcycles)
				vdeformation[iSize] = (2*(vdeformation[iSize-1])^(1-vC))-(vdeformation[iSize-2])^(1-vC))^(1/(1-vC));
				// Perform convolution
				int iRet = fft_fft_convolution(iSize, vdeformation, vcycles);
	           //Correct the convolution by multiplying the sampling interval
	            vdeformation = (vcycles[1]-vcycles[0])*vdeformation;
	 
	 		}
	 		NLSFCURRINFO    stCurrInfo;
		pCtxt->GetFitCurrInfo(&stCurrInfo);
		// Get the data index for the iteration
		int nCurrentIndex = stCurrInfo.nCurrDataIndex;
		// Get the evaluated y value
		y = vdeformation[nCurrentIndex];
		// For compile the function, since we haven't use x here.
		x;
	}
	// End of editable part


Also please not that the Y0 and Y1 cant be parameters. The value have to be updated for each iteration from the y_data.

Please help!

Thanks

Nithin S.
quote:
Originally posted by yuki_wu

Hi Nithin S,

Firstly, you need to define the two initial values of y_data, y0 and y1, as parameters.

In order to get the fitted y_data during fitting, you need to use several methods of NLFitContext class, including GetSourceDataRange, IsNewParamValues, GetFitCurrInfo:
http://www.originlab.com/doc/OriginC/ref/NLFitContext

Basically, you can refer to this tutorial, it may help you to create your own fitting function by imitating the code of that example.
http://www.originlab.com/doc/Tutorials/Fitting-Convolution

Hope it helps.

Regards,
Yuki
OriginLab


yuki_wu Posted - 03/02/2017 : 01:13:29 AM
Hi Nithin S,

Firstly, you need to define the two initial values of y_data, y0 and y1, as parameters.

In order to get the fitted y_data during fitting, you need to use several methods of NLFitContext class, including GetSourceDataRange, IsNewParamValues, GetFitCurrInfo:
http://www.originlab.com/doc/OriginC/ref/NLFitContext

Basically, you can refer to this tutorial, it may help you to create your own fitting function by imitating the code of that example.
http://www.originlab.com/doc/Tutorials/Fitting-Convolution

Hope it helps.

Regards,
Yuki
OriginLab
nithinsudersanan Posted - 03/01/2017 : 06:22:22 AM
Hi Yuki,

Thanks for your response.

Further to your advise to explain about the problem. I am hereby defining the problem. I wish to fit the curve with the PDEM model using USER DEFINED fitting function. The model is as follows.




Delta in the model is the y_data while t is the x_data. C is a shape function, a & m are material parameters which has to be found out during fitting. The code I have posted prior was an attempt to fit the same. The sequential steps were attached as snapshots.







Please help me to run the fitting successfully.

Thanks in advance.

Regards,

Nithin S
yuki_wu Posted - 03/01/2017 : 04:16:36 AM
Hi,

I am sorry that I cannot see anything from your code since it is raw and not in accord with the rule of programming.

Please post more details, such as your data, your fitting model and etc. Of course, you can also contact the tech support for more help. You will find the contact information here: http://www.originlab.com/index.aspx?go=COMPANY/ContactUS

Regards,
Yuki
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000