Replicated Focusing Belief Propagation

Functions

template<class Mag>
double theta_node_update_approx(MagVec<Mag> m, Mag &M, const double *xi, MagVec<Mag> u, Mag &U, const Params<Mag> &params, const long int &nxi, const long int &nm)

Messages update for a perceptron-like factor graph (approximated version computationally efficient in the limit of large number of weights)

Return
Largest difference between new and old messages
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • m: Total magnetization of variables nodes belonging to lower layer
  • M: Total magnetization of variable node belonging to upper layer
  • xi: Single input pattern
  • u: Downward messages (cavity magnetizations) from factor node to lower variables nodes
  • U: Upward message (cavity magnetizations) from factor node to upper variable node
  • params: Parameters selected for the algorithm
  • nxi: Size of input pattern
  • nm: Number of variables node onto the lower layer

template<class Mag>
double theta_node_update_accurate(MagVec<Mag> m, Mag &M, const double *xi, MagVec<Mag> u, Mag &U, const Params<Mag> &params, const long int &nxi, const long int &nm)

Messages update for a perceptron-like factor graph (fast approximated version)

Return
Largest difference between new and old messages
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • m: Total magnetization of variables nodes belonging to lower layer
  • M: Total magnetization of variable node belonging to upper layer
  • xi: Single input pattern
  • u: Downward messages (cavity magnetizations) from factor node to lower variables nodes
  • U: Upward message (cavity magnetizations) from factor node to upper variable node
  • params: Parameters selected for the algorithm
  • nxi: Size of input pattern
  • nm: Number of variables node onto the lower layer

template<class Mag>
double theta_node_update_exact(MagVec<Mag> m, Mag &M, const double *xi, MagVec<Mag> u, Mag &U, const Params<Mag> &params, const long int &nxi, const long int &nm)

Messages update for a perceptron-like factor graph (exact version)

Return
Largest difference between new and old messages
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • m: Total magnetization of variables nodes belonging to lower layer
  • M: Total magnetization of variable node belonging to upper layer
  • xi: Single input pattern
  • u: Downward messages (cavity magnetizations) from factor node to lower variables nodes
  • U: Upward message (cavity magnetizations) from factor node to upper variable node
  • params: Parameters selected for the algorithm
  • nxi: Size of input pattern
  • nm: Number of variables node onto the lower layer

template<class Mag>
double free_energy_theta(const MagVec<Mag> m, const Mag &M, const double *xi, const MagVec<Mag> u, const Mag &U, const long int &nxi, const long int &nm)

Computation of the free energy for a perceptron-like factor graph (fast approximated version)

Return
Free energy for the system represented by a perceptron-like factor graph
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • m: Total magnetization of variables nodes belonging to lower layer
  • M: Total magnetization of variable node belonging to upper layer
  • xi: Single input pattern
  • u: Downward messages (cavity magnetizations) from factor node to lower variables nodes
  • U: Upward message (cavity magnetizations) from factor node to upper variable node
  • nxi: Size of input pattern
  • nm: Number of variables node onto the lower layer

template<class Mag>
double free_energy_theta_exact(MagVec<Mag> m, const Mag &M, const double *xi, MagVec<Mag> u, const Mag &U, const long int &nm)

Computation of the free energy for a perceptron-like factor graph (exact version)

Return
Free energy for the system represented by a perceptron-like factor graph
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • m: Total magnetization of variables nodes belonging to lower layer
  • M: Total magnetization of variable node belonging to upper layer
  • xi: Single input pattern
  • u: Downward messages (cavity magnetizations) from factor node to lower variables nodes
  • U: Upward message (cavity magnetizations) from factor node to upper variable node
  • nm: Number of variables node onto the lower layer

template<class Mag>
double m_star_update(Mag &m_j_star, Mag &m_star_j, Params<Mag> &params)

Extra message update rule due to replicas.

Return
Largest value between older maximum difference and the difference between new and old extra message
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • m_j_star: Total magnetization of a weight node
  • m_star_j: Extra message (cavity magnetizations) from replica node to its weight node
  • params: Parameters selected for the algorithm

template<class Mag>
double iterate(Cavity_Message<Mag> &messages, const Patterns &patterns, Params<Mag> &params)

Management of the single iteration.

Return
Largest difference between new and old messages across all updates
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • messages: All magnetizations, both total and cavity, container
  • patterns: All patterns, both input and output values, container
  • params: Parameters selected for the algorithm

template<class Mag>
bool converge(Cavity_Message<Mag> &messages, const Patterns &patterns, Params<Mag> &params)

Management of all iterations within protocol step (i.e. constant focusing and replica parameteres)

Return
True when convergence is reached, False otherwise
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • messages: All magnetizations, both total and cavity, container
  • patterns: All patterns, both input and output values, container
  • params: Parameters selected for the algorithm

long int *nonbayes_test(long int **const sign_m_j_star, const Patterns &patterns, const long int &K)

Prediction of labels given weights and input patterns.

Return
Predicted labels
Parameters
  • sign_m_j_star: Total magnetization of weights nodes
  • patterns: All patterns, both input and output values, container
  • K: Number of nodes onto the hidden layer

template<class Mag>
long int error_test(const Cavity_Message<Mag> &messages, const Patterns &patterns)

Computation of number of mistaken predicted labels.

Return
Number of mistaken predicted labels
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • messages: All magnetizations, both total and cavity, container
  • patterns: All patterns, both input and output values, container

template<class Mag>
double free_energy(const Cavity_Message<Mag> &messages, const Patterns &patterns, const Params<Mag> &params)

Computation of the free energy for the whole system.

Return
Total free energy of the system
Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • messages: All magnetizations, both total and cavity, container
  • patterns: All patterns, both input and output values, container
  • params: Parameters selected for the algorithm

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>void set_outfields(const Cavity_Message < Mag > & message, const long int * output, const double & beta)

Set the outcome variables nodes to training labels.

Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • message: All magnetizations, both total and cavity, container
  • output: Output patterns (training labels)
  • beta: Inverse of temperature (always infinite up to now)

template<class Mag>
long int **focusingBP(const long int &K, const Patterns &patterns, const long int &max_iters, const long int &max_steps, const long int &seed, const double &damping, const std::string &accuracy1, const std::string &accuracy2, const double &randfact, const FocusingProtocol &fprotocol, const double &epsil, int nth = 1, std::string outfile = "", std::string outmessfiletmpl = "", std::string initmess = "", const bool &bin_mess = false)

Management of all protocol step of the learning rule.

Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • K: Number of nodes onto the hidden layer
  • patterns: All patterns, both input and output values, container
  • max_iters: Highest number of iterations to run within same protocol step
  • max_steps: Number of protocol steps
  • seed: Seed for random generator inside Cavity_Message initial messages creator
  • damping: Damping parameter for regularization of messages updates
  • accuracy1: Accuracy level for first layer
  • accuracy2: Accuracy level for second layer
  • randfact: Random value used inside Cavity_Message initial messages creator
  • fprotocol: Protocol type
  • epsil: error tollerance
  • nth: Number of cores to exploit
  • outfile: Filename which evolution measurements can be stored in
  • outmessfiletmpl: Filename which final messages can be written on
  • initmess: Filename which initial messages can be taken from
  • bin_mess: True if messages filename but me read/written as binary files, text files otherwise

template<class Mag, typename std ::enable_if< std ::is_same< Mag, MagP64 > ::value > ::type * = nullptr>theta_function< Mag > get_accuracy(const std ::string & acc)

Switch case for the right accuracy function.

Template Parameters
  • Mag: magnetization type (MagP or MagT)
Parameters
  • acc: accuracy name (possible values are “accurate”, “exact”, and “none”)