Menu

Calling from Matlab

SPSens

SPSens includes functions to compile and run sensitivity and simulation algorithms from Matlab using the MEX interface. This can be helpful while initially creating the model as it allows for rapid analysis within Matlab and easy changes. An example file, '

In order to use this, MEX must first be properly configured on the machine. Plenty of documentation to introduce the MEX interface and to assist in its configuration can be found at http://www.mathworks.com/support/tech-notes/1600/1605.html.

Compiling sensitivity and simulation programs

Once MEX is configured properly and SPSens has been unpacked, one can build sensitivity and simulation programs for the problem at the Matlab command interface by taking the following steps:

  1. Create the problem and name it prob_\<probname>.c where \<probname> is whatever file name is desired. Make sure its directory is in the current path (can do this manually by using the command: addpath path_to_problem)

  2. Change working directory to SPSens_path/mex, or alternatively add the full directory path to the Matlab path.

  3. Build the sensitivity analysis program by calling:
    Build_spsmx_sens(probname,optional_argument)
    If successful this creates the function 'spsSens_\<prob_name>' in the current directory.

  4. Build the stochastic simulation programs by calling:
    Build_spsmx_sim(probname,optional_argument)
    If successful this creates the functions 'spsSim_\<prob_name>' and 'spsSP_\<prob_name>' in the current directory.

Notes:

  • If the problem file was not already in your search path or otherwise not recognized, Matlab will prompt you to locate the problem file manually.
  • If you want to name the file something besides what the C source file is named, use the desired name in Build, then search for the C source file manually.
  • If antithetic sampling is desired, then add '-a' as the optional argument following the problem name to each of the Build functions. (note it's not supported for generating sample paths in this release)
  • If you want to build the functions in a different directory, then make sure the SPSens_path/mex directory is added to your path and call Build_... from the directory in which you want the functions built.
  • A utility, setup_spsens_paths.m, was included to add all the paths for SPSens to the Matlab path when called from its default location.

Running stochastic sensitivity analysis

Once it has been built, sensitivity with respect to whichever set of parameters is desired is computed using the 'GetStochSens' function. Statistics of the estimates (point estimates of the sensitivity values and their confidence intervals) can be computed easily with the function 'GetSensitivityResultStats'. See help in matlab for both of these, along with the example file demonstrating use of each of the methods.

Generating a single realization of the process

After building, generate a sample path using the 'GetSamplePath' wrapper function. Check the help and the example file demonstrating proper use of the method.

Running ensemble of stochastic simulations

After building, generate an ensemble of trajectories sampled at a specified vector of times using the 'GetStochSim' function. Statistics of the estimates (point estimates of the expected value at each time point, confidence intervals of the point estimates, estimates of the variance) can be computed easily with the function 'GetSimulationResultStats'. See help in Matlab and the example file demonstrating proper use of these functions.


Related

Wiki: Home

MongoDB Logo MongoDB