hslt: new mutator interface with last succeeded mutation record.

metadata
johannes hanika 2014-11-03 17:52:09 +01:00 committed by Wenzel Jakob
parent ef48c84915
commit d9d567bc42
13 changed files with 23 additions and 17 deletions

View File

@ -64,7 +64,7 @@ public:
EMutationType getType() const; EMutationType getType() const;
Float suitability(const Path &path) const; Float suitability(const Path &path) const;
bool sampleMutation(Path &source, Path &proposal, MutationRecord &muRec); bool sampleMutation(Path &source, Path &proposal, MutationRecord &muRec, const MutationRecord& sourceMuRec);
Float Q(const Path &source, const Path &proposal, Float Q(const Path &source, const Path &proposal,
const MutationRecord &muRec) const; const MutationRecord &muRec) const;
void accept(const MutationRecord &muRec); void accept(const MutationRecord &muRec);

View File

@ -63,7 +63,7 @@ public:
EMutationType getType() const; EMutationType getType() const;
Float suitability(const Path &path) const; Float suitability(const Path &path) const;
bool sampleMutation(Path &source, Path &proposal, bool sampleMutation(Path &source, Path &proposal,
MutationRecord &muRec); MutationRecord &muRec, const MutationRecord& sourceMuRec);
Float Q(const Path &source, const Path &proposal, Float Q(const Path &source, const Path &proposal,
const MutationRecord &muRec) const; const MutationRecord &muRec) const;
void accept(const MutationRecord &muRec); void accept(const MutationRecord &muRec);

View File

@ -63,7 +63,7 @@ public:
EMutationType getType() const; EMutationType getType() const;
Float suitability(const Path &path) const; Float suitability(const Path &path) const;
bool sampleMutation(Path &source, Path &proposal, bool sampleMutation(Path &source, Path &proposal,
MutationRecord &muRec); MutationRecord &muRec, const MutationRecord& sourceMuRec);
Float Q(const Path &source, const Path &proposal, Float Q(const Path &source, const Path &proposal,
const MutationRecord &muRec) const; const MutationRecord &muRec) const;
void accept(const MutationRecord &muRec); void accept(const MutationRecord &muRec);

View File

@ -61,7 +61,7 @@ public:
EMutationType getType() const; EMutationType getType() const;
Float suitability(const Path &path) const; Float suitability(const Path &path) const;
bool sampleMutation(Path &source, Path &proposal, bool sampleMutation(Path &source, Path &proposal,
MutationRecord &muRec); MutationRecord &muRec, const MutationRecord& sourceMuRec);
Float Q(const Path &source, const Path &proposal, Float Q(const Path &source, const Path &proposal,
const MutationRecord &muRec) const; const MutationRecord &muRec) const;
void accept(const MutationRecord &muRec); void accept(const MutationRecord &muRec);

View File

@ -63,7 +63,7 @@ public:
EMutationType getType() const; EMutationType getType() const;
Float suitability(const Path &path) const; Float suitability(const Path &path) const;
bool sampleMutation(Path &source, Path &proposal, bool sampleMutation(Path &source, Path &proposal,
MutationRecord &muRec); MutationRecord &muRec, const MutationRecord& sourceMuRec);
Float Q(const Path &source, const Path &proposal, Float Q(const Path &source, const Path &proposal,
const MutationRecord &muRec) const; const MutationRecord &muRec) const;
void accept(const MutationRecord &muRec); void accept(const MutationRecord &muRec);

View File

