Fix PLNnetwork crash issues from glasso - #176
Open
rfriedman22 wants to merge 3 commits into
Open
rfriedman22 wants to merge 3 commits into
rfriedman22 wants to merge 3 commits into
Conversation
…e entire loop in tryCatch, rather than each post-treatment
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.
The problem
Short version
When some sparsity parameters are too small,
PLNnetwork()crashes completely and returns nothing. It can take quite a while to reach the crash point and there is not a straightforward way to select sparsities or themin_ratioto avoid this issue. All that you get back is an error message like the following:Similarly, even if the
PLNnetworkfamilyfits successfully, the same issue can occur when runningstability_selection(), which gives a slightly different error:Long version
When the sparsity for a
PLNnetworkfitis sufficiently small,glassoFastdiverges on the first iteration of VEM and returnsNAs. This causes aPLNnetworkfitto break out of the loop beforeOmegais set:This doesn't stop
myPLN$optimize()from running for the rest of thePLNnetworkfamily. However, it fails during post-treatments because eachPLNnetworkfitinherits its post-treatment method fromPLNfit, which errors at the following line becauseOmegaisNULL:This causes the entire call to
PLNnetworkto crash without returning anything, even if the rest of the network family is fine.This issue can also come up when running
myPLN$stability_selection(), even if it does not cause an issue when fitting thePLNnetworkfamilyon the full data. Here, the error is caused when calculating the stability across samples. Specifically,as.matrix(model$latent_network("support"))errors because the latent network isNULLand thus cannot be converted to a matrix.The solution
I decided to modify the
PLNfamily$postTreatment()method so that the call to each model's post-treatment is wrapped in atryCatch. If it catches an error for modeli,PLNfamily$postTreatment()emits a warning and then truncates the family to only include models1toi - 1.Then, I extended the
postTreatment()method toPLNnetworkfamilyso that after calling the super-method, it also truncates the list of penalties accordingly.For the
stability_selection()inPLNnetworkfamilyandZIPLNnetworkfamily, ifOmegaisNULLon a subsample, then I interpret the entire network to be unstable at that sparsity, so I return a matrix of zeros.I'm open to other solutions -- what matters to me is that I am able to run
PLNnetwork()andstability_selection()without a complete crash midway through the grid of sparsities.Validation
I reinstalled a local build of the package and was able to call
PLNnetwork()with the exact same data and parameters and get a result where it was previously crashing. I confirmed that thePLNnetworkfamilyis correctly truncated and did not see other errors when Iprinted it. I was also able to callPLNnetwork()on a second dataset where I only had an issue withstability_selection()(and not fitting on the whole data) and was able to get a result when it was previously crashing.I don't run
PLNPCA()so I haven't checked or modifiedPLNPCAfamilywhich also inherits fromPLNfamily.