def barrierScore(xd, yd, pp, weights=None, thr=3e9): """ Calculate score for barrier model """ ppq = pp.copy() # ppq[0]+=3.05 ydatax = barrierModel(xd, ppq) sc = np.abs(ydatax - yd) scalefac = thr #sc=robustCost(sc, thr) sc = np.sqrt(robustCost(sc / scalefac, thr / scalefac, 'BZ0')) * scalefac if weights is not None: sc = sc * weights sc = np.linalg.norm(sc, ord=4) / sc.size return sc
def pat_one_ele_score(self, xd, yd, pp, weights=None, thr=2e9): """ Calculate score for pat one electron model Args: xd (array): x coordinates of peaks in sensor signal yd (array): y coordinates of peaks in sensor signal pp (array): model parameters """ ydatax = one_ele_pat_model(xd, pp) charge_change = np.abs(np.abs(pp[1]) * (xd - pp[0]) / np.sqrt((pp[1] * (xd - pp[0]))**2 + 4 * pp[2]**2)) sc = np.abs(ydatax - yd) * charge_change scalefac = thr sc = np.sqrt(robustCost(sc / scalefac, thr / scalefac, 'BZ0')) * scalefac if weights is not None: sc = sc * weights sc = np.linalg.norm(sc, ord=4) / sc.size if pp[1] < 10: sc *= 10 if pp[2] > 150: sc *= 10 return sc
def pat_two_ele_score(self, xd, yd, pp, weights=None, thr=2e9): """ Calculate score for pat two electron model Args: xd (array): x coordinates of peaks in sensor signal yd (array): y coordinates of peaks in sensor signal pp (array): model parameters """ ymodel = two_ele_pat_model(xd, pp) denom = np.sqrt((pp[1] * (xd - pp[0]))**2 + 8 * pp[2]**2) charge_changes = [] charge_changes.append(1 / 2 * (1 + pp[1] * (xd - pp[0]) / denom)) charge_changes.append(np.abs(pp[1] * (xd - pp[0]) / denom)) charge_changes.append(1 / 2 * (1 - pp[1] * (xd - pp[0]) / denom)) linesize = ymodel[0].shape[0] if self.branch_reduction is None or self.branch_reduction == 'minimum': sc = np.inf * np.ones(linesize) for idval, val in enumerate(self.even_branches): if val: sc = np.minimum(sc, np.abs(ymodel[idval] - yd)) elif self.branch_reduction == 'mean': sc = [] for idval, val in enumerate(self.even_branches): if val: sc.append(np.abs(ymodel[idval] - yd)) sc = np.mean(np.array(sc), axis=1) else: raise NotImplementedError('branch_reduction %s not implemented' % self.branch_reduction) scalefac = thr sc = np.sqrt(robustCost(sc / scalefac, thr / scalefac, 'BZ0')) * scalefac if weights is not None: sc *= weights sc = np.linalg.norm(sc, ord=4) / sc.size if pp[1] < 10: sc *= 10000 return sc
def test_robust_cost(): x = np.array([0, 1, 2, 3, 4, 5]) _ = pgeometry.robustCost(x, 2) _ = pgeometry.robustCost(x, 'auto')