File: setup_integration_nodes.m

package info (click to toggle)
dynare 6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,648 kB
  • sloc: cpp: 79,109; ansic: 28,917; objc: 12,430; yacc: 4,528; pascal: 1,993; lex: 1,441; sh: 1,129; python: 634; makefile: 626; lisp: 163; xml: 18
file content (39 lines) | stat: -rw-r--r-- 1,939 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function [nodes,weights,nnodes] = setup_integration_nodes(EpOptions,pfm)
if EpOptions.stochastic.order
    % Compute weights and nodes for the stochastic version of the extended path.
    switch EpOptions.stochastic.IntegrationAlgorithm
      case 'Tensor-Gaussian-Quadrature'
        % Get the nodes and weights from a univariate Gauss-Hermite quadrature.
        [nodes0,weights0] = gauss_hermite_weights_and_nodes(EpOptions.stochastic.quadrature.nodes);
        % Replicate the univariate nodes for each innovation and dates, and, if needed, correlate them.
        nodes0 = repmat(nodes0,1,pfm.number_of_shocks*pfm.stochastic_order)*kron(eye(pfm.stochastic_order),pfm.Omega);
        % Put the nodes and weights in cells
        for i=1:pfm.number_of_shocks
            rr(i) = {nodes0(:,i)};
            ww(i) = {weights0};
        end
        % Build the tensorial grid
        nodes = cartesian_product_of_sets(rr{:});
        weights = prod(cartesian_product_of_sets(ww{:}),2);
        nnodes = length(weights);
      case 'Stroud-Cubature-3'
        [nodes,weights] = cubature_with_gaussian_weight(pfm.number_of_shocks*pfm.stochastic_order,3,'Stroud')
        nodes = kron(eye(pfm.stochastic_order),transpose(pfm.Omega))*nodes;
        weights = weights;
        nnodes = length(weights);
      case 'Stroud-Cubature-5'
        [nodes,weights] = cubature_with_gaussian_weight(pfm.number_of_shocks*pfm.stochastic_order,5,'Stroud')
        nodes = kron(eye(pfm.stochastic_order),transpose(pfm.Omega))*nodes;
        weights = weights;
        nnodes = length(weights);
      case 'Unscented'
        p = pfm.number_of_shocks;
        k = 3;%EpOptions.ut.k;
        C = sqrt(pfm.number_of_shocks + k)*pfm.Omega';
        nodes = [zeros(1,p); -C; C];
        weights = [k/(p+k); (1/(2*(p+k)))*ones(2*p,1)];
        nnodes = 2*p+1;
      otherwise
        error('Stochastic extended path:: Unknown integration algorithm!')
    end
end