LatNet Builder Manual  2.0.1-11
Software Package for Constructing Highly Uniform Point Sets
Extending LatBuilder

Implementing Custom Weights

To compute weight values for any of the supported weight types (product, order-dependent, POD, projection-dependent), it is possible to use the enter an expression function from the web user interface. But let us assuming that we want to do this by deriving a new class of weights from an existing one. Consider product weights that depend a single parameter \(\eta\) and that take the value

\[ \gamma_{\mathfrak u} = \prod_{j \in \mathfrak u} (1 / j^\eta) \]

for projection \(\mathfrak u\). First, we define the new weights class that overrides ProductWeights::getWeightForCoordinate() in latticetester/include/latticetester/MyWeights.h:

#include "latticetester/ProductWeights.h"
namespace LatticeTester {
class MyWeights : public ProductWeights {
public:
explicit MyWeights(Weight parameter=1.0) : m_parameter(parameter) {}
virtual ~MyWeights() {}
virtual Weight getWeightForCoordinate(Coordinates::size_type coordinate) const
{ return std::pow(coordinate + 1, -m_parameter); }
protected:
virtual void format(std::ostream& os) const
{ os << "MyWeights(" << m_parameter << ")"; }
Weight m_parameter;
};
}

Next, we declare a new member function in Parser::Weights in include/latbuilder/Parser/Weights.h:

static std::unique_ptr<LatticeTester::Weights>
parseMyWeights(const std::string& arg, Real powerScale);

and implement it in src/Parser/Weights.cc:

std::unique_ptr<LatticeTester::Weights>
Weights::parseMyWeights(const std::string& arg, Real powerScale)
{
auto ka = splitPair<std::string, Real>(arg, ':');
if (ka.first != "my-weights") return nullptr;
auto w = new LatticeTester::MyWeights(ka.second);
return std::unique_ptr<LatticeTester::Weights>(w);
}

after, of course, adding the new header with:

#include "latticetester/MyWeights.h"

We also need to add a conditional block in Parser::Weights::parse:

if (auto p = parseMyWeights(arg, powerScale))
return p;

Then, after recompiling LatNet Builder, the new weights should be available to use by invoking latnetbuilder with the option –weights MyWeights:1.5, for example.