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
Bundling.hpp
#ifndef __macrovsa_Bundling__
#define __macrovsa_Bundling__
#include "Symbol.hpp"
#include <map>
namespace macrovsa {
class AssociativeMap;
/**
* @class Bundling
* @description Implements a macroscopic ersatz of a VSA bundling.
* - A bundling or superposition is created adding new symbols.
* - The bundling belief `tau = tau_1 tau_2 ...` and `sigma = sigma_1 + sigma_2 + ...` is calculated from its member belief.
* - Note: a bundling can not be copied, use the [clone()](Symbol.html/#.clone) method instead.
* @extends Symbol
* @param {string} [name] An optional name. By default, a `#index` unique name is generated.
* @param {...Symbol} symbol Symbol added to the bundling from 0 to 8 in this implementation
*/
class Bundling: public Symbol {
friend class Symbol;
// Bundling data structure symbol-ID => Symbol
std::unordered_map < unsigned int, Symbol * > values;
bool values_changed = false;
// Non assignable
Bundling& operator = (const Bundling&) = delete;
// Residual noise
double sigma0 = 0;
protected:
// Symbol remanence
mutable Symbols symbols;
// Mesoscopic implementation
friend class AssociativeMap;
virtual void setVector(double *vector) const;
public:
Bundling() : Symbol("", bundling) {}
Bundling(String name) : Symbol(name, bundling) {}
Bundling(String name, const Symbol& s1) : Symbol(name, bundling) {
add(s1);
}
Bundling(String name, const Symbol& s1, const Symbol& s2) : Symbol(name, bundling) {
add(s1), add(s2);
}
Bundling(String name, const Symbol& s1, const Symbol& s2, const Symbol& s3) : Symbol(name, bundling) {
add(s1), add(s2), add(s3);
}
Bundling(String name, const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4) : Symbol(name, bundling) {
add(s1), add(s2), add(s3), add(s4);
}
Bundling(String name, const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4, const Symbol& s5) : Symbol(name, bundling) {
add(s1), add(s2), add(s3), add(s4), add(s5);
}
Bundling(String name, const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4, const Symbol& s5, const Symbol& s6) : Symbol(name, bundling) {
add(s1), add(s2), add(s3), add(s4), add(s5), add(s6);
}
Bundling(String name, const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4, const Symbol& s5, const Symbol& s6, const Symbol& s7) : Symbol(name, bundling) {
add(s1), add(s2), add(s3), add(s4), add(s5), add(s6), add(s7);
}
Bundling(String name, const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4, const Symbol& s5, const Symbol& s6, const Symbol& s7, const Symbol& s8) : Symbol(name, bundling) {
add(s1), add(s2), add(s3), add(s4), add(s5), add(s6), add(s7), add(s8);
}
Bundling(const Symbol& s1) : Symbol("", bundling) {
add(s1);
}
Bundling(const Symbol& s1, const Symbol& s2) : Symbol("", bundling) {
add(s1), add(s2);
}
Bundling(const Symbol& s1, const Symbol& s2, const Symbol& s3) : Symbol("", bundling) {
add(s1), add(s2), add(s3);
}
Bundling(const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4) : Symbol("", bundling) {
add(s1), add(s2), add(s3), add(s4);
}
Bundling(const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4, const Symbol& s5) : Symbol("", bundling) {
add(s1), add(s2), add(s3), add(s4), add(s5);
}
Bundling(const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4, const Symbol& s5, const Symbol& s6) : Symbol("", bundling) {
add(s1), add(s2), add(s3), add(s4), add(s5), add(s6);
}
Bundling(const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4, const Symbol& s5, const Symbol& s6, const Symbol& s7) : Symbol("", bundling) {
add(s1), add(s2), add(s3), add(s4), add(s5), add(s6), add(s7);
}
Bundling(const Symbol& s1, const Symbol& s2, const Symbol& s3, const Symbol& s4, const Symbol& s5, const Symbol& s6, const Symbol& s7, const Symbol& s8) : Symbol("", bundling) {
add(s1), add(s2), add(s3), add(s4), add(s5), add(s6), add(s7), add(s8);
}
Bundling(Bundling const&);
virtual ~Bundling() {}
virtual const Belief& getBelief() const;
virtual void setBelief(double tau, double sigma);
virtual bool equals(const Symbol& symbol, char what = 'i') const;
static bool equals(const std::unordered_map < unsigned int, Symbol * > &v1, const std::unordered_map < unsigned int, Symbol * > &v2, char what);
virtual std::string asString() const;
/**
* @function add
* @memberof Bundling
* @instance
* @description Adds a new symbol to the container.
* @param {Symbol} symbol The symbol to add.
*/
void add(const Symbol& symbol);
protected:
static void add(std::unordered_map < unsigned int, Symbol * > &values, Symbol *symbol);
public:
/**
* @function erase
* @memberof Bundling
* @instance
* @description Erases a symbol in the container.
* @param {Symbol} [symbol ] The symbol to erase.
* - Without key argument erases all keys, it is a synonym for clear().
*/
virtual void erase(const Symbol& symbol);
void erase()
{
clear();
}
virtual void clear();
/**
* @function getSorted
* @memberof Bundling
* @instance
* @description Returns the bundling symbols as a decreasing tau value sorted associative map.
* - This corresponds to a microscopic implementation of a spike time activity rank sorting mechanism
* @param {uint} [count = 0] If `count > 0`, considers only the `count` symbols with a maximal tau value, otherwise all symbols.
* @return {JSON} A `std::vector<const Symbol*>` temporary reference to the sorted list of string representation of symbols.
*/
std::vector < const Symbol * > getSorted(unsigned int count = 0) const;
/**
* @function get
* @memberof Bundling
* @instance
* @description Defines an iterator over the bundling symbols, used in a construct of the form:
* ```
* for(auto it = bundling.Bundling::get().cbegin(); it != bundling.Bundling::get().cend(); it++) {
* const Symbol& symbol = *(it->second);
* ../..
* }
* ```
* - This is NOT a VSA plausible operation (unless another List data structure is used) by a debugging function.
* - The `bundling.Bundling::get().size()` construct returns the number of symbols in this bundling.
* @return A `const std::unordered_map < unsigned int, const Symbol* >` reference, with symbols indexed by their IDs.
*/
const std::unordered_map < unsigned int, Symbol * >& get() const {
return values;
}
/**
* @function getComputationTIme
* @memberof Bundling
* @instance
* @description Returns a relative estimation of the computation time order of magnitude.
* - It has been calibrated on a `Intel® CoreTM i5-8265U CPU @ 1.60GHz × 8 cores processor`with no use of GPU.
* - This provides obviously only relative values, useful for comparison between orders of magnitude.
* @return {double} A `O(dimension bundling-size)` computation time order of magnitude estimation in milli-seconds.
*/
double getComputationTime();
};
}
#endif
