aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
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 >
BayesNet< GUM_SCALAR > learnBN (GRAPH_CHANGES_SELECTOR &selector, PARAM_ESTIMATOR &estimator, 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< NodeId, NodeId >, 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 (NodeId x, NodeId y, const std::vector< NodeId > &ui, const MixedGraph &graph, CorrectedMutualInformation<> &I, Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double >, GreaterPairOn2nd > &_rank)
 finds the best contributor node for a pair given a conditioning set More...
 
std::vector< std::pair< std::tuple< NodeId, NodeId, NodeId > *, double > > _getUnshieldedTriples (const MixedGraph &graph, CorrectedMutualInformation<> &I, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &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< NodeId, NodeId, NodeId > *, double, double, double > > _getUnshieldedTriplesMIIC (const MixedGraph &graph, CorrectedMutualInformation<> &I, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sep_set, HashTable< std::pair< NodeId, NodeId >, 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< NodeId, NodeId, NodeId > *, double, double, double > > _updateProbaTriples (const MixedGraph &graph, std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId > *, 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< NodeId, NodeId >, std::vector< NodeId > > &sep_set, Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double >, GreaterPairOn2nd > &_rank)
 Initiation phase. More...
 
void _iteration (CorrectedMutualInformation<> &I, MixedGraph &graph, HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sep_set, Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double >, GreaterPairOn2nd > &_rank)
 Iteration phase. More...
 
void _orientation_3off2 (CorrectedMutualInformation<> &I, MixedGraph &graph, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sep_set)
 Orientation phase from the 3off2 algorithm, returns a CPDAG. More...
 
void _orientation_latents (CorrectedMutualInformation<> &I, MixedGraph &graph, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &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< NodeId, NodeId >, std::vector< NodeId > > &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 106 of file Miic.h.

Member Enumeration Documentation

◆ ApproximationSchemeSTATE

The different state of an approximation scheme.

Enumerator
Undefined 
Continue 
Epsilon 
Rate 
Limit 
TimeLimit 
Stopped 

Definition at line 65 of file IApproximationSchemeConfiguration.h.

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

Constructor & Destructor Documentation

◆ Miic() [1/4]

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

default constructor

Definition at line 43 of file Miic.cpp.

43 { GUM_CONSTRUCTOR(Miic); }
Miic()
default constructor
Definition: Miic.cpp:43

◆ Miic() [2/4]

gum::learning::Miic::Miic ( int  maxLog)

default constructor with maxLog

Definition at line 46 of file Miic.cpp.

46 : __maxLog(maxLog) { GUM_CONSTRUCTOR(Miic); }
Miic()
default constructor
Definition: Miic.cpp:43
int __maxLog
Fixes the maximum log that we accept in exponential computations.
Definition: Miic.h:350

◆ Miic() [3/4]

gum::learning::Miic::Miic ( const Miic from)

copy constructor

Definition at line 49 of file Miic.cpp.

49  : ApproximationScheme(from) {
50  GUM_CONS_CPY(Miic);
51  }
ApproximationScheme(bool verbosity=false)
Miic()
default constructor
Definition: Miic.cpp:43

◆ Miic() [4/4]

gum::learning::Miic::Miic ( Miic &&  from)

move constructor

Definition at line 54 of file Miic.cpp.

54  : ApproximationScheme(std::move(from)) {
55  GUM_CONS_MOV(Miic);
56  }
ApproximationScheme(bool verbosity=false)
Miic()
default constructor
Definition: Miic.cpp:43

◆ ~Miic()

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

destructor

Definition at line 59 of file Miic.cpp.

59 { GUM_DESTRUCTOR(Miic); }
Miic()
default constructor
Definition: Miic.cpp:43

Member Function Documentation

◆ __existsDirectedPath()

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 1072 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().

1074  {
1075  // not recursive version => use a FIFO for simulating the recursion
1076  List< NodeId > nodeFIFO;
1077  nodeFIFO.pushBack(n2);
1078 
1079  // mark[node] = successor if visited, else mark[node] does not exist
1080  NodeProperty< NodeId > mark;
1081  mark.insert(n2, n2);
1082 
1083  NodeId current;
1084 
1085  while (!nodeFIFO.empty()) {
1086  current = nodeFIFO.front();
1087  nodeFIFO.popFront();
1088 
1089  // check the parents
1090 
1091  for (const auto new_one: graph.parents(current)) {
1092  if (mark.exists(new_one)) // if this node is already marked, do not
1093  continue; // check it again
1094 
1095  if (graph.existsArc(current,
1096  new_one)) // if there is a double arc, pass
1097  continue;
1098 
1099  mark.insert(new_one, current);
1100 
1101  if (new_one == n1) { return true; }
1102 
1103  nodeFIFO.pushBack(new_one);
1104  }
1105  }
1106 
1107  return false;
1108  }
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _findBestContributor()

void gum::learning::Miic::_findBestContributor ( NodeId  x,
NodeId  y,
const std::vector< NodeId > &  ui,
const MixedGraph graph,
CorrectedMutualInformation<> &  I,
Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, 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 764 of file Miic.cpp.

References __maxLog, M_LN2, and gum::learning::CorrectedMutualInformation< ALLOC >::score().

Referenced by _initiation(), and _iteration().

773  {
774  double maxP = -1.0;
775  NodeId maxZ = 0;
776 
777  // compute N
778  //__N = I.N();
779  const double Ixy_ui = I.score(x, y, ui);
780 
781  for (const NodeId z: graph) {
782  // if z!=x and z!=y and z not in ui
783  if (z != x && z != y && std::find(ui.begin(), ui.end(), z) == ui.end()) {
784  double Pnv;
785  double Pb;
786 
787  // Computing Pnv
788  const double Ixyz_ui = I.score(x, y, z, ui);
789  double calc_expo1 = -Ixyz_ui * M_LN2;
790  // if exponentials are too high or to low, crop them at |__maxLog|
791  if (calc_expo1 > __maxLog) {
792  Pnv = 0.0;
793  } else if (calc_expo1 < -__maxLog) {
794  Pnv = 1.0;
795  } else {
796  Pnv = 1 / (1 + std::exp(calc_expo1));
797  }
798 
799  // Computing Pb
800  const double Ixz_ui = I.score(x, z, ui);
801  const double Iyz_ui = I.score(y, z, ui);
802 
803  calc_expo1 = -(Ixz_ui - Ixy_ui) * M_LN2;
804  double calc_expo2 = -(Iyz_ui - Ixy_ui) * M_LN2;
805 
806  // if exponentials are too high or to low, crop them at __maxLog
807  if (calc_expo1 > __maxLog || calc_expo2 > __maxLog) {
808  Pb = 0.0;
809  } else if (calc_expo1 < -__maxLog && calc_expo2 < -__maxLog) {
810  Pb = 1.0;
811  } else {
812  double expo1, expo2;
813  if (calc_expo1 < -__maxLog) {
814  expo1 = 0.0;
815  } else {
816  expo1 = std::exp(calc_expo1);
817  }
818  if (calc_expo2 < -__maxLog) {
819  expo2 = 0.0;
820  } else {
821  expo2 = std::exp(calc_expo2);
822  }
823  Pb = 1 / (1 + expo1 + expo2);
824  }
825 
826  // Getting max(min(Pnv, pb))
827  const double min_pnv_pb = std::min(Pnv, Pb);
828  if (min_pnv_pb > maxP) {
829  maxP = min_pnv_pb;
830  maxZ = z;
831  }
832  } // if z not in (x, y)
833  } // for z in graph.nodes
834  // storing best z in _rank
835  std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
836  double >
837  final;
838  auto tup = new std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >{
839  x, y, maxZ, ui};
840  final.first = tup;
841  final.second = maxP;
842  _rank.insert(final);
843  }
#define M_LN2
Definition: math.h:44
int __maxLog
Fixes the maximum log that we accept in exponential computations.
Definition: Miic.h:350
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getUnshieldedTriples()

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

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

Definition at line 848 of file Miic.cpp.

References gum::learning::CorrectedMutualInformation< ALLOC >::score().

Referenced by _orientation_3off2(), and _orientation_latents().

852  {
853  std::vector< std::pair< std::tuple< NodeId, NodeId, NodeId >*, double > >
854  triples;
855  for (NodeId z: graph) {
856  for (NodeId x: graph.neighbours(z)) {
857  for (NodeId y: graph.neighbours(z)) {
858  if (y < x && !graph.existsEdge(x, y)) {
859  std::vector< NodeId > ui;
860  std::pair< NodeId, NodeId > key = {x, y};
861  std::pair< NodeId, NodeId > rev_key = {y, x};
862  if (sep_set.exists(key)) {
863  ui = sep_set[key];
864  } else if (sep_set.exists(rev_key)) {
865  ui = sep_set[rev_key];
866  }
867  // remove z from ui if it's present
868  const auto iter_z_place = std::find(ui.begin(), ui.end(), z);
869  if (iter_z_place != ui.end()) { ui.erase(iter_z_place); }
870 
871  double Ixyz_ui = I.score(x, y, z, ui);
872  std::pair< std::tuple< NodeId, NodeId, NodeId >*, double > triple;
873  auto tup = new std::tuple< NodeId, NodeId, NodeId >{x, y, z};
874  triple.first = tup;
875  triple.second = Ixyz_ui;
876  triples.push_back(triple);
877  }
878  }
879  }
880  }
881  std::sort(triples.begin(), triples.end(), GreaterAbsPairOn2nd());
882  return triples;
883  }
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getUnshieldedTriplesMIIC()

std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId > *, double, double, double > > gum::learning::Miic::_getUnshieldedTriplesMIIC ( const MixedGraph graph,
CorrectedMutualInformation<> &  I,
const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &  sep_set,
HashTable< std::pair< NodeId, NodeId >, 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 890 of file Miic.cpp.

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

Referenced by _orientation_miic().

895  {
896  std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
897  double,
898  double,
899  double > >
900  triples;
901  for (NodeId z: graph) {
902  for (NodeId x: graph.neighbours(z)) {
903  for (NodeId y: graph.neighbours(z)) {
904  if (y < x && !graph.existsEdge(x, y)) {
905  std::vector< NodeId > ui;
906  std::pair< NodeId, NodeId > key = {x, y};
907  std::pair< NodeId, NodeId > rev_key = {y, x};
908  if (sep_set.exists(key)) {
909  ui = sep_set[key];
910  } else if (sep_set.exists(rev_key)) {
911  ui = sep_set[rev_key];
912  }
913  // remove z from ui if it's present
914  const auto iter_z_place = std::find(ui.begin(), ui.end(), z);
915  if (iter_z_place != ui.end()) { ui.erase(iter_z_place); }
916 
917  const double Ixyz_ui = I.score(x, y, z, ui);
918  auto tup = new std::tuple< NodeId, NodeId, NodeId >{x, y, z};
919  std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
920  double,
921  double,
922  double >
923  triple{tup, Ixyz_ui, 0.5, 0.5};
924  triples.push_back(triple);
925  if (!marks.exists({x, z})) { marks.insert({x, z}, 'o'); }
926  if (!marks.exists({z, x})) { marks.insert({z, x}, 'o'); }
927  if (!marks.exists({y, z})) { marks.insert({y, z}, 'o'); }
928  if (!marks.exists({z, y})) { marks.insert({z, y}, 'o'); }
929  }
930  }
931  }
932  }
933  triples = _updateProbaTriples(graph, triples);
934  std::sort(triples.begin(), triples.end(), GreaterTupleOnLast());
935  return triples;
936  }
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< NodeId, NodeId, NodeId > *, double, double, double > > _updateProbaTriples(const MixedGraph &graph, std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId > *, double, double, double > > proba_triples)
Gets the orientation probabilities like MIIC for the orientation phase.
Definition: Miic.cpp:942
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _initiation()

void gum::learning::Miic::_initiation ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &  sep_set,
Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, 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 150 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< ALLOC >::score(), gum::Set< Key, Alloc >::size(), and gum::Timer::step().

Referenced by learnMixedStructure().

157  {
158  NodeId x, y;
159  EdgeSet edges = graph.edges();
160  Size steps_init = edges.size();
161 
162  for (const Edge& edge: edges) {
163  x = edge.first();
164  y = edge.second();
165  double Ixy = I.score(x, y);
166 
167  if (Ixy <= 0) { //< K
168  graph.eraseEdge(edge);
169  sep_set.insert(std::make_pair(x, y), __empty_set);
170  } else {
171  _findBestContributor(x, y, __empty_set, graph, I, _rank);
172  }
173 
174  ++_current_step;
175  if (onProgress.hasListener()) {
176  GUM_EMIT3(
177  onProgress, (_current_step * 33) / steps_init, 0., _timer.step());
178  }
179  }
180  }
void _findBestContributor(NodeId x, NodeId y, const std::vector< NodeId > &ui, const MixedGraph &graph, CorrectedMutualInformation<> &I, Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double >, GreaterPairOn2nd > &_rank)
finds the best contributor node for a pair given a conditioning set
Definition: Miic.cpp:764
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:42
Signaler3< Size, double, double > onProgress
Progression, error and time.
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size _current_step
The current step.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
const std::vector< NodeId > __empty_set
an empty conditioning set
Definition: Miic.h:352
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:42
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _iteration()

void gum::learning::Miic::_iteration ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &  sep_set,
Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, 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 188 of file Miic.cpp.

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

Referenced by learnMixedStructure().

195  {
196  // if no triples to further examine pass
197  std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
198  double >
199  best;
200 
201  Size steps_init = _current_step;
202  Size steps_iter = _rank.size();
203 
204  try {
205  while (_rank.top().second > 0.5) {
206  best = _rank.pop();
207 
208  const NodeId x = std::get< 0 >(*(best.first));
209  const NodeId y = std::get< 1 >(*(best.first));
210  const NodeId z = std::get< 2 >(*(best.first));
211  std::vector< NodeId > ui = std::move(std::get< 3 >(*(best.first)));
212 
213  ui.push_back(z);
214  const double Ixy_ui = I.score(x, y, ui);
215  if (Ixy_ui < 0) {
216  graph.eraseEdge(Edge(x, y));
217  sep_set.insert(std::make_pair(x, y), std::move(ui));
218  } else {
219  _findBestContributor(x, y, ui, graph, I, _rank);
220  }
221 
222  delete best.first;
223 
224  ++_current_step;
225  if (onProgress.hasListener()) {
227  (_current_step * 66) / (steps_init + steps_iter),
228  0.,
229  _timer.step());
230  }
231  }
232  } catch (...) {} // here, rank is empty
233  _current_step = steps_init + steps_iter;
234  if (onProgress.hasListener()) {
235  GUM_EMIT3(onProgress, 66, 0., _timer.step());
236  }
237  _current_step = steps_init + steps_iter;
238  }
void _findBestContributor(NodeId x, NodeId y, const std::vector< NodeId > &ui, const MixedGraph &graph, CorrectedMutualInformation<> &I, Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double >, GreaterPairOn2nd > &_rank)
finds the best contributor node for a pair given a conditioning set
Definition: Miic.cpp:764
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:42
Signaler3< Size, double, double > onProgress
Progression, error and time.
Size _current_step
The current step.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:42
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _orientation_3off2()

void gum::learning::Miic::_orientation_3off2 ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &  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 245 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().

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

◆ _orientation_latents()

void gum::learning::Miic::_orientation_latents ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &  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 433 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().

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

◆ _orientation_miic()

void gum::learning::Miic::_orientation_miic ( CorrectedMutualInformation<> &  I,
MixedGraph graph,
const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &  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 585 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().

588  {
589  // structure to store the orientations marks -, o, or >,
590  // Considers the head of the arc/edge first node -* second node
591  HashTable< std::pair< NodeId, NodeId >, char > marks = __initial_marks;
592 
593  // marks always correspond to the head of the arc/edge. - is for a forbidden
594  // arc, > for a mandatory arc
595  // we start by adding the mandatory arcs
596  for (auto iter = marks.begin(); iter != marks.end(); ++iter) {
597  if (graph.existsEdge(iter.key().first, iter.key().second)
598  && iter.val() == '>') {
599  graph.eraseEdge(Edge(iter.key().first, iter.key().second));
600  graph.addArc(iter.key().first, iter.key().second);
601  }
602  }
603 
604  std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
605  double,
606  double,
607  double > >
608  proba_triples = _getUnshieldedTriplesMIIC(graph, I, sep_set, marks);
609 
610  Size steps_orient = proba_triples.size();
611  Size past_steps = _current_step;
612 
613  std::tuple< std::tuple< NodeId, NodeId, NodeId >*, double, double, double >
614  best;
615  if (steps_orient > 0) { best = proba_triples[0]; }
616 
617  while (!proba_triples.empty()
618  && std::max(std::get< 2 >(best), std::get< 3 >(best)) > 0.5) {
619  NodeId x, y, z;
620  x = std::get< 0 >(*std::get< 0 >(best));
621  y = std::get< 1 >(*std::get< 0 >(best));
622  z = std::get< 2 >(*std::get< 0 >(best));
623 
624  const double i3 = std::get< 1 >(best);
625 
626  if (i3 <= 0) {
627  // v-structure discovery
628  if (marks[{x, z}] == 'o' && marks[{y, z}] == 'o') {
629  graph.eraseEdge(Edge(x, z));
630  graph.eraseEdge(Edge(y, z));
631  graph.addArc(x, z);
632  graph.addArc(y, z);
633  marks[{x, z}] = '>';
634  marks[{y, z}] = '>';
635  if (graph.existsArc(z, x)
636  && std::find(
637  __latent_couples.begin(), __latent_couples.end(), Arc(z, x))
638  == __latent_couples.end()
639  && std::find(
640  __latent_couples.begin(), __latent_couples.end(), Arc(x, z))
641  == __latent_couples.end()) {
642  __latent_couples.push_back(Arc(z, x));
643  }
644  if (graph.existsArc(z, y)
645  && std::find(
646  __latent_couples.begin(), __latent_couples.end(), Arc(z, y))
647  == __latent_couples.end()
648  && std::find(
649  __latent_couples.begin(), __latent_couples.end(), Arc(y, z))
650  == __latent_couples.end()) {
651  __latent_couples.push_back(Arc(z, y));
652  }
653  if (!__arc_probas.exists(Arc(x, z)))
654  __arc_probas.insert(Arc(x, z), std::get< 2 >(best));
655  if (!__arc_probas.exists(Arc(y, z)))
656  __arc_probas.insert(Arc(y, z), std::get< 3 >(best));
657  } else if (marks[{x, z}] == '>' && marks[{y, z}] == 'o') {
658  graph.eraseEdge(Edge(y, z));
659  graph.addArc(y, z);
660  marks[{y, z}] = '>';
661  if (graph.existsArc(z, y)
662  && std::find(
663  __latent_couples.begin(), __latent_couples.end(), Arc(z, y))
664  == __latent_couples.end()
665  && std::find(
666  __latent_couples.begin(), __latent_couples.end(), Arc(y, z))
667  == __latent_couples.end()) {
668  __latent_couples.push_back(Arc(z, y));
669  }
670  if (!__arc_probas.exists(Arc(y, z)))
671  __arc_probas.insert(Arc(y, z), std::get< 3 >(best));
672  } else if (marks[{y, z}] == '>' && marks[{x, z}] == 'o') {
673  graph.eraseEdge(Edge(x, z));
674  graph.addArc(x, z);
675  marks[{x, z}] = '>';
676  if (graph.existsArc(z, x)
677  && std::find(
678  __latent_couples.begin(), __latent_couples.end(), Arc(z, x))
679  == __latent_couples.end()
680  && std::find(
681  __latent_couples.begin(), __latent_couples.end(), Arc(x, z))
682  == __latent_couples.end()) {
683  __latent_couples.push_back(Arc(z, x));
684  }
685  if (!__arc_probas.exists(Arc(x, z)))
686  __arc_probas.insert(Arc(x, z), std::get< 2 >(best));
687  }
688 
689  } else {
690  // orientation propagation
691  if (marks[{x, z}] == '>' && marks[{y, z}] == 'o'
692  && marks[{z, y}] != '-') {
693  graph.eraseEdge(Edge(z, y));
694  if (!__existsDirectedPath(graph, y, z) && graph.parents(y).empty()) {
695  graph.addArc(z, y);
696  marks[{z, y}] = '>';
697  marks[{y, z}] = '-';
698  if (!__arc_probas.exists(Arc(z, y)))
699  __arc_probas.insert(Arc(z, y), std::get< 3 >(best));
700  } else if (!__existsDirectedPath(graph, z, y)
701  && graph.parents(z).empty()) {
702  graph.addArc(y, z);
703  marks[{z, y}] = '-';
704  marks[{y, z}] = '>';
705  __latent_couples.push_back(Arc(y, z));
706  if (!__arc_probas.exists(Arc(y, z)))
707  __arc_probas.insert(Arc(y, z), std::get< 3 >(best));
708  }
709  } else if (marks[{y, z}] == '>' && marks[{x, z}] == 'o'
710  && marks[{z, x}] != '-') {
711  graph.eraseEdge(Edge(z, x));
712  if (!__existsDirectedPath(graph, x, z) && graph.parents(x).empty()) {
713  graph.addArc(z, x);
714  marks[{z, x}] = '>';
715  marks[{x, z}] = '-';
716  if (!__arc_probas.exists(Arc(z, x)))
717  __arc_probas.insert(Arc(z, x), std::get< 2 >(best));
718  } else if (!__existsDirectedPath(graph, z, x)
719  && graph.parents(z).empty()) {
720  graph.addArc(x, z);
721  marks[{z, x}] = '-';
722  marks[{x, z}] = '>';
723  __latent_couples.push_back(Arc(x, z));
724  if (!__arc_probas.exists(Arc(x, z)))
725  __arc_probas.insert(Arc(x, z), std::get< 2 >(best));
726  }
727  }
728  }
729 
730  delete std::get< 0 >(best);
731  proba_triples.erase(proba_triples.begin());
732  // actualisation of the list of triples
733  proba_triples = _updateProbaTriples(graph, proba_triples);
734 
735  best = proba_triples[0];
736 
737  ++_current_step;
738  if (onProgress.hasListener()) {
740  (_current_step * 100) / (steps_orient + past_steps),
741  0.,
742  _timer.step());
743  }
744  } // while
745 
746  // erasing the double headed arcs
747  for (auto iter = __latent_couples.rbegin(); iter != __latent_couples.rend();
748  ++iter) {
749  graph.eraseArc(Arc(iter->head(), iter->tail()));
750  if (__existsDirectedPath(graph, iter->head(), iter->tail())) {
751  // if we find a cycle, we force the competing edge
752  graph.addArc(iter->head(), iter->tail());
753  graph.eraseArc(Arc(iter->tail(), iter->head()));
754  *iter = Arc(iter->head(), iter->tail());
755  }
756  }
757 
758  if (onProgress.hasListener()) {
759  GUM_EMIT3(onProgress, 100, 0., _timer.step());
760  }
761  }
ArcProperty< double > __arc_probas
Storing the propabilities for each arc set in the graph.
Definition: Miic.h:362
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:42
Signaler3< Size, double, double > onProgress
Progression, error and time.
HashTable< std::pair< NodeId, NodeId >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:365
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:354
std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId > *, double, double, double > > _getUnshieldedTriplesMIIC(const MixedGraph &graph, CorrectedMutualInformation<> &I, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sep_set, HashTable< std::pair< NodeId, NodeId >, char > &marks)
gets the list of unshielded triples in the graph in decreasing value of |I&#39;(x, y, z|{ui})|...
Definition: Miic.cpp:890
Size _current_step
The current step.
std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId > *, double, double, double > > _updateProbaTriples(const MixedGraph &graph, std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId > *, double, double, double > > proba_triples)
Gets the orientation probabilities like MIIC for the orientation phase.
Definition: Miic.cpp:942
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:1072
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:42
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _propagatesHead()

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

Propagates the orientation from a node to its neighbours.

Definition at line 1018 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().

1018  {
1019  const auto neighbours = graph.neighbours(node);
1020  for (auto& neighbour: neighbours) {
1021  // only propagate if it doesn't create a circle and isn't forbidden
1022  // and doesn't create a new v-structure
1023  if (!__existsDirectedPath(graph, neighbour, node)
1024  && !(__initial_marks.exists({node, neighbour})
1025  && __initial_marks[{node, neighbour}] == '-')
1026  && graph.parents(neighbour).empty()) {
1027  graph.eraseEdge(Edge(neighbour, node));
1028  graph.addArc(node, neighbour);
1029  _propagatesHead(graph, neighbour);
1030  } else if (!__existsDirectedPath(graph, node, neighbour)
1031  && !(__initial_marks.exists({neighbour, node})
1032  && __initial_marks[{neighbour, node}] == '-')
1033  && graph.parents(node).empty()) {
1034  graph.eraseEdge(Edge(neighbour, node));
1035  graph.addArc(neighbour, node);
1036  } else if (!graph.parents(neighbour).empty()
1037  && !graph.parents(node).empty()) {
1038  graph.eraseEdge(Edge(neighbour, node));
1039  graph.addArc(node, neighbour);
1040  __latent_couples.push_back(Arc(node, neighbour));
1041  } else {
1042  graph.eraseEdge(Edge(neighbour, node));
1043  }
1044  }
1045  }
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:1018
HashTable< std::pair< NodeId, NodeId >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:365
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:354
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:1072
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _updateProbaTriples()

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

Gets the orientation probabilities like MIIC for the orientation phase.

Definition at line 942 of file Miic.cpp.

References gum::ArcGraphPart::existsArc().

Referenced by _getUnshieldedTriplesMIIC(), and _orientation_miic().

947  {
948  for (auto& triple: proba_triples) {
949  NodeId x, y, z;
950  x = std::get< 0 >(*std::get< 0 >(triple));
951  y = std::get< 1 >(*std::get< 0 >(triple));
952  z = std::get< 2 >(*std::get< 0 >(triple));
953  const double Ixyz = std::get< 1 >(triple);
954  double Pxz = std::get< 2 >(triple);
955  double Pyz = std::get< 3 >(triple);
956 
957  if (Ixyz <= 0) {
958  const double expo = std::exp(Ixyz);
959  const double P0 = (1 + expo) / (1 + 3 * expo);
960  // distinguish betweeen the initialization and the update process
961  if (Pxz == Pyz && Pyz == 0.5) {
962  std::get< 2 >(triple) = P0;
963  std::get< 3 >(triple) = P0;
964  } else {
965  if (graph.existsArc(x, z) && Pxz >= P0) {
966  std::get< 3 >(triple) = Pxz * (1 / (1 + expo) - 0.5) + 0.5;
967  } else if (graph.existsArc(y, z) && Pyz >= P0) {
968  std::get< 2 >(triple) = Pyz * (1 / (1 + expo) - 0.5) + 0.5;
969  }
970  }
971  } else {
972  const double expo = std::exp(-Ixyz);
973  if (graph.existsArc(x, z) && Pxz >= 0.5) {
974  std::get< 3 >(triple) = Pxz * (1 / (1 + expo) - 0.5) + 0.5;
975  } else if (graph.existsArc(y, z) && Pyz >= 0.5) {
976  std::get< 2 >(triple) = Pyz * (1 / (1 + expo) - 0.5) + 0.5;
977  }
978  }
979  }
980  std::sort(proba_triples.begin(), proba_triples.end(), GreaterTupleOnLast());
981  return proba_triples;
982  }
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addConstraints()

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

Set a ensemble of constraints for the orientation phase.

Definition at line 1066 of file Miic.cpp.

References __initial_marks.

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

1067  {
1068  this->__initial_marks = constraints;
1069  }
HashTable< std::pair< NodeId, NodeId >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:365
+ Here is the caller graph for this function:

◆ continueApproximationScheme()

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 227 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::GibbsBNdistance< GUM_SCALAR >::_computeKL(), gum::SamplingInference< GUM_SCALAR >::_loopApproxInference(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), and gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::makeInference().

227  {
228  // For coherence, we fix the time used in the method
229 
230  double timer_step = _timer.step();
231 
232  if (_enabled_max_time) {
233  if (timer_step > _max_time) {
235  return false;
236  }
237  }
238 
239  if (!startOfPeriod()) { return true; }
240 
242  GUM_ERROR(OperationNotAllowed,
243  "state of the approximation scheme is not correct : "
245  }
246 
247  if (verbosity()) { _history.push_back(error); }
248 
249  if (_enabled_max_iter) {
250  if (_current_step > _max_iter) {
252  return false;
253  }
254  }
255 
257  _current_epsilon = error; // eps rate isEnabled needs it so affectation was
258  // moved from eps isEnabled below
259 
260  if (_enabled_eps) {
261  if (_current_epsilon <= _eps) {
263  return false;
264  }
265  }
266 
267  if (_last_epsilon >= 0.) {
268  if (_current_epsilon > .0) {
269  // ! _current_epsilon can be 0. AND epsilon
270  // isEnabled can be disabled !
271  _current_rate =
273  }
274  // limit with current eps ---> 0 is | 1 - ( last_eps / 0 ) | --->
275  // infinity the else means a return false if we isEnabled the rate below,
276  // as we would have returned false if epsilon isEnabled was enabled
277  else {
279  }
280 
281  if (_enabled_min_rate_eps) {
282  if (_current_rate <= _min_rate_eps) {
284  return false;
285  }
286  }
287  }
288 
290  if (onProgress.hasListener()) {
292  }
293 
294  return true;
295  } else {
296  return false;
297  }
298  }
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:42
Signaler3< Size, double, double > onProgress
Progression, error and time.
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.
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 _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.
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
bool verbosity() const
Returns true if verbosity is enabled.
std::string messageApproximationScheme() const
Returns the approximation scheme message.
double _last_epsilon
Last epsilon value.
Size _max_iter
The maximum iterations.
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:42
ApproximationSchemeSTATE _current_state
The current state.
double _max_time
The timeout.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ currentTime()

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 128 of file approximationScheme_inl.h.

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

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

128 { return _timer.step(); }
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disableEpsilon()

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

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 54 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

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

54 { _enabled_eps = false; }
bool _enabled_eps
If true, the threshold convergence is enabled.
+ Here is the caller graph for this function:

◆ disableMaxIter()

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

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 105 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().

105 { _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:

◆ disableMaxTime()

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

Disable stopping criterion on timeout.

Returns
Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 131 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

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

131 { _enabled_max_time = false; }
bool _enabled_max_time
If true, the timeout is enabled.
+ Here is the caller graph for this function:

◆ disableMinEpsilonRate()

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

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 79 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

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

79  {
80  _enabled_min_rate_eps = false;
81  }
bool _enabled_min_rate_eps
If true, the minimal threshold for epsilon rate is enabled.
+ Here is the caller graph for this function:

◆ enableEpsilon()

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

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 57 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

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

57 { _enabled_eps = true; }
bool _enabled_eps
If true, the threshold convergence is enabled.
+ Here is the caller graph for this function:

◆ enableMaxIter()

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

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 108 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

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

108 { _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:

◆ enableMaxTime()

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

Enable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 134 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().

134 { _enabled_max_time = true; }
bool _enabled_max_time
If true, the timeout is enabled.
+ Here is the caller graph for this function:

◆ enableMinEpsilonRate()

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

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 84 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

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

84  {
85  _enabled_min_rate_eps = true;
86  }
bool _enabled_min_rate_eps
If true, the minimal threshold for epsilon rate is enabled.
+ Here is the caller graph for this function:

◆ epsilon()

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

Returns the value of epsilon.

Returns
Returns the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 51 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_eps.

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

51 { return _eps; }
double _eps
Threshold for convergence.
+ Here is the caller graph for this function:

◆ history()

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 173 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().

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

◆ initApproximationScheme()

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

Initialise the scheme.

Definition at line 187 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::GibbsBNdistance< GUM_SCALAR >::_computeKL(), gum::SamplingInference< GUM_SCALAR >::_loopApproxInference(), gum::SamplingInference< GUM_SCALAR >::_onStateChanged(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::learning::GreedyHillClimbing::learnStructure(), and gum::learning::LocalSearchWithTabuList::learnStructure().

187  {
189  _current_step = 0;
191  _history.clear();
192  _timer.reset();
193  }
double _current_epsilon
Current epsilon.
void reset()
Reset the timer.
Definition: timer_inl.h:32
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:

◆ isEnabledEpsilon()

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 61 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

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

61  {
62  return _enabled_eps;
63  }
bool _enabled_eps
If true, the threshold convergence is enabled.
+ Here is the caller graph for this function:

◆ isEnabledMaxIter()

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 112 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

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

112  {
113  return _enabled_max_iter;
114  }
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.
+ Here is the caller graph for this function:

◆ isEnabledMaxTime()

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 138 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

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

138  {
139  return _enabled_max_time;
140  }
bool _enabled_max_time
If true, the timeout is enabled.
+ Here is the caller graph for this function:

◆ isEnabledMinEpsilonRate()

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 90 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

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

90  {
91  return _enabled_min_rate_eps;
92  }
bool _enabled_min_rate_eps
If true, the minimal threshold for epsilon rate is enabled.
+ Here is the caller graph for this function:

◆ latentVariables()

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

get the list of arcs hiding latent variables

Definition at line 1048 of file Miic.cpp.

References __latent_couples.

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

1048  {
1049  return __latent_couples;
1050  }
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:354
+ Here is the caller graph for this function:

◆ learnBN()

template<typename GUM_SCALAR , typename GRAPH_CHANGES_SELECTOR , typename PARAM_ESTIMATOR >
BayesNet< GUM_SCALAR > gum::learning::Miic::learnBN ( GRAPH_CHANGES_SELECTOR &  selector,
PARAM_ESTIMATOR &  estimator,
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 1056 of file Miic.cpp.

References learnStructure().

1058  {
1059  return DAG2BNLearner<>::createBN< GUM_SCALAR >(
1060  estimator, learnStructure(selector, initial_dag));
1061  }
static BayesNet< GUM_SCALAR > createBN(ParamEstimator< ALLOC > &estimator, const DAG &dag)
create a BN from a DAG using a one pass generator (typically ML)
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:986
+ Here is the call graph for this function:

◆ learnMixedStructure()

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 112 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().

113  {
114  _timer.reset();
115  _current_step = 0;
116 
117  // clear the vector of latent arcs to be sure
118  __latent_couples.clear();
119 
121  Heap<
122  std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
123  double >,
124  GreaterPairOn2nd >
125  _rank;
126 
128  HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > sep_set;
129 
130  _initiation(I, graph, sep_set, _rank);
131 
132  _iteration(I, graph, sep_set, _rank);
133 
134  if (__usemiic) {
135  _orientation_miic(I, graph, sep_set);
136  } else {
137  _orientation_3off2(I, graph, sep_set);
138  }
139 
140  return graph;
141  }
void _iteration(CorrectedMutualInformation<> &I, MixedGraph &graph, HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sep_set, Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double >, GreaterPairOn2nd > &_rank)
Iteration phase.
Definition: Miic.cpp:188
void _orientation_miic(CorrectedMutualInformation<> &I, MixedGraph &graph, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sep_set)
Orientation phase from the MIIC algorithm, returns a mixed graph that may contain circles...
Definition: Miic.cpp:585
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:359
void reset()
Reset the timer.
Definition: timer_inl.h:32
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:354
Size _current_step
The current step.
void _initiation(CorrectedMutualInformation<> &I, MixedGraph &graph, HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sep_set, Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double >, GreaterPairOn2nd > &_rank)
Initiation phase.
Definition: Miic.cpp:150
void _orientation_3off2(CorrectedMutualInformation<> &I, MixedGraph &graph, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sep_set)
Orientation phase from the 3off2 algorithm, returns a CPDAG.
Definition: Miic.cpp:245
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ learnStructure()

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 986 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().

987  {
988  MixedGraph essentialGraph = learnMixedStructure(I, initialGraph);
989 
990  // Second, orientate remaining edges
991  const Sequence< NodeId > order = essentialGraph.topologicalOrder();
992  // first, propagate existing orientations
993  for (NodeId x: order) {
994  if (!essentialGraph.parents(x).empty()) {
995  _propagatesHead(essentialGraph, x);
996  }
997  }
998  // then decide the orientation by the topological order and propagate them
999  for (NodeId x: order) {
1000  if (!essentialGraph.neighbours(x).empty()) {
1001  _propagatesHead(essentialGraph, x);
1002  }
1003  }
1004 
1005  // turn the mixed graph into a dag
1006  DAG dag;
1007  for (auto node: essentialGraph) {
1008  dag.addNodeWithId(node);
1009  }
1010  for (const Arc& arc: essentialGraph.arcs()) {
1011  dag.addArc(arc.tail(), arc.head());
1012  }
1013 
1014  return dag;
1015  }
MixedGraph learnMixedStructure(CorrectedMutualInformation<> &I, MixedGraph graph)
learns the structure of an Essential Graph
Definition: Miic.cpp:112
void _propagatesHead(MixedGraph &graph, NodeId node)
Propagates the orientation from a node to its neighbours.
Definition: Miic.cpp:1018
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maxIter()

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 102 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_max_iter.

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

102 { return _max_iter; }
Size _max_iter
The maximum iterations.
+ Here is the caller graph for this function:

◆ maxTime()

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

Returns the timeout (in seconds).

Returns
Returns the timeout (in seconds).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 125 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_max_time.

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

125 { return _max_time; }
double _max_time
The timeout.
+ Here is the caller graph for this function:

◆ messageApproximationScheme()

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

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 40 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().

40  {
41  std::stringstream s;
42 
43  switch (stateApproximationScheme()) {
44  case ApproximationSchemeSTATE::Continue: s << "in progress"; break;
45 
47  s << "stopped with epsilon=" << epsilon();
48  break;
49 
51  s << "stopped with rate=" << minEpsilonRate();
52  break;
53 
55  s << "stopped with max iteration=" << maxIter();
56  break;
57 
59  s << "stopped with timeout=" << maxTime();
60  break;
61 
62  case ApproximationSchemeSTATE::Stopped: s << "stopped on request"; break;
63 
64  case ApproximationSchemeSTATE::Undefined: s << "undefined state"; break;
65  };
66 
67  return s.str();
68  }
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:

◆ minEpsilonRate()

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 74 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_min_rate_eps.

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

74  {
75  return _min_rate_eps;
76  }
double _min_rate_eps
Threshold for the epsilon rate.
+ Here is the caller graph for this function:

◆ nbrIterations()

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 163 of file approximationScheme_inl.h.

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

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

163  {
165  GUM_ERROR(OperationNotAllowed,
166  "state of the approximation scheme is undefined");
167  }
168 
169  return _current_step;
170  }
Size _current_step
The current step.
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [1/2]

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

copy operator

Definition at line 62 of file Miic.cpp.

62  {
63  ApproximationScheme::operator=(from);
64  return *this;
65  }

◆ operator=() [2/2]

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

move operator

Definition at line 68 of file Miic.cpp.

68  {
69  ApproximationScheme::operator=(std::move(from));
70  return *this;
71  }

◆ periodSize()

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

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 149 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_period_size.

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

149 { return _period_size; }
Size _period_size
Checking criteria frequency.
+ Here is the caller graph for this function:

◆ remainingBurnIn()

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

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 210 of file approximationScheme_inl.h.

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

210  {
211  if (_burn_in > _current_step) {
212  return _burn_in - _current_step;
213  } else {
214  return 0;
215  }
216  }
Size _burn_in
Number of iterations before checking stopping criteria.
Size _current_step
The current step.

◆ set3off2Behaviour()

void gum::learning::Miic::set3off2Behaviour ( )

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

Definition at line 1064 of file Miic.cpp.

References __usemiic.

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

1064 { this->__usemiic = false; }
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:359
+ Here is the caller graph for this function:

◆ setEpsilon()

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 43 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::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsSampling< GUM_SCALAR >::GibbsSampling(), gum::learning::GreedyHillClimbing::GreedyHillClimbing(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::genericBNLearner::setEpsilon().

43  {
44  if (eps < 0.) { GUM_ERROR(OutOfLowerBound, "eps should be >=0"); }
45 
46  _eps = eps;
47  _enabled_eps = true;
48  }
bool _enabled_eps
If true, the threshold convergence is enabled.
double _eps
Threshold for convergence.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ setMaxIter()

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 95 of file approximationScheme_inl.h.

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

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

95  {
96  if (max < 1) { GUM_ERROR(OutOfLowerBound, "max should be >=1"); }
97  _max_iter = max;
98  _enabled_max_iter = true;
99  }
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:55
+ Here is the caller graph for this function:

◆ setMaxTime()

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 118 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::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::genericBNLearner::setMaxTime().

118  {
119  if (timeout <= 0.) { GUM_ERROR(OutOfLowerBound, "timeout should be >0."); }
120  _max_time = timeout;
121  _enabled_max_time = true;
122  }
bool _enabled_max_time
If true, the timeout is enabled.
double _max_time
The timeout.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ setMiicBehaviour()

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

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

Definition at line 1063 of file Miic.cpp.

References __usemiic.

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

1063 { this->__usemiic = true; }
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:359
+ Here is the caller graph for this function:

◆ setMinEpsilonRate()

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 66 of file approximationScheme_inl.h.

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

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

66  {
67  if (rate < 0) { GUM_ERROR(OutOfLowerBound, "rate should be >=0"); }
68 
69  _min_rate_eps = rate;
70  _enabled_min_rate_eps = true;
71  }
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:55
+ Here is the caller graph for this function:

◆ setPeriodSize()

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 143 of file approximationScheme_inl.h.

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

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

143  {
144  if (p < 1) { GUM_ERROR(OutOfLowerBound, "p should be >=1"); }
145 
146  _period_size = p;
147  }
Size _period_size
Checking criteria frequency.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ setVerbosity()

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 152 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_verbosity.

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

152 { _verbosity = v; }
bool _verbosity
If true, verbosity is enabled.
+ Here is the caller graph for this function:

◆ startOfPeriod()

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 197 of file approximationScheme_inl.h.

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

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

197  {
198  if (_current_step < _burn_in) { return false; }
199 
200  if (_period_size == 1) { return true; }
201 
202  return ((_current_step - _burn_in) % _period_size == 0);
203  }
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:

◆ stateApproximationScheme()

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 158 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().

158  {
159  return _current_state;
160  }
ApproximationSchemeSTATE _current_state
The current state.
+ Here is the caller graph for this function:

◆ stopApproximationScheme()

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

Stop the approximation scheme.

Definition at line 219 of file approximationScheme_inl.h.

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

Referenced by gum::learning::DAG2BNLearner< ALLOC >::createBN(), 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:

◆ updateApproximationScheme()

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 206 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_current_step.

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

206  {
207  _current_step += incr;
208  }
Size _current_step
The current step.
+ Here is the caller graph for this function:

◆ verbosity()

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 154 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_verbosity.

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

154 { return _verbosity; }
bool _verbosity
If true, verbosity is enabled.
+ Here is the caller graph for this function:

Member Data Documentation

◆ __arc_probas

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

Storing the propabilities for each arc set in the graph.

Definition at line 362 of file Miic.h.

Referenced by _orientation_miic().

◆ __empty_set

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

an empty conditioning set

Definition at line 352 of file Miic.h.

Referenced by _initiation().

◆ __initial_marks

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

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

Definition at line 365 of file Miic.h.

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

◆ __latent_couples

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

an empty vector of arcs

Definition at line 354 of file Miic.h.

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

◆ __maxLog

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

Fixes the maximum log that we accept in exponential computations.

Definition at line 350 of file Miic.h.

Referenced by _findBestContributor().

◆ __N

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

size of the database

Definition at line 357 of file Miic.h.

◆ __usemiic

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

wether to use the miic algorithm or not

Definition at line 359 of file Miic.h.

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

◆ _burn_in

◆ _current_epsilon

double gum::ApproximationScheme::_current_epsilon
protectedinherited

◆ _current_rate

double gum::ApproximationScheme::_current_rate
protectedinherited

◆ _current_state

◆ _current_step

◆ _enabled_eps

◆ _enabled_max_iter

bool gum::ApproximationScheme::_enabled_max_iter
protectedinherited

◆ _enabled_max_time

◆ _enabled_min_rate_eps

bool gum::ApproximationScheme::_enabled_min_rate_eps
protectedinherited

◆ _eps

double gum::ApproximationScheme::_eps
protectedinherited

◆ _history

std::vector< double > gum::ApproximationScheme::_history
protectedinherited

◆ _last_epsilon

double gum::ApproximationScheme::_last_epsilon
protectedinherited

Last epsilon value.

Definition at line 372 of file approximationScheme.h.

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

◆ _max_iter

Size gum::ApproximationScheme::_max_iter
protectedinherited

◆ _max_time

double gum::ApproximationScheme::_max_time
protectedinherited

◆ _min_rate_eps

double gum::ApproximationScheme::_min_rate_eps
protectedinherited

◆ _period_size

Size gum::ApproximationScheme::_period_size
protectedinherited

◆ _timer

◆ _verbosity

bool gum::ApproximationScheme::_verbosity
protectedinherited

If true, verbosity is enabled.

Definition at line 420 of file approximationScheme.h.

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

◆ onProgress

Signaler3< Size, double, double > gum::IApproximationSchemeConfiguration::onProgress
inherited

◆ onStop

Signaler1< std::string > gum::IApproximationSchemeConfiguration::onStop
inherited

Criteria messageApproximationScheme.

Definition at line 62 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: