aGrUM  0.13.2
gum::learning::Miic Class Reference

The miic learning algorithm. More...

#include <Miic.h>

+ Inheritance diagram for gum::learning::Miic:
+ Collaboration diagram for gum::learning::Miic:

Public Attributes

Signaler3< Size, double, doubleonProgress
 Progression, error and time. More...
 
Signaler1< std::string > onStop
 Criteria messageApproximationScheme. More...
 

Public Member Functions

Miicoperator= (const Miic &from)
 copy operator More...
 
Miicoperator= (Miic &&from)
 move operator More...
 
Constructors / Destructors
 Miic ()
 default constructor More...
 
 Miic (int maxLog)
 default constructor with maxLog More...
 
 Miic (const Miic &from)
 copy constructor More...
 
 Miic (Miic &&from)
 move constructor More...
 
 ~Miic ()
 destructor More...
 
Accessors / Modifiers
MixedGraph learnMixedStructure (CorrectedMutualInformation<> &I, MixedGraph graph)
 learns the structure of an Essential Graph More...
 
DAG learnStructure (CorrectedMutualInformation<> &I, MixedGraph graph)
 learns the structure of an Bayesian network, ie a DAG, by first learning an Essential graph and then directing the remaining edges. More...
 
template<typename GUM_SCALAR = double, typename GRAPH_CHANGES_SELECTOR , typename PARAM_ESTIMATOR , typename CELL_TRANSLATORS >
BayesNet< GUM_SCALAR > learnBN (GRAPH_CHANGES_SELECTOR &selector, PARAM_ESTIMATOR &estimator, const std::vector< std::string > &names, const std::vector< Size > &modal, const CELL_TRANSLATORS &translator, DAG initial_dag=DAG())
 learns the structure and the parameters of a BN More...
 
const std::vector< ArclatentVariables () const
 get the list of arcs hiding latent variables More...
 
void setMiicBehaviour ()
 Sets the orientation phase to follow the one of the MIIC algorithm. More...
 
void set3off2Behaviour ()
 Sets the orientation phase to follow the one of the 3off2 algorithm. More...
 
void addConstraints (HashTable< std::pair< Idx, Idx >, char > constraints)
 Set a ensemble of constraints for the orientation phase. More...
 
Getters and setters
void setEpsilon (double eps)
 Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|. More...
 
double epsilon () const
 Returns the value of epsilon. More...
 
void disableEpsilon ()
 Disable stopping criterion on epsilon. More...
 
void enableEpsilon ()
 Enable stopping criterion on epsilon. More...
 
bool isEnabledEpsilon () const
 Returns true if stopping criterion on epsilon is enabled, false otherwise. More...
 
void setMinEpsilonRate (double rate)
 Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|). More...
 
double minEpsilonRate () const
 Returns the value of the minimal epsilon rate. More...
 
void disableMinEpsilonRate ()
 Disable stopping criterion on epsilon rate. More...
 
void enableMinEpsilonRate ()
 Enable stopping criterion on epsilon rate. More...
 
bool isEnabledMinEpsilonRate () const
 Returns true if stopping criterion on epsilon rate is enabled, false otherwise. More...
 
void setMaxIter (Size max)
 Stopping criterion on number of iterations. More...
 
Size maxIter () const
 Returns the criterion on number of iterations. More...
 
void disableMaxIter ()
 Disable stopping criterion on max iterations. More...
 
void enableMaxIter ()
 Enable stopping criterion on max iterations. More...
 
bool isEnabledMaxIter () const
 Returns true if stopping criterion on max iterations is enabled, false otherwise. More...
 
void setMaxTime (double timeout)
 Stopping criterion on timeout. More...
 
double maxTime () const
 Returns the timeout (in seconds). More...
 
double currentTime () const
 Returns the current running time in second. More...
 
void disableMaxTime ()
 Disable stopping criterion on timeout. More...
 
void enableMaxTime ()
 Enable stopping criterion on timeout. More...
 
bool isEnabledMaxTime () const
 Returns true if stopping criterion on timeout is enabled, false otherwise. More...
 
void setPeriodSize (Size p)
 How many samples between two stopping is enable. More...
 
Size periodSize () const
 Returns the period size. More...
 
void setVerbosity (bool v)
 Set the verbosity on (true) or off (false). More...
 
bool verbosity () const
 Returns true if verbosity is enabled. More...
 
ApproximationSchemeSTATE stateApproximationScheme () const
 Returns the approximation scheme state. More...
 
Size nbrIterations () const
 Returns the number of iterations. More...
 
const std::vector< double > & history () const
 Returns the scheme history. More...
 
void initApproximationScheme ()
 Initialise the scheme. More...
 
bool startOfPeriod ()
 Returns true if we are at the beginning of a period (compute error is mandatory). More...
 
void updateApproximationScheme (unsigned int incr=1)
 Update the scheme w.r.t the new error and increment steps. More...
 
Size remainingBurnIn ()
 Returns the remaining burn in. More...
 
void stopApproximationScheme ()
 Stop the approximation scheme. More...
 
bool continueApproximationScheme (double error)
 Update the scheme w.r.t the new error. More...
 
Getters and setters
std::string messageApproximationScheme () const
 Returns the approximation scheme message. More...
 

Public Types

enum  ApproximationSchemeSTATE : char {
  ApproximationSchemeSTATE::Undefined, ApproximationSchemeSTATE::Continue, ApproximationSchemeSTATE::Epsilon, ApproximationSchemeSTATE::Rate,
  ApproximationSchemeSTATE::Limit, ApproximationSchemeSTATE::TimeLimit, ApproximationSchemeSTATE::Stopped
}
 The different state of an approximation scheme. More...
 

Protected Attributes

double _current_epsilon
 Current epsilon. More...
 
double _last_epsilon
 Last epsilon value. More...
 
double _current_rate
 Current rate. More...
 
Size _current_step
 The current step. More...
 
Timer _timer
 The timer. More...
 
ApproximationSchemeSTATE _current_state
 The current state. More...
 
std::vector< double_history
 The scheme history, used only if verbosity == true. More...
 
double _eps
 Threshold for convergence. More...
 
bool _enabled_eps
 If true, the threshold convergence is enabled. More...
 
double _min_rate_eps
 Threshold for the epsilon rate. More...
 
bool _enabled_min_rate_eps
 If true, the minimal threshold for epsilon rate is enabled. More...
 
double _max_time
 The timeout. More...
 
bool _enabled_max_time
 If true, the timeout is enabled. More...
 
Size _max_iter
 The maximum iterations. More...
 
bool _enabled_max_iter
 If true, the maximum iterations stopping criterion is enabled. More...
 
Size _burn_in
 Number of iterations before checking stopping criteria. More...
 
Size _period_size
 Checking criteria frequency. More...
 
bool _verbosity
 If true, verbosity is enabled. More...
 

Protected Member Functions

void _findBestContributor (Idx x, Idx y, const std::vector< Idx > &ui, const MixedGraph &graph, CorrectedMutualInformation<> &I, Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &_rank)
 finds the best contributor node for a pair given a conditioning set More...
 
std::vector< std::pair< std::tuple< Idx, Idx, Idx > *, double > > _getUnshieldedTriples (const MixedGraph &graph, CorrectedMutualInformation<> &I, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set)
 gets the list of unshielded triples in the graph in decreasing value of |I'(x, y, z|{ui})| More...
 
std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > _getUnshieldedTriplesMIIC (const MixedGraph &graph, CorrectedMutualInformation<> &I, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set, HashTable< std::pair< Idx, Idx >, char > &marks)
 gets the list of unshielded triples in the graph in decreasing value of |I'(x, y, z|{ui})|, prepares the orientation matrix for MIIC More...
 
std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > _updateProbaTriples (const MixedGraph &graph, std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > proba_triples)
 Gets the orientation probabilities like MIIC for the orientation phase. More...
 
void _propagatesHead (MixedGraph &graph, NodeId node)
 Propagates the orientation from a node to its neighbours. More...
 
Main phases
void _initiation (CorrectedMutualInformation<> &I, MixedGraph &graph, HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set, Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &_rank)
 Initiation phase. More...
 
void _iteration (CorrectedMutualInformation<> &I, MixedGraph &graph, HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set, Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &_rank)
 Iteration phase. More...
 
void _orientation_3off2 (CorrectedMutualInformation<> &I, MixedGraph &graph, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set)
 Orientation phase from the 3off2 algorithm, returns a CPDAG. More...
 
void _orientation_latents (CorrectedMutualInformation<> &I, MixedGraph &graph, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set)
 Modified version of the orientation phase that tries to propagate orientations from both orientations in case of a bidirected arc, not used. More...
 
void _orientation_miic (CorrectedMutualInformation<> &I, MixedGraph &graph, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set)
 Orientation phase from the MIIC algorithm, returns a mixed graph that may contain circles. More...
 

Detailed Description

The miic learning algorithm.

The miic class implements the miic algorithm based on https://doi.org/10.1371/journal.pcbi.1005662. It starts by eliminating edges that correspond to independent variables to build the skeleton of the graph, and then directs the remaining edges to get an essential graph. Latent variables can be detected using bi-directed arcs.

The variant 3off2 is also implemented as proposed by Affeldt and al. in https://doi.org/10.1186/s12859-015-0856-x. Only the orientation phase differs from miic, with a different ranking method and different propagation rules.

Definition at line 98 of file Miic.h.

Member Enumeration Documentation

The different state of an approximation scheme.

Enumerator
Undefined 
Continue 
Epsilon 
Rate 
Limit 
TimeLimit 
Stopped 

Definition at line 64 of file IApproximationSchemeConfiguration.h.

64  : char {
65  Undefined,
66  Continue,
67  Epsilon,
68  Rate,
69  Limit,
70  TimeLimit,
71  Stopped
72  };

Constructor & Destructor Documentation

gum::learning::Miic::Miic ( )

default constructor

Definition at line 40 of file Miic.cpp.

40 { GUM_CONSTRUCTOR(Miic); }
Miic()
default constructor
Definition: Miic.cpp:40
gum::learning::Miic::Miic ( int  maxLog)

default constructor with maxLog

Definition at line 43 of file Miic.cpp.

43 : __maxLog(maxLog) { GUM_CONSTRUCTOR(Miic); }
Miic()
default constructor
Definition: Miic.cpp:40
int __maxLog
Fixes the maximum log that we accept in exponential computations.
Definition: Miic.h:336
gum::learning::Miic::Miic ( const Miic from)

copy constructor

Definition at line 46 of file Miic.cpp.

46  : ApproximationScheme(from) {
47  GUM_CONS_CPY(Miic);
48  }
Miic()
default constructor
Definition: Miic.cpp:40
gum::learning::Miic::Miic ( Miic &&  from)

move constructor

Definition at line 51 of file Miic.cpp.

51  : ApproximationScheme(std::move(from)) {
52  GUM_CONS_MOV(Miic);
53  }
Miic()
default constructor
Definition: Miic.cpp:40
gum::learning::Miic::~Miic ( )

destructor

Definition at line 56 of file Miic.cpp.

56 { GUM_DESTRUCTOR(Miic); }
Miic()
default constructor
Definition: Miic.cpp:40

Member Function Documentation

const bool gum::learning::Miic::__existsDirectedPath ( const MixedGraph graph,
const NodeId  n1,
const NodeId  n2 
) const
private

