def Merge(self, prec=epsilon): """ Merge merges consecutive ramp(s) if they have the same acceleration """ if not self.isEmpty: if Abs((Abs(mp.log10(prec)) - (Abs(mp.floor(mp.log10(prec)))))) < Abs((Abs(mp.log10(prec)) - (Abs(mp.ceil(mp.log10(prec)))))): precexp = mp.floor(mp.log10(prec)) else: precexp = mp.ceil(mp.log10(prec)) aCur = self.ramps[0].a nmerged = 0 # the number of merged ramps for i in xrange(1, len(self.ramps)): j = i - nmerged if (Abs(self.ramps[j].a) > 1): if Abs((Abs(mp.log10(Abs(self.ramps[j].a))) - (Abs(mp.floor(mp.log10(Abs(self.ramps[j].a))))))) < Abs((Abs(mp.log10(Abs(self.ramps[j].a))) - (Abs(mp.ceil(mp.log10(Abs(self.ramps[j].a))))))): threshold = 10**(precexp + mp.floor(mp.log10(Abs(self.ramps[j].a))) + 1) else: threshold = 10**(precexp + mp.ceil(mp.log10(Abs(self.ramps[j].a))) + 1) else: threshold = 10**(precexp) if Abs(Sub(self.ramps[j].a, aCur)) < threshold: # merge ramps redundantRamp = self.ramps.pop(j) newDur = Add(self.ramps[j - 1].duration, redundantRamp.duration) self.ramps[j - 1].UpdateDuration(newDur) # merge switchpointsList self.switchpointsList.pop(j) nmerged += 1 else: aCur = self.ramps[j].a
def v(sigma, t, a0, ksumcache): if (sigma >= 0): return 1 + 0.4 * mp.power(9, sigma) / a0 + 0.346 * mp.power( 2, 3 * sigma / 2.0) / (a0**2) if (sigma < 0): K = int(mp.floor(-1 * sigma) + 3) return 1 + mp.power(0.9, mp.ceil(-1 * sigma)) * ksumcache[K]
def compress(self, time_series: List[int]) -> int: if time_series is None or len(time_series) == 0: return 0 one_letter_probability = mp.mpf(1.0) / (self._alphabet_max_symbol - self._alphabet_min_symbol + 1) series_probability = mp.power(one_letter_probability, len(time_series)) return int(mp.ceil(-mp.log(series_probability, 2)))
def v(sigma, s, t): T0 = s.imag T0dash = T0 + mp.pi() * t / 8.0 a0 = mp.sqrt(T0dash / (2 * mp.pi())) if (sigma >= 0): return 1 + 0.4 * mp.power(9, sigma) / a0 + 0.346 * mp.power( 2, 3 * sigma / 2.0) / (a0**2) if (sigma < 0): K = int(mp.floor(-1 * sigma) + 3) ksum = 0.0 for k in range(1, K + 2): ksum += mp.power(1.1 / a0, k) * mp.gamma(mp.mpf(k) / 2.0) return 1 + mp.power(0.9, mp.ceil(-1 * sigma)) * ksum
b = [root for root in roots if mp.im(root) == mp.mpf(0)][0] bottom = b + mp.power(b, 2) / (wx + b) print( "Print dimensions: {wx!s} x {wy!s}\n" "Resulting border: {b!s}\n" "Resulting bottom border: {bottom!s}" .format(wx=wx, wy=wy, b=b, bottom=bottom) ) v = dict( mat_l=0 - b, mat_t=b, mat_w=wx + 2 * b, mat_h=-1 * (wy + b + bottom), ) v['grid_l'] = 0 - mp.ceil(b) v['grid_t'] = mp.ceil(b) v['grid_w'] = mp.ceil(v['mat_w']) v['grid_h'] = mp.ceil(v['mat_h'] - 1) print(r""" \begin{{tikzpicture}} \draw[help lines,very thin,color=blue!50!green!50,step=1] ({grid_l!s}, {grid_t!s}) grid +({grid_w!s}, {grid_h!s}); % Mat \draw[fill=black,opacity=0.5] ({mat_l!s},{mat_t!s}) rectangle +({mat_w!s},{mat_h!s}); % Window \draw[fill=white] (0,0) rectangle +(9,-6); \end{{tikzpicture}} """.format(**v))
# Compute roots and weights for different values of x # Note that there may be some "duplication" if the end of one interval # does not exactly match the beginning of the next (which may occur with frange) rtswts = {} for x in xlist: if (x in rtswts): continue roots, weights = rysroots(n, x) rtswts[x] = [roots, weights] print('x = {0}'.format(figs(x))) for i in range(len(roots)): print('{0}: {1} {2}'.format(i+1, figs(mp.sqrt(roots[i])), figs(weights[i], exp=True))) xlist = xlists[n-1] # Now proceed with the fitting l_min = int(mp.ceil((fit_degree+1)*fine_step/dx[n-1]))+1 nx = len(xlist) num = [] coeff = [] center = [] ini = 0 print() print('{0} points'.format(nx)) l_prev = 0 while (ini < nx-1): # TODO: bad luck if there are not enough points left to fit if (ini+l_min > nx): raise # l is the number of data points to fit (minimum is l_min) # ini is the initial point to include in the fit, so the range is ini to ini+l-1 (ini:ini+l for python) l_max = nx-ini
def segregate(n): n = int(mp.floor(mp.sqrt(n)) + 1) n_d = int(mp.ceil(mp.fdiv(n, pro_cnt))) n_list = [[x, x + n_d] for x in range(1, n, n_d)] n_list[0][0], n_list[-1][1] = 2, n return n_list, len(n_list)