Skip to content

Commit

Permalink
Cleaned the code. Refs #7847.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Sep 11, 2013
1 parent 23f2e64 commit a6368a3
Showing 1 changed file with 0 additions and 152 deletions.
152 changes: 0 additions & 152 deletions Code/Mantid/Framework/CurveFitting/src/LeBailFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,159 +1515,7 @@ namespace CurveFitting
" unphyiscal parameters values.");
}

#if 0
// Set starting parameters
currR = startR;
m_bestRwp = currR.Rwp + 0.001;
m_bestRp = currR.Rp + 0.001;
bookKeepBestMCResult(parammap, vecBkgd, currR, 0);

g_log.notice() << "[MC-Start] Random-walk Starting Rwp = " << currR.Rwp
<< ", Rp = " << currR.Rp << "\n";

// Random walk loops
// generate some MC trace structure
vector<double> vecIndex(maxcycles+1);
vector<Rfactor> vecR(maxcycles+1);
size_t numinvalidmoves = 0;
size_t numacceptance = 0;
bool prevcyclebetterR = true;

// Annealing record
int numRecentAcceptance = 0;
int numRecentSteps = 0;

// Loop start
srand(randomseed);

for (size_t icycle = 1; icycle <= maxcycles; ++icycle)
{
// Refine parameters (for all parameters in turn) to data with background removed
for (map<int, vector<string> >::iterator giter = m_MCGroups.begin(); giter != m_MCGroups.end(); ++giter)
{
// Propose new value for ONE AND ONLY ONE Monte Carlo parameter group
/*
int igroup = giter->first; // group id
g_log.debug() << "BigTrouble: Group " << igroup << "\n";
*/
bool hasnewvalues = proposeNewValues(giter->second, currR, parammap, newparammap,
prevcyclebetterR);

if (!hasnewvalues)
{
// No parameter to have value updated in this MC group. Skip evaluation of LeBail function.
continue;
}

// Evaluate LeBail function
map<string, double> newpardblmap = convertToDoubleMap(newparammap);
m_lebailFunction->setProfileParameterValues(newpardblmap);
bool validparams = calculateDiffractionPattern(vecX, vecPurePeak, false, false, vecBkgd,
purepeakvalues, newR);
g_log.debug() << "[Calculation] Rwp = " << newR.Rwp << ", Rp = " << newR.Rp << ".\n";

// Determine whether to take the change or not
bool acceptchange;
if (!validparams)
{
++ numinvalidmoves;
acceptchange = false;
prevcyclebetterR = false;
}
else
{
acceptchange = acceptOrDeny(currR, newR);

if (newR.Rwp < currR.Rwp)
prevcyclebetterR = true;
else
prevcyclebetterR = false;
}

g_log.debug() << "[DBx317] Step " << icycle << ": New Rwp = " << setprecision(10)
<< newR.Rwp << ", Rp = " << setprecision(5) << newR.Rp
<< "; Accepted = " << acceptchange << "; Proposed parameters valid ="
<< validparams << "\n";

// Apply change and book keeping
if (acceptchange)
{
// Apply the change to current
applyParameterValues(newparammap, parammap);
currR = newR;

// All tim ebest
// FIXME - [RPRWP] Use Rp now
if (currR.Rwp < m_bestRwp)
{
// Book keep the best
bookKeepBestMCResult(parammap, vecBkgd, currR, icycle);
}
// FIXME - After determining to use Rp or Rwp, this should be got into bookKeepBestMCResult
if (currR.Rp < m_bestRp)
m_bestRp = currR.Rp;
if (currR.Rwp < m_bestRwp)
m_bestRwp = currR.Rwp;

// Statistic
++ numacceptance;
++ numRecentAcceptance;
}
++ numRecentSteps;

// e) Annealing
if (m_useAnnealing)
{
// FIXME : Here are some magic numbers
if (numRecentSteps == 10)
{
// i. Change temperature
if (numRecentAcceptance <= 2)
{
m_Temperature *= 2.0;
}
else if (numRecentAcceptance >= 8)
{
m_Temperature /= 2.0;
}
// ii Reset counters
numRecentAcceptance = 0;
numRecentSteps = 0;
}
}

// e) Debug output
// exportDomainValueToFile(domain, values, "mc_step0_group0.dat");
} // END FOR Group

// v. Improve the background
// FIXME - [RPRWP] Use Rp now
if (currR.Rwp < m_bestRwp)
{
// FIXME - Fit background is disabled at this moment
// fitBackground(m_wsIndex, domainB, valuesB, background);
}

// vi. Record some information
vecIndex[icycle] = static_cast<double>(icycle);
if (currR.Rwp < 1.0E5)
vecR[icycle] = currR;
else
{
Rfactor dum(-1, -1);
vecR[icycle] = dum;
}

// vii. progress
if (icycle%10 == 0)
progress(double(icycle)/double(maxcycles));

} // ENDFOR MC Cycles

progress(1.0);
#else
doMarkovChain(parammap, vecX, vecPurePeak, vecBkgd, maxcycles, startR, randomseed);
#endif

// 5. Sum up: retrieve the best result from class variable: m_bestParameters
Rfactor finalR(-DBL_MAX, -DBL_MAX);
Expand Down

0 comments on commit a6368a3

Please sign in to comment.