Funcfit for multivariable (over 20) equation

I am working on funcfit for multi-variable equation with over 20 variables.

Please see attached exp files.


The algorithm is following:

1) Load experimental data wave (not included in the attached file)

2) After recall function setup_display_range() and calculation(), open parameter control macro

3) Setup parameters in order to obtain similar generated graph for the experimental data


// THE FOLLOWING IS FUNCFIT BUT I CANNOT //
4) Save parameters in the panels as initial value of fitting

5) Run funcfit function


For 4) and 5), I should recall all the parameters as coefficient wave and WRITE DOWN ALL THE EQUATION SUCH AS F_uc, F_ctr, and so on.

Is there are clear way to design simple function to get funcfit?
Fitting Compiler.pxp (826.56 KB)
I think what you are asking would be answered with code built on this pattern:

	Make/O/N=30/D coefwave		// Is 30 correct?
	ControlInfo SetVar0
	coefwave[0] = V_value
	ControlInfo SetVar1
	coefwave[1] = V_value
	ControlInfo SetVar2
	coefwave[2] = V_value
	... etc. ...

	FuncFit myHugeFitFunct, coefwave, ...


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote: I think what you are asking would be answered with code built on this pattern:

	Make/O/N=30/D coefwave		// Is 30 correct?
	ControlInfo SetVar0
	coefwave[0] = V_value
	ControlInfo SetVar1
	coefwave[1] = V_value
	ControlInfo SetVar2
	coefwave[2] = V_value
	... etc. ...

	FuncFit myHugeFitFunct, coefwave, ...


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com




Thank you for your sincere help.

Unfortunately, my question was more focused on how to build myHugeFitFunct.

As you can see in the experiments, I want to utilize CALCULATION() function as myHugeFitFunc.

Is there any nice solution for that?
You need to re-write Calculation() in the form of a fit function. Read about fitting to a user-defined fit function:

DisplayHelpTopic "Fitting to a User-Defined Function"

That topic talks about using the Curve Fit dialog to build and use a user-defined fit function. For your purposes, you will want to edit the Calculation function to make it into a fit function. To learn the proper format, read this topic:

DisplayHelpTopic "User-Defined Fitting Function: Detailed Description"

It's hard to tell from your code what the independent variable is (variables?) or which are constants. The use of global variables for adjustable parameters is discouraged- it makes it hard to debug problems, and easy to make mistakes in setting up to run the function. It is also inefficient for use as a fitting function.

If you want to use Calculation() as the engine for both simulations and for fitting, I would do this:

1) Use the Constant keyword to define numbers that are truly constants, that you will never change. I presume that the global variable that you declare this way:
	variable/g atomic_frac_Y = 0.148

are actually constants. That one could be defined this way, above the definition of the function:
Constant atomic_frac_Y = 0.148


2) Make the adjustable parameters into input parameters. Assuming that the uninitialized globals are actually adjustable parameters, you would do something like

Function Calculation(atomic_frac_Zr, atomic_frac_Ovoid, .... and several more ....)
	Variable atomic_frac_Zr, atomic_frac_Ovoid, ...


3) It's probably easiest to use the standard fit function format that calls the function once for each X value, and returns one Y value for each. I see
wave Q_x, atomic_position
at the top of Calculation(). Assuming that Q_x is the X value, now the function would look like

Function Calculation(Q_x, atomic_frac_Zr, atomic_frac_Ovoid, .... and several more ....)
	Variable Q_x
	Variable atomic_frac_Zr, atomic_frac_Ovoid, ...

	.... lots of code ....

	return <the calculated value>
end

4) Now, to create a fit function you might write this:

Function Fit_Calculation(pw, Q_x) : FitFunc
	Wave pw
	Variable Q_x
	
	return Calculation(Q_x, pw[0], pw[1], ... lots more ...)
end


To be sure, I see some things that suggest that perhaps you need to compute all results at the same time. In the detailed description help cited above, you need to read about all-at-once fit functions. They take in an X wave (or waves if it is a multivariate fit) and set the Y values in the Y wave input parameter. They return nothing. All-at-once functions are more challenging to write and debug but generally run faster. Some problems can only be computed using an all-at-once fit function.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com