checks for directed paths in a graph, consider double arcs like edges

Definition at line 1039 of file Miic.cpp.

References gum::List< Val, Alloc >::empty(), gum::HashTable< Key, Val, Alloc >::exists(), gum::ArcGraphPart::existsArc(), gum::List< Val, Alloc >::front(), gum::HashTable< Key, Val, Alloc >::insert(), gum::ArcGraphPart::parents(), gum::List< Val, Alloc >::popFront(), and gum::List< Val, Alloc >::pushBack().

Referenced by _orientation_3off2(), _orientation_miic(), and _propagatesHead().

1041  {
1042  // not recursive version => use a FIFO for simulating the recursion
1043  List< NodeId > nodeFIFO;
1044  nodeFIFO.pushBack(n2);
1045 
1046  // mark[node] = successor if visited, else mark[node] does not exist
1047  NodeProperty< NodeId > mark;
1048  mark.insert(n2, n2);
1049 
1050  NodeId current;
1051 
1052  while (!nodeFIFO.empty()) {
1053  current = nodeFIFO.front();
1054  nodeFIFO.popFront();
1055 
1056  // check the parents
1057 
1058  for (const auto new_one : graph.parents(current)) {
1059  if (mark.exists(new_one)) // if this node is already marked, do not
1060  continue; // check it again
1061 
1062  if (graph.existsArc(current,
1063  new_one)) // if there is a double arc, pass
1064  continue;
1065 
1066  mark.insert(new_one, current);
1067 
1068  if (new_one == n1) { return true; }
1069 
1070  nodeFIFO.pushBack(new_one);
1071  }
1072  }
1073 
1074  return false;
1075  }
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gum::learning::Miic::_findBestContributor ( Idx  x,
Idx  y,
const std::vector< Idx > &  ui,
const MixedGraph graph,
CorrectedMutualInformation<> &  I,
Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &  _rank 
)
protected

finds the best contributor node for a pair given a conditioning set

Parameters
xfirst node
ysecond node
uiconditioning set
IA mutual information instance that will do the computations and has loaded the database.
graphcontaining the assessed nodes
_rankthe heap of ranks of the algorithm

Definition at line 738 of file Miic.cpp.

References __maxLog, __N, gum::learning::CorrectedMutualInformation< IdSetAlloc, CountAlloc >::N(), and gum::learning::CorrectedMutualInformation< IdSetAlloc, CountAlloc >::score().

Referenced by _initiation(), and _iteration().

745  {
746  double maxP = -1.0;
747  Idx maxZ;
748 
749  // compute N
750  __N = I.N();
751  const double Ixy_ui = I.score(x, y, ui);
752 
753  for (const Idx z : graph) {
754  // if z!=x and z!=y and z not in ui
755  if (z != x && z != y && std::find(ui.begin(), ui.end(), z) == ui.end()) {
756  double Pnv;
757  double Pb;
758 
759  // Computing Pnv
760  const double Ixyz_ui = I.score(x, y, z, ui);
761  double calc_expo1 = -Ixyz_ui * __N;
762  // if exponentials are too high or to low, crop them at |__maxLog|
763  if (calc_expo1 > __maxLog) {
764  Pnv = 0.0;
765  } else if (calc_expo1 < -__maxLog) {
766  Pnv = 1.0;
767  } else {
768  Pnv = 1 / (1 + std::exp(calc_expo1));
769  }
770 
771  // Computing Pb
772  const double Ixz_ui = I.score(x, z, ui);
773  const double Iyz_ui = I.score(y, z, ui);
774 
775  calc_expo1 = -(Ixz_ui - Ixy_ui) * __N;
776  double calc_expo2 = -(Iyz_ui - Ixy_ui) * __N;
777 
778  // if exponentials are too high or to low, crop them at __maxLog
779  if (calc_expo1 > __maxLog || calc_expo2 > __maxLog) {
780  Pb = 0.0;
781  } else if (calc_expo1 < -__maxLog && calc_expo2 < -__maxLog) {
782  Pb = 1.0;
783  } else {
784  double expo1, expo2;
785  if (calc_expo1 < -__maxLog) {
786  expo1 = 0.0;
787  } else {
788  expo1 = std::exp(calc_expo1);
789  }
790  if (calc_expo2 < -__maxLog) {
791  expo2 = 0.0;
792  } else {
793  expo2 = std::exp(calc_expo2);
794  }
795  Pb = 1 / (1 + expo1 + expo2);
796  }
797 
798  // Getting max(min(Pnv, pb))
799  if (std::min(Pnv, Pb) > maxP) {
800  maxP = std::min(Pnv, Pb);
801  maxZ = z;
802  }
803  } // if z not in (x, y)
804  } // for z in graph.nodes
805  // storing best z in _rank
806  std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > >*, double > final;
807  auto tup =
808  new std::tuple< Idx, Idx, Idx, std::vector< Idx > >{x, y, maxZ, ui};
809  final.first = tup;
810  final.second = maxP;
811  _rank.insert(final);
812  }
int __maxLog
Fixes the maximum log that we accept in exponential computations.
Definition: Miic.h:336
Size __N
size of the database
Definition: Miic.h:343
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::pair< std::tuple< Idx, Idx, Idx > *, double > > gum::learning::Miic::_getUnshieldedTriples ( const MixedGraph graph,
CorrectedMutualInformation<> &  I,
const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &  sep_set 
)
protected

gets the list of unshielded triples in the graph in decreasing value of |I'(x, y, z|{ui})|

Definition at line 817 of file Miic.cpp.

References gum::learning::CorrectedMutualInformation< IdSetAlloc, CountAlloc >::score().

Referenced by _orientation_3off2(), and _orientation_latents().

820  {
821  std::vector< std::pair< std::tuple< Idx, Idx, Idx >*, double > > triples;
822  for (Idx z : graph) {
823  for (Idx x : graph.neighbours(z)) {
824  for (Idx y : graph.neighbours(z)) {
825  if (y < x && !graph.existsEdge(x, y)) {
826  std::vector< Idx > ui;
827  std::pair< Idx, Idx > key = {x, y};
828  std::pair< Idx, Idx > rev_key = {y, x};
829  if (sep_set.exists(key)) {
830  ui = sep_set[key];
831  } else if (sep_set.exists(rev_key)) {
832  ui = sep_set[rev_key];
833  }
834  // remove z from ui if it's present
835  const auto iter_z_place = std::find(ui.begin(), ui.end(), z);
836  if (iter_z_place != ui.end()) { ui.erase(iter_z_place); }
837 
838  double Ixyz_ui = I.score(x, y, z, ui);
839  std::pair< std::tuple< Idx, Idx, Idx >*, double > triple;
840  auto tup = new std::tuple< Idx, Idx, Idx >{x, y, z};
841  triple.first = tup;
842  triple.second = Ixyz_ui;
843  triples.push_back(triple);
844  }
845  }
846  }
847  }
848  std::sort(triples.begin(), triples.end(), GreaterAbsPairOn2nd());
849  return triples;
850  }
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > gum::learning::Miic::_getUnshieldedTriplesMIIC ( const MixedGraph graph,
CorrectedMutualInformation<> &  I,
const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &  sep_set,
HashTable< std::pair< Idx, Idx >, char > &  marks 
)
protected

gets the list of unshielded triples in the graph in decreasing value of |I'(x, y, z|{ui})|, prepares the orientation matrix for MIIC

Definition at line 856 of file Miic.cpp.

References _updateProbaTriples(), and gum::learning::CorrectedMutualInformation< IdSetAlloc, CountAlloc >::score().

Referenced by _orientation_miic().

860  {
861  std::vector<
862  std::tuple< std::tuple< Idx, Idx, Idx >*, double, double, double > >
863  triples;
864  for (Idx z : graph) {
865  for (Idx x : graph.neighbours(z)) {
866  for (Idx y : graph.neighbours(z)) {
867  if (y < x && !graph.existsEdge(x, y)) {
868  std::vector< Idx > ui;
869  std::pair< Idx, Idx > key = {x, y};
870  std::pair< Idx, Idx > rev_key = {y, x};
871  if (sep_set.exists(key)) {
872  ui = sep_set[key];
873  } else if (sep_set.exists(rev_key)) {
874  ui = sep_set[rev_key];
875  }
876  // remove z from ui if it's present
877  const auto iter_z_place = std::find(ui.begin(), ui.end(), z);
878  if (iter_z_place != ui.end()) { ui.erase(iter_z_place); }
879 
880  const double Ixyz_ui = I.score(x, y, z, ui);
881  auto tup = new std::tuple< Idx, Idx, Idx >{x, y, z};
882  std::tuple< std::tuple< Idx, Idx, Idx >*, double, double, double >
883  triple{tup, Ixyz_ui, 0.5, 0.5};
884  triples.push_back(triple);
885  if (!marks.exists({x, z})) { marks.insert({x, z}, 'o'); }
886  if (!marks.exists({z, x})) { marks.insert({z, x}, 'o'); }
887  if (!marks.exists({y, z})) { marks.insert({y, z}, 'o'); }
888  if (!marks.exists({z, y})) { marks.insert({z, y}, 'o'); }
889  }
890  }
891  }
892  }
893  triples = _updateProbaTriples(graph, triples);
894  std::sort(triples.begin(), triples.end(), GreaterTupleOnLast());
895  return triples;
896  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > _updateProbaTriples(const MixedGraph &graph, std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > proba_triples)
Gets the orientation probabilities like MIIC for the orientation phase.
Definition: Miic.cpp:901
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gum::learning::Miic::_initiation ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &  sep_set,
Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &  _rank 
)
protected

Initiation phase.

We go over all edges and test if the variables are marginally independent. If they are, the edge is deleted. If not, the best contributor is found.

Parameters
IA mutual information instance that will do the computations and has loaded the database.
graphthe MixedGraph we start from for the learning
sep_setthe separation set for independent couples, here set to {}
_rankthe heap of ranks of the algorithm

Definition at line 139 of file Miic.cpp.

References __empty_set, gum::ApproximationScheme::_current_step, _findBestContributor(), gum::ApproximationScheme::_timer, gum::EdgeGraphPart::edges(), gum::EdgeGraphPart::eraseEdge(), GUM_EMIT3, gum::IApproximationSchemeConfiguration::onProgress, gum::learning::CorrectedMutualInformation< IdSetAlloc, CountAlloc >::score(), gum::Set< Key, Alloc >::size(), and gum::Timer::step().

Referenced by learnMixedStructure().

144  {
145  Idx x, y;
146  EdgeSet edges = graph.edges();
147  Size steps_init = edges.size();
148 
149  for (const Edge& edge : edges) {
150  x = edge.first();
151  y = edge.second();
152  double Ixy = I.score(x, y);
153 
154  if (Ixy <= 0) { //< K
155  graph.eraseEdge(edge);
156  sep_set.insert(std::make_pair(x, y), __empty_set);
157  } else {
158  _findBestContributor(x, y, __empty_set, graph, I, _rank);
159  }
160 
161  ++_current_step;
162  if (onProgress.hasListener()) {
163  GUM_EMIT3(
164  onProgress, (_current_step * 33) / steps_init, 0., _timer.step());
165  }
166  }
167  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Signaler3< Size, double, double > onProgress
Progression, error and time.
void _findBestContributor(Idx x, Idx y, const std::vector< Idx > &ui, const MixedGraph &graph, CorrectedMutualInformation<> &I, Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &_rank)
finds the best contributor node for a pair given a conditioning set
Definition: Miic.cpp:738
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
const std::vector< Idx > __empty_set
an empty conditioning set
Definition: Miic.h:338
Size _current_step
The current step.
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:40
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gum::learning::Miic::_iteration ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &  sep_set,
Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &  _rank 
)
protected