@ -64,13 +64,17 @@ public:
* \param muRec * \param muRec
* Data record that describes the sampled mutation strategy * Data record that describes the sampled mutation strategy
* *
* \param sourceMuRec
* Data record that describes the last successful mutation strategy
* (for the source path)
*
* \return \a true upon success. When the sampling step is * \return \a true upon success. When the sampling step is
* unsuccessful (this could happen due to various * unsuccessful (this could happen due to various
* reasons), the function returns <tt>false</tt>. * reasons), the function returns <tt>false</tt>.
*/ */
virtual bool sampleMutation(Path &source, Path &proposal, virtual bool sampleMutation(Path &source, Path &proposal,
MutationRecord &muRec) = 0; MutationRecord &muRec, const MutationRecord& sourceMuRec) = 0;
/** /**
* \brief For a pair of paths, this function computes the inverse * \brief For a pair of paths, this function computes the inverse

View File

@ -174,7 +174,7 @@ public:
std::ostringstream oss; std::ostringstream oss;
Spectrum relWeight(0.0f); Spectrum relWeight(0.0f);
Float accumulatedWeight = 0; Float accumulatedWeight = 0;
MutationRecord muRec; MutationRecord muRec, currentMuRec(Mutator::EMutationTypeCount, 0, 0, 0, Spectrum(0.f));
Path *current = new Path(), Path *current = new Path(),
*proposed = new Path(); *proposed = new Path();
size_t mutations = 0; size_t mutations = 0;
@ -211,7 +211,7 @@ public:
mutator = m_mutators[mutatorIdx].get(); mutator = m_mutators[mutatorIdx].get();
/* Sample a mutated path */ /* Sample a mutated path */
success = mutator->sampleMutation(*current, *proposed, muRec); success = mutator->sampleMutation(*current, *proposed, muRec, currentMuRec);
statsAccepted.incrementBase(1); statsAccepted.incrementBase(1);
if (success) { if (success) {
@ -258,6 +258,7 @@ public:
std::swap(current, proposed); std::swap(current, proposed);
relWeight = current->getRelativeWeight(); relWeight = current->getRelativeWeight();
mutator->accept(muRec); mutator->accept(muRec);
currentMuRec = muRec;
accumulatedWeight = a; accumulatedWeight = a;
++statsAccepted; ++statsAccepted;
++mutations; ++mutations;

View File

@ -127,7 +127,7 @@ public:
BDAssert(!relWeight.isZero()); BDAssert(!relWeight.isZero());
DiscreteDistribution suitabilities(m_mutators.size()); DiscreteDistribution suitabilities(m_mutators.size());
MutationRecord muRec; MutationRecord muRec, currentMuRec(Mutator::EMutationTypeCount,0,0,0,Spectrum(0.f));
ref<Timer> timer = new Timer(); ref<Timer> timer = new Timer();
size_t consecRejections = 0; size_t consecRejections = 0;
@ -171,7 +171,7 @@ public:
mutator = m_mutators[mutatorIdx].get(); mutator = m_mutators[mutatorIdx].get();
/* Sample a mutated path */ /* Sample a mutated path */
success = mutator->sampleMutation(*current, *proposed, muRec); success = mutator->sampleMutation(*current, *proposed, muRec, currentMuRec);
#if defined(MTS_BD_DEBUG_HEAVY) #if defined(MTS_BD_DEBUG_HEAVY)
if (backup != *current) if (backup != *current)
@ -263,11 +263,12 @@ public:
std::swap(current, proposed); std::swap(current, proposed);
relWeight = current->getRelativeWeight(); relWeight = current->getRelativeWeight();
mutator->accept(muRec); mutator->accept(muRec);
currentMuRec = muRec;
accumulatedWeight = a; accumulatedWeight = a;
consecRejections = 0; consecRejections = 0;
++statsAccepted; ++statsAccepted;
} else { } else {
/* The mutation was rejected */ /* The mutation was rejected */
proposed->release(muRec.l, muRec.l + muRec.ka + 1, *m_pool); proposed->release(muRec.l, muRec.l + muRec.ka + 1, *m_pool);
consecRejections++; consecRejections++;
if (a > 0) { if (a > 0) {

View File

@ -44,7 +44,7 @@ Float BidirectionalMutator::suitability(const Path &path) const {
} }
bool BidirectionalMutator::sampleMutation( bool BidirectionalMutator::sampleMutation(
Path &source, Path &proposal, MutationRecord &muRec) { Path &source, Path &proposal, MutationRecord &muRec, const MutationRecord& sourceMuRec) {
TwoTailedGeoDistr desiredLength(2), deletionLength(2); TwoTailedGeoDistr desiredLength(2), deletionLength(2);
int k = source.length(); int k = source.length();

View File

@ -73,7 +73,7 @@ Float CausticPerturbation::suitability(const Path &path) const {
} }
bool CausticPerturbation::sampleMutation( bool CausticPerturbation::sampleMutation(
Path &source, Path &proposal, MutationRecord &muRec) { Path &source, Path &proposal, MutationRecord &muRec, const MutationRecord& sourceMuRec) {
int k = source.length(), m = k - 1, l = m - 1; int k = source.length(), m = k - 1, l = m - 1;
if (k < 4 || !source.vertex(l)->isConnectable()) if (k < 4 || !source.vertex(l)->isConnectable())

View File

@ -70,7 +70,7 @@ Float LensPerturbation::suitability(const Path &path) const {
} }
bool LensPerturbation::sampleMutation( bool LensPerturbation::sampleMutation(
Path &source, Path &proposal, MutationRecord &muRec) { Path &source, Path &proposal, MutationRecord &muRec, const MutationRecord& sourceMuRec) {
int k = source.length(), m = k-1, l = m-1; int k = source.length(), m = k-1, l = m-1;
while (!source.vertex(l)->isConnectable() && l >= 0) while (!source.vertex(l)->isConnectable() && l >= 0)
--l; --l;

View File

@ -230,7 +230,7 @@ bool ManifoldPerturbation::sampleMutationRecord(
} }
bool ManifoldPerturbation::sampleMutation( bool ManifoldPerturbation::sampleMutation(
Path &source, Path &proposal, MutationRecord &muRec) { Path &source, Path &proposal, MutationRecord &muRec, const MutationRecord& sourceMuRec) {
int k = source.length(); int k = source.length();
int a, b, c, step, tries = 0; int a, b, c, step, tries = 0;

View File

@ -66,7 +66,7 @@ Float MultiChainPerturbation::suitability(const Path &path) const {
} }
bool MultiChainPerturbation::sampleMutation( bool MultiChainPerturbation::sampleMutation(
Path &source, Path &proposal, MutationRecord &muRec) { Path &source, Path &proposal, MutationRecord &muRec, const MutationRecord& sourceMuRec) {
int k = source.length(), m = k - 1, l = m-1, nChains = 1; int k = source.length(), m = k - 1, l = m-1, nChains = 1;
while (l-1 >= 0 && (!source.vertex(l)->isConnectable() while (l-1 >= 0 && (!source.vertex(l)->isConnectable()