input: y_Arai, y_tail, t_Arai, tail_temps, n_tail
    output: max_check, diffs
771061
def get_max_tail_check(y_Arai, y_tail, t_Arai, tail_temps, n_tail):
    
    if not n_tail:
        return float('nan'), []
    tail_compare = []
    y_Arai_compare = []
    for temp in tail_temps[:n_tail]:
        tail_index = list(tail_temps).index(temp)
        tail_check = y_tail[tail_index]
        tail_compare.append(tail_check)
        arai_index = list(t_Arai).index(temp)
        nrm_orig = y_Arai[arai_index]
        y_Arai_compare.append(nrm_orig)
    diffs = numpy.array(y_Arai_compare) - numpy.array(tail_compare)
    abs_diffs = abs(diffs)
    max_check = max(abs_diffs)
    return max_check, diffs
914731
def runningstd(t, data, width):
    
    ne = len(t) - width
    t_new = np.zeros(ne)
    std_r = np.zeros(ne)
    for i in range(ne):
        t_new[i] = np.mean(t[i:i+width+1])
        std_r[i] = scipy.stats.nanstd(data[i:i+width+1])
    return t_new, std_r
710514
def infer_last_epoch_num(data_dir):
  """"""
  names = os.listdir(data_dir)
  epochs_str = [re.findall(pattern=r".*\.(-?\d+)$", string=name)
                for name in names]
  epochs_str = sum(epochs_str, [])
  return max([int(epoch_str) for epoch_str in epochs_str])
851412
def run_all(logdir, verbose=False):
  
  for initial_temperature in [270.0, 310.0, 350.0]:
    for final_temperature in [270.0, 310.0, 350.0]:
      for heat_coefficient in [0.001, 0.005]:
        run_name = 'temperature:t0=%g,tA=%g,kH=%g' % (
            initial_temperature, final_temperature, heat_coefficient)
        if verbose:
          print('--- Running: %s' % run_name)
        run(logdir, run_name,
            initial_temperature, final_temperature, heat_coefficient)
1153751
def errors(self):
        

        n = self.n
        dt = self.dt
        order = self._order
        sigma = self.sigma

        error = np.zeros(order + 1)
        std = np.zeros(order + 1)

        if n == 0:
            return (error, std)

        if order == 0:
            error[0] = sigma/sqrt(n)
            std[0] = sigma/sqrt(n)

        elif order == 1:
            if n > 1:
                error[0] = sigma * sqrt(2*(2*n-1) / (n*(n+1)))
                error[1] = sigma * sqrt(12. / (n*(n*n-1)*dt*dt))
            std[0] = sigma * sqrt((2*(2*n-1)) / (n*(n+1)))
            std[1] = (sigma/dt) * sqrt(12. / (n*(n*n-1)))

        elif order == 2:
            dt2 = dt * dt

            if n >= 3:
                error[0] = sigma * sqrt(3*(3*n*n-3*n+2) / (n*(n+1)*(n+2)))
                error[1] = sigma * sqrt(12*(16*n*n-30*n+11) /
                                        (n*(n*n-1)*(n*n-4)*dt2))
                error[2] = sigma * sqrt(720/(n*(n*n-1)*(n*n-4)*dt2*dt2))

            std[0] = sigma * sqrt((3*(3*n*n - 3*n + 2)) / (n*(n+1)*(n+2)))
            std[1] = (sigma/dt) * sqrt((12*(16*n*n - 30*n + 11)) /
                                       (n*(n*n - 1)*(n*n - 4)))
            std[2] = (sigma/dt2) * sqrt(720 / (n*(n*n-1)*(n*n-4)))

        return error, std
179728
def last_update_time(self) -> float:
        """"""
        stdout = self.stdout_interceptor
        stderr = self.stderr_interceptor

        return max([
            self._last_update_time,
            stdout.last_write_time if stdout else 0,
            stderr.last_write_time if stderr else 0,
        ])
1292066
def Max(a, axis, keep_dims):
    
    return np.amax(a, axis=axis if not isinstance(axis, np.ndarray) else tuple(axis),
                   keepdims=keep_dims),
674579
public static <T> int calcStackDeep(List<T> input, List<T> output) {
        int max = 0;
        //当前已有交集大小
        int helper = 0;
        for (int i = 0; i < output.size(); i++) {
            // 求出出栈元素在原队列中的位置index，然后算出原队列0-index区间与出栈队列0-i区间的交集，用index-该交集长度加上当前元素占用
            // 位置就是当前栈深度，然后遍历出栈队列取最大栈深度即可
            Object obj = output.get(i);
            int index = input.indexOf(obj);
            if ((index - Math.min(index, i) + 1 - helper) <= max) {
                continue;
            }
            int repeat = helper = intersection(input, 0, index, output, 0, i).size();
            int temp = index - repeat + 1;
            max = temp > max ? temp : max;
        }
        return max;
    }
995101
def tdist_ci(x, df, stderr, level):
    
    q = (1 + level)/2
    delta = stats.t.ppf(q, df) * stderr
    return x - delta, x + delta
1113940
def prox_max(X, step, thresh=0):
    
    thresh_ = _step_gamma(step, thresh)
    above = X - thresh_ > 0
    X[above] = thresh_
    return X
