Polynomial Chaos Expansion

A polynomial chaos expansion is a series expansion of a random variable $X=f(\boldsymbol \xi)$ in the following form: $$\color{blue}{f(\boldsymbol{\xi})}\approx \color{red}{\sum_{\mathbf{j}\in\mathcal{J}}\gamma_{\mathbf{j}} \psi_{\mathbf{j}}(\xi_1,\xi_2,\dots,\xi_n)}.$$ In this expansion, $\mathbf{j}=(j_1,\dots,j_n)^T\in\mathbb{N}^n$ is a multiindex and $\gamma_{\mathbf{j}}$ are scalar coefficients. $\{\xi_i\}_{i=1}^n$ are independent random variables defined on the probability space $(\Omega,\mathcal{F}(\boldsymbol{\xi}),\mathbb{P})$ and $\boldsymbol{\xi}=(\xi_1,\dots,\xi_n)^T$. $\psi_{\mathbf{j}}(\xi_1,\dots,\xi_n)$ is a $n$-variate orthogonal polynomial with the highest degree term being $\xi_1^{j_1}\xi_2^{j_2}\cdots\xi_n^{j_n}$. The polynomials $\{\psi_\mathbf{j}\}_{\mathbf{j}>\mathbf{0}}$ are orthogonal, i.e., $$\langle \psi_\boldsymbol{\alpha},\psi_\boldsymbol{\beta}\rangle:=\mathbb{E}[\psi_\boldsymbol{\alpha}\psi_\boldsymbol{\beta}]=\int \psi_\boldsymbol{\alpha}(\boldsymbol\xi)\psi_\boldsymbol{\beta}(\boldsymbol\xi)p_1(\xi_1)\cdots p_n(\xi_n)\,\text{d}\boldsymbol{\xi}=\delta_{\boldsymbol{\alpha}\boldsymbol{\beta}}$$ where $p_i(\xi_i)$ is the pdf of $\xi_i$.
Function must be a javascript expression in terms of x[0] and x[1].