Code written by Namrata Vaswani
If you use this code, please cite:
N. Vaswani, Particle Filtering for Large Dimensional State Spaces with Multimodal Observation Likelihoods, To Appear in IEEE Trans. Signal Processing
http://www.ece.iastate.edu/~namrata/pfmtpap.pdf

Use as "sim=1; Tset = 20; runsimspfmt": simulates temperature sensor network data for "Tset" time instants and tracks it using PF-EIS,  PF-EIS-MT,  PF-MT, PF-Gordon, PF-Doucet, PF - K dim
Use "sim = 0; runsimspfmt"  to only plot the statistics (RMSE, % of out of track realizations, etc)

IMPORTANT FILES DESCRIBED BELOW
- It will be helpful to go through the paper cited above before trying to understand the code 
- Can delete most of the commented code

gspf.m : separate file to compare our algorithms against GS-PF. 

MAIN FILE: runsimspfmt  (older version main file was runsimsKvary)
- runs "totiter" iterations of simulation plus tracking with all PFs
- In each iteration, 
    temperature sensor network data is generated using gendata2, 
    and then tracked using various choices of "Npf = Nchoice" and "pftype = ['d','e','g','m','c','s']" (choice 'g' for Gordon, 'd' for Doucet, 'e' for PF-EIS, 'm' for PF-MT, 'c' for PF-EIS-MT, 's': PF-Gordon-K dim)
    - For each choice of "Npf", "pftype",  pfeis is called. 
    - pfeis implements the "pftype" type of PF with "Npf" particles
    - simulated data and its MMSE estimates stored into a file
- Rest of the code is for plotting different statistics for comparing performance

pfeis: 
- sets "K", "Km" (or K2) for "pftype" PF
- calls the functions impsample and resample at each t. 

resample: 
- common piece of code for resampling in any of type of PF

impsample: 
- implements importance sampling and weighting steps based on the values of "K", "Km", "pftype"

- if " pftype == 'g' or 's' "
    no mode finding is required, the importance sampling/weighting is just 6-7 lines of code

- else (pftype is 'e' or 'c' or 'm' or 'd') : the following is done for each particle "i"
    - Call getmode : uses fminunc to compute the mode of the conditional posterior (minimizes L = E + D): denoted "mt"
        getmode applies fminunc to the function computeL (which computes L)
            computeL calls computeE to compute E, followed by computing D and then computing L = E + D

    - The covariance of Gaussian approximation is computed: denoted "SigIS"

    - The next few lines of code take care of error conditions in the mode computation 

    - Finally we sample from a Gaussian with mean "mt" and covariance "SigIS" 

- Compute the weights and normalized weights

- Check if sum of weights near zero : then add a constant

- Save the new set of particles and their normalized, unnormalized weights







**************************************************************************
STUFF for OLD VERSION

This will be useful for you when you get to implementing PF-EIS and PF-MT
Main File for comparing PF-MT with PF-EIS PF-Doucet and PF-Gordon: runsimspfmt

Main File for comparing PF-EIS with PF-Doucet and PF-Gordon: runsimsKvary



********************************************************************
EVEN OLDER STUFF
********************************************************************
dat*M10_N40 : uses A_s=1, A_r = 1
pfeis and pfmt almost equally good (pfmt better), pfg fails

for N=20: pfmt works, all others fail