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)
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])
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)
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]
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)
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)
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)
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]
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))
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)
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))
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
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)
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]})
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)
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)
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)
def normal8Old(): m = stocPy.unifCont(0, 10000, obs=True) for datum in normalData: stocPy.normal(m, 1, datum)
def normal1(): m = stocPy.normal(0, 1, obs=True) stocPy.normal(m, 1, obs)
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)
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)
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)
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)
def normal9(): #prior = post m = stocPy.normal(0, 1, obs=True)
def normal8Part2(): m = stocPy.stocPrim("uniform", (0, 10000), obs=True, part=10) for datum in normalData: stocPy.normal(m, 1, datum)
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)
def normal8(): m = stocPy.stocPrim("uniform", (0, 10000), obs=True) for datum in normalData: stocPy.normal(m, 1, datum)
def normal6(): m = stocPy.normal(0, 10, obs=True) for datum in normalData: stocPy.normal(m, 1, datum)