-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adaptive MCMC in the refactor! #79
Conversation
…into feature_adaption_update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this
covariance/covarianceBase.cpp
Outdated
// HW : Here be adaption | ||
void covarianceBase::initialiseAdaption(manager* fitMan){ | ||
/* | ||
HW: Idea is that adaption can simply read the YAML config | ||
Options : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you pass const YAML::Node& Adapt
isntead of fitMan.
Seem cleaner
covariance/covarianceBase.cpp
Outdated
} | ||
|
||
// Finally, we accept that we want to read the matrix from a file! | ||
|
||
setThrowMatrixFromFile(fitMan->raw()["AdaptionOptions"]["Covariance"][matrixName_str]["ExternalMatrixFileName"].as<std::string>(), | ||
fitMan->raw()["AdaptionOptions"]["Covariance"][matrixName_str]["ExternalMatrixName"].as<std::string>(), | ||
fitMan->raw()["AdaptionOptions"]["Covariance"][matrixName_str]["ExternalMeansName"].as<std::string>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some prinout wiht basic info about adaptive settings? Additional Verbose is always helpfull
covariance/covarianceBase.cpp
Outdated
start_adaptive_throw = fitMan->raw()["AdaptionOptions"]["Settings"]["AdaptionStartThrow"].as<int>(); | ||
start_adaptive_update = fitMan->raw()["AdaptionOptions"]["Settings"]["AdaptionStartUpdate"].as<int>(); | ||
end_adaptive_update = fitMan->raw()["AdaptionOptions"]["Settings"]["AdaptionEndUpdate"].as<int>(); | ||
adaptive_update_step = fitMan->raw()["AdaptionOptions"]["Settings"]["AdaptionUpdateStep"].as<int>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use GetFromManager
function to set default values and avoid crushes due to bad yaml?
covariance/covarianceBase.h
Outdated
// Indices for block-matrix adaption | ||
std::vector<int> adapt_block_matrix_indices; | ||
// Size of blocks for adaption | ||
std::vector<int> adapt_block_sizes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicky but if you replace // with /// above variable then this is recongised by Doxygen. Would be nice to have this in doxy docueamtnion
covariance/covarianceBase.cpp
Outdated
adaptiveCovariance = new TMatrixDSym(size); | ||
adaptiveCovariance->Zero(); | ||
par_means = std::vector<double>(size, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I just noticed this but adaptiveCovariance is not being destroyed in destructor
covariance/covarianceBase.cpp
Outdated
if(block_lb>getNpars() || block_ub>getNpars()){ | ||
MACH3LOG_ERROR("Cannot set matrix block with edges {}, {} for matrix of size {}", | ||
block_lb, block_ub, getNpars()); | ||
throw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you replace throw
with
throw MaCh3Exception(__FILE__ , __LINE__ );
outFile->cd(); | ||
adaptiveCovariance->Write(systematicName+"_postfit_matrix"); | ||
outMeanVec->Write(systematicName+"_mean_vec"); | ||
outFile->Close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would delete outMeanVec just in case. i don't trust ROOT
void covarianceBase::setThrowMatrixFromFile(std::string matrix_file_name, std::string matrix_name, std::string means_name){ | ||
// Lets you set the throw matrix externally | ||
// Open file | ||
std::unique_ptr<TFile>matrix_file(new TFile(matrix_file_name.c_str())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG more smart poiinters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SMART POINTERS 4 LIFE
covariance/covarianceBase.h
Outdated
// When do we start throwing? | ||
int start_adaptive_throw; | ||
//Thresholds for when to turn on/off updating adaptive MCMC | ||
int start_adaptive_update; | ||
// When do we stop update the adaptive matrix? | ||
int end_adaptive_update; | ||
// Steps between changing throw matrix | ||
int adaptive_update_step; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder wheter it make sesne to make small adaptation struct. Might be cleaner way to separate adaptive way.
Also if most of adaptive things are in struct then it is easier to move stuff from cov to Actual MCMC algorithm. Not that it will happen soon.
Up to you
Pull request description:
Ports adaptive MCMC to the MaCh3 refactor.
Changes or fixes:
Examples:
Fit performed on JUST parameter priors
test_t2k_outputfile_not_delayed_fixdcp_python.pdf_posteriors.pdf