Ejemplo n.º 1
0
from numpy import *
import current as pc

dist = pc.Normal()
orths = []
for poly in pc.basis(0, 4, dim=1):

    for orth in orths:

        coef = pc.E(orth * poly, dist) / pc.E(orth**2, dist)
        poly = poly - orth * coef

    orths.append(poly)

orths = pc.Poly(orths)
print orths
#  [1.0, q0, q0^2-1.0, q0^3-3.0q0, q0^4-6.0q0^2+3.0]
#end

orths2 = pc.outer(orths, orths)
print pc.E(orths2, dist)
#  [[  1.   0.   0.   0.   0.]
#   [  0.   1.   0.   0.   0.]
#   [  0.   0.   2.   0.   0.]
#   [  0.   0.   0.   6.   0.]
#   [  0.   0.   0.   0.  24.]]
#end

dist = pc.Gamma(2)
print pc.orth_bert(2, dist)
#  [1.0, q0-2.0, q0^2-6.0q0+6.0]
Ejemplo n.º 2
0
from pylab import *
import current as pc

rc("figure", figsize=[8., 4.])
rc("figure.subplot", left=.08, top=.93, right=.98)
seed(1000)

dist = pc.Iid(pc.Normal(), 2)
nodes, weights = pc.quadgen(1, dist, rule="G")
print nodes
#  [[-1. -1.  1.  1.]
#   [-1.  1. -1.  1.]]
print weights
#  [ 0.25  0.25  0.25  0.25]
#end

dist = pc.Iid(pc.Uniform(), 2)
nodes1, weights1 = pc.quadgen([3, 5], dist, rule="C", sparse=True)
print len(weights1)
#  105

nodes2, weights2 = pc.quadgen([3, 5], dist, rule="C", growth=True)
print len(weights2)
#  297
#end

subplot(122)
scatter(nodes2[0],
        nodes2[1],
        marker="s",
        s=50 * sqrt(weights2),
Ejemplo n.º 3
0
from pylab import *
import current as pc

rc("figure", figsize=[8.,4.])
rc("figure.subplot", left=.08, top=.95, right=.98)
seed(1000)

Q1 = pc.Gamma(2)
Q2 = pc.Normal(0, Q1)
Q = pc.J(Q1, Q2)
#end

subplot(121)
s,t = meshgrid(linspace(0,5,200), linspace(-6,6,200))
contourf(s,t,Q.pdf([s,t]),50)
xlabel("$q_1$")
ylabel("$q_2$")
subplot(122)
Qr = Q.sample(500)
scatter(*Qr)
xlabel("$Q_1$")
ylabel("$Q_2$")
axis([0,5,-6,6])

savefig("mv1.pdf"); clf()

Q2 = pc.Gamma(1)
Q1 = pc.Normal(Q2**2, Q2+1)
Q = pc.J(Q1, Q2)
#end
Ejemplo n.º 4
0
plot(z, q05, "k:")
plot(z, q95, "k:")

xlabel(r"Spacial location \verb;x;")
ylabel(r"Flow velocity")
axis([0, 1, 0, 1])
legend(loc="upper left")

savefig("intro3.pdf")
clf()

mu = [0.001, 0.01, 0.1]
Sigma = [[1, .5, .5], [.5, 1, .5], [.5, .5, 1]]
#end

N = pc.Iid(pc.Normal(0, 1), 3)
L = linalg.cholesky(Sigma)
Q = e**(N0 * L + mu)
#end

orth_poly = pc.orth_ttr(2, N)
#end

approx = pc.pcm(model_wrapper, 2, Q, proxy_dist=N)
fail

print len(w)
#  9

print approx
#  [0.0, -0.014499323957q1-0.014499323957q0+0.240519453193,
Ejemplo n.º 5
0
from pylab import *
import current as pc

dist_main = pc.MvNormal([0, 0], [[1, .5], [.5, 1]])
#end

dist_aux = pc.Iid(pc.Normal(), 2)
#end

orth, norms = pc.orth_ttr(2, dist_aux, retall=True)
print orth
#  [1.0, q1, q0, q1^2-1.0, q0q1, q0^2-1.0]
#end

nodes_aux, weights = pc.quadgen(3, dist_aux, rule="G")
#end

function = lambda q: q[0] * e**-q[1] + 1
#end

nodes_main = dist_main.inv(dist_aux.fwd(nodes_aux))
solves = [function(q) for q in nodes_main.T]
#end

approx = pc.fitter_quad(orth, nodes_aux, weights, solves, norms=norms)
print pc.E(approx, dist_aux)
#  0.175824752014
#end