https://gitlab.inria.fr/line/aide-group/macrovsa
Tip revision: 31a87d848f8ab28a06ccf77d0b359fc966974138 authored by vthierry on 15 December 2025, 21:31:50 UTC
sync from makefile
sync from makefile
Tip revision: 31a87d8
algo.hpp
#ifndef __macrovsa_algo__
#define __macrovsa_algo__
#include "Belief.hpp"
#include "Symbol.hpp"
#include "Bundling.hpp"
#include <map>
namespace macrovsa {
class algo {
/**
* @class algo
* @description Specifies the macroscopic algorithmic ersatz on VSA symbol.
* - These functions are accessible via the `macrovsa::` prefix.
*/
public:
/**
* @function reduce
* @memberof algo
* @static
* @description Reduces a symbol with respect to binding/unbinding operations.
* @param {Symbol} symbol The symbol to reduce.
* @return {Symbol} A reference to the reduced symbol. Available until program end.
*/
static const Symbol& reduce(const Symbol& symbol);
private:
static const Symbol& reduce(const Symbol& symbol, Symbol::Symbols& symbols);
static const Symbol& reduce(Bundling *bundling, Symbol::Symbols& symbols);
public:
/**
* @function sim
* @memberof algo
* @static
* @description Returns the similarity between two symbols.
* - For convinience the symbol can be given by its name, considering that `tau = 1, sigma = 0`.
* - A similarity is non-negligible up to a confidence interval of `99%` if ``tau > 2 sigma`.
* @param {Symbol|String} s1 A reference to the first symbol, or its string representation as defined in [fromJSON()](./Symbol.html#.fromJSON).
* @param {Symbol|String} s2 A reference to the second symbol, or its string representation as defined in [fromJSON()](./Symbol.html#.fromJSON).
* @return {Belief} The similarity or 0 if out of bounds, as belief, thus with an error estimation.
*/
static Belief sim(const Symbol& s1, const Symbol& s2, bool reduce = true);
static Belief sim(String s1, const Symbol& s2, bool reduce = true)
{
return sim(Symbol::fromJSON(s1), s2, reduce);
}
static Belief sim(const Symbol& s1, String s2, bool reduce = true)
{
return sim(s1, Symbol::fromJSON(s2), reduce);
}
static Belief sim(String s1, String s2, bool reduce = true)
{
return sim(Symbol::fromJSON(s1), Symbol::fromJSON(s1), reduce);
}
/**
* @function msim
* @memberof algo
* @static
* @description Returns the mesoscopic similarity between two symbol vectors.
* @param {Symbol s1 A reference to the first symbol.
* @param {Symbol} s2 A reference to the second symbol.
* @return {double} The similarity, using the dotprod.
*/
static double msim(const Symbol& s1, const Symbol& s2);
/**
* @function conj
* @memberof algo
* @static
* @description Calculates the conjuction of belief values (and operator).
* - Here the `max(0,min(...))` operator is used as [T-Norm](https://en.wikipedia.org/wiki/T-norm).
* @param {...Belief} degree... Degree of belief values, at least 2 and up to 8 arguments, in this implementation.
* @return {Belief} The computed value.
*/
static Belief conj(const Belief& a1, const Belief& a2);
static Belief conj(const Belief& a1, const Belief& a2, const Belief& a3);
static Belief conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4);
static Belief conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4, const Belief& a5);
static Belief conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4, const Belief& a5, const Belief& a6);
static Belief conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4, const Belief& a5, const Belief& a6, const Belief& a7);
static Belief conj(const Belief& a1, const Belief& a2, const Belief& a3, const Belief& a4, const Belief& a5, const Belief& a6, const Belief& a7, const Belief& a8);
/**
* @member {double} sigma_0
* @memberof algo
* @static
* @description The standard-deviation of the additive noise generated by an approximate operation.
* - Its value order of magnitude is `O(1/d)` where `d` is the VSA space dimension, default value is `d=10000`, and is calibrated on the [(Schlegel et al 2020)](https://arxiv.org/abs/2001.11797) numerical results, here set to `1/d/64`.
*/
static double sigma_0;
// sigma_0^(1/4)
static double sigma_04;
};
}
#endif
