Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

which is the version python can run best for chaospy. #89

Closed
nguyenhoaiThanhbk2811 opened this issue May 28, 2018 · 1 comment
Closed

Comments

@nguyenhoaiThanhbk2811
Copy link

I have practised run the tutorial but when I run this tutorial then it notified I need to install Odespy package. But Now, I am using the python 3.0 while Odespy only runs on the Python 2.7. So How way to install Odespy for python 3.0 on the Window.

import chaospy as cp
import numpy as np
import odespy

#Intrusive Galerkin method

dist_a = cp.Uniform(0, 0.1)
dist_I = cp.Uniform(8, 10)
dist = cp.J(dist_a, dist_I) # joint multivariate dist

P, norms = cp.orth_ttr(2, dist, retall=True)
variable_a, variable_I = cp.variable(2)

PP = cp.outer(P, P)
E_aPP = cp.E(variable_aPP, dist)
E_IP = cp.E(variable_I
P, dist)

def right_hand_side(c, x): # c' = right_hand_side(c, x)
return -np.dot(E_aPP, c)/norms # -M*c

initial_condition = E_IP/norms
solver = odespy.RK4(right_hand_side)
solver.set_initial_condition(initial_condition)
x = np.linspace(0, 10, 1000)
c = solver.solve(x)[0]
u_hat = cp.dot(P, c)

#Rosenblat transformation using point collocation

def u(x,a, I):
return Inp.exp(-ax)

dist_R = cp.J(cp.Normal(), cp.Normal())
C = [[1, 0.5], [0.5, 1]]
mu = [0, 0]
dist_Q = cp.MvNormal(mu, C)

P = cp.orth_ttr(2, dist_R)
nodes_R = dist_R.sample(2*len(P), "M")
nodes_Q = dist_Q.inv(dist_R.fwd(nodes_R))

x = np.linspace(0, 1, 100)
samples_u = [u(x, *node) for node in nodes_Q.T]
u_hat = cp.fit_regression(P, nodes_R, samples_u)

#Rosenblat transformation using pseudo spectral

def u(x,a, I):
return Inp.exp(-ax)

C = [[1,0.5],[0.5,1]]
mu = np.array([0, 0])
dist_R = cp.J(cp.Normal(), cp.Normal())
dist_Q = cp.MvNormal(mu, C)

P = cp.orth_ttr(2, dist_R)
nodes_R, weights_R = cp.generate_quadrature(3, dist_R)
nodes_Q = dist_Q.inv(dist_R.fwd(nodes_R))
weights_Q = weights_R*dist_Q.pdf(nodes_Q)/dist_R.pdf(nodes_R)

x = np.linspace(0, 1, 100)
samples_u = [u(x, *node) for node in nodes_Q.T]
u_hat = cp.fit_quadrature(P, nodes_R, weights_Q, samples_u)

@jonathf
Copy link
Owner

jonathf commented May 29, 2018

Yeah, examples can be outdated some times.

If you want to run this example, I would recommend using the fork introduced here:
hplgit/odespy#10

clone https://github.com/phn/odespy
cd odespy
git checkout py36

Then install as normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants