Skip to content

Commit

Permalink
Memory optimization
Browse files Browse the repository at this point in the history
and Windows 64 b deployement preparation
  • Loading branch information
chrono35 committed Dec 16, 2016
1 parent c923680 commit 9f8ebac
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 289 deletions.
Binary file removed deploy/windows/additionnal_files/Qt5Core.dll
Binary file not shown.
Binary file removed deploy/windows/additionnal_files/Qt5Gui.dll
Binary file not shown.
Binary file removed deploy/windows/additionnal_files/Qt5Svg.dll
Binary file not shown.
Binary file removed deploy/windows/additionnal_files/Qt5Widgets.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed deploy/windows/additionnal_files/libfftw3f-3.dll
Binary file not shown.
Binary file removed deploy/windows/additionnal_files/libgcc_s_dw2-1.dll
Binary file not shown.
Binary file removed deploy/windows/additionnal_files/libstdc++-6.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
85 changes: 35 additions & 50 deletions src/mcmc/MCMCLoopMain.cpp
Expand Up @@ -450,64 +450,57 @@ void MCMCLoopMain::update()

//--------------------- Update Event -----------------------------------------

// for (Event* event : mModel->mEvents) {
for (QList<Event*>::iterator event = mModel->mEvents.begin(); event!= mModel->mEvents.end(); ++event) {

// for ( Date& date : event->mDates ) {
//for ( auto& date : event->mDates ) {
for (QList<Date>::iterator date = (*event)->mDates.begin(); date!= (*event)->mDates.end(); ++date) {
date->updateDelta(*event);
date->updateTheta(*event);
date->updateSigma(*event);
date->updateWiggle();
for (auto&& event : mModel->mEvents) {
for ( auto&& date : event->mDates ) {
date.updateDelta(event);
date.updateTheta(event);
date.updateSigma(event);
date.updateWiggle();

if (doMemo) {
date->mTheta.memo();
date->mSigma.memo();
date->mWiggle.memo();
date.mTheta.memo();
date.mSigma.memo();
date.mWiggle.memo();

date->mTheta.saveCurrentAcceptRate();
date->mSigma.saveCurrentAcceptRate();
}
date.mTheta.saveCurrentAcceptRate();
date.mSigma.saveCurrentAcceptRate();
}

}
//--------------------- Update Events -----------------------------------------
#ifdef TEST
// event->mTheta.mX = 0.;
#else
(*event)->updateTheta(t_min,t_max);
event->updateTheta(t_min,t_max);
#endif
if (doMemo) {
(*event)->mTheta.memo();
(*event)->mTheta.saveCurrentAcceptRate();
event->mTheta.memo();
event->mTheta.saveCurrentAcceptRate();
}

//--------------------- Update Phases -set mAlpha and mBeta they coud be used by the Event in the other Phase ----------------------------------------

// for (auto phInEv : (*event)->mPhases)
for (QList<Phase*>::iterator phInEv = (*event)->mPhases.begin(); phInEv!= (*event)->mPhases.end(); ++phInEv)
(*phInEv)->updateAll(t_min, t_max);

for (auto&& phInEv : event->mPhases)
phInEv->updateAll(t_min, t_max);
}


//--------------------- Memo Phases -----------------------------------------
if (doMemo) {
//for (auto ph : mModel->mPhases)
for (QList<Phase*>::iterator ph = mModel->mPhases.begin(); ph!= mModel->mPhases.end(); ++ph)
(*ph)->memoAll();
for (auto&& ph : mModel->mPhases)
ph->memoAll();
}

//--------------------- Update Phases constraints -----------------------------------------
// for (auto phConst : mModel->mPhaseConstraints )
for (QList<PhaseConstraint*>::iterator phConst = mModel->mPhaseConstraints.begin(); phConst!= mModel->mPhaseConstraints.end(); ++phConst)
(*phConst)->updateGamma();
for (auto&& phConst : mModel->mPhaseConstraints )
phConst->updateGamma();

}

