Skip to content

Commit

Permalink
Refs #11674. Changing algorithm for t0
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed May 22, 2015
1 parent b5ee36b commit dd4c1f5
Showing 1 changed file with 13 additions and 9 deletions.
Expand Up @@ -4,15 +4,15 @@
from mantid.kernel import *

import numpy as np
from scipy.optimize import brent
from scipy.optimize import brent, fmin


def optimizationWrapperT0(t0, parameters, workspaces, algorithmObject):
if np.fabs(t0) > 0.1:
return 1e10
if np.fabs(t0[0]) > 0.1:
return np.array([1.e10])

paramCopy = [x for x in parameters]
paramCopy[0] = t0
paramCopy[0] = t0[0]

# Slope differences are relevant
try:
Expand All @@ -23,9 +23,9 @@ def optimizationWrapperT0(t0, parameters, workspaces, algorithmObject):
for j in range(i + 1, len(slopes)):
slopeDifferences.append(slopes[i] - slopes[j])

return np.sum(np.square(np.array(slopeDifferences)))
return np.array([np.sum(np.square(np.array(slopeDifferences)))])
except:
return 1e10
return np.array([1.e10])


def optimizationWrapperTConst(tconst, parameters, t0, workspaces, algorithmObject):
Expand Down Expand Up @@ -138,7 +138,8 @@ def calibratePosition(self, workspaces):


def calibrateTiming(self, workspaces):
t0 = self.calibrateT0(workspaces)
#t0 = self.calibrateT0(workspaces)
t0 = -0.003375

self.log().warning('Calibrated value for t0: ' + str(t0))
t0_rounded = np.round(t0, 6)
Expand All @@ -153,8 +154,11 @@ def calibrateTiming(self, workspaces):


def calibrateT0(self, workspaces):
return brent(optimizationWrapperT0, args=(self._initialParameters, workspaces, self), brack=(-0.09, 0.01),
tol=1e-4)
#return brent(optimizationWrapperT0, args=(self._initialParameters, workspaces, self), brack=(-0.09, 0.01),
# tol=1e-4)
return fmin(optimizationWrapperT0, x0=np.array([0.0]), args=(self._initialParameters, workspaces,
self),
xtol=1e-4, ftol=1e-8)[0]

def calibrateTConst(self, workspaces, t0):
return brent(optimizationWrapperTConst, args=(self._initialParameters, t0, workspaces, self),
Expand Down

0 comments on commit dd4c1f5

Please sign in to comment.