{"action":"opened","issue":{"url":"https://api.github.com/repos/jonathf/chaospy/issues/38","repository_url":"https://api.github.com/repos/jonathf/chaospy","labels_url":"https://api.github.com/repos/jonathf/chaospy/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/jonathf/chaospy/issues/38/comments","events_url":"https://api.github.com/repos/jonathf/chaospy/issues/38/events","html_url":"https://github.com/jonathf/chaospy/issues/38","id":195794439,"number":38,"title":"Joint distributions with dependencies and numpy.poly1d","user":{"login":"davidovitch","id":2007257,"avatar_url":"https://avatars.githubusercontent.com/u/2007257?v=3","gravatar_id":"","url":"https://api.github.com/users/davidovitch","html_url":"https://github.com/davidovitch","followers_url":"https://api.github.com/users/davidovitch/followers","following_url":"https://api.github.com/users/davidovitch/following{/other_user}","gists_url":"https://api.github.com/users/davidovitch/gists{/gist_id}","starred_url":"https://api.github.com/users/davidovitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidovitch/subscriptions","organizations_url":"https://api.github.com/users/davidovitch/orgs","repos_url":"https://api.github.com/users/davidovitch/repos","events_url":"https://api.github.com/users/davidovitch/events{/privacy}","received_events_url":"https://api.github.com/users/davidovitch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-15T12:33:06Z","updated_at":"2016-12-15T12:33:06Z","closed_at":null,"body":"I am trying to construct a joint distribution in which the second depends on the first. This is also used in the examples created here https://github.com/jp5000/PCE-4-WindEnergy/blob/master/Example/8)_Example.ipynb. I am running \r\n\r\n```python\r\nimport numpy as np\r\nimport chaospy as cp\r\nfrom matplotlib import pyplot as plt\r\n\r\n# manually calculate the what np.poly1d is supposed to do\r\ndef calc_poly(poly, x):\r\n    exp = 0.0\r\n    degree = len(poly)\r\n    for i, coeff in enumerate(poly):\r\n        exp += (coeff*np.power(x, degree-i))\r\n    return exp\r\n\r\ndef p1(x):\r\n    return ( 1. + (1.4)**2./(0.75*x + 3.8)**2.0)**0.5\r\n\r\ndef p2(x):\r\n    return ( 1. + (1.4)**2./(0.75*x + 3.8)**2.0)\r\n\r\n# we have the following dependency\r\ndist1_x_rng = np.arange(0, 30, 1)\r\nmu = p1(dist1_x_rng)\r\nsigma = p2(dist1_x_rng)\r\n\r\n# fit a polynomial to it\r\nmu_pfit = np.poly1d(np.polyfit(dist1_x_rng, mu, 6))\r\nsigma_pfit = np.poly1d(np.polyfit(dist1_x_rng, sigma, 6))\r\n\r\n# is calc_poly doing what it is supposed to do?\r\nassert np.allclose(calc_poly(mu_pfit, dist1_x_rng), mu_pfit(dist1_x_rng))\r\n\r\n#plt.plot(dist1_x_rng, mu)\r\n#plt.plot(dist1_x_rng, calc_poly(mu_pfit, dist1_x_rng))\r\n#assert np.allclose(calc_poly(mu_pfit, dist1_x_rng), mu)\r\n\r\ndist_1 = cp.Normal()\r\n# indicate the dependency using the np.poly1d object\r\ndist_2a = cp.Lognormal(mu=mu_pfit(dist_1), sigma=sigma_pfit(dist_1))\r\n# or using calc_poly\r\ndist_2b = cp.Lognormal(mu=calc_poly(mu_pfit, dist_1), sigma=calc_poly(sigma_pfit, dist_1))\r\n# or using the polynomials directly\r\ndist_2c = cp.Lognormal(mu=p1(dist_1), sigma=p2(dist_1))\r\n\r\n# join the distribution and sample, but this will fail\r\ndist_Q = cp.J(dist_1, dist_2a)\r\nsample_Q_a = dist_Q.sample(size=512, rule='H')\r\n# see below for the lengthy traceback\r\n\r\n# works\r\ndist_Q = cp.J(dist_1, dist_2b)\r\nsample_Q_b = dist_Q.sample(size=512, rule='H')\r\n\r\n# works\r\ndist_Q = cp.J(dist_1, dist_2c)\r\nsample_Q_c = dist_Q.sample(size=512, rule='H')\r\n```\r\n\r\nI think this example worked at some point with Chaospy but I haven't figured out when it broke. I will also add this as a test case in PR #31. I have not figured out yet why it fails with ```numpy.poly1d```, but would like to create an issue for it in case someone knows already what is going on here.\r\n"}}
{"actor":{"display_login":"davidovitch"}}