chaospy icon indicating copy to clipboard operation
chaospy copied to clipboard

Hi,jonathf!

Open lihy213 opened this issue 2 years ago • 11 comments

I am doing a problem of UQ, using the tensor product expansion method in chaospy, but the function orth_ttr does not seem to have it, and how to substitute the simulated response value into chaospy, and construct the coefficient solution matrix with the sample points? It seems that they need to satisfy a certain corresponding input relationship. I seem to be unable to achieve this when using this method. I have three dimensions of parameters, they were simulated in a black box, then I got the response. How could I solve it? Here are my codes:

c1 = cpy.Uniform(0.006153054, 0.013412845)
c2 = cpy.Uniform(0.714023424, 0.9041208)
c3 = cpy.Uniform(1536.464448, 2072.4)
distribution = cpy.J(c1, c2, c3)
expansion = cpy.generate_expansion(4, distribution)
samples = np.array([[0.00768723, 0.01187867], [0.75419573, 0.8639485], [1649.72095639, 1959.14349161]])   # Here the parameters
evaluations = np.array([[8152.2335, 8635.0539, 8920.6844, 9452.4850],
                         [6595.1225, 6981.8657, 7222.9050, 7645.6002]])       # Here the responses
approx_solver = cpy.fit_regression(expansion, samples, evaluations)
expected = cpy.E(approx_solver, distribution)
deviation = cpy.Std(approx_solver, distribution)

Thanks a lot for your reply!

lihy213 avatar May 07 '22 01:05 lihy213

I am doing a problem of UQ, using the tensor product expansion method in chaospy, but the function orth_ttr does not seem to have it, and how to substitute the simulated response value into chaospy,

You mean somehitng like:

simulated_response = approx_solver(*samples)

and construct the coefficient solution matrix with the sample points?

Coefficient solution matrix? You mean the Fourier coefficients? Like:

approx_solver, coefficients = cpy.fit_regression(expansion, samples, evaluations, retall=True)

It seems that they need to satisfy a certain corresponding input relationship. I seem to be unable to achieve this when using this method. I have three dimensions of parameters, they were simulated in a black box, then I got the response. How could I solve it?

It is hard to tell exactly what you are looking for, so please correct me if I misunderstand.

jonathf avatar May 07 '22 10:05 jonathf

Thanks a lot! I will try it soon! :)

lihy213 avatar May 07 '22 12:05 lihy213

I am doing a problem of UQ, using the tensor product expansion method in chaospy, but the function orth_ttr does not seem to have it, and how to substitute the simulated response value into chaospy,

You mean somehitng like:

simulated_response = approx_solver(*samples)

and construct the coefficient solution matrix with the sample points?

Coefficient solution matrix? You mean the Fourier coefficients? Like:

approx_solver, coefficients = cpy.fit_regression(expansion, samples, evaluations, retall=True)

It seems that they need to satisfy a certain corresponding input relationship. I seem to be unable to achieve this when using this method. I have three dimensions of parameters, they were simulated in a black box, then I got the response. How could I solve it?

It is hard to tell exactly what you are looking for, so please correct me if I misunderstand.

Well, there are 'Total-order' and 'tensor product' expansion. And how can I use them correctly? Something like this:

distribution = cpy.J(cpy.Uniform(0.006153054, 0.013412845), cpy.Uniform(0.714023424, 0.9041208),
                     cpy.Uniform(1536.464448, 2072.4))
abscissas, weights = cpy.generate_quadrature(order=3, dist=distribution, rule="legendre")
polynomials, norms = cpy.expansion.stieltjes(3, distribution, normed=True, retall=True)
proxy_model, coeffs = cpy.fit_quadrature(polynomials, abscissas, weights, evaluations, retall=True)

I mean, the distribution is uniform, three dimensions are included, I will choose Legendre expansion as the basic function. Then 'tensor product' is going to be selected to perform the PCE and quantify the uncertainty of response. How could I reach my goal? Am I right as above? Thanks a lot!

lihy213 avatar May 11 '22 07:05 lihy213

When TTR/Stieltjes used on multivariate expansions, all expansions are constructed using "tensor product". I am not familiar with any other approach.

Total-order typically refers to the truncation scheme for which polynomial to include. As the default is graded reverse lexicographically, you will need to create the expansion with:

polynomials, norms = cpy.generate_expansion(
    order=3, dist=distribution, normed=True, retall=True, cross_truncation=numpy.inf)

The trunction scheme is covered here: https://chaospy.readthedocs.io/en/master/user_guide/polynomial/truncation_scheme.html

jonathf avatar May 11 '22 07:05 jonathf

When the distribution is uniform, the basic function will be Legendre, right? Now I know the basic function and the samples are derived from 'legendre nodes', after that, I can get simulation results, finally I choose 'tensor product' expansion to establish the PCE. How can I make the whole process come true with chaospy codes? Just like what I've mentioned above? Thanks for your patient reply! : )

lihy213 avatar May 11 '22 11:05 lihy213

Legendre is only orthogonal if the distribution is uniform on the interval [-1, 1]. But yes, the difference between Legendre and the orthogonal polynomial is a simple linear mapping, so calling it Legendre isn't entirely off.

Your rule="legendre" is Legendre, and works when the distribution is Uniform. For other distribution, it will differ, as Legendre double as a finite interval general purpose integration. Use rule="gaussian" if you want a more robust approach.

Looks like you already have it all figure out in your first and third posts for point collocation and pseudo-spectral projections respectivly. All the tensor product stuff is handle automatically in Chaospy. I am not sure what more you need.

jonathf avatar May 11 '22 12:05 jonathf

Uha....I mean, the pseudo-spectral projection is a type of discrete expansion, but in my mind, one type of spectral projection tensor product quadrature is my major choice... ): If there is some misunderstanding? But also appreciate it!:)

lihy213 avatar May 11 '22 12:05 lihy213

Spectral projection basically is a re-representing of a problem. It is a question of representation, and not really limited to "descrete expansions". PCE for example is a form of spectral projection.

In practice "pseudo-spectral projection" is a name reserved for building PCE using numerical intergration to estimate Feurier coefficients. No idea why, but many seem to use the term.

jonathf avatar May 11 '22 13:05 jonathf

Fine! I got it! Thanks again from the bottom of my heart! :)

lihy213 avatar May 11 '22 13:05 lihy213

One new question: is there any method to verify the precision of PCE model? And how could I use chaospy to achieve it? Thanks a lot! :)

lihy213 avatar May 20 '22 02:05 lihy213

Depends.

If you know the true analytical answer, then of course. Just compare true values against PCE approximation, like done in the tutorials.

If you are making a toy example, but is complicated enough that there is no true analytical answer, then I usually take the time to make a Monte-Carlo reference with an exagerated amount of data.

If we are talking about models that are costly to evaluate, but have some nice analytical properties that that allows for functional analysis, then there is likely somehting out there likely to give some lower and upper bounds, but that is beyond my experties.

If we are in full black-box mode, I'm afraid you are out of luck as far as I know.

jonathf avatar May 20 '22 13:05 jonathf