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

Joining input dist and qoi_dist #44

Closed
pvaezi opened this issue Apr 24, 2017 · 6 comments
Closed

Joining input dist and qoi_dist #44

pvaezi opened this issue Apr 24, 2017 · 6 comments

Comments

@pvaezi
Copy link

pvaezi commented Apr 24, 2017

Hi,

I want to make contours of QoI-distribution versus input-distribution after obtaining QoI-distribution using PCM. I am using cp.J(dist, qoi_dist) to join the distributions and make multivariate distribution. However, it seems cp.J does not properly create co-variance matrix between two distributions (I believe qoi_dist should be a dependent distribution with respect to input dist). Is there an easy way to obtain the joined distributions co-variance matrix using U_hat and P?

I have copied the relevant part of my code here:

dist = cp.Lognormal(-0.0408,0.012)
nodes = dist.sample(nosamples,"M")
P = cp.orth_ttr(order, dist)
U_hat = cp.fit_regression(P, nodes, solves, rule="LS")
qoi_dist = cp.QoI_Dist(U_hat, dist)
joined_prob = cp.J(dist, qoi_dist)
x, y = np.meshgrid(x_range, y_range)
prob_pdf = joined_prob.pdf([x, y])
ax.contour(x, y, prob_pdf)

Thanks,
Payam

@jonathf
Copy link
Owner

jonathf commented May 5, 2017

I have looked closer at the code for QoI distribution, and the current implementation uses a sampling scheme to be able to create the distribution. This makes it very difficult to add the proper dependency structure that you are looking for through QoI.

But if all you need is the co-variance between P and U_hat should be straight forward manually for each polynomial in P (requires loops in the multivariate case and/or vector version of U_hat):

cov = cp.E(P*U_hat, dist) - cp.E(P, dist)*cp.E(U_hat, dist)

@jonathf
Copy link
Owner

jonathf commented May 6, 2017

Oh, and you can can add that co-variance dependency structure into the joint. E.g.:

joined_prob = (joined_prob - cp.E(joined_prob)) / cp.Std(joined_prob) * numpy.linalg.cholesky(cov) + cp.E(joined_prob)

@pvaezi
Copy link
Author

pvaezi commented May 7, 2017

Thanks for the instructive comments. I am still a little confused. Now, cov is a covariances vector of P with U_hat. How is it possible to perform Cholesky decomposition on it?

@jonathf
Copy link
Owner

jonathf commented May 8, 2017

cov in the last equation is the full joint co-variance matrix, not the vector as in the first case. In the case where len(P) == 2, give the following matrix:

Cov = [[Var(P[0]), Cov(P[0], P[1]), Cov(P[0], Uhat))],
       [Cov(P[0], P[1]), Var(P[1]), Cov(P[1], Uhat)],
       [Cov(P[0], Uhat), Cov(P[1], Uhat), Var(Uhat)]]

You should easily be able to generalize upon this using a for-loop or two.

@pvaezi
Copy link
Author

pvaezi commented May 8, 2017

Oh, I see! I found this conversation very useful. Thanks for your quick response and follow up!

@jonathf
Copy link
Owner

jonathf commented Oct 22, 2017

I consider this matter as closed.

@jonathf jonathf closed this as completed Oct 22, 2017
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