Iteration phase.

As long as we find important nodes for edges, we go over them to see if we can assess the conditional independence of the variables.

Parameters
IA mutual information instance that will do the computations and has loaded the database.
graphthe MixedGraph returned from the previous phase
sep_setthe separation set for independent couples, built during the iterations of the phase
_rankthe heap of ranks of the algorithm

Definition at line 175 of file Miic.cpp.

References gum::ApproximationScheme::_current_step, _findBestContributor(), gum::ApproximationScheme::_timer, gum::EdgeGraphPart::eraseEdge(), GUM_EMIT3, gum::IApproximationSchemeConfiguration::onProgress, gum::learning::CorrectedMutualInformation< IdSetAlloc, CountAlloc >::score(), and gum::Timer::step().

Referenced by learnMixedStructure().

180  {
181  // if no triples to further examine pass
182  std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > >*, double > best;
183  if (!_rank.empty()) {
184  best = _rank.pop();
185  } else {
186  auto tup =
187  new std::tuple< Idx, Idx, Idx, std::vector< Idx > >{0, 0, 0, {}};
188  best.first = tup;
189  best.second = 0;
190  }
191 
192  Size steps_init = _current_step;
193  Size steps_iter = _rank.size();
194 
195  while (best.second > 0.5) {
196  Idx x, y, z;
197  std::vector< Idx > ui;
198  x = std::get< 0 >(*best.first);
199  y = std::get< 1 >(*best.first);
200  z = std::get< 2 >(*best.first);
201  ui = std::get< 3 >(*best.first);
202 
203  ui.push_back(z);
204  double Ixy_ui = I.score(x, y, ui);
205  if (Ixy_ui <= 0) {
206  graph.eraseEdge(Edge(x, y));
207  sep_set.insert(std::make_pair(x, y), std::move(ui));
208  } else {
209  _findBestContributor(x, y, ui, graph, I, _rank);
210  }
211 
212  delete best.first;
213  best = _rank.pop();
214 
215  ++_current_step;
216  if (onProgress.hasListener()) {
218  (_current_step * 66) / (steps_init + steps_iter),
219  0.,
220  _timer.step());
221  }
222  }
223  _current_step = steps_init + steps_iter;
224  if (onProgress.hasListener()) {
225  GUM_EMIT3(onProgress, 66, 0., _timer.step());
226  }
227  _current_step = steps_init + steps_iter;
228  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Signaler3< Size, double, double > onProgress
Progression, error and time.
void _findBestContributor(Idx x, Idx y, const std::vector< Idx > &ui, const MixedGraph &graph, CorrectedMutualInformation<> &I, Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &_rank)
finds the best contributor node for a pair given a conditioning set
Definition: Miic.cpp:738
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
Size _current_step
The current step.
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:40
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gum::learning::Miic::_orientation_3off2 ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &  sep_set 
)
protected

Orientation phase from the 3off2 algorithm, returns a CPDAG.

Parameters
IA mutual information instance that will do the computations and has loaded the database.
graphthe MixedGraph returned from the previous phase
sep_setthe separation set for independent couples, built during the previous phase

Definition at line 235 of file Miic.cpp.

References __existsDirectedPath(), __initial_marks, __latent_couples, gum::ApproximationScheme::_current_step, _getUnshieldedTriples(), gum::ApproximationScheme::_timer, gum::DiGraph::addArc(), gum::HashTable< Key, Val, Alloc >::begin(), gum::HashTable< Key, Val, Alloc >::end(), gum::ArcGraphPart::eraseArc(), gum::EdgeGraphPart::eraseEdge(), gum::HashTable< Key, Val, Alloc >::exists(), gum::ArcGraphPart::existsArc(), gum::EdgeGraphPart::existsEdge(), GUM_EMIT3, gum::IApproximationSchemeConfiguration::onProgress, and gum::Timer::step().

Referenced by learnMixedStructure().

238  {
239  std::vector< std::pair< std::tuple< Idx, Idx, Idx >*, double > > triples =
240  _getUnshieldedTriples(graph, I, sep_set);
241  Size steps_orient = triples.size();
242  Size past_steps = _current_step;
243 
244  // marks always correspond to the head of the arc/edge. - is for a forbidden
245  // arc, > for a mandatory arc
246  // we start by adding the mandatory arcs
247  for (auto iter = __initial_marks.begin(); iter != __initial_marks.end();
248  ++iter) {
249  if (graph.existsEdge(iter.key().first, iter.key().second)
250  && iter.val() == '>') {
251  graph.eraseEdge(Edge(iter.key().first, iter.key().second));
252  graph.addArc(iter.key().first, iter.key().second);
253  }
254  }
255 
256  Idx i = 0;
257  // list of elements that we shouldnt read again, ie elements that are
258  // eligible to
259  // rule 0 after the first time they are tested, and elements on which rule 1
260  // has been applied
261  while (i < triples.size()) {
262  // if i not in do_not_reread
263  std::pair< std::tuple< Idx, Idx, Idx >*, double > triple = triples[i];
264  Idx x, y, z;
265  x = std::get< 0 >(*triple.first);
266  y = std::get< 1 >(*triple.first);
267  z = std::get< 2 >(*triple.first);
268 
269  std::vector< Idx > ui;
270  std::pair< Idx, Idx > key = {x, y};
271  std::pair< Idx, Idx > rev_key = {y, x};
272  if (sep_set.exists(key)) {
273  ui = sep_set[key];
274  } else if (sep_set.exists(rev_key)) {
275  ui = sep_set[rev_key];
276  }
277  double Ixyz_ui = triple.second;
278  bool reset{false};
279  // try Rule 0
280  if (Ixyz_ui < 0) {
281  // if ( z not in Sep[x,y])
282  if (std::find(ui.begin(), ui.end(), z) == ui.end()) {
283  if (!graph.existsArc(x, z) && !graph.existsArc(z, x)) {
284  // when we try to add an arc to the graph, we always verify if
285  // we are allowed to do so, ie it is not a forbidden arc an it
286  // does not create a cycle
287  if (!__existsDirectedPath(graph, z, x)
288  && !(__initial_marks.exists({x, z})
289  && __initial_marks[{x, z}] == '-')) {
290  reset = true;
291  graph.eraseEdge(Edge(x, z));
292  graph.addArc(x, z);
293  } else if (__existsDirectedPath(graph, z, x)
294  && !(__initial_marks.exists({z, x})
295  && __initial_marks[{z, x}] == '-')) {
296  reset = true;
297  graph.eraseEdge(Edge(x, z));
298  // if we find a cycle, we force the competing edge
299  graph.addArc(z, x);
300  if (std::find(
301  __latent_couples.begin(), __latent_couples.end(), Arc(z, x))
302  == __latent_couples.end()) {
303  __latent_couples.push_back(Arc(z, x));
304  }
305  }
306  } else if (!graph.existsArc(y, z) && !graph.existsArc(z, y)) {
307  if (!__existsDirectedPath(graph, z, y)
308  && !(__initial_marks.exists({x, z})
309  && __initial_marks[{x, z}] == '-')) {
310  reset = true;
311  graph.eraseEdge(Edge(y, z));
312  graph.addArc(y, z);
313  } else if (__existsDirectedPath(graph, z, y)
314  && !(__initial_marks.exists({z, y})
315  && __initial_marks[{z, y}] == '-')) {
316  reset = true;
317  graph.eraseEdge(Edge(y, z));
318  // if we find a cycle, we force the competing edge
319  graph.addArc(z, y);
320  if (std::find(
321  __latent_couples.begin(), __latent_couples.end(), Arc(z, y))
322  == __latent_couples.end()) {
323  __latent_couples.push_back(Arc(z, y));
324  }
325  }
326  } else {
327  // checking if the anti-directed arc already exists, to register a
328  // latent variable
329  if (graph.existsArc(z, x)
330  && std::find(
331  __latent_couples.begin(), __latent_couples.end(), Arc(z, x))
332  == __latent_couples.end()
333  && std::find(
334  __latent_couples.begin(), __latent_couples.end(), Arc(x, z))
335  == __latent_couples.end()) {
336  __latent_couples.push_back(Arc(z, x));
337  }
338  if (graph.existsArc(z, y)
339  && std::find(
340  __latent_couples.begin(), __latent_couples.end(), Arc(z, y))
341  == __latent_couples.end()
342  && std::find(
343  __latent_couples.begin(), __latent_couples.end(), Arc(y, z))
344  == __latent_couples.end()) {
345  __latent_couples.push_back(Arc(z, y));
346  }
347  }
348  }
349  } else { // try Rule 1
350  if (graph.existsArc(x, z) && !graph.existsArc(z, y)
351  && !graph.existsArc(y, z)) {
352  if (!__existsDirectedPath(graph, y, z)
353  && !(__initial_marks.exists({z, y})
354  && __initial_marks[{z, y}] == '-')) {
355  reset = true;
356  graph.eraseEdge(Edge(z, y));
357  graph.addArc(z, y);
358  } else if (__existsDirectedPath(graph, y, z)
359  && !(__initial_marks.exists({y, z})
360  && __initial_marks[{y, z}] == '-')) {
361  reset = true;
362  graph.eraseEdge(Edge(z, y));
363  // if we find a cycle, we force the competing edge
364  graph.addArc(y, z);
365  if (std::find(
366  __latent_couples.begin(), __latent_couples.end(), Arc(y, z))
367  == __latent_couples.end()) {
368  __latent_couples.push_back(Arc(y, z));
369  }
370  }
371  }
372  if (graph.existsArc(y, z) && !graph.existsArc(z, x)
373  && !graph.existsArc(x, z)) {
374  if (!__existsDirectedPath(graph, x, z)
375  && !(__initial_marks.exists({z, x})
376  && __initial_marks[{z, x}] == '-')) {
377  reset = true;
378  graph.eraseEdge(Edge(z, x));
379  graph.addArc(z, x);
380  } else if (__existsDirectedPath(graph, x, z)
381  && !(__initial_marks.exists({x, z})
382  && __initial_marks[{x, z}] == '-')) {
383  reset = true;
384  graph.eraseEdge(Edge(z, x));
385  // if we find a cycle, we force the competing edge
386  graph.addArc(x, z);
387  if (std::find(
388  __latent_couples.begin(), __latent_couples.end(), Arc(x, z))
389  == __latent_couples.end()) {
390  __latent_couples.push_back(Arc(x, z));
391  }
392  }
393  }
394  } // if rule 0 or rule 1
395 
396  // if what we want to add already exists : pass to the next triplet
397  if (reset) {
398  i = 0;
399  } else {
400  ++i;
401  }
402  if (onProgress.hasListener()) {
404  ((_current_step + i) * 100) / (past_steps + steps_orient),
405  0.,
406  _timer.step());
407  }
408  } // while
409 
410  // erasing the the double headed arcs
411  for (const Arc& arc : __latent_couples) {
412  graph.eraseArc(Arc(arc.head(), arc.tail()));
413  }
414  }
iterator begin()
Returns an unsafe iterator pointing to the beginning of the hashtable.
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Signaler3< Size, double, double > onProgress
Progression, error and time.
const iterator & end() noexcept
Returns the unsafe iterator pointing to the end of the hashtable.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:340
Size _current_step
The current step.
std::vector< std::pair< std::tuple< Idx, Idx, Idx > *, double > > _getUnshieldedTriples(const MixedGraph &graph, CorrectedMutualInformation<> &I, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set)
gets the list of unshielded triples in the graph in decreasing value of |I&#39;(x, y, z|{ui})| ...
Definition: Miic.cpp:817
HashTable< std::pair< Idx, Idx >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:351
const bool __existsDirectedPath(const MixedGraph &graph, const NodeId n1, const NodeId n2) const
checks for directed paths in a graph, consider double arcs like edges
Definition: Miic.cpp:1039
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:40
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gum::learning::Miic::_orientation_latents ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &  sep_set 
)
protected