1083544
def roll_mean(input, window):
    ''''''
    nobs, i, j, sum_x = 0,0,0,0.
    N = len(input)

    if window > N:
        raise ValueError('Out of bound')

    output = np.ndarray(N-window+1,dtype=input.dtype)

    for val in input[:window]:
        if val == val:
            nobs += 1
            sum_x += val

    output[j] = NaN if not nobs else sum_x / nobs

    for val in input[window:]:
        prev = input[j]
        if prev == prev:
            sum_x -= prev
            nobs -= 1

        if val == val:
            nobs += 1
            sum_x += val

        j += 1
        output[j] = NaN if not nobs else sum_x / nobs

    return output
116246
def estimate_global_norm_range(N_t, func, num_of_sample=10, func_args={},
                               percen_lower=1, percen_upper=99, show_progress=True):
    

    ## Check input arguments
    for arg in [N_t, num_of_sample]:
        assert is_integer_valued_real(arg)
    assert num_of_sample <= N_t
    for arg in [percen_lower, percen_upper]:
        assert is_real_number(arg)
        assert (0 <= arg) and (arg <= 100)
    assert percen_lower <= percen_upper

    assert callable(func)
    assert type(func_args) is dict

    assert type(show_progress) is bool

    sample_indices = np.random.randint(0, N_t-1, num_of_sample)

    if show_progress:
        progress_bar = Progress_Bar(num_of_sample)
    uppers = []
    lowers = []

    for idx, sample_index in enumerate(sample_indices):
        frame_data = func(sample_index, **func_args)
        lowers.append(np.percentile(frame_data, percen_lower))
        uppers.append(np.percentile(frame_data, percen_upper))
        if show_progress:
            progress_bar.print(idx)

    vmin = np.percentile(lowers, percen_lower)
    vmax = np.percentile(uppers, percen_upper)

    return vmin, vmax
610978
def compute(self, xt1, yt1, xt, yt, theta1t1, theta2t1, theta1, theta2):
    
    dx = xt - xt1
    dy = yt - yt1

    if self.numPoints < self.maxPoints:
      self.dxValues[self.numPoints,0] = dx
      self.dxValues[self.numPoints,1] = dy

      self.thetaValues[self.numPoints,0] = theta1
      self.thetaValues[self.numPoints,1] = theta2

      self.numPoints += 1

      # print >>sys.stderr, "Xt's: ", xt1, yt1, xt, yt, "Delta's: ", dx, dy
      # print >>sys.stderr, "Theta t-1: ", theta1t1, theta2t1, "t:",theta1, theta2

    elif self.numPoints == self.maxPoints:
      print >> sys.stderr,"Max points exceeded, analyzing ",self.maxPoints,"points only"
      self.numPoints += 1
762666
def intervals(_min, _max=None, size=1):
    
    if _max == None:
        _max = _min
        _min = 0
    _max = int(mo_math.ceiling(_max))
    _min = int(mo_math.floor(_min))

    output = ((x, min(x + size, _max)) for x in _range(_min, _max, size))
    return output
754742
def tail(self, since, filter_pattern, limit=10000, keep_open=True, colorize=True, http=False, non_http=False, force_colorize=False):
        

        try:
            since_stamp = string_to_timestamp(since)

            last_since = since_stamp
            while True:
                new_logs = self.zappa.fetch_logs(
                    self.lambda_name,
                    start_time=since_stamp,
                    limit=limit,
                    filter_pattern=filter_pattern,
                    )

                new_logs = [ e for e in new_logs if e['timestamp'] > last_since ]
                self.print_logs(new_logs, colorize, http, non_http, force_colorize)

                if not keep_open:
                    break
                if new_logs:
                    last_since = new_logs[-1]['timestamp']
                time.sleep(1)
        except KeyboardInterrupt: # pragma: no cover
            # Die gracefully
            try:
                sys.exit(0)
            except SystemExit:
                os._exit(130)
571905
def get_anomalies(smoothed_errors, y_true, z, window, all_anomalies, error_buffer):
    

    mu = np.mean(smoothed_errors)
    sigma = np.std(smoothed_errors)

    epsilon = mu + (z * sigma)

    # compare to epsilon
    errors_seq, anomaly_indices, max_error_below_e = group_consecutive_anomalies(
        smoothed_errors,
        epsilon,
        y_true,
        error_buffer,
        window,
        all_anomalies
    )

    if len(errors_seq) > 0:
        anomaly_indices = prune_anomalies(
            errors_seq,
            smoothed_errors,
            max_error_below_e,
            anomaly_indices
        )

    return anomaly_indices
496616
def main():
    
    input_tif = "../tests/data/Jamaica_dem.tif"
    output_tif = "../tests/data/tmp_results/log_dem.tif"
    rst = RasterUtilClass.read_raster(input_tif)
    # raster data (with noDataValue as numpy.nan) as numpy array
    rst_valid = rst.validValues
    output_data = np.log(rst_valid)
    # write output raster
    RasterUtilClass.write_gtiff_file(output_tif, rst.nRows, rst.nCols, output_data, rst.geotrans,
                                     rst.srs, rst.noDataValue, rst.dataType)