This example shows how to use signals in order to interrupt the computation of a weighted figure of merit when its value has become too large.
This example shows how to use signals in order to interrupt the computation of a weighted figure of merit when its value has become too large.
#include "latbuilder/WeightedFigureOfMerit.h"
#include "latticetester/ProductWeights.h"
#include "latticetester/CoordinateSets.h"
#include "latbuilder/ProjDepMerit/Spectral.h"
#include "latticetester/NormaBestLat.h"
#include "latbuilder/ProjDepMerit/CoordUniform.h"
#include "latbuilder/Kernel/PAlphaTilde.h"
#include "latbuilder/Accumulator.h"
#include "latbuilder/Storage.h"
#include "latbuilder/Functor/binary.h"
#include "latbuilder/LatSeq/Korobov.h"
#include "latbuilder/GenSeq/GeneratingValues.h"
#include "latbuilder/TextStream.h"
#include <iostream>
#include <limits>
using TextStream::operator<<;
template <typename T, typename... ARGS>
std::unique_ptr<T> unique(ARGS&&... args)
{ return std::unique_ptr<T>(new T(std::forward<ARGS>(args)...)); }
template<LatticeType LA>
class Observer {
public:
Observer() { reset(); }
void reset() { m_bestMerit = std::numeric_limits<Real>::infinity(); }
const LatDef& bestLat() { return m_bestLat; }
const Real bestMerit() {
return m_bestMerit; }
void observe(const LatDef& lat, Real merit)
{
std::cout << lat;
std::cout << "Merit: " << merit;
if (merit < m_bestMerit) {
std::cout << " <-- best";
m_bestMerit = merit;
m_bestLat = lat;
}
std::cout << std::endl;
}
bool onProgress(Real merit) const
{ return merit < m_bestMerit; }
void onAbort(const LatDef& lat) const
{ std::cout << "rejected:" << std::endl << lat; }
private:
LatDef m_bestLat;
};
template <LatticeType LA, EmbeddingType L, Compress C>
{
auto weights = unique<LatticeTester::ProductWeights>();
weights->setDefaultWeight(0.7);
std::cout << "figure of merit: " << figure << std::endl;
auto weights = unique<LatticeTester::ProductWeights>();
weights->setDefaultWeight(0.7);
typedef ProjDepMerit::CoordUniform<Kernel::PAlphaTilde> ProjDep;
WeightedFigureOfMerit<ProjDep, Functor::Sum> figure(2, std::move(weights), ProjDep(2));
std::cout << "figure of merit: " << figure << std::endl;
*/
storage.sizeParam(),
Coprime(storage.sizeParam().modulus()),
dimension
);
1, latSeq.latDimension(),
0, latSeq.latDimension() - 1
);
std::cout << "projections: " << allProjections << std::endl;
auto initialMerit = storage.createMeritValue(0.0);
auto eval = figure.evaluator(storage);
Observer<LA> obs;
eval.onProgress().connect(boost::bind(&Observer<LA>::onProgress, &obs, _1));
eval.onAbort().connect(boost::bind(&Observer<LA>::onAbort, &obs, _1));
for (const auto& lat : latSeq) {
auto merit =
eval(lat, allProjections, initialMerit);
obs.observe(lat, merit);
}
std::cout << "BEST LATTICE: " << std::endl << obs.bestLat() << "Merit value: " << obs.bestMerit() << std::endl;
}
int main()
{
SET_PATH_TO_LATNETBUILDER_FOR_EXAMPLES();
test(Storage<LatticeType::POLYNOMIAL, EmbeddingType::UNILEVEL, Compress::NONE>(PolynomialFromInt(13)), dim);
*/
return 0;
}
This file contains a global variable PATH_TO_LATNETBUILDER_DIR which should always equal the path to ...
Indexed sequence of generating values: -For ordinary lattices: integers coprime with a specified modu...
Definition GeneratingValues.h:48
Definition of a rank-1 lattice.
Definition LatDef.h:40
Figure of merit based on the spectral test.
Definition Spectral.h:46
Storage policy.
Definition Storage.h:114
A CoordinateSets for coordinates within a given range.
Definition CoordinateSets.h:144
Korobov< LR, ET, GENSEQ > korobov(const SizeParam< LR, ET > &size, const GENSEQ &genSeqs, Dimension dimension)
Creates a Korobov lattice sequence.
Definition Korobov.h:81
Eval< LR, ET, COMPRESS, PLO, FIGURE > eval(Storage< LR, ET, COMPRESS, PLO > storage, Dimension dimension, FIGURE figure, typename LatticeTraits< LR >::GeneratingVector genVec)
Explicit construction (evaluates a figure of merit for a single lattice).
Definition Eval.h:44
LatBuilder namespace.
Definition libtut_lat.dox:17
size_t Dimension
Scalar integer type for dimension.
Definition Types.h:53
double Real
Scalar floating-point type.
Definition Types.h:44