In order to use the well-known unconstrained optimization routine fminunc from the Optimization toolbox for posterior mode estimation in YADA, you need to edit certain files according to file-change information specified in a set of diff-files that can be downloaded from the YADA website. Which files you need to edit depends on the matlab version you have.
The reason why you can't use fminunc directly for estimating the posterior mode is that additional output from these routines is required in YADA. In addition, the changes allow for the use of a progress dialog or a wait dialog, where the user can optionally cancel the optimization run.
The zip-file that archives the diff-files has the same directory structure as the finished files should have within the YADA directory structure. Moreover, the filename of each diff-file is identical to the corresponding m-file in the optimization toolbox. The number of files that need to be changed is limited.
If you have a version 5.x of Matlab, the relevant diff-files are found in the sub-directory matlab5 once you have unzipped the archive. Similarly, if you have version 7 of Matlab, you should look in the matlab7 sub-directory, while for version 7.5 of Matlab, the sub-directory is named matlab75. For other versions of Matlab, it is suggested that you make use of the files relevant to the version "closest" to the one you have. For example, if you have version 7.2 of Matlab you may first look at the files for version 7. If you have version 7.3 or 7.4, you may still turn to the version 7 files as an option to the files in the matlab75 directory.
It is more difficult to provide a recommendation if you have Matlab 6.x. In this case, you should probably first consider the version 7 files. In particular, you should check if the version you have has a directory called optimlib below the shared directory. If so, then the files in the matlab7 directory are probably closer to those you have than those in the directory matlab5. Please also note that the Optimization toolbox has version numbers of its own and the above version numbers are not those for this toolbox.
Example
This example shows how you can make use of the data in the diff-files. In the matlab7 sub-directory you'll find a file called lineSeach.diff that can be applied to the lineSearch.m file from the Optimization toolbox.
1. Copy lineSearch.m to the directory where lineSearch.diff is located and rename it YADAlineSearch7.m. Make sure the original lineSearch.m file remains where it was.
2. Open lineSearch.diff in a text editor such as Notepad or the matlab editor.
3. Lines 2 and 3 in lineSearch.m are given by:
lineSearch(funfcn,xInitial,xRows,xCols,numberOfVariables, ...
dir,fInitial,fPrimeInitial,initialStepLength,rho,sigma, ...
Replace these lines with:
YADAlineSearch7(funfcn,xInitial,xRows,xCols,numberOfVariables, ...
direction,fInitial,fPrimeInitial,initialStepLength,rho,sigma, ...
The differences have been marked in red above. Above the latter two lines you'll find the code 2,3c2,3 in the diff-file. The numbers before the c refers to the range of line number in the changed file (YADAlineSearch7.m), while those after the c refers to range of line numbers in the original file (lineSearch.m). The character c means change.
If you have a Matlab version between 7 and 7.5, it's possible that the line numbers don't match exactly with those given in the diff-files. In that case, it is recommended that you search for the expression to replace using the search function in your text editor.
In some cases you'll find line number code that has the character d instead of c. This means a difference between the files. For instance, in the file fminunc.diff you find the code:
157,160d156
< %
< % force verbosity to 0
< %
< verbosity = 0;
This means that in the file YADAfminunc7.m you should add 4 lines of text after line 156. Namely, the following lines should be inserted:
%
% force verbosity to 0
%
verbosity = 0;
Hence, you should not delete any text in this case.
If you choose to setup the matlab5 directory for fminunc in YADA, you need to create 8 files. For the matlab7 and matlab75 cases you need to create 3 files in that directory. Below it there should be a directory optimlib, which should hold 6 files. One of these is a p-file called constrsh.p that needn't be edited, but whose filename should be changed to YADAconstrsh.p.
Page url: http://www.texlips.net/yada/help/index.html?how_can_i_use_matlabs_fminunc_.htm