LatNet Builder Manual 2.1.3-6
Software Package for Constructing Highly Uniform Point Sets
Loading...
Searching...
No Matches
tutorial/FilteredCBC.cc

This example shows how to transform, using filters, a sequence of merit values based on a component-by-component sequence of lattice definitions.

This example shows how to transform, using filters, a sequence of merit values based on a component-by-component sequence of lattice definitions.

// This file is part of LatNet Builder.
//
// Copyright (C) 2012-2021 The LatNet Builder author's, supervised by Pierre L'Ecuyer, Universite de Montreal.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "latbuilder/CoordUniformFigureOfMerit.h"
#include "latticetester/ProductWeights.h"
#include "latbuilder/Kernel/PAlpha.h"
#include "latbuilder/Kernel/PAlphaTilde.h"
#include "latbuilder/Accumulator.h"
#include "latbuilder/Functor/binary.h"
#include "latbuilder/Storage.h"
#include "latbuilder/MeritFilterList.h"
#include "latbuilder/MeritCombiner.h"
#include "latbuilder/MeritFilter.h"
#include "latbuilder/Norm/Normalizer.h"
#include "latbuilder/Norm/PAlphaSL10.h"
#include "latbuilder/Functor/LowPass.h"
#include "latbuilder/MeritSeq/CoordUniformCBC.h"
#include "latbuilder/MeritSeq/CoordUniformInnerProd.h"
#include "latbuilder/GenSeq/GeneratingValues.h"
#include "latbuilder/GenSeq/Creator.h"
#include "latbuilder/TextStream.h"
#include "Path.h"
#include <iostream>
#include <limits>
using namespace LatBuilder;
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 NORMALIZER>
void setLevelWeights(NORMALIZER&, const SizeParam<LA, EmbeddingType::UNILEVEL>&)
{}
template <LatticeType LA, class NORMALIZER>
void setLevelWeights(NORMALIZER& normalizer, const SizeParam<LA, EmbeddingType::MULTILEVEL>& sizeParam)
{
normalizer.setWeights(RealVector(
sizeParam.maxLevel() + 1,
1.0 / sizeParam.maxLevel()
));
}
template<LatticeType LA>
template<LatticeType LA>
template <LatticeType LA, EmbeddingType L, Compress C>
void test(const Storage<LA, L, C>& storage, Dimension dimension)
{
auto weights = unique<LatticeTester::ProductWeights>();
weights->setDefaultWeight(0.7);
CoordUniformFigureOfMerit<Kernel::PAlpha> figure(std::move(weights), 2);
std::cout << "figure of merit: " << figure << std::endl;
/*
// The P_{\alpha,PLR} figure of merit for polynomial lattices
auto weights = unique<LatticeTester::ProductWeights>();
weights->setDefaultWeight(0.7);
CoordUniformFigureOfMerit<Kernel::PAlphaTilde> figure(std::move(weights), 2);
std::cout << "figure of merit: " << figure << std::endl;
*/
typedef GenSeq::GeneratingValues<LA, decltype(figure)::suggestedCompression()> Coprime;
auto genSeq = GenSeq::Creator<Coprime>::create(storage.sizeParam());
setCombiner(filters);
auto normalizer = unique<Norm::Normalizer<LA, L, Norm::PAlphaSL10>>(
Norm::PAlphaSL10(figure.kernel().alpha(), figure.weights())
);
setLevelWeights(*normalizer, storage.sizeParam());
filters.add(std::move(normalizer));
auto lowPass = unique<MeritFilter<LA, L>>(Functor::LowPass<Real>(1.0), "low-pass");
filters.add(std::move(lowPass));
std::cout << "filters: " << filters << std::endl;
while (cbc.baseLat().dimension() < dimension) {
Dimension baseDim = cbc.baseLat().dimension();
std::cout << "CBC search for dimension: " << (baseDim + 1) << std::endl;
std::cout << "base lattice: " << std::endl << cbc.baseLat();
std::cout << "base merit value: " << cbc.baseMerit() << std::endl;
auto meritSeq = cbc.meritSeq(baseDim == 0 ? genSeq0 : genSeq);
auto filteredSeq = filters.apply(meritSeq);
auto best = std::min_element(filteredSeq.begin(), filteredSeq.end());
cbc.select(best.base());
std::cout << "BEST LATTICE: " << std::endl << cbc.baseLat() << "Merit value: " << *best << std::endl;
}
}
int main()
{
SET_PATH_TO_LATNETBUILDER_FOR_EXAMPLES();
Dimension dim = 3;
/*
test(Storage<LatticeType::POLYNOMIAL, EmbeddingType::UNILEVEL, Compress::NONE>(PolynomialFromInt(115)), dim);
test(Storage<LatticeType::POLYNOMIAL, EmbeddingType::MULTILEVEL, Compress::NONE>(PolynomialFromInt(115)), dim);
*/
return 0;
}
This file contains a global variable PATH_TO_LATNETBUILDER_DIR which should always equal the path to ...
Base base class for coordinate-uniform figures of merit.
Definition CoordUniformFigureOfMerit.h:33
Low pass filter.
Definition LowPass.h:28
Indexed sequence of generating values: -For ordinary lattices: integers coprime with a specified modu...
Definition GeneratingValues.h:48
Functor that sums the merit values of embedded lattices to produce a compound merit value.
Definition MeritCombiner.h:51
List of filters for merit values.
Definition MeritFilterList.h:176
Seq< MERITSEQ > apply(MERITSEQ meritSeq) const
Applies the filters to the input sequence meritSeq of merit values.
Definition MeritFilterList.h:243
Bound on the weighted discrepancy.
Definition PAlphaSL10.h:113
Lattice size parameter.
Definition SizeParam.h:30
Storage policy.
Definition Storage.h:114
CBC< LR, ET, GENSEQ > cbc(LatDef< LR, ET > baseLat, GENSEQ genSeq)
Creates a CBC lattice sequence.
Definition CBC.h:148
CBC< LR, ET, COMPRESS, PLO, PROJDEP, ACC > cbc(Storage< LR, ET, COMPRESS, PLO > storage, const WeightedFigureOfMerit< PROJDEP, ACC > &figure)
Creates a CBC algorithm.
Definition CBC.h:221
LatBuilder namespace.
Definition libtut_lat.dox:17
size_t Dimension
Scalar integer type for dimension.
Definition Types.h:53
boost::numeric::ublas::vector< Real > RealVector
Vector of floating-point values.
Definition Types.h:47
static result_type create(const SizeParam< LR, L > &sizeParam, ARGS &&... t)
Creates a new sequence object.
Definition Creator.h:43
Lattice traits.
Definition Types.h:92