Esempio n. 1
0
def kmeans(X, assign, k):
    C = par.map(calc_centroid, arange(k), fixed=(X, assign))
    converged = False
    while not converged:
        lastAssign = assign
        assign = par.map(minidx, X, fixed=C)
        converged = np.all(assign == lastAssign)
        C = parakeet.map(calc_centroid, arange(k), fixed=(X, assign))
    return C
def test_black_scholes():
  CallFlags = np.array([True, False, True, False])
  A = np.array([2.0, 1.0, 2.0, 1.0])
  inputs = (CallFlags, A, A, A, A, A)
  x = parakeet.map(scalar_black_scholes, *inputs) 
  y = slow_black_scholes(*inputs)
  print "BLACK SCHOLES RESULTS Parakeet = %s\n Python = %s" % (x,y)
  assert np.all(np.abs(x -  y) < 0.00001)
Esempio n. 3
0
def test_cnd(): 
  print "RUNNING CND"
  x = np.arange(10000, dtype='float32')
  y = parakeet.map(CND, x)
  z = np.array([CND(xi) for xi in x])
  print "Parakeet: ", y
  print "Python: ", z 
  assert np.sum(abs(y-z)) < 0.00001
Esempio n. 4
0
def test_rule30():
  output = init.copy()
  cur = init
  zero_array = np.array([0])
  indices = np.arange(1,size+1)
  for _ in range(size/2):
    extended = np.concatenate((zero_array, cur, zero_array))

    def run_rule30(i):
      return rule30(extended, i)
    parakeet_iter = parakeet.map(run_rule30, indices)
    cur = np.array(map(run_rule30, indices))
    assert eq(parakeet_iter, cur), \
       "Parakeet result (%s) didn't match Python result(%s)" % \
       (parakeet_iter, cur)
    output = np.vstack((output,cur))
Esempio n. 5
0
def norm_cdf(ary):
  def _inner(x):
    a1 = 0.31938153
    a2 = -0.356563782
    a3 = 1.781477937
    a4 = -1.821255978
    a5 = 1.330274429
    L = abs(x)
    K = 1.0 / (1.0 + 0.2316419 * L)
    w = 1.0 - 1.0/sqrt(2*3.141592653589793) * exp(-1*L*L/2.) * (a1*K +
                                                                a2*K*K + a3*K*K*K + a4*K*K*K*K + a5*K*K*K*K*K)
    if x < 0:
      w = 1.0-w
    return w

  return parakeet.map(_inner, ary)
Esempio n. 6
0
def test_rule30():
    output = init.copy()
    cur = init
    zero_array = np.array([0])
    indices = np.arange(1, size + 1)
    for _ in range(size / 2):
        extended = np.concatenate((zero_array, cur, zero_array))

        def run_rule30(i):
            return rule30(extended, i)

        parakeet_iter = parakeet.map(run_rule30, indices)
        cur = np.array(map(run_rule30, indices))
        assert eq(parakeet_iter, cur), \
           "Parakeet result (%s) didn't match Python result(%s)" % \
           (parakeet_iter, cur)
        output = np.vstack((output, cur))
Esempio n. 7
0
def norm_cdf(ary):
    def _inner(x):
        a1 = 0.31938153
        a2 = -0.356563782
        a3 = 1.781477937
        a4 = -1.821255978
        a5 = 1.330274429
        L = abs(x)
        K = 1.0 / (1.0 + 0.2316419 * L)
        w = 1.0 - 1.0 / sqrt(2 * 3.141592653589793) * exp(
            -1 * L * L / 2.) * (a1 * K + a2 * K * K + a3 * K * K * K +
                                a4 * K * K * K * K + a5 * K * K * K * K * K)
        if x < 0:
            w = 1.0 - w
        return w

    return parakeet.map(_inner, ary)
Esempio n. 8
0
def mult_vec_scalar(x,y):
  return parakeet.map(parakeet.mult, x, y)
Esempio n. 9
0
def dct(I):
  return par.map(dct_val, idxs, fixed=[I])
Esempio n. 10
0
def map_add(x):
  return parakeet.map(parakeet.add, x, x)
Esempio n. 11
0
def map_increase_rank(x):
  return parakeet.map(increase_rank, x)
Esempio n. 12
0
def simple_map(x):
  return parakeet.map(incr, x)
Esempio n. 13
0
def calc_assigns(X, C):
  return parakeet.map(calc_assign, X, fixed=[C])
Esempio n. 14
0
def calc_centroids(X, assign, a):
  return parakeet.map(calc_centroid, a, fixed=[X, assign])
Esempio n. 15
0
def calc_assign(C, x):
  return np.argmin(parakeet.map(sqr_dist, C, fixed=[x]))
Esempio n. 16
0
def map_mult_cols(mat, col):
  return parakeet.map(parakeet.mult, mat, col, axis=0)
Esempio n. 17
0
def simple_map(x):
  return parakeet.map(incr, x)
Esempio n. 18
0
def minidx(C, x):
    return par.argmin(parakeet.map(sqr_dist, C, fixed=x))
Esempio n. 19
0
def map_increase_rank(x):
  return parakeet.map(increase_rank, x)