bool MCMCLoopMain::adapt()
{
ChainSpecs& chain = mChains[mChainIndex];
// QList<Event*>& events = mModel->mEvents;

const double taux_min = 41.; // taux_min minimal rate of acceptation=42
const double taux_max = 47.; // taux_max maximal rate of acceptation=46
Expand All @@ -518,47 +511,39 @@ bool MCMCLoopMain::adapt()

double delta = (chain.mBatchIndex < 10000) ? 0.01 : (1. / sqrt(chain.mBatchIndex));

//for (int i=0; i<events.size(); ++i) {
// // Event* event = events[i];
for (QList<Event*>::iterator event = mModel->mEvents.begin(); event!= mModel->mEvents.end(); ++event) {

for (auto&& event : mModel->mEvents ) {

// for (int j=0; j<event->mDates.size(); ++j) {
// Date& date = event->mDates[j];
for (QList<Date>::iterator date = (*event)->mDates.begin(); date!= (*event)->mDates.end(); ++date) {

for (auto&& date : event->mDates) {

//--------------------- Adapt Sigma MH de Theta i -----------------------------------------

if (date->mMethod == Date::eMHSymGaussAdapt) {
const double taux = 100. * date->mTheta.getCurrentAcceptRate();
if (date.mMethod == Date::eMHSymGaussAdapt) {
const double taux = 100. * date.mTheta.getCurrentAcceptRate();
if (taux <= taux_min || taux >= taux_max) {
allOK = false;
double sign = (taux <= taux_min) ? -1. : 1.;
date->mTheta.mSigmaMH *= pow(10., sign * delta);
const double sign = (taux <= taux_min) ? -1. : 1.;
date.mTheta.mSigmaMH *= pow(10., sign * delta);
}
}

//--------------------- Adapt Sigma MH de Sigma i -----------------------------------------

const double taux = 100. * date->mSigma.getCurrentAcceptRate();
const double taux = 100. * date.mSigma.getCurrentAcceptRate();
if (taux <= taux_min || taux >= taux_max) {
allOK = false;
double sign = (taux <= taux_min) ? -1. : 1.;
date->mSigma.mSigmaMH *= pow(10., sign * delta);
const double sign = (taux <= taux_min) ? -1. : 1.;
date.mSigma.mSigmaMH *= pow(10., sign * delta);
}
}

//--------------------- Adapt Sigma MH de Theta f -----------------------------------------

if (((*event)->mType != Event::eKnown) && ( (*event)->mMethod == Event::eMHAdaptGauss) ) {
const double taux = 100. * (*event)->mTheta.getCurrentAcceptRate();
// qDebug()<<"MCMCLoopMain adapt"<< event->mTheta.mSigmaMH;
if ((event->mType != Event::eKnown) && ( event->mMethod == Event::eMHAdaptGauss) ) {
const double taux = 100. * event->mTheta.getCurrentAcceptRate();
if (taux <= taux_min || taux >= taux_max) {
allOK = false;
double sign = (taux <= taux_min) ? -1. : 1.;
(*event)->mTheta.mSigmaMH *= pow(10., sign * delta);
// qDebug()<<"MCMCLoopMain adapt"<< event->mTheta.mSigmaMH<<" delta="<<delta;
const double sign = (taux <= taux_min) ? -1. : 1.;
event->mTheta.mSigmaMH *= pow(10., sign * delta);
}
}
}
Expand Down
44 changes: 3 additions & 41 deletions src/mcmc/MetropolisVariable.cpp
Expand Up @@ -72,46 +72,7 @@ MetropolisVariable::MetropolisVariable (const MetropolisVariable& origin)

}

/** Move constructor */
MetropolisVariable::MetropolisVariable (MetropolisVariable&& origin) noexcept /* noexcept needed to enable optimizations in containers */
{
//MetropolisVariable(origin);
mX = origin.mX;
mRawTrace = new QVector<double>(origin.mRawTrace->size());
std::copy(origin.mRawTrace->begin(),origin.mRawTrace->end(),mRawTrace->begin());

mFormatedTrace= new QVector<double>(origin.mFormatedTrace->size());
std::copy(origin.mFormatedTrace->begin(),origin.mFormatedTrace->end(),mFormatedTrace->begin());

mSupport = origin.mSupport;
mFormat = origin.mFormat;

mHisto = origin.mHisto;
mChainsHistos = origin.mChainsHistos;

mCorrelations = origin.mCorrelations;

mHPD = origin.mHPD;
mCredibility = origin.mCredibility;

mExactCredibilityThreshold = origin.mExactCredibilityThreshold;

mResults = origin.mResults;
mChainsResults = origin.mChainsResults;

mfftLenUsed = origin.mBandwidthUsed;
mBandwidthUsed = origin.mBandwidthUsed;
mThresholdUsed = origin.mThresholdUsed;

mtminUsed = origin.mtminUsed;
mtmaxUsed = origin.mtmaxUsed;

QObject::connect(this, &MetropolisVariable::formatChanged, this, &MetropolisVariable::updateFormatedTrace);

//origin.reset();
QObject::disconnect(&origin, &MetropolisVariable::formatChanged, &origin, &MetropolisVariable::updateFormatedTrace);
origin.~MetropolisVariable();
}


/** Destructor */
Expand Down Expand Up @@ -777,11 +738,12 @@ QDataStream &operator<<( QDataStream &stream, const MetropolisVariable &data )
break;
};


stream << data.mRawTrace->size();
for(QVector<double>::const_iterator v = data.mRawTrace->cbegin(); v != data.mRawTrace->cend(); ++v)
// for (auto& v : data.mRawTrace )
stream << *v;

qDebug()<<"&operator<<( QDataStream &stream, const MetropolisVariable &data )"<<data.mRawTrace->size();
// qDebug()<<"&operator<<( QDataStream &stream, const MetropolisVariable &data )"<<data.mRawTrace->size();

// *out << this->mFormatedTrace; // useless

Expand Down
2 changes: 1 addition & 1 deletion src/mcmc/MetropolisVariable.h
Expand Up @@ -20,7 +20,7 @@ class MetropolisVariable: public QObject
public:
MetropolisVariable(QObject *parent = nullptr);
MetropolisVariable (const MetropolisVariable& origin);
MetropolisVariable (MetropolisVariable&& origin) noexcept;
// MetropolisVariable (MetropolisVariable&& origin) noexcept;
virtual ~MetropolisVariable();
MetropolisVariable& operator=(const MetropolisVariable & origin);
// MetropolisVariable& operator=(MetropolisVariable && origin);
Expand Down
2 changes: 1 addition & 1 deletion src/model/Event.cpp
Expand Up @@ -89,7 +89,7 @@ void Event::copyFrom(const Event& event)

Event::~Event()
{
for (Date date : mDates) {
for (auto&& date : mDates) {
date.mTheta.reset();
date.mSigma.reset();
date.mWiggle.reset();
Expand Down

0 comments on commit 9f8ebac

Please sign in to comment.