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),
#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] #end q = pc.variable() dist = pc.Normal() print pc.E(q, dist) # 0.0 #end
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,
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)
from numpy import * import current as pc function = lambda q: q[0] * e**q[1] + 1 dist = pc.Iid(pc.Normal(), 2) approx = pc.pcm(function, 2, dist, rule="G") print pc.around(approx, 14) # 1.64234906518q0q1+1.64796896005q0+1.0 print pc.E(approx, dist) # 1.0 print pc.Var(approx, dist) # 5.41311214518 #end
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)
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