Modified version of the orientation phase that tries to propagate orientations from both orientations in case of a bidirected arc, not used.

varient trying to propagate both orientations in a bidirected arc

Parameters
IA mutual information instance that will do the computations and has loaded the database.
graphthe MixedGraph returned from the previous phase
sep_setthe separation set for independent couples, built during the previous phase

Definition at line 417 of file Miic.cpp.

References __latent_couples, gum::ApproximationScheme::_current_step, _getUnshieldedTriples(), gum::ApproximationScheme::_timer, gum::DiGraph::addArc(), gum::ArcGraphPart::directedPath(), gum::ArcGraphPart::eraseArc(), gum::EdgeGraphPart::eraseEdge(), gum::ArcGraphPart::existsArc(), GUM_EMIT3, gum::IApproximationSchemeConfiguration::onProgress, and gum::Timer::step().

420  {
421  std::vector< std::pair< std::tuple< Idx, Idx, Idx >*, double > > triples =
422  _getUnshieldedTriples(graph, I, sep_set);
423  Size steps_orient = triples.size();
424  Size past_steps = _current_step;
425 
426  Idx i = 0;
427  // list of elements that we shouldnt read again, ie elements that are
428  // eligible to
429  // rule 0 after the first time they are tested, and elements on which rule 1
430  // has been applied
431  while (i < triples.size()) {
432  // if i not in do_not_reread
433  std::pair< std::tuple< Idx, Idx, Idx >*, double > triple = triples[i];
434  Idx x, y, z;
435  x = std::get< 0 >(*triple.first);
436  y = std::get< 1 >(*triple.first);
437  z = std::get< 2 >(*triple.first);
438 
439  std::vector< Idx > ui;
440  std::pair< Idx, Idx > key = {x, y};
441  std::pair< Idx, Idx > rev_key = {y, x};
442  if (sep_set.exists(key)) {
443  ui = sep_set[key];
444  } else if (sep_set.exists(rev_key)) {
445  ui = sep_set[rev_key];
446  }
447  double Ixyz_ui = triple.second;
448  // try Rule 0
449  if (Ixyz_ui < 0) {
450  // if ( z not in Sep[x,y])
451  if (std::find(ui.begin(), ui.end(), z) == ui.end()) {
452  // if what we want to add already exists : pass
453  if ((graph.existsArc(x, z) || graph.existsArc(z, x))
454  && (graph.existsArc(y, z) || graph.existsArc(z, y))) {
455  ++i;
456  } else {
457  i = 0;
458  graph.eraseEdge(Edge(x, z));
459  graph.eraseEdge(Edge(y, z));
460  // checking for cycles
461  if (graph.existsArc(z, x)) {
462  graph.eraseArc(Arc(z, x));
463  try {
464  std::vector< NodeId > path = graph.directedPath(z, x);
465  // if we find a cycle, we force the competing edge
466  __latent_couples.push_back(Arc(z, x));
467  } catch (gum::NotFound) { graph.addArc(x, z); }
468  graph.addArc(z, x);
469  } else {
470  try {
471  std::vector< NodeId > path = graph.directedPath(z, x);
472  // if we find a cycle, we force the competing edge
473  graph.addArc(z, x);
474  __latent_couples.push_back(Arc(z, x));
475  } catch (gum::NotFound) { graph.addArc(x, z); }
476  }
477  if (graph.existsArc(z, y)) {
478  graph.eraseArc(Arc(z, y));
479  try {
480  std::vector< NodeId > path = graph.directedPath(z, y);
481  // if we find a cycle, we force the competing edge
482  __latent_couples.push_back(Arc(z, y));
483  } catch (gum::NotFound) { graph.addArc(y, z); }
484  graph.addArc(z, y);
485  } else {
486  try {
487  std::vector< NodeId > path = graph.directedPath(z, y);
488  // if we find a cycle, we force the competing edge
489  graph.addArc(z, y);
490  __latent_couples.push_back(Arc(z, y));
491 
492  } catch (gum::NotFound) { graph.addArc(y, z); }
493  }
494  if (graph.existsArc(z, x)
495  && std::find(
496  __latent_couples.begin(), __latent_couples.end(), Arc(z, x))
497  == __latent_couples.end()
498  && std::find(
499  __latent_couples.begin(), __latent_couples.end(), Arc(x, z))
500  == __latent_couples.end()) {
501  __latent_couples.push_back(Arc(z, x));
502  }
503  if (graph.existsArc(z, y)
504  && std::find(
505  __latent_couples.begin(), __latent_couples.end(), Arc(z, y))
506  == __latent_couples.end()
507  && std::find(
508  __latent_couples.begin(), __latent_couples.end(), Arc(y, z))
509  == __latent_couples.end()) {
510  __latent_couples.push_back(Arc(z, y));
511  }
512  }
513  } else {
514  ++i;
515  }
516  } else { // try Rule 1
517  bool reset{false};
518  if (graph.existsArc(x, z) && !graph.existsArc(z, y)
519  && !graph.existsArc(y, z)) {
520  reset = true;
521  graph.eraseEdge(Edge(z, y));
522  try {
523  std::vector< NodeId > path = graph.directedPath(y, z);
524  // if we find a cycle, we force the competing edge
525  graph.addArc(y, z);
526  __latent_couples.push_back(Arc(y, z));
527  } catch (gum::NotFound) { graph.addArc(z, y); }
528  }
529  if (graph.existsArc(y, z) && !graph.existsArc(z, x)
530  && !graph.existsArc(x, z)) {
531  reset = true;
532  graph.eraseEdge(Edge(z, x));
533  try {
534  std::vector< NodeId > path = graph.directedPath(x, z);
535  // if we find a cycle, we force the competing edge
536  graph.addArc(x, z);
537  __latent_couples.push_back(Arc(x, z));
538  } catch (gum::NotFound) { graph.addArc(z, x); }
539  }
540 
541  if (reset) {
542  i = 0;
543  } else {
544  ++i;
545  }
546  } // if rule 0 or rule 1
547  if (onProgress.hasListener()) {
549  ((_current_step + i) * 100) / (past_steps + steps_orient),
550  0.,
551  _timer.step());
552  }
553  } // while
554 
555  // erasing the the double headed arcs
556  for (const Arc& arc : __latent_couples) {
557  graph.eraseArc(Arc(arc.head(), arc.tail()));
558  }
559  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Signaler3< Size, double, double > onProgress
Progression, error and time.
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:340
Size _current_step
The current step.
std::vector< std::pair< std::tuple< Idx, Idx, Idx > *, double > > _getUnshieldedTriples(const MixedGraph &graph, CorrectedMutualInformation<> &I, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set)
gets the list of unshielded triples in the graph in decreasing value of |I&#39;(x, y, z|{ui})| ...
Definition: Miic.cpp:817
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:40
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

void gum::learning::Miic::_orientation_miic ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &  sep_set 
)
protected

Orientation phase from the MIIC algorithm, returns a mixed graph that may contain circles.

varient using the orientation protocol of MIIC

Parameters
IA mutual information instance that will do the computations and has loaded the database.
graphthe MixedGraph returned from the previous phase
sep_setthe separation set for independent couples, built during the previous phase

Definition at line 562 of file Miic.cpp.

References __arc_probas, __existsDirectedPath(), __initial_marks, __latent_couples, gum::ApproximationScheme::_current_step, _getUnshieldedTriplesMIIC(), gum::ApproximationScheme::_timer, _updateProbaTriples(), gum::DiGraph::addArc(), gum::HashTable< Key, Val, Alloc >::begin(), gum::Set< Key, Alloc >::empty(), gum::HashTable< Key, Val, Alloc >::end(), gum::ArcGraphPart::eraseArc(), gum::EdgeGraphPart::eraseEdge(), gum::ArcGraphPart::existsArc(), gum::EdgeGraphPart::existsEdge(), GUM_EMIT3, gum::IApproximationSchemeConfiguration::onProgress, gum::ArcGraphPart::parents(), and gum::Timer::step().

Referenced by learnMixedStructure().

