aGrUM  0.14.2
gum::learning::Miic Class Reference

The miic learning algorithm. More...

#include <Miic.h>

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

Public Attributes

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

Public Member Functions

Miicoperator= (const Miic &from)
 copy operator More...
 
Miicoperator= (Miic &&from)
 move operator More...
 
Constructors / Destructors
 Miic ()
 default constructor More...
 
 Miic (int maxLog)
 default constructor with maxLog More...
 
 Miic (const Miic &from)
 copy constructor More...
 
 Miic (Miic &&from)
 move constructor More...
 
 ~Miic ()
 destructor More...
 
Accessors / Modifiers
MixedGraph learnMixedStructure (CorrectedMutualInformation<> &I, MixedGraph graph)
 learns the structure of an Essential Graph More...
 
DAG learnStructure (CorrectedMutualInformation<> &I, MixedGraph graph)
 learns the structure of an Bayesian network, ie a DAG, by first learning an Essential graph and then directing the remaining edges. More...
 
template<typename GUM_SCALAR = double, typename GRAPH_CHANGES_SELECTOR , typename PARAM_ESTIMATOR >
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 103 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 63 of file IApproximationSchemeConfiguration.h.

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

Constructor & Destructor Documentation

◆ Miic() [1/4]

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

default constructor

Definition at line 41 of file Miic.cpp.

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

◆ Miic() [2/4]

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

default constructor with maxLog

Definition at line 44 of file Miic.cpp.

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

◆ Miic() [3/4]

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

copy constructor

Definition at line 47 of file Miic.cpp.

47  : ApproximationScheme(from) {
48  GUM_CONS_CPY(Miic);
49  }
Miic()
default constructor
Definition: Miic.cpp:41

◆ Miic() [4/4]

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

move constructor

Definition at line 52 of file Miic.cpp.

52  : ApproximationScheme(std::move(from)) {
53  GUM_CONS_MOV(Miic);
54  }
Miic()
default constructor
Definition: Miic.cpp:41

◆ ~Miic()

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

destructor

Definition at line 57 of file Miic.cpp.

57 { GUM_DESTRUCTOR(Miic); }
Miic()
default constructor
Definition: Miic.cpp:41

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

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

◆ _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 762 of file Miic.cpp.

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

Referenced by _initiation(), and _iteration().

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

◆ _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 846 of file Miic.cpp.

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

Referenced by _orientation_3off2(), and _orientation_latents().

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

◆ _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 888 of file Miic.cpp.

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

Referenced by _orientation_miic().

893  {
894  std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
895  double,
896  double,
897  double > >
898  triples;
899  for (NodeId z : graph) {
900  for (NodeId x : graph.neighbours(z)) {
901  for (NodeId y : graph.neighbours(z)) {
902  if (y < x && !graph.existsEdge(x, y)) {
903  std::vector< NodeId > ui;
904  std::pair< NodeId, NodeId > key = {x, y};
905  std::pair< NodeId, NodeId > rev_key = {y, x};
906  if (sep_set.exists(key)) {
907  ui = sep_set[key];
908  } else if (sep_set.exists(rev_key)) {
909  ui = sep_set[rev_key];
910  }
911  // remove z from ui if it's present
912  const auto iter_z_place = std::find(ui.begin(), ui.end(), z);
913  if (iter_z_place != ui.end()) { ui.erase(iter_z_place); }
914 
915  const double Ixyz_ui = I.score(x, y, z, ui);
916  auto tup = new std::tuple< NodeId, NodeId, NodeId >{x, y, z};
917  std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
918  double,
919  double,
920  double >
921  triple{tup, Ixyz_ui, 0.5, 0.5};
922  triples.push_back(triple);
923  if (!marks.exists({x, z})) { marks.insert({x, z}, 'o'); }
924  if (!marks.exists({z, x})) { marks.insert({z, x}, 'o'); }
925  if (!marks.exists({y, z})) { marks.insert({y, z}, 'o'); }
926  if (!marks.exists({z, y})) { marks.insert({z, y}, 'o'); }
927  }
928  }
929  }
930  }
931  triples = _updateProbaTriples(graph, triples);
932  std::sort(triples.begin(), triples.end(), GreaterTupleOnLast());
933  return triples;
934  }
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:940
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:97
+ 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 148 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().

155  {
156  NodeId x, y;
157  EdgeSet edges = graph.edges();
158  Size steps_init = edges.size();
159 
160  for (const Edge& edge : edges) {
161  x = edge.first();
162  y = edge.second();
163  double Ixy = I.score(x, y);
164 
165  if (Ixy <= 0) { //< K
166  graph.eraseEdge(edge);
167  sep_set.insert(std::make_pair(x, y), __empty_set);
168  } else {
169  _findBestContributor(x, y, __empty_set, graph, I, _rank);
170  }
171 
172  ++_current_step;
173  if (onProgress.hasListener()) {
174  GUM_EMIT3(
175  onProgress, (_current_step * 33) / steps_init, 0., _timer.step());
176  }
177  }
178  }
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:762
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
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:45
const std::vector< NodeId > __empty_set
an empty conditioning set
Definition: Miic.h:349
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:40
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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 186 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().

193  {
194  // if no triples to further examine pass
195  std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
196  double >
197  best;
198 
199  Size steps_init = _current_step;
200  Size steps_iter = _rank.size();
201 
202  try {
203  while (_rank.top().second > 0.5) {
204  best = _rank.pop();
205 
206  const NodeId x = std::get< 0 >(*(best.first));
207  const NodeId y = std::get< 1 >(*(best.first));
208  const NodeId z = std::get< 2 >(*(best.first));
209  std::vector< NodeId > ui = std::move(std::get< 3 >(*(best.first)));
210 
211  ui.push_back(z);
212  const double Ixy_ui = I.score(x, y, ui);
213  if (Ixy_ui < 0) {
214  graph.eraseEdge(Edge(x, y));
215  sep_set.insert(std::make_pair(x, y), std::move(ui));
216  } else {
217  _findBestContributor(x, y, ui, graph, I, _rank);
218  }
219 
220  delete best.first;
221 
222  ++_current_step;
223  if (onProgress.hasListener()) {
225  (_current_step * 66) / (steps_init + steps_iter),
226  0.,
227  _timer.step());
228  }
229  }
230  } catch (...) {} // here, rank is empty
231  _current_step = steps_init + steps_iter;
232  if (onProgress.hasListener()) {
233  GUM_EMIT3(onProgress, 66, 0., _timer.step());
234  }
235  _current_step = steps_init + steps_iter;
236  }
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:762
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
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:45
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:40
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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 243 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().

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

◆ _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 431 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().

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

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

◆ _propagatesHead()

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

Propagates the orientation from a node to its neighbours.

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

1016  {
1017  const auto neighbours = graph.neighbours(node);
1018  for (auto& neighbour : neighbours) {
1019  // only propagate if it doesn't create a circle and isn't forbidden
1020  // and doesn't create a new v-structure
1021  if (!__existsDirectedPath(graph, neighbour, node)
1022  && !(__initial_marks.exists({node, neighbour})
1023  && __initial_marks[{node, neighbour}] == '-')
1024  && graph.parents(neighbour).empty()) {
1025  graph.eraseEdge(Edge(neighbour, node));
1026  graph.addArc(node, neighbour);
1027  _propagatesHead(graph, neighbour);
1028  } else if (!__existsDirectedPath(graph, node, neighbour)
1029  && !(__initial_marks.exists({neighbour, node})
1030  && __initial_marks[{neighbour, node}] == '-')
1031  && graph.parents(node).empty()) {
1032  graph.eraseEdge(Edge(neighbour, node));
1033  graph.addArc(neighbour, node);
1034  } else if (!graph.parents(neighbour).empty()
1035  && !graph.parents(node).empty()) {
1036  graph.eraseEdge(Edge(neighbour, node));
1037  graph.addArc(node, neighbour);
1038  __latent_couples.push_back(Arc(node, neighbour));
1039  } else {
1040  graph.eraseEdge(Edge(neighbour, node));
1041  }
1042  }
1043  }
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:1016
HashTable< std::pair< NodeId, NodeId >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:362
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:351
const bool __existsDirectedPath(const MixedGraph &graph, const NodeId n1, const NodeId n2) const
checks for directed paths in a graph, consider double arcs like edges
Definition: Miic.cpp:1070
+ 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 940 of file Miic.cpp.

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

