Exemplo n.º 1
0
Arquivo: run.py Projeto: wz125/courses
def probabilityDensity():
  print '## Estimating the Probability Density 估计概率密度'
  reload(numpredict)
  print '40 80   ',numpredict.probguess(data,[99,20],40,80)
  print '80 120  ',numpredict.probguess(data,[99,20],80,120)
  print '120 1000',numpredict.probguess(data,[99,20],120,1000)
  print '30 120  ',numpredict.probguess(data,[99,20],30,120)
def av_probs(data, vec1, highnum, k, weightf, width_a):
    dicus = {}

    for a in range(0, highnum + 1):
        b = numpredict.probguess(data, vec1, a, a + width_a, k, weightf)

        for c in range(a, a + width_a):
            if c not in dicus: dicus[c] = []
            dicus[c].append(b)

    high2 = 0

    for prob in dicus:
        if len(dicus[prob]) > high2:
            high2 = len(dicus[prob])

    for x in dicus:
        a = sum(dicus[x])
        if a == 0:
            dicus[x] = 0.0
        else:
            b = a / high2
            dicus[x] = b

    list1 = []

    for a in dicus:
        b = (a, int(dicus[a] * 500))
        list1.append(b)

    del dicus

    return list1
def cumulativegraph(data,
                    vec1,
                    high,
                    k=5,
                    weightfun=numpredict.gaussianweight):
    t1 = arange(0.0, high, S)
    cprob = array(
        [numpredict.probguess(data, vec1, 0, v, k, weightfun) for v in t1])
    plot(t1, cprob)
def probabilitygraph(data, vec1, high, k=5, weightfun=numpredict.gaussianweight,
    ss=5.0/10):
  t1 = arange(0.0, high, S)
  probs = [numpredict.probguess(data, vec1, v, v+S, k, weightfun) for v in t1]

  # gaussian smooth with nearby points
  smoothed = []
  for i in range(len(probs)):  # O(n^2)
    sv = 0.0
    for j in range(0, len(probs)):
      dist = abs(i - j)*0.1
      weight = numpredict.gaussianweight(dist, sigma=ss)
      sv += weight*probs[j]
    smoothed.append(sv)

  plot(t1, array(probs))
  plot(t1, array(smoothed))
def probabilitygraph(data,
                     vec1,
                     high,
                     k=5,
                     weightfun=numpredict.gaussianweight,
                     ss=5.0 / 10):
    t1 = arange(0.0, high, S)
    probs = [
        numpredict.probguess(data, vec1, v, v + S, k, weightfun) for v in t1
    ]

    # gaussian smooth with nearby points
    smoothed = []
    for i in range(len(probs)):  # O(n^2)
        sv = 0.0
        for j in range(0, len(probs)):
            dist = abs(i - j) * 0.1
            weight = numpredict.gaussianweight(dist, sigma=ss)
            sv += weight * probs[j]
        smoothed.append(sv)

    plot(t1, array(probs))
    plot(t1, array(smoothed))
def cumulativegraph(data, vec1, high, k=5, weightfun=numpredict.gaussianweight):
  t1 = arange(0.0, high, S)
  cprob = array([numpredict.probguess(data, vec1, 0, v, k, weightfun)
    for v in t1])
  plot(t1, cprob)