Use of Hold in DoNewGlobalFit
geologic
This function is not utilizing the hold functionality like I thought...when I use print getdimlabel(coefwave,1,-1), though, it returns Hold. The fit functions are included at the bottom. They might have a typo...I was trying to use hold to test them.
function ngf(base0,base1,templist,cfstr0,cfvar0,cfstr1,cfvar1,cfstr2,cfvar2,cfstr3,cfvar3,cfstr4,cfvar4)
// base0 and base1 are the basenames of the two data sets (without temperature)
string base0, base1, templist
string cfstr0
variable cfvar0
string cfstr1
variable cfvar1
string cfstr2
variable cfvar2
string cfstr3
variable cfvar3
string cfstr4
variable cfvar4
variable i, numdatapts
// name of data
make/o/n=(2,2)/t datasets
DataSets[0][0]=base0+"_"+stringfromlist(i,templist)
DataSets[1][0]=base1+"_"+stringfromlist(i,templist)
DataSets[0][1]="_calculated_"
DataSets[1][1]="_calculated_"
// extract number of points in data wave
wave sampledataset = $datasets[0][0]
numdatapts = numpnts(sampledataset)
// format: [row][column]
// a row for each data set
// # columns: (max # of coefficients used by any fit functions) + 4
make/o/n=(2,8) CoefDataSetLinkage
// fit functions
make/o/t/n=2 fitfuncnames
fitfuncnames[0]="sigma1ff"
fitfuncnames[1]="eps1ff"
// column 0: contains index in the fitfuncnames where the name of a fitting function will be found
CoefDataSetLinkage[0][0]=0
// column 1: point # within concatenated data set where this data set begins
CoefDataSetLinkage[0][1]=0
// column 2: point # where a given data set ends (this number is not used...)
CoefDataSetLinkage[0][2]=numdatapts-1
// column 3: how many fit coefficents are used by the fit function for the corresponding data set
CoefDataSetLinkage[0][3]=4
// column 4: index to the master coefficient wave
CoefDataSetLinkage[0][4]=0
CoefDataSetLinkage[0][5]=1
CoefDataSetLinkage[0][6]=2
CoefDataSetLinkage[0][7]=3
// column 0: contains index in the fitfuncnames where the name of a fitting function will be found
CoefDataSetLinkage[1][0]=0
// column 1: point # within concatenated data set where this data set begins
CoefDataSetLinkage[1][1]=numdatapts
// column 2: point # where a given data set ends (this number is not used...)
CoefDataSetLinkage[1][2]=2*numdatapts-1
// column 3: how many fit coefficents are used by the fit function for the corresponding data set
CoefDataSetLinkage[1][3]=4
// column 4: index to the master coefficient wave
CoefDataSetLinkage[1][4]=4
CoefDataSetLinkage[1][5]=1
CoefDataSetLinkage[1][6]=2
CoefDataSetLinkage[1][7]=3
// coefwave contains initial guesses
// inidices established in coefdatasetlinkage are repeated here
// i.e. the length of coefwave will be the total number of variables, not just the number
// used by any particular fit function
make/o/n=(5,2) coefwave
setdimlabel 1, -1, Hold, coefwave
coefwave[0][0]=cfvar0
coefwave[1][0]=cfvar1
coefwave[2][0]=cfvar2
coefwave[3][0]=cfvar3
coefwave[4][0]=cfvar4
// set coefwave[n][1]=0 to not hold n, 1 to hold n
coefwave[][1]=1
// coefnames provides strings for the variable names
// same index convention as coefwave and coefdatasetlinkage
make/o/t/n=5 coefnames
coefnames[0]=cfstr0
coefnames[1]=cfstr1
coefnames[2]=cfstr2
coefnames[3]=cfstr3
coefnames[4]=cfstr4
donewglobalfit(FitFuncNames, DataSets, CoefDataSetLinkage, CoefWave, CoefNames, $"",NewGFOptionAPPEND_RESULTS, 200, 1)
end
function eps1ff(w,x) : FitFunc
wave w
variable x
//CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
//CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 4
//CurveFitDialog/ w[0] = eps_inf
//CurveFitDialog/ w[1] = sj1
//CurveFitDialog/ w[2] = fj1
//CurveFitDialog/ w[3] = gj1
// return real(8.854*4*pi*2*pi*x*(w[0]-1+w[1]*(2*pi*w[2])^2 / ((2*pi*w[2])^2-(2*pi*x)^2-sqrt(-1)*w[3]*x*(2*pi)^2)+ w[4]*(2*pi*w[5])^2 / ((2*pi*w[5])^2-(2*pi*x)^2-sqrt(-1)*w[6]*x*(2*pi)^2) ) / (100*4* pi * sqrt(-1)))
return real(w[0]-1+w[1]*(2*pi*w[2])^2 / ((2*pi*w[2])^2-(2*pi*x)^2-sqrt(-1)*w[3]*x*(2*pi)^2))
end
function sigma1ff(w,x) : FitFunc
wave w
variable x
//CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
//CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 4
//CurveFitDialog/ w[0] = sigma0
//CurveFitDialog/ w[1] = sj1
//CurveFitDialog/ w[2] = fj1
//CurveFitDialog/ w[3] = gj1
return real( 8.854*4*pi*2*pi*x *(w[0]+w[1]*(2*pi*w[2])^2 / ((2*pi*w[2])^2-(2*pi*x)^2-sqrt(-1)*w[3]*x*(2*pi)^2)))
end
// base0 and base1 are the basenames of the two data sets (without temperature)
string base0, base1, templist
string cfstr0
variable cfvar0
string cfstr1
variable cfvar1
string cfstr2
variable cfvar2
string cfstr3
variable cfvar3
string cfstr4
variable cfvar4
variable i, numdatapts
// name of data
make/o/n=(2,2)/t datasets
DataSets[0][0]=base0+"_"+stringfromlist(i,templist)
DataSets[1][0]=base1+"_"+stringfromlist(i,templist)
DataSets[0][1]="_calculated_"
DataSets[1][1]="_calculated_"
// extract number of points in data wave
wave sampledataset = $datasets[0][0]
numdatapts = numpnts(sampledataset)
// format: [row][column]
// a row for each data set
// # columns: (max # of coefficients used by any fit functions) + 4
make/o/n=(2,8) CoefDataSetLinkage
// fit functions
make/o/t/n=2 fitfuncnames
fitfuncnames[0]="sigma1ff"
fitfuncnames[1]="eps1ff"
// column 0: contains index in the fitfuncnames where the name of a fitting function will be found
CoefDataSetLinkage[0][0]=0
// column 1: point # within concatenated data set where this data set begins
CoefDataSetLinkage[0][1]=0
// column 2: point # where a given data set ends (this number is not used...)
CoefDataSetLinkage[0][2]=numdatapts-1
// column 3: how many fit coefficents are used by the fit function for the corresponding data set
CoefDataSetLinkage[0][3]=4
// column 4: index to the master coefficient wave
CoefDataSetLinkage[0][4]=0
CoefDataSetLinkage[0][5]=1
CoefDataSetLinkage[0][6]=2
CoefDataSetLinkage[0][7]=3
// column 0: contains index in the fitfuncnames where the name of a fitting function will be found
CoefDataSetLinkage[1][0]=0
// column 1: point # within concatenated data set where this data set begins
CoefDataSetLinkage[1][1]=numdatapts
// column 2: point # where a given data set ends (this number is not used...)
CoefDataSetLinkage[1][2]=2*numdatapts-1
// column 3: how many fit coefficents are used by the fit function for the corresponding data set
CoefDataSetLinkage[1][3]=4
// column 4: index to the master coefficient wave
CoefDataSetLinkage[1][4]=4
CoefDataSetLinkage[1][5]=1
CoefDataSetLinkage[1][6]=2
CoefDataSetLinkage[1][7]=3
// coefwave contains initial guesses
// inidices established in coefdatasetlinkage are repeated here
// i.e. the length of coefwave will be the total number of variables, not just the number
// used by any particular fit function
make/o/n=(5,2) coefwave
setdimlabel 1, -1, Hold, coefwave
coefwave[0][0]=cfvar0
coefwave[1][0]=cfvar1
coefwave[2][0]=cfvar2
coefwave[3][0]=cfvar3
coefwave[4][0]=cfvar4
// set coefwave[n][1]=0 to not hold n, 1 to hold n
coefwave[][1]=1
// coefnames provides strings for the variable names
// same index convention as coefwave and coefdatasetlinkage
make/o/t/n=5 coefnames
coefnames[0]=cfstr0
coefnames[1]=cfstr1
coefnames[2]=cfstr2
coefnames[3]=cfstr3
coefnames[4]=cfstr4
donewglobalfit(FitFuncNames, DataSets, CoefDataSetLinkage, CoefWave, CoefNames, $"",NewGFOptionAPPEND_RESULTS, 200, 1)
end
function eps1ff(w,x) : FitFunc
wave w
variable x
//CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
//CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 4
//CurveFitDialog/ w[0] = eps_inf
//CurveFitDialog/ w[1] = sj1
//CurveFitDialog/ w[2] = fj1
//CurveFitDialog/ w[3] = gj1
// return real(8.854*4*pi*2*pi*x*(w[0]-1+w[1]*(2*pi*w[2])^2 / ((2*pi*w[2])^2-(2*pi*x)^2-sqrt(-1)*w[3]*x*(2*pi)^2)+ w[4]*(2*pi*w[5])^2 / ((2*pi*w[5])^2-(2*pi*x)^2-sqrt(-1)*w[6]*x*(2*pi)^2) ) / (100*4* pi * sqrt(-1)))
return real(w[0]-1+w[1]*(2*pi*w[2])^2 / ((2*pi*w[2])^2-(2*pi*x)^2-sqrt(-1)*w[3]*x*(2*pi)^2))
end
function sigma1ff(w,x) : FitFunc
wave w
variable x
//CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
//CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 4
//CurveFitDialog/ w[0] = sigma0
//CurveFitDialog/ w[1] = sj1
//CurveFitDialog/ w[2] = fj1
//CurveFitDialog/ w[3] = gj1
return real( 8.854*4*pi*2*pi*x *(w[0]+w[1]*(2*pi*w[2])^2 / ((2*pi*w[2])^2-(2*pi*x)^2-sqrt(-1)*w[3]*x*(2*pi)^2)))
end
I realized I hadn't identified the column I wanted, but labeled used Hold as a dimlabel for all columns. Donewglobalfit probably pulled the first column, saw that none of the numbers were 1, and didn't hold anything. I replaced the setdimlabel line as:
March 29, 2017 at 11:39 am - Permalink
I did not use DoNewGlobalFit in past. So I find it very interesting when I get to know it.
After reading the whole help document about DoNewGlobalFit I understand what id dones.
Now what makes me puzzled is how the global parameters are linked!
Is it fitted in the first data and then holded as constant for other data?
Thanks
March 30, 2017 at 04:06 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
March 30, 2017 at 04:36 pm - Permalink