The problem I'm having is related to looping a function over a grid of inputs. More specifically, I seem to be unable to create an initial matrix for preallocation such that the estimated output is stored properly. I'll provide a brief description before moving on to the actual code.
The goal is to loop a maximum likelihood function over a grid of three arrays. The underlying maximum likelihood function utilizes simulated annealing to numerically estimate thirteen parameters. This maximum likelihood function utilizes a kalman filter to decompose observables into unobservables; trend and cyclical terms. To overcome the identification issue related to having two error terms, I omit the error term parameters pertaining to the cyclical variables, and impose relative variances in the initial variance bounds restrictions.
Therfore, the goal is to loop the maximum likelihood function with three relative variances; such that all outputs (parameters and their associated likelihoods) are stored after every estimation (for every relative variance).
The idea is to loop the maximum likelihood function over a grid of three arrays. In this case, these are given by [g1, g2, g3]. For simplicity, these are (0.5:1:2.5).
1) The [P] output is a function of simulated annealing ("SIMANN") and a likelihood function ("likelihoodfunction"). The main concern here is not related to the codes within these functions, but to the storing of output values they create.
2) The "SIMANN" function only permits one input variable (theta), which is why I have chosen to loop this process multiple times, rather than modifying the "SIMANN" function directly. This isn't the most kosher way of doing this, but the underlying code in the "SIMANN" function isn't something I want to tinker with.
3) The "P" output array is 1x13, whereas "L" is 1x1.
4) In the segment below, I have tried to modify the answer from one of the threads here. This portion is only for the "L" portion of the problem at hand.
L = zeros(3,3,3)
fidx = zeros(3,3,3,3)
fidx(g1,g2,g3,:) = [g1,g2,g3];
g1 = reshape(fidx(:,:,:,1), , 1);
g2 = reshape(fidx(:,:,:,2), , 1);
g3 = reshape(fidx(:,:,:,3), , 1);
L = L(:);
results = table(g1, g2, g3, :);
To reiterate, the objective is to loop this segment of the code over a grid of three input arrays. The problem I'm having is how to properly define the preallocation matrix for parameters and the likelihood function, such that all estimated parameters and the associated likelihoods are properly aligned.
The code I receive, after producing "P", is as follows:
Index in position 1 is invalid. Array indices must be positive integers or
My problem is related to defining properly the matrix for "P" and "L" such that the loop saves the associated values into a proper matrix.