MCCL Inverse Solutions - VirtualPhotonics/Vts.MonteCarlo GitHub Wiki
Usage Notes:
We currently have code in the MATLAB interop to run inverse problem solutions using perturbation and differential Monte Carlo (pMC/dMC). However, this interop code will not work on Linux or Mac. This prompted us to write code that could perform these inversions using MATLAB/Octave and bash/powershell shell script files. Included in the Linux, Mac and Windows MCCL download zip are the files that show examples of inversions using R(rho) and R(rho,wavelength) measurements without the use of the MATLAB interop code:
- mc_inverse.m (mc_inverse_Win.m for Windows) - this MATLAB/Octave file includes example scripts to:
- Example 1: replicate the MATLAB interop inversion code in vts_mc_demo.m Example 7
- Example 2: R(rho,wavelength) inversion to determine chromophore concentrations
- Example 3: R(rho,wavelength) inversion to determine chromophore concentrations and scatterer coefficients
- get_optical_properties.m - this script calls
- get_mua - obtains mua values for specified wavelengths from a spectral spread sheet sample SpectralDictionary.xlsx taken from the Vts library
- get_musp - obtains mus' values for specified wavelengths using a single power law = A(lambda)^(-b)
- infile_pMC_db_gen_template.txt - this is a template file that is to be "filled in" by running the bash script "sub_ops.sh" (see mc_inverse.m for examples). After being filled out and executed with "mc", it will generate the baseline database for the inversion
- pmc_F_dmc_J_ex1, ex2, ex3 (pmc_Chi2_ex1, ex2, ex3 for fminsearch) - these MATLAB/Octave scripts serve as the forward function in the inversion (for Example 1, 2, 3 respectively) and produce estimates of reflectance using pMC and derivatives of reflectance with respect to mua and mus using dMC. This function is called within lsqcurvefit (or fminsearch). The function "fills in" a post-processing template infile_PP_pMC_est_template.txt with the current iteration estimate of mua and mus and runs MCPP to generate reflectance estimates
- load_for_inv_results.m - this is a subset of load_results_script.m that loads the results for ROfRho, pMCROfRho, dMCdROfRhodMua and dMCdROfRhodMus, the forward reflectance estimates and derivatives
Troubleshooting:
- Make sure that you are running the MATLAB script files from the Monte Carlo zip
- Make sure that the "jsonlab" folder is in the MATLAB/Octave "path"
- sub_ops.sh (for Linux and Mac) - this is a bash shell script that fills in the infile used by the Monte Carlo simulation. Windows adds line endings that are not compatible with Linux. To correct this, please run "dos2unix sub_ops.sh" before running mc_inverse.m.
- replace_string.ps1 (for Windows) - this is a powershell script that fills in the infile used by the Monte Carlo simulation. If you get an error "replace_string.ps1 cannot be loaded because running scripts is disabled on this system" or "ps1 is not digitally signed", open Windows PowerShell as admin, change directory to MATLAB interop folder, and run these two commands; "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned" and "Unblock-File -Path replace_string.ps1".
- On Linux - when running first example error comes to screen "version `GLIBCXX_x.x.xx' not found", add "export LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc++.so.6" to .bashrc and run "source .bashrc".