Linearly anneal from `start` to `end` as pct goes from 0.0 to 1.0.
770333
def annealing_linear(start:Number, end:Number, pct:float)->Number:
    ""
    return start + pct * (end-start)
1146221
def scale_to_zero_one(x):
    
    xscaled = x - np.min(x)
    xscaled /= np.max(xscaled)
    return xscaled
951337
def lnprior(x):
    """"""
    per, t0, b = x
    if b < -1 or b > 1:
        return -np.inf
    elif per < 7 or per > 10:
        return -np.inf
    elif t0 < 1978 or t0 > 1979:
        return -np.inf
    else:
        return 0.
76859
def interpolate_series(start, end, steps, how='linear'):
    
    return INTERP_DICT[how](start, end, steps)
755854
def _fixedpoint(D, tol=1e-7, maxiter=None):
    ''''''
    N, K = D.shape
    logp = log(D).mean(axis=0)
    a0 = _init_a(D)

    # Start updating
    if maxiter is None:
        maxiter = MAXINT
    for i in xrange(maxiter):
        a1 = _ipsi(psi(a0.sum()) + logp)
        # if norm(a1-a0) < tol:
        if abs(loglikelihood(D, a1)-loglikelihood(D, a0)) < tol: # much faster
            return a1
        a0 = a1
    raise Exception('Failed to converge after {} iterations, values are {}.'
                    .format(maxiter, a1))
793108
def _get_padded(data, start, end):
    
    if start < 0 and end > data.shape[0]:
        raise RuntimeError()
    if start < 0:
        start_zeros = np.zeros((-start, data.shape[1]),
                               dtype=data.dtype)
        return np.vstack((start_zeros, data[:end]))
    elif end > data.shape[0]:
        end_zeros = np.zeros((end - data.shape[0], data.shape[1]),
                             dtype=data.dtype)
        return np.vstack((data[start:], end_zeros))
    else:
        return data[start:end]
336146
def on_backward_begin(self, last_loss:Rank0Tensor, **kwargs:Any) -> Rank0Tensor:
        ""
        #To avoid gradient underflow, we scale the gradients
        ret_loss = last_loss * self.loss_scale
        return {'last_loss': ret_loss}
622926
def interpolate_logscale(start, end, steps):
    
    if start <= 0.0:
        warnings.warn("Start of logscale interpolation must be positive!")
        start = 1e-5

    return np.logspace(np.log10(float(start)), np.log10(float(end)), steps)
773774
def zero(self):
        """"""
        tmp = self.element()
        self.lincomb(0, tmp, 0, tmp, tmp)
        return tmp
1161169
def y0astep():
    
    """

    global mp_b
    mp_b[:] = mp_inv_off_diag * np.sum((mp_S + mp_rho*(mp_DX+mp_U0)),
                                       axis=mp_axisM, keepdims=True)
1159741
def annealing_cos(start:Number, end:Number, pct:float)->Number:
    ""
    cos_out = np.cos(np.pi * pct) + 1
    return end + (start-end)/2 * cos_out
850771
def anneal(self):
        
        step = 0
        self.start = time.time()

        # Precompute factor for exponential cooling from Tmax to Tmin
        if self.Tmin <= 0.0:
            raise Exception('Exponential cooling requires a minimum "\
                "temperature greater than zero.')
        Tfactor = -math.log(self.Tmax / self.Tmin)

        # Note initial state
        T = self.Tmax
        E = self.energy()
        prevState = self.copy_state(self.state)
        prevEnergy = E
        self.best_state = self.copy_state(self.state)
        self.best_energy = E
        trials, accepts, improves = 0, 0, 0
        if self.updates > 0:
            updateWavelength = self.steps / self.updates
            self.update(step, T, E, None, None)

        # Attempt moves to new states
        while step < self.steps and not self.user_exit:
            step += 1
            T = self.Tmax * math.exp(Tfactor * step / self.steps)
            self.move()
            E = self.energy()
            dE = E - prevEnergy
            trials += 1
            if dE > 0.0 and math.exp(-dE / T) < random.random():
                # Restore previous state
                self.state = self.copy_state(prevState)
                E = prevEnergy
            else:
                # Accept new state and compare to best state
                accepts += 1
                if dE < 0.0:
                    improves += 1
                prevState = self.copy_state(self.state)
                prevEnergy = E
                if E < self.best_energy:
                    self.best_state = self.copy_state(self.state)
                    self.best_energy = E
            if self.updates > 1:
                if (step // updateWavelength) > ((step - 1) // updateWavelength):
                    self.update(
                        step, T, E, accepts / trials, improves / trials)
                    trials, accepts, improves = 0, 0, 0

        self.state = self.copy_state(self.best_state)
        if self.save_state_on_exit:
            self.save_state()

        # Return best state and energy
        return self.best_state, self.best_energy
541295
def py3round(number):
    """"""
    if abs(round(number) - number) == 0.5:
        return int(2.0 * round(number / 2.0))

    return int(round(number))
599835
def linear(self, limits=None, k=5):
        """"""
        start, stop = limits or (self.minval, self.maxval)
        return np.linspace(start, stop, k)
949517
def open01(x, limit=1.e-6):
    """"""
    try:
        return np.array([min(max(y, limit), 1. - limit) for y in x])
    except TypeError:
        return min(max(x, limit), 1. - limit)
955517
def move_phasecenter(d, l1, m1, u, v):
    

    logger.info('Rephasing data to (l, m)=(%.4f, %.4f).' % (l1, m1))
    data_resamp = numpyview(data_resamp_mem, 'complex64', datashape(d))
    rtlib.phaseshift_threaded(data_resamp, d, l1, m1, u, v)
1129129
def par_y0bstep(i):
    
    """

    global mp_Y0
    mp_Y0[i] = 1/mp_rho*mp_S + mp_DX[i] + mp_U0[i] + mp_b