Referenced by _getUnshieldedTriplesMIIC(), and _orientation_miic().

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

◆ 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 1064 of file Miic.cpp.

References __initial_marks.

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

1065  {
1066  this->__initial_marks = constraints;
1067  }
HashTable< std::pair< NodeId, NodeId >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:362
+ 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 225 of file approximationScheme_inl.h.

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

Referenced by gum::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().

225  {
226  // For coherence, we fix the time used in the method
227 
228  double timer_step = _timer.step();
229 
230  if (_enabled_max_time) {
231  if (timer_step > _max_time) {
233  return false;
234  }
235  }
236 
237  if (!startOfPeriod()) { return true; }
238 
240  GUM_ERROR(OperationNotAllowed,
241  "state of the approximation scheme is not correct : "
243  }
244 
245  if (verbosity()) { _history.push_back(error); }
246 
247  if (_enabled_max_iter) {
248  if (_current_step > _max_iter) {
250  return false;
251  }
252  }
253 
255  _current_epsilon = error; // eps rate isEnabled needs it so affectation was
256  // moved from eps isEnabled below
257 
258  if (_enabled_eps) {
259  if (_current_epsilon <= _eps) {
261  return false;
262  }
263  }
264 
265  if (_last_epsilon >= 0.) {
266  if (_current_epsilon > .0) {
267  // ! _current_epsilon can be 0. AND epsilon
268  // isEnabled can be disabled !
269  _current_rate =
271  }
272  // limit with current eps ---> 0 is | 1 - ( last_eps / 0 ) | --->
273  // infinity the else means a return false if we isEnabled the rate below,
274  // as we would have returned false if epsilon isEnabled was enabled
275  else {
277  }
278 
279  if (_enabled_min_rate_eps) {
280  if (_current_rate <= _min_rate_eps) {
282  return false;
283  }
284  }
285  }
286 
288  if (onProgress.hasListener()) {
290  }
291 
292  return true;
293  } else {
294  return false;
295  }
296  }
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
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:40
ApproximationSchemeSTATE _current_state
The current state.
double _max_time
The timeout.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 126 of file approximationScheme_inl.h.

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

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

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

◆ disableEpsilon()

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

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 52 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

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

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

◆ disableMaxIter()

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

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 103 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

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

103 { _enabled_max_iter = false; }
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.
+ Here is the caller graph for this function:

◆ disableMaxTime()

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

Disable stopping criterion on timeout.

Returns
Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 129 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

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

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

◆ disableMinEpsilonRate()

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

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 77 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

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

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

◆ enableEpsilon()

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

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 55 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

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

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

◆ enableMaxIter()

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

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 106 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

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

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

◆ enableMaxTime()

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

Enable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 132 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

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

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

◆ enableMinEpsilonRate()

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

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 82 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

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

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

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

References gum::ApproximationScheme::_eps.

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

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

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

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

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

171  {
173  GUM_ERROR(OperationNotAllowed,
174  "state of the approximation scheme is udefined");
175  }
176 
177  if (verbosity() == false) {
178  GUM_ERROR(OperationNotAllowed, "No history when verbosity=false");
179  }
180 
181  return _history;
182  }
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:52
+ 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 185 of file approximationScheme_inl.h.

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

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__mcInitApproximationScheme(), gum::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().

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

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

References gum::ApproximationScheme::_enabled_eps.

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

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

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

References gum::ApproximationScheme::_enabled_max_iter.

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

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

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

References gum::ApproximationScheme::_enabled_max_time.

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

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

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

References gum::ApproximationScheme::_enabled_min_rate_eps.

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

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

◆ latentVariables()

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

get the list of arcs hiding latent variables

Definition at line 1046 of file Miic.cpp.

References __latent_couples.

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

1046  {
1047  return __latent_couples;
1048  }
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:351
+ 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 1054 of file Miic.cpp.

References learnStructure().

1056  {
1057  return DAG2BNLearner<>::createBN< GUM_SCALAR >(
1058  estimator, learnStructure(selector, initial_dag));
1059  }
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:984
+ 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 110 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().

