Calculated fit curves wrong in multi fit

This fit bug, with a multi fit with tied parameters, is also observed in the Muon Interface but seems to be more general.

Expected behavior

The calculated curves in the output workspaces should be the function evaluated at the final parameter values, so for a good fit the Calc and Data curves should be nearly equal and Diff nearly zero

Actual behaviour

Even with a good fit, for all but the first function, the Calc curves are wrong. Diff is the difference between the data and this wrong curve. Are some of the tied parameters not being copied across properly, despite appearing in the xx_Parameters tables as normal?

Steps to reproduce the behavior

Try this script. It fits the same two spectra in either order, and gets the same parameters as expected, but it’s always the second one’s Calc and Diff curves that are wrong.

w=LoadMuonNexus("//musr/data/musr00062301.nxs")
for selection in ( ("set06", 0,6), ("set60", 6,0) ):
	function="""composite=MultiDomainFunction,NumDeriv=true;
	(composite=CompositeFunction,$domains=0;
		name=UserFunction,Formula=N0*exp(-x/2.19703)*(1+A*cos(2*3.14159265*Freq*x+Phi)),N0=1500.000000,A=0.260000,Freq=0.338750,Phi=4.7);
	(composite=CompositeFunction,$domains=1;
		name=UserFunction,Formula=N0*exp(-x/2.19703)*(1+A*cos(2*3.14159265*Freq*x+Phi)),N0=1500.000000,A=0.260000,Freq=0.338750,Phi=4.7);
	ties=(f1.f0.Freq=f0.f0.Freq)"""
	args={'StartX_1': 0.1, 'StartX': 0.1, 'MaxIterations': 200, 'InputWorkspace': w[0], 'InputWorkspace_1':w[0],
		'EndX': 8.0, 'WorkspaceIndex': selection[1], 'WorkspaceIndex_1': selection[2], 'Output': selection[0],
		'Minimizer': 'Levenberg-MarquardtMD,MuMax=1e+06,AbsError=0.0001,Debug=0', 'EndX_1': 8.0}
	print "Fitting to spectra ",selection
	f=Fit(function,**args)
	print "Cost Function",f[1]
	plot_spectrum(f[4][0],range(3))
	plot_spectrum(f[4][1],range(3))

Platforms affected

Mantid 3.9.0 and 3.9.1 (running on Windows, maybe others)

I just ran your script and the parameters are different. I get:

set60

f0.f0.N0 974.01958629746412 2.8566551744004314
f0.f0.A 0.31336059033462937 0.0043761276348696079
f0.f0.Freq 0.34824462824044317 0.00085142901409268059
f0.f0.Phi 4.0942505661306496 0.016609401084199279
f1.f0.N0 1,410.9201713624759 3.4029860684529978
f1.f0.A 0.25874268533596517 0.0033124953734837638
f1.f0.Freq 0.34824462824044317 0
f1.f0.Phi 5.161022038599886 0.018702520109927543
Cost 0.48626363440993176 0

and for set06

f0.f0.N0 1,410.9201713624757 3.4029860684529258
f0.f0.A 0.25874268533596606 0.0033124953734838939
f0.f0.Freq 0.3482446282404435 0.00085142901409267994
f0.f0.Phi 5.1610220385998833 0.018702520109927175
f1.f0.N0 974.019586297464 2.8566551744004407
f1.f0.A 0.31336059033463048 0.0043761276348694119
f1.f0.Freq 0.3482446282404435 0
f1.f0.Phi 4.0942505661306434 0.016609401084200174
Cost 0.48626363440993142 0

I have created an issue for this Plot does not match the function · Issue #19115 · mantidproject/mantid · GitHub

This will be fixed in the patch release 3.9.2

1 Like