Comments (8)
I have just confirmed that the problem occurs also for Uniform
distribution.
from chaospy.
It works for me if I use a rv with a mean of 0. I haven't used chaospy much, but generally high-ish order polynomials work better with mean-0, standard-deviation-1 abscissae. If you can afford to, work in such a space, and then translate any results back to the original space as needed by an appropriate (scaling and) shifting.
Unless this capability is supposed to be built-in to chaospy, which would make sense.
from chaospy.
As @tsbertalan said. Try to parameterize the problem in terms of standard distributions when going to higher order.
Polynomial chaos expansions allows you to address the problem trough a proxy variable:
from numpy import std
from chaospy import Normal, generate_quadrature, orth_ttr, fit_quadrature, Std
def f(x):
return x
order = 6
rv = Normal(10, 0.1)
rv_proxy = Normal(0, 1)
data = f(rv.sample(order+1))
nodes, weights = generate_quadrature(order, rv_proxy, rule='G')
P, norms = orth_ttr(order, rv_proxy, normed=False, retall=True)
evals = f(rv.inv(rv_proxy.fwd(nodes[0])))
u_hat = fit_quadrature(P, nodes, weights, evals, norms=norms)
print(Std(u_hat, rv_proxy))
print(std(data))
This approximation works well as long as the mapping between rv
and rv_proxy
is smooth.
from chaospy.
I just want to say for now, thanks for your feedback and ideas. Both suggestions look like exactly what I was looking for. I will leave it open for now at least before I get the time to properly try it all out. Sorry for late responses.
from chaospy.
Right, I finally sat down and tested it out. Briefly, proxy method rocks. I focused on a variance and used the code below. I take that that the evals
in your example simply transform to unit square through forward Rosenblatt and then transform to desired distribution through inverse Rosenblatt.
So clearly this is the property of the method. Is there a place in the literature where this has been described?
def f(x):
return x**3
def direct(rv, order=4):
nodes, weights = generate_quadrature(order, rv, rule='G')
evals = f(nodes[0])
Ps, norms = orth_ttr(order, rv, normed=False, retall=True)
u_hat = fit_quadrature(Ps, nodes, weights, evals, norms=norms)
return Var(u_hat, rv)
def proxy(rv, order=4):
rv_proxy = Normal(0, 1)
nodes, weights = generate_quadrature(order, rv_proxy, rule='G')
evals = f(rv.inv(rv_proxy.fwd(nodes[0])))
Ps, norms = orth_ttr(order, rv_proxy, normed=False, retall=True)
u_hat = fit_quadrature(Ps, nodes, weights, evals, norms=norms)
return Var(u_hat, rv_proxy)
rv = Normal(10, 0.1)
orders = arange(1, 11)
proxy_variance = array([proxy(rv, o) for o in orders])
direct_variance = array([direct(rv, o) for o in orders])
from chaospy.
That is correct, those are Rosenblatt transformations.
Rosenblatt is usually discussed in the context of transforming from and to stochastically independent variables, but the rules are exactly the same applied to achieve stability in higher orders. There should be something more specific to what you are asking out there, but unfortunately I don't remember what they are.
If you want to read up on the transformation itself, then the guys who made the DAKOTA software library discusses the topic here:
https://www.researchgate.net/profile/Michael_Eldred/publication/242068651_Recent_Advances_in_Non-Intrusive_Polynomial_Chaos_and_Stochastic_Collocation_Methods_for_Uncertainty_Analysis_and_Design/links/53d6abb30cf220632f3dc635.pdf
from chaospy.
I consider the issue as resolved.
If you consider that not to be the case, or if there are other problems related to the same issue, feel free to re-open the issue.
from chaospy.
Yes, Jonathan. Thanks a lot for your help here - the discussion was very useful to me. I should closed it before actually.
from chaospy.
Related Issues (20)
- chaospy.approximate_moment(normal, [2]) doesn't run HOT 1
- Divergence for higher orders using Pseudo-spectral projection HOT 3
- Problem Defining dependant random variables with absolute and minimum operators HOT 4
- cp.fit_regression()has no atrribute 'A' HOT 1
- The test chaospy/distributions/sampler/sequences/additive_recursion.py hangs
- sampling for several times or one-shot at one time HOT 1
- Depreciation pkg_resources HOT 1
- Uniform distribution with lower and upper band functions HOT 3
- Transform dependent distribution HOT 1
- Inconsistent behavior under presence of variable with zero-only coefficients HOT 1
- How to speed up Kernel Density Estimation based sampling HOT 1
- .sample() method is much slower for GaussianKDE HOT 1
- Recommendations for Implementing Importance Sampling HOT 1
- Question about obtain the skewness and kurtosis of PCE HOT 1
- Wrong results with Scipy 1.13 HOT 3
- High-Order 1-Dimensional Gaussian Quadrature Bug HOT 2
- Python Importing Fashion Affects the Sampler Output's Shape HOT 1
- Questions about `fit_regression` function HOT 5
- Create orthonormal expansion from glexindex output HOT 10
- chaospy does not support numpy 2.0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chaospy.