Ejemplo n.º 1
0
def normal2():
  m = stocPy.normal(0, 1, obs=True)
  v = stocPy.invGamma(3, 1)
  cond = None
  if init:
    cond = obs
  stocPy.normal(m, math.sqrt(v), cond)
Ejemplo n.º 2
0
def hmm():
  states = []
  states.append(stocPy.stocPrim("categorical", (sProbs,), obs=True, part=pind))
  for i in range(1,17):
    #print states
    states.append(stocPy.stocPrim("categorical", (tProbs[states[i-1]],), obs=True, part=pind))
    stocPy.normal(eMeans[states[i]], 1, cond=obs[i-1])
Ejemplo n.º 3
0
def normal9Dec15():
  n = 15
  var = 1.0
  ms = []
  for i in range(n):
    ms.append(stocPy.normal(0, math.sqrt(var/(2**(i+1))), obs=True))
  ms.append(stocPy.normal(0, math.sqrt(var/(2**n)), obs=True))
  m = sum(ms)
Ejemplo n.º 4
0
def hmmExp():
  states = []
  states.append(categoricalExp(sProbs, name="s0"))
  for i in range(1,17):
    states.append(categoricalExp(tProbs[states[i-1]], name="s"+str(i)))
    stocPy.normal(eMeans[states[i]], 1, cond=obs[i-1], name="c"+str(i))
  global stateHist
  global singleStateHist
  curTime = time.time() - startTime
  singleStateHist[curTime] = states[sind]
Ejemplo n.º 5
0
def normal8DecU20():
  n = stocPy.stocPrim("randint", (0, 21))
  var = 1.0
  ms = []
  for i in range(n):
    ms.append(stocPy.normal(0, math.sqrt(var/(2**(i+1))), obs=True))
  ms.append(stocPy.normal(0, math.sqrt(var/(2**n)), obs=True))
  m = 10000 * ss.norm.cdf(sum(ms), loc = 0, scale = 1)
  for datum in normalData:
    stocPy.normal(m, 1, datum)
Ejemplo n.º 6
0
def normal7Dec15():
  n = 15
  var = 1.0
  ms = []
  for i in range(n):
    ms.append(stocPy.normal(0, math.sqrt(var/(2**(i+1))), obs=True))
  ms.append(stocPy.normal(0, math.sqrt(var/(2**n)), obs=True))
  m = 100 * ss.norm.cdf(sum(ms), loc = 0, scale = 1)
  for datum in normalData:
    stocPy.normal(m, 1, datum)
Ejemplo n.º 7
0
def normal6Dec15():
  n = 15
  var = 10.0
  ms = []
  for i in range(n):
    ms.append(stocPy.normal(0, math.sqrt(var/(2**(i+1))), obs=True))
  ms.append(stocPy.normal(0, math.sqrt(var/(2**n)), obs=True))
  m = sum(ms)
  for datum in normalData:
    stocPy.normal(m, 1, datum)
Ejemplo n.º 8
0
def hmm1():
  states = []
  states.append(categorical(sProbs))
  for i in range(1,17):
    states.append(categorical(tProbs[states[i-1]]))
  for i in range(1,17):
    stocPy.normal(eMeans[states[i]], 1, cond=obs[i-1])
  global singleStateHist
  curTime = time.time() - startTime
  singleStateHist[curTime] = states[sind]
Ejemplo n.º 9
0
def dpmLazy():
  crp = stocPy.crp(1.72)
  sds = {}
  ms = {}
  for i in range(len(obs)):
    c = crp(i)
    if c not in ms:
      sds[c] = math.sqrt(10 * stocPy.stocPrim("invgamma", (1, 0, 10), part=4))
      ms[c] = stocPy.stocPrim("normal", (0, sds[c]), part=4)
    stocPy.normal(ms[c], sds[c], obs[i])
  obsLens.append(len(ms))
Ejemplo n.º 10
0
def normal4():
  global ms
  global vs
  m = stocPy.normal(0, 1, obs=True)
  if m > 0:
    v = 1.0/3
  else:
    v = stocPy.invGamma(3, 1)
    vs.append(v)
  stocPy.normal(m, math.sqrt(v), cond=obs)

  ms.append(m)
Ejemplo n.º 11
0
def dpmEager():
  crp = stocPy.crp(1.72, 10)
  sds = {}
  ms = {}
  cs = {}
  for ps in range(len(crp)):
    sds[ps] = math.sqrt(10 * stocPy.stocPrim("invgamma", (1, 0, 10), part=2))
    ms[ps] = stocPy.stocPrim("normal", (0, sds[ps]), part=2)
    for p in crp[ps]:
     cs[p] = ps

  for i in range(len(obs)):
    stocPy.normal(ms[cs[i]], sds[cs[i]], obs[i])
  obsLens.append(len(ms))
Ejemplo n.º 12
0
def tdfDecomp(init=False):
  ys = []
  d1 = stocPy.normal(0, 1, obs=init)
  d2 = stocPy.normal(0, 2, obs=init)
  d3 = stocPy.normal(0, 4, obs=init)
  d4 = stocPy.normal(0, 8, obs=init)
  d5 = stocPy.normal(0, 16, obs=init)
  dof = 2 + 98 * ss.norm.cdf(d1+d2+d3+d4+d5, loc = 0, scale = math.sqrt(sum([x**2 for x in [1,2,4,8,16]])))
  for i in range(len(conds)):
    cond = None
    if init:
      cond = conds[i]
    ys.append(stocPy.studentT(dof, cond=cond))
  return ys
Ejemplo n.º 13
0
def normal3():
  global ms
  global vs
  m = stocPy.normal(0, 1, obs=True)
  if m > 0:
    v = 1
  else:
    v = stocPy.invGamma(3, 1)
    vs.append(v)
  cond = None
  if init:
    cond = obs
  stocPy.normal(m, math.sqrt(v), cond)

  ms.append(m)
Ejemplo n.º 14
0
def hmmSpec():
  states = []
  states.append(categorical(sProbs))
  for i in range(1,17):
    states.append(categorical(tProbs[states[i-1]]))
    stocPy.normal(eMeans[states[i]], 1, cond=obs[i-1])
  #global singleStateHist
  curTime = time.time() - startTime
  #singleStateHist[curTime] = states[sind]
  global stateHist
  for i in range(len(states)):
    try:
      stateHist[i][curTime] = states[i]
    except:
      stateHist.append({curTime:states[i]})
Ejemplo n.º 15
0
def normal1Dec():
  m1 = stocPy.normal(0, math.sqrt(0.5), obs=True)
  m2 = stocPy.normal(0, math.sqrt(0.25), obs=True)
  m3 = stocPy.normal(0, math.sqrt(0.125), obs=True)
  m4 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m5 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m = m1+m2+m3+m4+m5
  cond = None
  if init:
    cond = obs
  stocPy.normal(m, 1, cond)
Ejemplo n.º 16
0
def normal2Dec1():
  m1 = stocPy.normal(0, math.sqrt(0.5), obs=True)
  m2 = stocPy.normal(0, math.sqrt(0.25), obs=True)
  m3 = stocPy.normal(0, math.sqrt(0.125), obs=True)
  m4 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m5 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m = m1+m2+m3+m4+m5
  v = stocPy.invGamma(3, 1)
  cond = None
  if init:
    cond = obs
  stocPy.normal(m, math.sqrt(v), cond)
Ejemplo n.º 17
0
def normal4Dec1():
  global ms
  global vs
  m1 = stocPy.normal(0, math.sqrt(0.5), obs=True)
  m2 = stocPy.normal(0, math.sqrt(0.25), obs=True)
  m3 = stocPy.normal(0, math.sqrt(0.125), obs=True)
  m4 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m5 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m = m1+m2+m3+m4+m5s
  if m > 0:
    v = 1.0/3
  else:
    v = stocPy.invGamma(3, 1)
    vs.append(v)
  cond = None
  if init:
    cond = obs
  stocPy.normal(m, math.sqrt(v), cond)

  ms.append(m)
Ejemplo n.º 18
0
def normal8Old():
  m = stocPy.unifCont(0, 10000, obs=True)
  for datum in normalData:
    stocPy.normal(m, 1, datum)
Ejemplo n.º 19
0
def normal1():
  m = stocPy.normal(0, 1, obs=True)
  stocPy.normal(m, 1, obs)
Ejemplo n.º 20
0
def normalMean():
  mean = stocPy.normal(1, math.sqrt(5), obs=True)
  stocPy.normal(mean, math.sqrt(2), cond=9)
  stocPy.normal(mean, math.sqrt(2), cond=8)
Ejemplo n.º 21
0
def marsagliaMean():
  global sampleInd
  mean = marsaglia(1, 5)
  stocPy.normal(mean, math.sqrt(2), cond=9)
  stocPy.normal(mean, math.sqrt(2), cond=8)
  obsMean.append(mean)
Ejemplo n.º 22
0
def normal4Dec2():
  global ms
  global vs
  m1 = stocPy.normal(0, math.sqrt(0.5), obs=True)
  m2 = stocPy.normal(0, math.sqrt(0.25), obs=True)
  m3 = stocPy.normal(0, math.sqrt(0.125), obs=True)
  m4 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m5 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m = m1+m2+m3+m4+m5
  if m > 0:
    v = 1.0/3
  else:
    v1 = stocPy.normal(0, math.sqrt(0.5))
    v2 = stocPy.normal(0, math.sqrt(0.25))
    v3 = stocPy.normal(0, math.sqrt(0.125))
    v4 = stocPy.normal(0, math.sqrt(0.0625))
    v5 = stocPy.normal(0, math.sqrt(0.0625))
    vn = ss.norm.cdf(v1+v2+v3+v4+v5, loc=0, scale=1)
    v = ss.invgamma.ppf(vn, 3, loc=0, scale=1) 
    vs.append(v)
  cond = None
  if init:
    cond = obs
  stocPy.normal(m, math.sqrt(v), cond)

  ms.append(m)
Ejemplo n.º 23
0
def normal2Dec2():
  m1 = stocPy.normal(0, math.sqrt(0.5), obs=True)
  m2 = stocPy.normal(0, math.sqrt(0.25), obs=True)
  m3 = stocPy.normal(0, math.sqrt(0.125), obs=True)
  m4 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m5 = stocPy.normal(0, math.sqrt(0.0625), obs=True)
  m = m1+m2+m3+m4+m5

  v1 = stocPy.normal(0, math.sqrt(0.5))
  v2 = stocPy.normal(0, math.sqrt(0.25))
  v3 = stocPy.normal(0, math.sqrt(0.125))
  v4 = stocPy.normal(0, math.sqrt(0.0625))
  v5 = stocPy.normal(0, math.sqrt(0.0625))
  vn = ss.norm.cdf(v1+v2+v3+v4+v5, loc=0, scale=1)
  v = ss.invgamma.ppf(vn, 3, loc=0, scale=1) 
  cond = None
  if init:
    cond = obs
  stocPy.normal(m, math.sqrt(v), cond)
Ejemplo n.º 24
0
def normal9(): #prior = post
  m = stocPy.normal(0, 1, obs=True)
Ejemplo n.º 25
0
def normal8Part2():
  m = stocPy.stocPrim("uniform", (0, 10000), obs=True, part=10)
  for datum in normalData:
    stocPy.normal(m, 1, datum)
Ejemplo n.º 26
0
def normal8Part():
  m = stocPy.stocPrim("uniform", (0, 10000), obs=True, part=stocPy.stocPrim("randint", (0, 21)))
  for datum in normalData:
    stocPy.normal(m, 1, datum)
Ejemplo n.º 27
0
def normal8():
  m = stocPy.stocPrim("uniform", (0, 10000), obs=True)
  for datum in normalData:
    stocPy.normal(m, 1, datum)
Ejemplo n.º 28
0
def normal6():
  m = stocPy.normal(0, 10, obs=True)
  for datum in normalData:
    stocPy.normal(m, 1, datum)