Ejemplo n.º 1
0
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]
#end

dist = pc.Uniform(-1, 1)
print dist.ttr([0, 1, 2, 3])
#  [[ 0.          0.          0.          0.        ]
#   [-0.          0.33333333  0.26666667  0.25714286]]
#end

dist = pc.Lognormal(0.01)
orths = pc.orth_ttr(2, dist)
print orths
#  [1.0, q0-1.00501252086, q0^2-2.04042818514q0+0.842739860094]
#end

dist = pc.Iid(pc.Gamma(1), 2)
orths = pc.orth_ttr(2, dist)
print orths
#  [1.0, q1-1.0, q0-1.0, q1^2-4.0q1+2.0, q0q1-q1-q0+1.0, q0^2-4.0q0+2.0]
Ejemplo n.º 2
0
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),
        alpha=.7,
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)

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)
Ejemplo n.º 4
0
# you mistype something
#end

from pylab import *
import current as pc

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

U1 = pc.Uniform(0, 1)
U2 = pc.Uniform(0, 1)
add = U1 + U2
Q = pc.J(U1, add)
#end


def cdf(self, q, G):

    if "par1" in G.K:
        num = G.K["par1"]
        dist = G.D["par2"]

    else:
        num = G.K["par2"]
        dist = G.D["par1"]

    return G(q - num, dist)


#end
Ejemplo n.º 5
0
nodes, weights = pc.quadgen(1, [0,1], rule="E", composite=2)
print nodes
#  [[ 0.10566243  0.39433757  0.60566243  0.89433757]]
print weights
#  [ 0.25  0.25  0.25  0.25]
#end

nodes, weights = pc.quadgen(1, [0,1], rule="E", composite=[0.2])
print nodes
#  [[ 0.04226497  0.15773503  0.36905989  0.83094011]]
print weights
#  [ 0.1  0.1  0.4  0.4]
#end

dist = pc.Uniform(0,1)
print dist.mom([0,1,2])
#  [ 1.          0.5         0.33333333]
#end

def mom(self, k):
    return 1./(1+k)
dist.addattr(mom=mom)
#end


def pdf(self, x):
    out = 9/16.*(x+1)*(x<1/3.)
    out += 3/4.*(x>=1/3.)
    return out
Ejemplo n.º 6
0
from pylab import *
import current as pc

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

Q = pc.Iid(pc.Uniform(0,4), 2)
C = pc.Frank(Q, 1.5)
#end

subplot(121)
R = C.sample(1000)
scatter(R[0], R[1], marker="s", color="k", alpha=.7)
xlabel(r"$Q_0$")
ylabel(r"$Q_1$")
xticks(range(5))
yticks(range(5))
axis([0,4,0,4])
title("Scatter")

subplot(122)
s,t = meshgrid(linspace(0,4,100), linspace(0,4,100))
contourf(s,t,C.pdf([s,t]), 30)
xlabel(r"$q_0$")
ylabel(r"$q_1$")
xticks(range(5))
yticks(range(5))
title("Probability Density")

subplots_adjust(bottom=0.12, right=0.85, top=0.9)