Example #1
0
Z = pc.Iid(pc.Normal(), 4)
orth_poly = pc.orth_ttr(2, Z)
#end

nodes, weights = pc.quadgen(3, Z, gaussian=True, sparse=True)
print len(weights)
# 137
#end

mapped_nodes = Q.inv(Z.fwd(nodes))

t = linspace(0, 10, 100)
evaluations = [model_solver(t, q) for q in mapped_nodes.T]
#end

model_approx = pc.fitter_quad(orth_poly, nodes, weights, evaluations)
#end

samples_Z = Z.sample(100)
samples_Y = model_approx(*samples_Z)
E = pc.E(model_approx, Z)
#end

t = linspace(0, 10, 100)
plot(t, samples_Y, "k")
plot(t, E, "w-", lw=3)
plot(t, E, "k--", lw=3)

axis([0, 10, 0, 4])
xticks(range(11))
xlabel("time $t$")
Example #2
0
# end

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


def model_solver(q):
    return [q[0] * q[1], q[0] * e ** -q[1] + 1]


solves = [model_solver(q) for q in nodes.T]
# end

approx = pc.fitter_quad(orth, nodes, weights, solves)
print pc.around(approx, 14)
#  [q0q1, -1.58058656357q0q1+1.63819248006q0+1.0]
# end


orth, norms = pc.orth_ttr(2, dist, retall=True)
approx2 = pc.fitter_quad(orth, nodes, weights, solves, norms=norms)
# end

print np.max(abs(approx - approx2).coeffs(), -1)
#  [  2.44249065e-15   3.77475828e-15]
# end

nodes = dist.sample(12, "M")
print nodes
Example #3
0
                                    growth=True)
        vals = [model_solver(q) for q in nodes.T]
        #end

        residuals = pc.cross_validate(orth, nodes, vals, folds=5)
        error = sum(residuals**2)
        #end

        if error < current_error:
            current_error = error
            proposed_dir = current + direction
        #end

    current = proposed_dir
    #end

print current
#  [ 1  3  4  6  1]
#end

orth, norms = pc.orth_ttr(current, dist, retall=True)
nodes, weights = pc.quadgen(current, dist, rule="C", growth=True)
vals = [model_solver(q) for q in nodes.T]
approx = pc.fitter_quad(orth, nodes, weights, vals, norms=norms)

print pc.E(approx, dist)
#  0.678773985695
print pc.Var(approx, dist)
#  0.0854146399504
#end
Example #4
0
Z = pc.Iid(pc.Normal(), 4)
orth_poly = pc.orth_ttr(2, Z)
#end

nodes, weights = pc.quadgen(3, Z, gaussian=True, sparse=True)
print len(weights)
# 137
#end

mapped_nodes = Q.inv(Z.fwd(nodes))

t = linspace(0,10,100)
evaluations = [model_solver(t, q) for q in mapped_nodes.T]
#end

model_approx = pc.fitter_quad(orth_poly, nodes, weights, evaluations)
#end

samples_Z = Z.sample(100)
samples_Y = model_approx(*samples_Z)
E = pc.E(model_approx, Z)
#end

t = linspace(0,10,100)
plot(t, samples_Y, "k")
plot(t, E, "w-", lw=3)
plot(t, E, "k--", lw=3)

axis([0,10,0,4])
xticks(range(11))
xlabel("time $t$")
Example #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
Example #6
0
                rule="C", growth=True)
        vals = [model_solver(q) for q in nodes.T]
        #end

        residuals = pc.cross_validate(orth, nodes, vals, folds=5)
        error = sum(residuals**2)
        #end

        if error < current_error:
            current_error = error
            proposed_dir = current+direction
        #end

    current = proposed_dir
    #end

print current
#  [ 1  3  4  6  1]
#end

orth, norms = pc.orth_ttr(current, dist, retall=True)
nodes, weights = pc.quadgen(current, dist, rule="C", growth=True)
vals = [model_solver(q) for q in nodes.T]
approx = pc.fitter_quad(orth, nodes, weights, vals, norms=norms)

print pc.E(approx, dist)
#  0.678773985695
print pc.Var(approx, dist)
#  0.0854146399504
#end