Replicated Focusing Belief Propagation¶
Functions
-
template<class
Mag
>
doubletheta_node_update_approx
(MagVec<Mag> m, Mag &M, const double *xi, MagVec<Mag> u, Mag &U, const Params<Mag> ¶ms, 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 layerM
: Total magnetization of variable node belonging to upper layerxi
: Single input patternu
: Downward messages (cavity magnetizations) from factor node to lower variables nodesU
: Upward message (cavity magnetizations) from factor node to upper variable nodeparams
: Parameters selected for the algorithmnxi
: Size of input patternnm
: Number of variables node onto the lower layer
-
template<class
Mag
>
doubletheta_node_update_accurate
(MagVec<Mag> m, Mag &M, const double *xi, MagVec<Mag> u, Mag &U, const Params<Mag> ¶ms, 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 layerM
: Total magnetization of variable node belonging to upper layerxi
: Single input patternu
: Downward messages (cavity magnetizations) from factor node to lower variables nodesU
: Upward message (cavity magnetizations) from factor node to upper variable nodeparams
: Parameters selected for the algorithmnxi
: Size of input patternnm
: Number of variables node onto the lower layer
-
template<class
Mag
>
doubletheta_node_update_exact
(MagVec<Mag> m, Mag &M, const double *xi, MagVec<Mag> u, Mag &U, const Params<Mag> ¶ms, 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 layerM
: Total magnetization of variable node belonging to upper layerxi
: Single input patternu
: Downward messages (cavity magnetizations) from factor node to lower variables nodesU
: Upward message (cavity magnetizations) from factor node to upper variable nodeparams
: Parameters selected for the algorithmnxi
: Size of input patternnm
: Number of variables node onto the lower layer
-
template<class
Mag
>
doublefree_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 layerM
: Total magnetization of variable node belonging to upper layerxi
: Single input patternu
: Downward messages (cavity magnetizations) from factor node to lower variables nodesU
: Upward message (cavity magnetizations) from factor node to upper variable nodenxi
: Size of input patternnm
: Number of variables node onto the lower layer
-
template<class
Mag
>
doublefree_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 layerM
: Total magnetization of variable node belonging to upper layerxi
: Single input patternu
: Downward messages (cavity magnetizations) from factor node to lower variables nodesU
: Upward message (cavity magnetizations) from factor node to upper variable nodenm
: Number of variables node onto the lower layer
-
template<class
Mag
>
doublem_star_update
(Mag &m_j_star, Mag &m_star_j, Params<Mag> ¶ms)¶ 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 nodem_star_j
: Extra message (cavity magnetizations) from replica node to its weight nodeparams
: Parameters selected for the algorithm
-
template<class
Mag
>
doubleiterate
(Cavity_Message<Mag> &messages, const Patterns &patterns, Params<Mag> ¶ms)¶ 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, containerpatterns
: All patterns, both input and output values, containerparams
: Parameters selected for the algorithm
-
template<class
Mag
>
boolconverge
(Cavity_Message<Mag> &messages, const Patterns &patterns, Params<Mag> ¶ms)¶ 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, containerpatterns
: All patterns, both input and output values, containerparams
: 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 nodespatterns
: All patterns, both input and output values, containerK
: Number of nodes onto the hidden layer
-
template<class
Mag
>
long interror_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, containerpatterns
: All patterns, both input and output values, container
-
template<class
Mag
>
doublefree_energy
(const Cavity_Message<Mag> &messages, const Patterns &patterns, const Params<Mag> ¶ms)¶ 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, containerpatterns
: All patterns, both input and output values, containerparams
: 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, containeroutput
: 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 layerpatterns
: All patterns, both input and output values, containermax_iters
: Highest number of iterations to run within same protocol stepmax_steps
: Number of protocol stepsseed
: Seed for random generator inside Cavity_Message initial messages creatordamping
: Damping parameter for regularization of messages updatesaccuracy1
: Accuracy level for first layeraccuracy2
: Accuracy level for second layerrandfact
: Random value used inside Cavity_Message initial messages creatorfprotocol
: Protocol typeepsil
: error tollerancenth
: Number of cores to exploitoutfile
: Filename which evolution measurements can be stored inoutmessfiletmpl
: Filename which final messages can be written oninitmess
: Filename which initial messages can be taken frombin_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”)