111  {
112  _timer.reset();
113  _current_step = 0;
114 
115  // clear the vector of latent arcs to be sure
116  __latent_couples.clear();
117 
119  Heap<
120  std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
121  double >,
122  GreaterPairOn2nd >
123  _rank;
124 
126  HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > sep_set;
127 
128  _initiation(I, graph, sep_set, _rank);
129 
130  _iteration(I, graph, sep_set, _rank);
131 
132  if (__usemiic) {
133  _orientation_miic(I, graph, sep_set);
134  } else {
135  _orientation_3off2(I, graph, sep_set);
136  }
137 
138  return graph;
139  }
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:186
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:583
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:356
void reset()
Reset the timer.
Definition: timer_inl.h:29
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:351
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:148
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:243
+ 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 984 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().

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

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

References gum::ApproximationScheme::_max_iter.

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

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

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

References gum::ApproximationScheme::_max_time.

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

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

◆ messageApproximationScheme()

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

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 38 of file IApproximationSchemeConfiguration_inl.h.

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

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

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

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

References gum::ApproximationScheme::_min_rate_eps.

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

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

◆ 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 161 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().

161  {
163  GUM_ERROR(OperationNotAllowed,
164  "state of the approximation scheme is undefined");
165  }
166 
167  return _current_step;
168  }
Size _current_step
The current step.
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 60 of file Miic.cpp.

60  {
61  ApproximationScheme::operator=(from);
62  return *this;
63  }

◆ operator=() [2/2]

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

move operator

Definition at line 66 of file Miic.cpp.

References gum::learning::GreaterPairOn2nd::operator()().

66  {
67  ApproximationScheme::operator=(std::move(from));
68  return *this;
69  }
+ Here is the call graph for this function:

◆ periodSize()

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

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 147 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_period_size.

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

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

◆ remainingBurnIn()

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

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 208 of file approximationScheme_inl.h.

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

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

◆ set3off2Behaviour()

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

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

Definition at line 1062 of file Miic.cpp.

References __usemiic.

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

1062 { this->__usemiic = false; }
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:356
+ 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 41 of file approximationScheme_inl.h.

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

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

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

93  {
94  if (max < 1) { GUM_ERROR(OutOfLowerBound, "max should be >=1"); }
95  _max_iter = max;
96  _enabled_max_iter = true;
97  }
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.
Size _max_iter
The maximum iterations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 116 of file approximationScheme_inl.h.

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

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

116  {
117  if (timeout <= 0.) { GUM_ERROR(OutOfLowerBound, "timeout should be >0."); }
118  _max_time = timeout;
119  _enabled_max_time = true;
120  }
bool _enabled_max_time
If true, the timeout is enabled.
double _max_time
The timeout.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 1061 of file Miic.cpp.

References __usemiic.

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

1061 { this->__usemiic = true; }
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:356
+ 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 64 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().

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

141  {
142  if (p < 1) { GUM_ERROR(OutOfLowerBound, "p should be >=1"); }
143 
144  _period_size = p;
145  }
Size _period_size
Checking criteria frequency.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 150 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().

150 { _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 195 of file approximationScheme_inl.h.

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

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

195  {
196  if (_current_step < _burn_in) { return false; }
197 
198  if (_period_size == 1) { return true; }
199 
200  return ((_current_step - _burn_in) % _period_size == 0);
201  }
Size _burn_in
Number of iterations before checking stopping criteria.
Size _current_step
The current step.
Size _period_size
Checking criteria frequency.
+ Here is the caller graph for this function:

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

References gum::ApproximationScheme::_current_state.

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

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

◆ stopApproximationScheme()

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

Stop the approximation scheme.

Definition at line 217 of file approximationScheme_inl.h.

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

Referenced by gum::learning::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 204 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().

204  {
205  _current_step += incr;
206  }
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 152 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_verbosity.

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

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

Member Data Documentation

◆ __arc_probas

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

Storing the propabilities for each arc set in the graph.

Definition at line 359 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 349 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 362 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 351 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 347 of file Miic.h.

Referenced by _findBestContributor().

◆ __N

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

size of the database

Definition at line 354 of file Miic.h.

Referenced by _updateProbaTriples().

◆ __usemiic

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

wether to use the miic algorithm or not

Definition at line 356 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 370 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 418 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 60 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: