smooth [arr] using moving average
492270
def staticMovingAverage(arr, fineness=10):
    
    s0 = arr.shape[0]
    window_len = int(round(s0 / fineness))

    start = arr[0] + arr[0] - arr[window_len - 1:0:-1]
    end = arr[-1] + arr[-1] - arr[-1:-window_len:-1]
    s = np.r_[start, arr, end]
    w = np.ones(window_len, 'd')
    w /= w.sum()
    a0 = np.convolve(w, s, mode='valid')[:s0]
    a1 = np.convolve(w, s[::-1], mode='valid')[:s0][::-1]
    return 0.5 * (a0 + a1)
275877
def first_order_gradient(arr, axis=0):
  '''
  
  '''
  grad_arr = difference(arr, n=1, axis=axis)
  return np.insert(grad_arr, grad_arr.shape[axis], 0, axis=axis)
682201
def compute(self):
        """"""
        self._compute_primary_smooths()
        self._smooth_the_residuals()
        self._select_best_smooth_at_each_point()
        self._enhance_bass()
        self._smooth_best_span_estimates()
        self._apply_best_spans_to_primaries()
        self._smooth_interpolated_smooth()
        self._store_unsorted_results(self.smooth_result, numpy.zeros(len(self.smooth_result)))
1061340
def average_true_range(close_data, period):
    
    tr = true_range(close_data, period)
    atr = smoothed_moving_average(tr, period)
    atr[0:period-1] = tr[0:period-1]
    return atr
1222562
function variance (arr) {
    let mean = avg(arr);
    return avg(arr.map(num => (num - mean) ** 2));
}
615266
function smoothFn (v, o, f, snap){
      v = !v ? 0 : v;
      f = f === undefined ? 0.1 : f;
      f = Math.min(f, snap);
      if (f < 0) { f = v > o ? Math.abs(snap) : -f; }
      return f * v + (1 - f) * o;
    }
37104
def _smooth(series, window_len, window):
    """"""

    windows = {
        "flat": np.ones,
        "hanning": np.hanning,
        "hamming": np.hamming,
        "bartlett": np.bartlett,
        "blackman": np.blackman,
    }
    data = series.values.copy()

    if window_len < 3:
        return pd.Series(data, index=series.index, name=series.name)

    if window not in list(windows.keys()):
        raise ValueError(
            """window must be one of 'flat', 'hanning',
                         'hamming', 'bartlett', 'blackman'"""
        )

    s = np.r_[
        2 * data[0] - data[window_len:1:-1],
        data,
        2 * data[-1] - data[-1:-window_len:-1],
    ]

    w = windows[window](window_len)

    data = np.convolve(w / w.sum(), s, mode="same")
    data = data[window_len - 1 : -window_len + 1]
    return pd.Series(data, index=series.index, name=series.name)
197986
def smoothEstimate(self, nodeShape, estimatedNodeCount):
        
        weightedEstimate = (1 - self.betaInertia) * estimatedNodeCount + \
                           self.betaInertia * self.previousWeightedEstimate[nodeShape]
        self.previousWeightedEstimate[nodeShape] = weightedEstimate
        return self._round(weightedEstimate)
65289
def variance(arr):
  
  avg = average(arr)
  return sum([(float(x)-avg)**2 for x in arr])/float(len(arr)-1)
1164689
def _smooth_best_span_estimates(self):
        """"""
        self._smoothed_best_spans = smoother.perform_smooth(self.x,
                                                            self._best_span_at_each_point,
                                                            MID_SPAN)
1195992
def confidenceInterval(n, k, alpha = 0.68, errorbar=False):
    
    try:
        e = float(k) / float(n)
    except ZeroDivisionError:
        return np.nan, [np.nan, np.nan]

    bins = 1000001
    dx = 1. / bins

    efficiency = np.linspace(0, 1, bins)

    # MODIFIED FOR LARGE NUMBERS
    if n + 2 > 1000:
        a = gammalnStirling(n + 2)
    else:
        a = scipy.special.gammaln(n + 2)
    if k + 1 > 1000:
        b = gammalnStirling(k + 1)
    else:
        b = scipy.special.gammaln(k + 1)
    if n - k + 1 > 1000:
        c = gammalnStirling(n - k + 1)
    else:
        c = scipy.special.gammaln(n - k + 1)

    if k == 0:
        p = np.concatenate([[np.exp(a - b - c)],
                               np.exp(a - b - c + (k * np.log(efficiency[1: -1])) + (n - k) * np.log(1. - efficiency[1: -1])),
                               [0.]])
    elif k == n:
        p = np.concatenate([[0.],
                               np.exp(a - b - c + (k * np.log(efficiency[1: -1])) + (n - k) * np.log(1. - efficiency[1: -1])),
                               [np.exp(a - b - c)]])
    else:
        p = np.concatenate([[0.],
                               np.exp(a - b - c + (k * np.log(efficiency[1: -1])) + (n - k) * np.log(1. - efficiency[1: -1])),
                               [0.]])

    i = np.argsort(p)[::-1]
    p_i = np.take(p, i)

    s = i[np.cumsum(p_i * dx) < alpha]

    low = min(np.min(s) * dx, e)
    high = max(np.max(s) * dx, e)

    if not errorbar:
        return e, [low, high]
    else:
        return e, [e - low, high - e]
471463
def _normalize(arr, keep_ratio=False):
    """"""
    (x_min, y_min), (x_max, y_max) = arr.min(axis=0), arr.max(axis=0)

    if keep_ratio:
        a = 1. / max(x_max - x_min, y_max - y_min)
        ax = ay = a
        bx = .5 - .5 * a * (x_max + x_min)
        by = .5 - .5 * a * (y_max + y_min)
    else:
        ax = 1. / (x_max - x_min)
        ay = 1. / (y_max - y_min)
        bx = -x_min / (x_max - x_min)
        by = -y_min / (y_max - y_min)

    arr_n = arr.copy()
    arr_n[:, 0] *= ax
    arr_n[:, 0] += bx
    arr_n[:, 1] *= ay
    arr_n[:, 1] += by

    return arr_n
592691
def smoothstep(edge0, edge1, x):
    
    # Scale, bias and saturate x to 0..1 range
    x = np.clip((x - edge0)/(edge1 - edge0), 0.0, 1.0)
    # Evaluate polynomial
    return x*x*(3 - 2*x)
902221
def smoother(self):
        
        if not self.filt:
            self.filter()
        self.smth = [self.filt[-1]]
        for t, f in reversed(list(enumerate(self.filt[:-1]))):
            self.smth += [smoother_step(self.ssm.F, f, self.pred[t + 1], 
                                        self.smth[t + 1])]
        self.smth.reverse()
1187787
def _prep_smooth(t, y, dy, span, t_out, span_out, period):
    """"""

    # If period is provided, sort by phases. Otherwise sort by t
    if period:
        t = t % period
        if t_out is not None:
            t_out = t_out % period

    t, y, dy = validate_inputs(t, y, dy, sort_by=t)

    if span_out is not None:
        if t_out is None:
            raise ValueError("Must specify t_out when span_out is given")
        if span is not None:
            raise ValueError("Must specify only one of span, span_out")
        span, t_out = np.broadcast_arrays(span_out, t_out)
        indices = np.searchsorted(t, t_out)
    elif span is None:
        raise ValueError("Must specify either span_out or span")
    else:
        indices = None

    return t, y, dy, span, t_out, span_out, indices
718579
def llinregress(x,y):
    
    TINY = 1.0e-20
    if len(x) != len(y):
        raise ValueError('Input values not paired in linregress.  Aborting.')
    n = len(x)
    x = [float(_) for _ in x]
    y = [float(_) for _ in y]
    xmean = mean(x)
    ymean = mean(y)
    r_num = float(n*(summult(x,y)) - sum(x)*sum(y))
    r_den = math.sqrt((n*ss(x) - square_of_sums(x))*(n*ss(y)-square_of_sums(y)))
    r = r_num / r_den
    z = 0.5*math.log((1.0+r+TINY)/(1.0-r+TINY))
    df = n-2
    t = r*math.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY)))
    prob = betai(0.5*df,0.5,df/(df+t*t))
    slope = r_num / float(n*ss(x) - square_of_sums(x))
    intercept = ymean - slope*xmean
    sterrest = math.sqrt(1-r*r)*samplestdev(y)
    return slope, intercept, r, prob, sterrest
645123
def smooth(data, fw):
    """"""
    if fw == 0:
        fdata = data
    else:
        fdata = lfilter(np.ones(fw)/fw, 1, data)
    return fdata