divide by actual mus in otRFmus/otWP/otWPTOF in SVMC replay, fix chain rule for mus/musp Jacobians in adjoint mode#263
Open
HirviP wants to merge 1 commit into
Open
divide by actual mus in otRFmus/otWP/otWPTOF in SVMC replay, fix chain rule for mus/musp Jacobians in adjoint mode#263HirviP wants to merge 1 commit into
HirviP wants to merge 1 commit into
Conversation
…h the current scattering coefficient in SVMC mode. Fix the scattering coefficient to be the true physical scattering coefficient, if cfg.unitinmm is not 1 and mus has been scaled (cfg->prop[i].mus *= cfg->unitinmm). NOTE: Currently compilation fails since cfg->unitinmm is undefined on line 2255! Where is it stored – gcfg does not have the field? Otherwise compilation is successful. In addition, fix the inner derivative sign when converting derivatives with respect to the diffusion coefficient (D) to derivatives with respect to the scattering coefficient (mus or musp) using the chain rule in the adjoint mode. In my simulations, this fix matches the signs of the adjoint and replay scattering Jacobians.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Update the code to divide "b"/"wptof" (otWPTOF) counts also with the current scattering coefficient in SVMC mode during ray-tracing in replay. Set weight to zero if mus=0, since scattering events shouldn't happen in theory (and I got one very high value on boundary, which might result from this). Fix the scattering coefficient to be the true physical scattering coefficient for the division, if cfg.unitinmm is not 1 and mus has been scaled previously (cfg->prop[i].mus *= cfg->unitinmm).
NOTE: Currently source code compilation fails since cfg->unitinmm is undefined on line 2255 in mcx_core.cu, where mus-division is performed. I did not find where the unitinmm is stored – gcfg does not have the field – can you help me? Otherwise compilation is successful.
The below figure shows that the voxel-based (A correct, B modified) and SVMC (C; 0.5 shift not fixed yet) "scattering Jacobians" only match if we multiply the voxel-wise scattering coefficients with cfg.unitinmm=0.5 (mus/2, B) before scaling (post-processing in MCX; same optical parameters used in both simulations):
2. Fix the inner derivative sign when converting derivatives with respect to the diffusion coefficient (D) to derivatives with respect to the scattering coefficient (mus or musp) using the chain rule in the adjoint mode, since:
dA/dmus = dA/dD * dD/dmus = J_D * ( - 1/(3*(1-g)*mus^2))
In my simulations with demo_mcx_adjoint_jacobian.m, this fix matched the signs of the adjoint and replay scattering Jacobians (dXdmus and dYdmus; should match up to a constant scaling factor depending on measurement type), as shown in the figure below (modified source code used):
Check List
Before you submit your pull-request, please verify and check all below items
make pretty(requiresastylein the command line) under thesrc/folder and formatted your C/C++/CUDA source codes before every commit; similarly, you should runpython3 -m black *.py(pip install blackfirst) to reformat all modified Python codes, or runmh_style --fix .(pip install miss-hitfirst) at the top-folder to format all MATLAB scripts.doxygenC formatIf your commits included in this PR contain changes that did not follow the above guidelines, you are strongly recommended to create a clean patch using
git rebaseandgit cherry-pickto prevent in-compliant history from appearing in the upstream code.Moreover, you are highly recommended to
mcx/test/testmcx.shscript, following existing examples, to test the newly added feature; or add a MATLAB script undermcxlab/examplesto gives examples of the desired outputsPlease copy/paste the corresponding Issue's URL after the below dash