1function [nodes,weights,nnodes] = setup_integration_nodes(EpOptions,pfm)
2if EpOptions.stochastic.order
3    % Compute weights and nodes for the stochastic version of the extended path.
4    switch EpOptions.stochastic.IntegrationAlgorithm
5      case 'Tensor-Gaussian-Quadrature'
6        % Get the nodes and weights from a univariate Gauss-Hermite quadrature.
7        [nodes0,weights0] = gauss_hermite_weights_and_nodes(EpOptions.stochastic.quadrature.nodes);
8        % Replicate the univariate nodes for each innovation and dates, and, if needed, correlate them.
9        nodes0 = repmat(nodes0,1,pfm.number_of_shocks*pfm.stochastic_order)*kron(eye(pfm.stochastic_order),pfm.Omega);
10        % Put the nodes and weights in cells
11        for i=1:pfm.number_of_shocks
12            rr(i) = {nodes0(:,i)};
13            ww(i) = {weights0};
14        end
15        % Build the tensorial grid
16        nodes = cartesian_product_of_sets(rr{:});
17        weights = prod(cartesian_product_of_sets(ww{:}),2);
18        nnodes = length(weights);
19      case 'Stroud-Cubature-3'
20        [nodes,weights] = cubature_with_gaussian_weight(pfm.number_of_shocks*pfm.stochastic_order,3,'Stroud')
21        nodes = kron(eye(pfm.stochastic_order),transpose(pfm.Omega))*nodes;
22        weights = weights;
23        nnodes = length(weights);
24      case 'Stroud-Cubature-5'
25        [nodes,weights] = cubature_with_gaussian_weight(pfm.number_of_shocks*pfm.stochastic_order,5,'Stroud')
26        nodes = kron(eye(pfm.stochastic_order),transpose(pfm.Omega))*nodes;
27        weights = weights;
28        nnodes = length(weights);
29      case 'Unscented'
30        p = pfm.number_of_shocks;
31        k = 3;%EpOptions.ut.k;
32        C = sqrt(pfm.number_of_shocks + k)*pfm.Omega';
33        nodes = [zeros(1,p); -C; C];
34        weights = [k/(p+k); (1/(2*(p+k)))*ones(2*p,1)];
35        nnodes = 2*p+1;
36      otherwise
37        error('Stochastic extended path:: Unknown integration algorithm!')
38    end
39end
40