565  {
566  // structure to store the orientations marks -, o, or >,
567  // Considers the head of the arc/edge first node -* second node
568  HashTable< std::pair< Idx, Idx >, char > marks = __initial_marks;
569 
570  // marks always correspond to the head of the arc/edge. - is for a forbidden
571  // arc, > for a mandatory arc
572  // we start by adding the mandatory arcs
573  for (auto iter = marks.begin(); iter != marks.end(); ++iter) {
574  if (graph.existsEdge(iter.key().first, iter.key().second)
575  && iter.val() == '>') {
576  graph.eraseEdge(Edge(iter.key().first, iter.key().second));
577  graph.addArc(iter.key().first, iter.key().second);
578  }
579  }
580 
581  std::vector<
582  std::tuple< std::tuple< Idx, Idx, Idx >*, double, double, double > >
583  proba_triples = _getUnshieldedTriplesMIIC(graph, I, sep_set, marks);
584 
585  Size steps_orient = proba_triples.size();
586  Size past_steps = _current_step;
587 
588  std::tuple< std::tuple< Idx, Idx, Idx >*, double, double, double > best;
589  if (steps_orient > 0) { best = proba_triples[0]; }
590 
591  while (!proba_triples.empty()
592  && std::max(std::get< 2 >(best), std::get< 3 >(best)) > 0.5) {
593  Idx x, y, z;
594  x = std::get< 0 >(*std::get< 0 >(best));
595  y = std::get< 1 >(*std::get< 0 >(best));
596  z = std::get< 2 >(*std::get< 0 >(best));
597 
598  const double i3 = std::get< 1 >(best);
599 
600  if (i3 <= 0) {
601  // v-structure discovery
602  if (marks[{x, z}] == 'o' && marks[{y, z}] == 'o') {
603  graph.eraseEdge(Edge(x, z));
604  graph.eraseEdge(Edge(y, z));
605  graph.addArc(x, z);
606  graph.addArc(y, z);
607  marks[{x, z}] = '>';
608  marks[{y, z}] = '>';
609  if (graph.existsArc(z, x)
610  && std::find(
611  __latent_couples.begin(), __latent_couples.end(), Arc(z, x))
612  == __latent_couples.end()
613  && std::find(
614  __latent_couples.begin(), __latent_couples.end(), Arc(x, z))
615  == __latent_couples.end()) {
616  __latent_couples.push_back(Arc(z, x));
617  }
618  if (graph.existsArc(z, y)
619  && std::find(
620  __latent_couples.begin(), __latent_couples.end(), Arc(z, y))
621  == __latent_couples.end()
622  && std::find(
623  __latent_couples.begin(), __latent_couples.end(), Arc(y, z))
624  == __latent_couples.end()) {
625  __latent_couples.push_back(Arc(z, y));
626  }
627  if (!__arc_probas.exists(Arc(x, z)))
628  __arc_probas.insert(Arc(x, z), std::get< 2 >(best));
629  if (!__arc_probas.exists(Arc(y, z)))
630  __arc_probas.insert(Arc(y, z), std::get< 3 >(best));
631  } else if (marks[{x, z}] == '>' && marks[{y, z}] == 'o') {
632  graph.eraseEdge(Edge(y, z));
633  graph.addArc(y, z);
634  marks[{y, z}] = '>';
635  if (graph.existsArc(z, y)
636  && std::find(
637  __latent_couples.begin(), __latent_couples.end(), Arc(z, y))
638  == __latent_couples.end()
639  && std::find(
640  __latent_couples.begin(), __latent_couples.end(), Arc(y, z))
641  == __latent_couples.end()) {
642  __latent_couples.push_back(Arc(z, y));
643  }
644  if (!__arc_probas.exists(Arc(y, z)))
645  __arc_probas.insert(Arc(y, z), std::get< 3 >(best));
646  } else if (marks[{y, z}] == '>' && marks[{x, z}] == 'o') {
647  graph.eraseEdge(Edge(x, z));
648  graph.addArc(x, z);
649  marks[{x, z}] = '>';
650  if (graph.existsArc(z, x)
651  && std::find(
652  __latent_couples.begin(), __latent_couples.end(), Arc(z, x))
653  == __latent_couples.end()
654  && std::find(
655  __latent_couples.begin(), __latent_couples.end(), Arc(x, z))
656  == __latent_couples.end()) {
657  __latent_couples.push_back(Arc(z, x));
658  }
659  if (!__arc_probas.exists(Arc(x, z)))
660  __arc_probas.insert(Arc(x, z), std::get< 2 >(best));
661  }
662 
663  } else {
664  // orientation propagation
665  if (marks[{x, z}] == '>' && marks[{y, z}] == 'o'
666  && marks[{z, y}] != '-') {
667  graph.eraseEdge(Edge(z, y));
668  if (!__existsDirectedPath(graph, y, z) && graph.parents(y).empty()) {
669  graph.addArc(z, y);
670  marks[{z, y}] = '>';
671  marks[{y, z}] = '-';
672  if (!__arc_probas.exists(Arc(z, y)))
673  __arc_probas.insert(Arc(z, y), std::get< 3 >(best));
674  } else if (!__existsDirectedPath(graph, z, y)
675  && graph.parents(z).empty()) {
676  graph.addArc(y, z);
677  marks[{z, y}] = '-';
678  marks[{y, z}] = '>';
679  __latent_couples.push_back(Arc(y, z));
680  if (!__arc_probas.exists(Arc(y, z)))
681  __arc_probas.insert(Arc(y, z), std::get< 3 >(best));
682  }
683  } else if (marks[{y, z}] == '>' && marks[{x, z}] == 'o'
684  && marks[{z, x}] != '-') {
685  graph.eraseEdge(Edge(z, x));
686  if (!__existsDirectedPath(graph, x, z) && graph.parents(x).empty()) {
687  graph.addArc(z, x);
688  marks[{z, x}] = '>';
689  marks[{x, z}] = '-';
690  if (!__arc_probas.exists(Arc(z, x)))
691  __arc_probas.insert(Arc(z, x), std::get< 2 >(best));
692  } else if (!__existsDirectedPath(graph, z, x)
693  && graph.parents(z).empty()) {
694  graph.addArc(x, z);
695  marks[{z, x}] = '-';
696  marks[{x, z}] = '>';
697  __latent_couples.push_back(Arc(x, z));
698  if (!__arc_probas.exists(Arc(x, z)))
699  __arc_probas.insert(Arc(x, z), std::get< 2 >(best));
700  }
701  }
702  }
703 
704  delete std::get< 0 >(best);
705  proba_triples.erase(proba_triples.begin());
706  // actualisation of the list of triples
707  proba_triples = _updateProbaTriples(graph, proba_triples);
708 
709  best = proba_triples[0];
710 
711  ++_current_step;
712  if (onProgress.hasListener()) {
714  (_current_step * 100) / (steps_orient + past_steps),
715  0.,
716  _timer.step());
717  }
718  } // while
719 
720  // erasing the double headed arcs
721  for (auto iter = __latent_couples.rbegin(); iter != __latent_couples.rend();
722  ++iter) {
723  graph.eraseArc(Arc(iter->head(), iter->tail()));
724  if (__existsDirectedPath(graph, iter->head(), iter->tail())) {
725  // if we find a cycle, we force the competing edge
726  graph.addArc(iter->head(), iter->tail());
727  graph.eraseArc(Arc(iter->tail(), iter->head()));
728  *iter = Arc(iter->head(), iter->tail());
729  }
730  }
731 
732  if (onProgress.hasListener()) {
733  GUM_EMIT3(onProgress, 100, 0., _timer.step());
734  }
735  }
ArcProperty< double > __arc_probas
Storing the propabilities for each arc set in the graph.
Definition: Miic.h:348
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Signaler3< Size, double, double > onProgress
Progression, error and time.
std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > _getUnshieldedTriplesMIIC(const MixedGraph &graph, CorrectedMutualInformation<> &I, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set, HashTable< std::pair< Idx, Idx >, char > &marks)
gets the list of unshielded triples in the graph in decreasing value of |I&#39;(x, y, z|{ui})|...
Definition: Miic.cpp:856
std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > _updateProbaTriples(const MixedGraph &graph, std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > proba_triples)
Gets the orientation probabilities like MIIC for the orientation phase.
Definition: Miic.cpp:901
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:340
Size _current_step
The current step.
HashTable< std::pair< Idx, Idx >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:351
const bool __existsDirectedPath(const MixedGraph &graph, const NodeId n1, const NodeId n2) const
checks for directed paths in a graph, consider double arcs like edges
Definition: Miic.cpp:1039
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:40
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gum::learning::Miic::_propagatesHead ( MixedGraph graph,
NodeId  node 
)
protected

Propagates the orientation from a node to its neighbours.

Definition at line 976 of file Miic.cpp.

References __existsDirectedPath(), __initial_marks, __latent_couples, gum::DiGraph::addArc(), gum::Set< Key, Alloc >::empty(), gum::EdgeGraphPart::eraseEdge(), gum::HashTable< Key, Val, Alloc >::exists(), gum::EdgeGraphPart::neighbours(), and gum::ArcGraphPart::parents().

Referenced by learnStructure().

976  {
977  const auto neighbours = graph.neighbours(node);
978  for (auto& neighbour : neighbours) {
979  // only propagate if it doesn't create a circle and isn't forbidden
980  // and doesn't create a new v-structure
981  if (!__existsDirectedPath(graph, neighbour, node)
982  && !(__initial_marks.exists({node, neighbour})
983  && __initial_marks[{node, neighbour}] == '-')
984  && graph.parents(neighbour).empty()) {
985  graph.eraseEdge(Edge(neighbour, node));
986  graph.addArc(node, neighbour);
987  _propagatesHead(graph, neighbour);
988  } else if (!__existsDirectedPath(graph, node, neighbour)
989  && !(__initial_marks.exists({neighbour, node})
990  && __initial_marks[{neighbour, node}] == '-')
991  && graph.parents(node).empty()) {
992  graph.eraseEdge(Edge(neighbour, node));
993  graph.addArc(neighbour, node);
994  } else if (!graph.parents(neighbour).empty()
995  && !graph.parents(node).empty()) {
996  graph.eraseEdge(Edge(neighbour, node));
997  graph.addArc(node, neighbour);
998  __latent_couples.push_back(Arc(node, neighbour));
999  } else {
1000  graph.eraseEdge(Edge(neighbour, node));
1001  }
1002  }
1003  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
void _propagatesHead(MixedGraph &graph, NodeId node)
Propagates the orientation from a node to its neighbours.
Definition: Miic.cpp:976
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:340
HashTable< std::pair< Idx, Idx >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:351
const bool __existsDirectedPath(const MixedGraph &graph, const NodeId n1, const NodeId n2) const
checks for directed paths in a graph, consider double arcs like edges
Definition: Miic.cpp:1039

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > > gum::learning::Miic::_updateProbaTriples ( const MixedGraph graph,
std::vector< std::tuple< std::tuple< Idx, Idx, Idx > *, double, double, double > >  proba_triples 
)
protected

Gets the orientation probabilities like MIIC for the orientation phase.

Definition at line 901 of file Miic.cpp.

References __N, and gum::ArcGraphPart::existsArc().

Referenced by _getUnshieldedTriplesMIIC(), and _orientation_miic().

905  {
906  for (auto& triple : proba_triples) {
907  Idx x, y, z;
908  x = std::get< 0 >(*std::get< 0 >(triple));
909  y = std::get< 1 >(*std::get< 0 >(triple));
910  z = std::get< 2 >(*std::get< 0 >(triple));
911  const double Ixyz = std::get< 1 >(triple);
912  double Pxz = std::get< 2 >(triple);
913  double Pyz = std::get< 3 >(triple);
914 
915  if (Ixyz <= 0) {
916  const double expo = std::exp(Ixyz * __N);
917  const double P0 = (1 + expo) / (1 + 3 * expo);
918  // distinguish betweeen the initialization and the update process
919  if (Pxz == Pyz && Pyz == 0.5) {
920  std::get< 2 >(triple) = P0;
921  std::get< 3 >(triple) = P0;
922  } else {
923  if (graph.existsArc(x, z) && Pxz >= P0) {
924  std::get< 3 >(triple) = Pxz * (1 / (1 + expo) - 0.5) + 0.5;
925  } else if (graph.existsArc(y, z) && Pyz >= P0) {
926  std::get< 2 >(triple) = Pyz * (1 / (1 + expo) - 0.5) + 0.5;
927  }
928  }
929  } else {
930  const double expo = std::exp(-Ixyz * __N);
931  if (graph.existsArc(x, z) && Pxz >= 0.5) {
932  std::get< 3 >(triple) = Pxz * (1 / (1 + expo) - 0.5) + 0.5;
933  } else if (graph.existsArc(y, z) && Pyz >= 0.5) {
934  std::get< 2 >(triple) = Pyz * (1 / (1 + expo) - 0.5) + 0.5;
935  }
936  }
937  }
938  std::sort(proba_triples.begin(), proba_triples.end(), GreaterTupleOnLast());
939  return proba_triples;
940  }
Size __N
size of the database
Definition: Miic.h:343
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gum::learning::Miic::addConstraints ( HashTable< std::pair< Idx, Idx >, char >  constraints)

Set a ensemble of constraints for the orientation phase.

Definition at line 1034 of file Miic.cpp.

References __initial_marks.

Referenced by gum::learning::genericBNLearner::__prepare_miic_3off2().

1034  {
1035  this->__initial_marks = constraints;
1036  }
HashTable< std::pair< Idx, Idx >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:351

+ Here is the caller graph for this function:

INLINE bool gum::ApproximationScheme::continueApproximationScheme ( double  error)
inherited

Update the scheme w.r.t the new error.

Test the stopping criterion that are enabled.

Parameters
errorThe new error value.
Returns
false if state become != ApproximationSchemeSTATE::Continue
Exceptions
OperationNotAllowedRaised if state != ApproximationSchemeSTATE::Continue.

Definition at line 225 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_current_epsilon, gum::ApproximationScheme::_current_rate, gum::ApproximationScheme::_current_state, gum::ApproximationScheme::_current_step, gum::ApproximationScheme::_enabled_eps, gum::ApproximationScheme::_enabled_max_iter, gum::ApproximationScheme::_enabled_max_time, gum::ApproximationScheme::_enabled_min_rate_eps, gum::ApproximationScheme::_eps, gum::ApproximationScheme::_history, gum::ApproximationScheme::_last_epsilon, gum::ApproximationScheme::_max_iter, gum::ApproximationScheme::_max_time, gum::ApproximationScheme::_min_rate_eps, gum::ApproximationScheme::_stopScheme(), gum::ApproximationScheme::_timer, gum::IApproximationSchemeConfiguration::Continue, gum::IApproximationSchemeConfiguration::Epsilon, GUM_EMIT3, GUM_ERROR, gum::IApproximationSchemeConfiguration::Limit, gum::IApproximationSchemeConfiguration::messageApproximationScheme(), gum::IApproximationSchemeConfiguration::onProgress, gum::IApproximationSchemeConfiguration::Rate, gum::ApproximationScheme::startOfPeriod(), gum::ApproximationScheme::stateApproximationScheme(), gum::Timer::step(), gum::IApproximationSchemeConfiguration::TimeLimit, and gum::ApproximationScheme::verbosity().

Referenced by gum::GibbsKL< GUM_SCALAR >::_computeKL(), gum::SamplingInference< GUM_SCALAR >::_loopApproxInference(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), and gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::makeInference().

225  {
226  // For coherence, we fix the time used in the method
227 
228  double timer_step = _timer.step();
229 
230  if (_enabled_max_time) {
231  if (timer_step > _max_time) {
233  return false;
234  }
235  }
236 
237  if (!startOfPeriod()) { return true; }
238 
240  GUM_ERROR(OperationNotAllowed,
241  "state of the approximation scheme is not correct : "
243  }
244 
245  if (verbosity()) { _history.push_back(error); }
246 
247  if (_enabled_max_iter) {
248  if (_current_step > _max_iter) {
250  return false;
251  }
252  }
253 
255  _current_epsilon = error; // eps rate isEnabled needs it so affectation was
256  // moved from eps isEnabled below
257 
258  if (_enabled_eps) {
259  if (_current_epsilon <= _eps) {
261  return false;
262  }
263  }
264 
265  if (_last_epsilon >= 0.) {
266  if (_current_epsilon > .0) {
267  // ! _current_epsilon can be 0. AND epsilon
268  // isEnabled can be disabled !
269  _current_rate =
271  }
272  // limit with current eps ---> 0 is | 1 - ( last_eps / 0 ) | --->
273  // infinity the else means a return false if we isEnabled the rate below,
274  // as we would have returned false if epsilon isEnabled was enabled
275  else {
277  }
278 
279  if (_enabled_min_rate_eps) {
280  if (_current_rate <= _min_rate_eps) {
282  return false;
283  }
284  }
285  }
286 
288  if (onProgress.hasListener()) {
290  }
291 
292  return true;
293  } else {
294  return false;
295  }
296  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
bool verbosity() const
Returns true if verbosity is enabled.
Signaler3< Size, double, double > onProgress
Progression, error and time.
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.
std::string messageApproximationScheme() const
Returns the approximation scheme message.
bool _enabled_eps
If true, the threshold convergence is enabled.
void _stopScheme(ApproximationSchemeSTATE new_state)
Stop the scheme given a new state.
double _current_epsilon
Current epsilon.
bool _enabled_min_rate_eps
If true, the minimal threshold for epsilon rate is enabled.
bool startOfPeriod()
Returns true if we are at the beginning of a period (compute error is mandatory). ...
double _eps
Threshold for convergence.
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
double _current_rate
Current rate.
bool _enabled_max_time
If true, the timeout is enabled.
Size _current_step
The current step.
std::vector< double > _history
The scheme history, used only if verbosity == true.
double _min_rate_eps
Threshold for the epsilon rate.
double _last_epsilon
Last epsilon value.
Size _max_iter
The maximum iterations.
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:40
ApproximationSchemeSTATE _current_state
The current state.
double _max_time
The timeout.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE double gum::ApproximationScheme::currentTime ( ) const
virtualinherited

Returns the current running time in second.

Returns
Returns the current running time in second.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 126 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_timer, and gum::Timer::step().

Referenced by gum::learning::genericBNLearner::currentTime().

126 { return _timer.step(); }
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::disableEpsilon ( )
virtualinherited

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 52 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

Referenced by gum::learning::genericBNLearner::disableEpsilon().

52 { _enabled_eps = false; }
bool _enabled_eps
If true, the threshold convergence is enabled.

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::disableMaxIter ( )
virtualinherited

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 103 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__mcInitApproximationScheme(), gum::learning::genericBNLearner::disableMaxIter(), and gum::learning::GreedyHillClimbing::GreedyHillClimbing().

103 { _enabled_max_iter = false; }
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::disableMaxTime ( )
virtualinherited

Disable stopping criterion on timeout.

Returns
Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 129 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

Referenced by gum::learning::genericBNLearner::disableMaxTime(), and gum::learning::GreedyHillClimbing::GreedyHillClimbing().

129 { _enabled_max_time = false; }
bool _enabled_max_time
If true, the timeout is enabled.

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::disableMinEpsilonRate ( )
virtualinherited

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 77 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__mcInitApproximationScheme(), gum::GibbsKL< GUM_SCALAR >::_computeKL(), gum::learning::genericBNLearner::disableMinEpsilonRate(), and gum::learning::GreedyHillClimbing::GreedyHillClimbing().

77  {
78  _enabled_min_rate_eps = false;
79  }
bool _enabled_min_rate_eps
If true, the minimal threshold for epsilon rate is enabled.

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::enableEpsilon ( )
virtualinherited

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 55 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__mcInitApproximationScheme(), and gum::learning::genericBNLearner::enableEpsilon().

55 { _enabled_eps = true; }
bool _enabled_eps
If true, the threshold convergence is enabled.

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::enableMaxIter ( )
virtualinherited

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 106 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

Referenced by gum::learning::genericBNLearner::enableMaxIter().

106 { _enabled_max_iter = true; }
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::enableMaxTime ( )
virtualinherited

Enable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 132 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::CNMonteCarloSampling(), and gum::learning::genericBNLearner::enableMaxTime().

132 { _enabled_max_time = true; }
bool _enabled_max_time
If true, the timeout is enabled.

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::enableMinEpsilonRate ( )
virtualinherited

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 82 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

Referenced by gum::GibbsKL< GUM_SCALAR >::_computeKL(), and gum::learning::genericBNLearner::enableMinEpsilonRate().

82  {
83  _enabled_min_rate_eps = true;
84  }
bool _enabled_min_rate_eps
If true, the minimal threshold for epsilon rate is enabled.

+ Here is the caller graph for this function:

INLINE double gum::ApproximationScheme::epsilon ( ) const
virtualinherited

Returns the value of epsilon.

Returns
Returns the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 49 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_eps.

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize(), and gum::learning::genericBNLearner::epsilon().

49 { return _eps; }
double _eps
Threshold for convergence.

+ Here is the caller graph for this function:

INLINE const std::vector< double > & gum::ApproximationScheme::history ( ) const
virtualinherited

Returns the scheme history.

Returns
Returns the scheme history.
Exceptions
OperationNotAllowedRaised if the scheme did not performed or if verbosity is set to false.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 171 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_history, GUM_ERROR, gum::ApproximationScheme::stateApproximationScheme(), gum::IApproximationSchemeConfiguration::Undefined, and gum::ApproximationScheme::verbosity().

Referenced by gum::learning::genericBNLearner::history().

171  {
173  GUM_ERROR(OperationNotAllowed,
174  "state of the approximation scheme is udefined");
175  }
176 
177  if (verbosity() == false) {
178  GUM_ERROR(OperationNotAllowed, "No history when verbosity=false");
179  }
180 
181  return _history;
182  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
bool verbosity() const
Returns true if verbosity is enabled.
std::vector< double > _history
The scheme history, used only if verbosity == true.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::initApproximationScheme ( )
inherited

Initialise the scheme.

Definition at line 185 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_current_epsilon, gum::ApproximationScheme::_current_rate, gum::ApproximationScheme::_current_state, gum::ApproximationScheme::_current_step, gum::ApproximationScheme::_history, gum::ApproximationScheme::_timer, gum::IApproximationSchemeConfiguration::Continue, and gum::Timer::reset().

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__mcInitApproximationScheme(), gum::GibbsKL< GUM_SCALAR >::_computeKL(), gum::SamplingInference< GUM_SCALAR >::_loopApproxInference(), gum::SamplingInference< GUM_SCALAR >::_onStateChanged(), gum::learning::GreedyHillClimbing::learnStructure(), and gum::learning::LocalSearchWithTabuList::learnStructure().

185  {
187  _current_step = 0;
189  _history.clear();
190  _timer.reset();
191  }
double _current_epsilon
Current epsilon.
void reset()
Reset the timer.
Definition: timer_inl.h:29
double _current_rate
Current rate.
Size _current_step
The current step.
std::vector< double > _history
The scheme history, used only if verbosity == true.
ApproximationSchemeSTATE _current_state
The current state.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE bool gum::ApproximationScheme::isEnabledEpsilon ( ) const
virtualinherited

Returns true if stopping criterion on epsilon is enabled, false otherwise.

Returns
Returns true if stopping criterion on epsilon is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 59 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

Referenced by gum::learning::genericBNLearner::isEnabledEpsilon().

59  {
60  return _enabled_eps;
61  }
bool _enabled_eps
If true, the threshold convergence is enabled.

+ Here is the caller graph for this function:

INLINE bool gum::ApproximationScheme::isEnabledMaxIter ( ) const
virtualinherited

Returns true if stopping criterion on max iterations is enabled, false otherwise.

Returns
Returns true if stopping criterion on max iterations is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 110 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

Referenced by gum::learning::genericBNLearner::isEnabledMaxIter().

110  {
111  return _enabled_max_iter;
112  }
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.

+ Here is the caller graph for this function:

INLINE bool gum::ApproximationScheme::isEnabledMaxTime ( ) const
virtualinherited

Returns true if stopping criterion on timeout is enabled, false otherwise.

Returns
Returns true if stopping criterion on timeout is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 136 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

Referenced by gum::learning::genericBNLearner::isEnabledMaxTime().

136  {
137  return _enabled_max_time;
138  }
bool _enabled_max_time
If true, the timeout is enabled.

+ Here is the caller graph for this function:

INLINE bool gum::ApproximationScheme::isEnabledMinEpsilonRate ( ) const
virtualinherited

Returns true if stopping criterion on epsilon rate is enabled, false otherwise.

Returns
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 88 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

Referenced by gum::GibbsKL< GUM_SCALAR >::_computeKL(), and gum::learning::genericBNLearner::isEnabledMinEpsilonRate().

88  {
89  return _enabled_min_rate_eps;
90  }
bool _enabled_min_rate_eps
If true, the minimal threshold for epsilon rate is enabled.

+ Here is the caller graph for this function:

const std::vector< Arc > gum::learning::Miic::latentVariables ( ) const

get the list of arcs hiding latent variables

Definition at line 1006 of file Miic.cpp.

References __latent_couples.

Referenced by gum::learning::genericBNLearner::latentVariables().

1006  {
1007  return __latent_couples;
1008  }
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:340

+ Here is the caller graph for this function:

template<typename GUM_SCALAR , typename GRAPH_CHANGES_SELECTOR , typename PARAM_ESTIMATOR , typename CELL_TRANSLATORS >
BayesNet< GUM_SCALAR > gum::learning::Miic::learnBN ( GRAPH_CHANGES_SELECTOR &  selector,
PARAM_ESTIMATOR &  estimator,
const std::vector< std::string > &  names,
const std::vector< Size > &  modal,
const CELL_TRANSLATORS &  translator,
DAG  initial_dag = DAG() 
)

learns the structure and the parameters of a BN

Parameters
selectorA selector class that computes the best changes that can be applied and that enables the user to get them very easily. Typically, the selector is a GraphChangesSelector4DiGraph<SCORE, STRUCT_CONSTRAINT, GRAPH_CHANGES_GENERATOR>.
estimatorA estimator.
namesThe variables names.
modalthe domain sizes of the random variables observed in the database
translatorThe cell translator to use.
initial_dagthe DAG we start from for our learning

Definition at line 1015 of file Miic.cpp.

References learnStructure().

1020  {
1021  return DAG2BNLearner::
1022  createBN< GUM_SCALAR, PARAM_ESTIMATOR, CELL_TRANSLATORS >(
1023  estimator,
1024  learnStructure(selector, modal, initial_dag),
1025  names,
1026  modal,
1027  translator);
1028  }
DAG learnStructure(CorrectedMutualInformation<> &I, MixedGraph graph)
learns the structure of an Bayesian network, ie a DAG, by first learning an Essential graph and then ...
Definition: Miic.cpp:944

+ Here is the call graph for this function:

MixedGraph gum::learning::Miic::learnMixedStructure ( CorrectedMutualInformation<> &  I,
MixedGraph  graph 
)

learns the structure of an Essential Graph

learns the structure of a MixedGraph

Parameters
IA mutual information instance that will do the computations and has loaded the database.
graphthe MixedGraph we start from for the learning

Definition at line 103 of file Miic.cpp.

References __latent_couples, __usemiic, gum::ApproximationScheme::_current_step, _initiation(), _iteration(), _orientation_3off2(), _orientation_miic(), gum::ApproximationScheme::_timer, and gum::Timer::reset().

Referenced by gum::learning::genericBNLearner::learnMixedStructure(), and learnStructure().

104  {
105  _timer.reset();
106  _current_step = 0;
107 
108  // clear the vector of latent arcs to be sure
109  __latent_couples.clear();
110 
112  Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > >*, double >,
113  GreaterPairOn2nd >
114  _rank;
115 
117  HashTable< std::pair< Idx, Idx >, std::vector< Idx > > sep_set;
118 
119  _initiation(I, graph, sep_set, _rank);
120 
121  _iteration(I, graph, sep_set, _rank);
122 
123  if (__usemiic) {
124  _orientation_miic(I, graph, sep_set);
125  } else {
126  _orientation_3off2(I, graph, sep_set);
127  }
128 
129  return graph;
130  }
void _orientation_miic(CorrectedMutualInformation<> &I, MixedGraph &graph, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set)
Orientation phase from the MIIC algorithm, returns a mixed graph that may contain circles...
Definition: Miic.cpp:562
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:345
void reset()
Reset the timer.
Definition: timer_inl.h:29
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:340
Size _current_step
The current step.
void _orientation_3off2(CorrectedMutualInformation<> &I, MixedGraph &graph, const HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set)
Orientation phase from the 3off2 algorithm, returns a CPDAG.
Definition: Miic.cpp:235
void _iteration(CorrectedMutualInformation<> &I, MixedGraph &graph, HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set, Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &_rank)
Iteration phase.
Definition: Miic.cpp:175
void _initiation(CorrectedMutualInformation<> &I, MixedGraph &graph, HashTable< std::pair< Idx, Idx >, std::vector< Idx > > &sep_set, Heap< std::pair< std::tuple< Idx, Idx, Idx, std::vector< Idx > > *, double >, GreaterPairOn2nd > &_rank)
Initiation phase.
Definition: Miic.cpp:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DAG gum::learning::Miic::learnStructure ( CorrectedMutualInformation<> &  I,
MixedGraph  graph 
)

learns the structure of an Bayesian network, ie a DAG, by first learning an Essential graph and then directing the remaining edges.

learns the structure of an Bayesian network, ie a DAG, from an Essential graph.

Parameters
IA mutual information instance that will do the computations and has loaded the database
graphthe MixedGraph we start from for the learning

Definition at line 944 of file Miic.cpp.

References _propagatesHead(), gum::DAG::addArc(), gum::NodeGraphPart::addNodeWithId(), gum::Set< Key, Alloc >::empty(), learnMixedStructure(), gum::EdgeGraphPart::neighbours(), gum::ArcGraphPart::parents(), and gum::DiGraph::topologicalOrder().

Referenced by gum::learning::genericBNLearner::__learnDAG(), and learnBN().

945  {
946  MixedGraph essentialGraph = learnMixedStructure(I, initialGraph);
947 
948  // Second, orientate remaining edges
949  const Sequence< NodeId > order = essentialGraph.topologicalOrder();
950  // first, propagate existing orientations
951  for (NodeId x : order) {
952  if (!essentialGraph.parents(x).empty()) {
953  _propagatesHead(essentialGraph, x);
954  }
955  }
956  // then decide the orientation by the topological order and propagate them
957  for (NodeId x : order) {
958  if (!essentialGraph.neighbours(x).empty()) {
959  _propagatesHead(essentialGraph, x);
960  }
961  }
962 
963  // turn the mixed graph into a dag
964  DAG dag;
965  for (auto node : essentialGraph) {
966  dag.addNodeWithId(node);
967  }
968  for (const Arc& arc : essentialGraph.arcs()) {
969  dag.addArc(arc.tail(), arc.head());
970  }
971 
972  return dag;
973  }
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
MixedGraph learnMixedStructure(CorrectedMutualInformation<> &I, MixedGraph graph)
learns the structure of an Essential Graph
Definition: Miic.cpp:103
void _propagatesHead(MixedGraph &graph, NodeId node)
Propagates the orientation from a node to its neighbours.
Definition: Miic.cpp:976

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE Size gum::ApproximationScheme::maxIter ( ) const
virtualinherited

Returns the criterion on number of iterations.

Returns
Returns the criterion on number of iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 100 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_max_iter.

Referenced by gum::learning::genericBNLearner::maxIter().

100 { return _max_iter; }
Size _max_iter
The maximum iterations.

+ Here is the caller graph for this function:

INLINE double gum::ApproximationScheme::maxTime ( ) const
virtualinherited

Returns the timeout (in seconds).

Returns
Returns the timeout (in seconds).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 123 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_max_time.

Referenced by gum::learning::genericBNLearner::maxTime().

123 { return _max_time; }
double _max_time
The timeout.

+ Here is the caller graph for this function:

INLINE std::string gum::IApproximationSchemeConfiguration::messageApproximationScheme ( ) const
inherited

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 38 of file IApproximationSchemeConfiguration_inl.h.

References gum::IApproximationSchemeConfiguration::Continue, gum::IApproximationSchemeConfiguration::Epsilon, gum::IApproximationSchemeConfiguration::epsilon(), gum::IApproximationSchemeConfiguration::Limit, gum::IApproximationSchemeConfiguration::maxIter(), gum::IApproximationSchemeConfiguration::maxTime(), gum::IApproximationSchemeConfiguration::minEpsilonRate(), gum::IApproximationSchemeConfiguration::Rate, gum::IApproximationSchemeConfiguration::stateApproximationScheme(), gum::IApproximationSchemeConfiguration::Stopped, gum::IApproximationSchemeConfiguration::TimeLimit, and gum::IApproximationSchemeConfiguration::Undefined.

Referenced by gum::ApproximationScheme::_stopScheme(), gum::ApproximationScheme::continueApproximationScheme(), and gum::credal::InferenceEngine< GUM_SCALAR >::getApproximationSchemeMsg().

38  {
39  std::stringstream s;
40 
41  switch (stateApproximationScheme()) {
42  case ApproximationSchemeSTATE::Continue: s << "in progress"; break;
43 
45  s << "stopped with epsilon=" << epsilon();
46  break;
47 
49  s << "stopped with rate=" << minEpsilonRate();
50  break;
51 
53  s << "stopped with max iteration=" << maxIter();
54  break;
55 
57  s << "stopped with timeout=" << maxTime();
58  break;
59 
60  case ApproximationSchemeSTATE::Stopped: s << "stopped on request"; break;
61 
62  case ApproximationSchemeSTATE::Undefined: s << "undefined state"; break;
63  };
64 
65  return s.str();
66  }
virtual double epsilon() const =0
Returns the value of epsilon.
virtual ApproximationSchemeSTATE stateApproximationScheme() const =0
Returns the approximation scheme state.
virtual double maxTime() const =0
Returns the timeout (in seconds).
virtual Size maxIter() const =0
Returns the criterion on number of iterations.
virtual double minEpsilonRate() const =0
Returns the value of the minimal epsilon rate.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE double gum::ApproximationScheme::minEpsilonRate ( ) const
virtualinherited

Returns the value of the minimal epsilon rate.

Returns
Returns the value of the minimal epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 72 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_min_rate_eps.

Referenced by gum::learning::genericBNLearner::minEpsilonRate().

72  {
73  return _min_rate_eps;
74  }
double _min_rate_eps
Threshold for the epsilon rate.

+ Here is the caller graph for this function:

INLINE Size gum::ApproximationScheme::nbrIterations ( ) const
virtualinherited

Returns the number of iterations.

Returns
Returns the number of iterations.
Exceptions
OperationNotAllowedRaised if the scheme did not perform.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 161 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_current_step, GUM_ERROR, gum::ApproximationScheme::stateApproximationScheme(), and gum::IApproximationSchemeConfiguration::Undefined.

Referenced by gum::GibbsKL< GUM_SCALAR >::_computeKL(), and gum::learning::genericBNLearner::nbrIterations().

161  {
163  GUM_ERROR(OperationNotAllowed,
164  "state of the approximation scheme is undefined");
165  }
166 
167  return _current_step;
168  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
Size _current_step
The current step.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Miic & gum::learning::Miic::operator= ( const Miic from)

copy operator

Definition at line 59 of file Miic.cpp.

59  {
60  ApproximationScheme::operator=(from);
61  return *this;
62  }
Miic & gum::learning::Miic::operator= ( Miic &&  from)

move operator

Definition at line 65 of file Miic.cpp.

65  {
66  ApproximationScheme::operator=(std::move(from));
67  return *this;
68  }
INLINE Size gum::ApproximationScheme::periodSize ( ) const
virtualinherited

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 147 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_period_size.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::makeInference(), and gum::learning::genericBNLearner::periodSize().

147 { return _period_size; }
Size _period_size
Checking criteria frequency.

+ Here is the caller graph for this function:

INLINE Size gum::ApproximationScheme::remainingBurnIn ( )
inherited

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 208 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_burn_in, and gum::ApproximationScheme::_current_step.

208  {
209  if (_burn_in > _current_step) {
210  return _burn_in - _current_step;
211  } else {
212  return 0;
213  }
214  }
Size _burn_in
Number of iterations before checking stopping criteria.
Size _current_step
The current step.
void gum::learning::Miic::set3off2Behaviour ( )

Sets the orientation phase to follow the one of the 3off2 algorithm.

Definition at line 1031 of file Miic.cpp.

References __usemiic.

Referenced by gum::learning::genericBNLearner::use3off2().

1031 { this->__usemiic = false; }
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:345

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::setEpsilon ( double  eps)
virtualinherited

Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.

If the criterion was disabled it will be enabled.

Parameters
epsThe new epsilon value.
Exceptions
OutOfLowerBoundRaised if eps < 0.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 41 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps, gum::ApproximationScheme::_eps, and GUM_ERROR.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__mcInitApproximationScheme(), gum::GibbsKL< GUM_SCALAR >::GibbsKL(), gum::GibbsSampling< GUM_SCALAR >::GibbsSampling(), gum::learning::GreedyHillClimbing::GreedyHillClimbing(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::genericBNLearner::setEpsilon().

41  {
42  if (eps < 0.) { GUM_ERROR(OutOfLowerBound, "eps should be >=0"); }
43 
44  _eps = eps;
45  _enabled_eps = true;
46  }
bool _enabled_eps
If true, the threshold convergence is enabled.
double _eps
Threshold for convergence.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::setMaxIter ( Size  max)
virtualinherited

Stopping criterion on number of iterations.

If the criterion was disabled it will be enabled.

Parameters
maxThe maximum number of iterations.
Exceptions
OutOfLowerBoundRaised if max <= 1.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 93 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter, gum::ApproximationScheme::_max_iter, and GUM_ERROR.

Referenced by gum::GibbsKL< GUM_SCALAR >::GibbsKL(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::genericBNLearner::setMaxIter().

93  {
94  if (max < 1) { GUM_ERROR(OutOfLowerBound, "max should be >=1"); }
95  _max_iter = max;
96  _enabled_max_iter = true;
97  }
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.
Size _max_iter
The maximum iterations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::setMaxTime ( double  timeout)
virtualinherited

Stopping criterion on timeout.

If the criterion was disabled it will be enabled.

Parameters
timeoutThe timeout value in seconds.
Exceptions
OutOfLowerBoundRaised if timeout <= 0.0.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 116 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time, gum::ApproximationScheme::_max_time, and GUM_ERROR.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::CNMonteCarloSampling(), gum::GibbsKL< GUM_SCALAR >::GibbsKL(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::genericBNLearner::setMaxTime().

116  {
117  if (timeout <= 0.) { GUM_ERROR(OutOfLowerBound, "timeout should be >0."); }
118  _max_time = timeout;
119  _enabled_max_time = true;
120  }
bool _enabled_max_time
If true, the timeout is enabled.
double _max_time
The timeout.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

void gum::learning::Miic::setMiicBehaviour ( )

Sets the orientation phase to follow the one of the MIIC algorithm.

Definition at line 1030 of file Miic.cpp.

References __usemiic.

Referenced by gum::learning::genericBNLearner::useMIIC().

1030 { this->__usemiic = true; }
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:345

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::setMinEpsilonRate ( double  rate)
virtualinherited

Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).

If the criterion was disabled it will be enabled

Parameters
rateThe minimal epsilon rate.
Exceptions
OutOfLowerBoundif rate<0

Implements gum::IApproximationSchemeConfiguration.

Definition at line 64 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps, gum::ApproximationScheme::_min_rate_eps, and GUM_ERROR.

Referenced by gum::GibbsKL< GUM_SCALAR >::GibbsKL(), gum::GibbsSampling< GUM_SCALAR >::GibbsSampling(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::genericBNLearner::setMinEpsilonRate().

64  {
65  if (rate < 0) { GUM_ERROR(OutOfLowerBound, "rate should be >=0"); }
66 
67  _min_rate_eps = rate;
68  _enabled_min_rate_eps = true;
69  }
bool _enabled_min_rate_eps
If true, the minimal threshold for epsilon rate is enabled.
double _min_rate_eps
Threshold for the epsilon rate.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::setPeriodSize ( Size  p)
virtualinherited

How many samples between two stopping is enable.

Parameters
pThe new period value.
Exceptions
OutOfLowerBoundRaised if p < 1.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 141 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_period_size, and GUM_ERROR.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::CNMonteCarloSampling(), gum::GibbsKL< GUM_SCALAR >::GibbsKL(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::genericBNLearner::setPeriodSize().

141  {
142  if (p < 1) { GUM_ERROR(OutOfLowerBound, "p should be >=1"); }
143 
144  _period_size = p;
145  }
Size _period_size
Checking criteria frequency.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::setVerbosity ( bool  v)
virtualinherited

Set the verbosity on (true) or off (false).

Parameters
vIf true, then verbosity is turned on.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 150 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_verbosity.

Referenced by gum::GibbsKL< GUM_SCALAR >::GibbsKL(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::genericBNLearner::setVerbosity().

150 { _verbosity = v; }
bool _verbosity
If true, verbosity is enabled.

+ Here is the caller graph for this function:

INLINE bool gum::ApproximationScheme::startOfPeriod ( )
inherited

Returns true if we are at the beginning of a period (compute error is mandatory).

Returns
Returns true if we are at the beginning of a period (compute error is mandatory).

Definition at line 195 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_burn_in, gum::ApproximationScheme::_current_step, and gum::ApproximationScheme::_period_size.

Referenced by gum::ApproximationScheme::continueApproximationScheme().

195  {
196  if (_current_step < _burn_in) { return false; }
197 
198  if (_period_size == 1) { return true; }
199 
200  return ((_current_step - _burn_in) % _period_size == 0);
201  }
Size _burn_in
Number of iterations before checking stopping criteria.
Size _current_step
The current step.
Size _period_size
Checking criteria frequency.

+ Here is the caller graph for this function:

INLINE IApproximationSchemeConfiguration::ApproximationSchemeSTATE gum::ApproximationScheme::stateApproximationScheme ( ) const
virtualinherited

Returns the approximation scheme state.

Returns
Returns the approximation scheme state.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 156 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_current_state.

Referenced by gum::ApproximationScheme::continueApproximationScheme(), gum::ApproximationScheme::history(), gum::ApproximationScheme::nbrIterations(), and gum::learning::genericBNLearner::stateApproximationScheme().

156  {
157  return _current_state;
158  }
ApproximationSchemeSTATE _current_state
The current state.

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::stopApproximationScheme ( )
inherited

Stop the approximation scheme.

Definition at line 217 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_current_state, gum::ApproximationScheme::_stopScheme(), gum::IApproximationSchemeConfiguration::Continue, and gum::IApproximationSchemeConfiguration::Stopped.

Referenced by gum::learning::GreedyHillClimbing::learnStructure(), and gum::learning::LocalSearchWithTabuList::learnStructure().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE void gum::ApproximationScheme::updateApproximationScheme ( unsigned int  incr = 1)
inherited

Update the scheme w.r.t the new error and increment steps.

Parameters
incrThe new increment steps.

Definition at line 204 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_current_step.

Referenced by gum::GibbsKL< GUM_SCALAR >::_computeKL(), gum::SamplingInference< GUM_SCALAR >::_loopApproxInference(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), and gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::makeInference().

204  {
205  _current_step += incr;
206  }
Size _current_step
The current step.

+ Here is the caller graph for this function:

INLINE bool gum::ApproximationScheme::verbosity ( ) const
virtualinherited

Returns true if verbosity is enabled.

Returns
Returns true if verbosity is enabled.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 152 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_verbosity.

Referenced by gum::ApproximationScheme::continueApproximationScheme(), gum::ApproximationScheme::history(), and gum::learning::genericBNLearner::verbosity().

152 { return _verbosity; }
bool _verbosity
If true, verbosity is enabled.

+ Here is the caller graph for this function:

Member Data Documentation

ArcProperty< double > gum::learning::Miic::__arc_probas
private

Storing the propabilities for each arc set in the graph.

Definition at line 348 of file Miic.h.

Referenced by _orientation_miic().

const std::vector< Idx > gum::learning::Miic::__empty_set
private

an empty conditioning set

Definition at line 338 of file Miic.h.

Referenced by _initiation().

HashTable< std::pair< Idx, Idx >, char > gum::learning::Miic::__initial_marks
private

Initial marks for the orientation phase, used to convey constraints.

Definition at line 351 of file Miic.h.

Referenced by _orientation_3off2(), _orientation_miic(), _propagatesHead(), and addConstraints().

std::vector< Arc > gum::learning::Miic::__latent_couples
private

an empty vector of arcs

Definition at line 340 of file Miic.h.

Referenced by _orientation_3off2(), _orientation_latents(), _orientation_miic(), _propagatesHead(), latentVariables(), and learnMixedStructure().

int gum::learning::Miic::__maxLog = 100
private

Fixes the maximum log that we accept in exponential computations.

Definition at line 336 of file Miic.h.

Referenced by _findBestContributor().

Size gum::learning::Miic::__N
private

size of the database

Definition at line 343 of file Miic.h.

Referenced by _findBestContributor(), and _updateProbaTriples().

bool gum::learning::Miic::__usemiic {false}
private

wether to use the miic algorithm or not

Definition at line 345 of file Miic.h.

Referenced by learnMixedStructure(), set3off2Behaviour(), and setMiicBehaviour().

double gum::ApproximationScheme::_current_epsilon
protectedinherited
double gum::ApproximationScheme::_current_rate
protectedinherited
bool gum::ApproximationScheme::_enabled_max_iter
protectedinherited
bool gum::ApproximationScheme::_enabled_min_rate_eps
protectedinherited
double gum::ApproximationScheme::_eps
protectedinherited
std::vector< double > gum::ApproximationScheme::_history
protectedinherited
double gum::ApproximationScheme::_last_epsilon
protectedinherited

Last epsilon value.

Definition at line 371 of file approximationScheme.h.

Referenced by gum::ApproximationScheme::continueApproximationScheme().

Size gum::ApproximationScheme::_max_iter
protectedinherited
double gum::ApproximationScheme::_max_time
protectedinherited
double gum::ApproximationScheme::_min_rate_eps
protectedinherited
Size gum::ApproximationScheme::_period_size
protectedinherited
bool gum::ApproximationScheme::_verbosity
protectedinherited

If true, verbosity is enabled.

Definition at line 419 of file approximationScheme.h.

Referenced by gum::ApproximationScheme::setVerbosity(), and gum::ApproximationScheme::verbosity().

Signaler3< Size, double, double > gum::IApproximationSchemeConfiguration::onProgress
inherited
Signaler1< std::string > gum::IApproximationSchemeConfiguration::onStop
inherited

Criteria messageApproximationScheme.

Definition at line 61 of file IApproximationSchemeConfiguration.h.

Referenced by gum::ApproximationScheme::_stopScheme(), and gum::learning::genericBNLearner::distributeStop().


The documentation for this class was generated from the following files: