Example #1
0
from pylab import *
import current as pc

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

dist = pc.Laplace(pi, .5)
f = pc.lazy_eval(dist.pdf)
#end

q0, w0 = pc.quadgen(2, [-10,10])
print q0
#  [[-10.   0.  10.]]
#end

comp = [-10, 0, 10]
q, w = pc.quadgen(2, [-10,10], composite=comp)
print q
#  [[-10.  -5.   0.   5.  10.]]
#end

def eval_errors(q, f):

    errors = [0.]
    for i in xrange(1, len(q[0])-1):

        a,b,c = q[0,i-1:i+2]
        f_approx = ((f(c)-f(a))*b + f(a)*c-f(c)*a)/(c-a)

        f_diff = abs(f(q[0,i]) - f_approx)
Example #2
0
#end

z = linspace(0, 1, 1000)


def model_wrapper(q):
    layers = [0.001, 1., 0.001, 1.]
    bounds = [0, q[0], q[1], q[2], 1]
    U_0, U_L = 0, 1
    sl = SerialLayers(layers, bounds, U_0, U_L)
    return sl(z)


#end

model_wrapper = pc.lazy_eval(model_wrapper, load="model_data.d")
#end
model_wrapper.save("model_data.d")
#end

samples = Q.sample(5)
U = [model_wrapper(q) for q in samples.T]
#end

plot(z, array(U).T, "k")
xlabel(r"Spacial location \verb;x;")
ylabel(r"Flow velocity \verb;U;")
savefig("intro1.pdf")
clf()

approx = pc.pcm(model_wrapper, 2, Q)
Example #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)

dist = pc.Iid(pc.Uniform(), 5)


def model_solver(q):
    return q[0] * e**-q[1] / (q[2] + 1) + sin(q[3])


model_solver = pc.lazy_eval(model_solver)
#end

current = array([1, 1, 1, 1, 1])
current_error = inf
#end

for step in range(10):

    for direction in eye(len(dist), dtype=int):
        #end

        orth = pc.orth_ttr(current + direction, dist)
        nodes, weights = pc.quadgen(current + direction,
                                    dist,
                                    rule="C",
                                    growth=True)
Example #4
0
q0 = pc.Triangle(0/6., 1/6., 2/6.)
q1 = pc.Triangle(2/6., 3/6., 4/6.)
q2 = pc.Triangle(4/6., 5/6., 6/6.)
Q = pc.J(q0,q1,q2)
#end

z = linspace(0,1,1000)
def model_wrapper(q):
    layers = [0.001, 1., 0.001, 1.]
    bounds = [0, q[0], q[1], q[2], 1]
    U_0, U_L = 0, 1
    sl = SerialLayers(layers, bounds, U_0, U_L)
    return sl(z)
#end

model_wrapper = pc.lazy_eval(model_wrapper, load="model_data.d")
#end
model_wrapper.save("model_data.d")
#end

samples = Q.sample(5)
U = [model_wrapper(q) for q in samples.T]
#end

plot(z, array(U).T, "k")
xlabel(r"Spacial location \verb;x;")
ylabel(r"Flow velocity \verb;U;")
savefig("intro1.pdf"); clf()

approx = pc.pcm(model_wrapper, 2, Q)
#end
Example #5
0
from pylab import *
import current as pc

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

dist = pc.Laplace(pi, .5)
f = pc.lazy_eval(dist.pdf)
#end

q0, w0 = pc.quadgen(2, [-10, 10])
print q0
#  [[-10.   0.  10.]]
#end

comp = [-10, 0, 10]
q, w = pc.quadgen(2, [-10, 10], composite=comp)
print q
#  [[-10.  -5.   0.   5.  10.]]
#end


def eval_errors(q, f):

    errors = [0.]
    for i in xrange(1, len(q[0]) - 1):

        a, b, c = q[0, i - 1:i + 2]
        f_approx = ((f(c) - f(a)) * b + f(a) * c - f(c) * a) / (c - a)
Example #6
0
from pylab import *
import current as pc

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

dist = pc.Iid(pc.Uniform(), 5)

def model_solver(q):
    return q[0]*e**-q[1]/(q[2]+1) + sin(q[3])
model_solver = pc.lazy_eval(model_solver)
#end

current = array([1,1,1,1,1])
current_error = inf
#end

for step in range(10):

    for direction in eye(len(dist), dtype=int):
        #end

        orth = pc.orth_ttr(current+direction, dist)
        nodes, weights = pc.quadgen(current+direction, dist,
                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)