aGrUM  0.16.0
gum::learning::Miic Class Reference

The miic learning algorithm. More...

#include <Miic.h>

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

Public Attributes

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

Public Member Functions

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

Public Types

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

Protected Attributes

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

Protected Member Functions

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

Detailed Description

The miic learning algorithm.

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

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

Definition at line 106 of file Miic.h.

Member Enumeration Documentation

◆ ApproximationSchemeSTATE

The different state of an approximation scheme.

Enumerator
Undefined 
Continue 
Epsilon 
Rate 
Limit 
TimeLimit 
Stopped 

Definition at line 65 of file IApproximationSchemeConfiguration.h.

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

Constructor & Destructor Documentation

◆ Miic() [1/4]

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

default constructor

Definition at line 44 of file Miic.cpp.

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

◆ Miic() [2/4]

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

default constructor with maxLog

Definition at line 47 of file Miic.cpp.

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

◆ Miic() [3/4]

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

copy constructor

Definition at line 50 of file Miic.cpp.

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

◆ Miic() [4/4]

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

move constructor

Definition at line 55 of file Miic.cpp.

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

◆ ~Miic()

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

destructor

Definition at line 60 of file Miic.cpp.

60 { GUM_DESTRUCTOR(Miic); }
Miic()
default constructor
Definition: Miic.cpp:44

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

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

◆ _findBestContributor()

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

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

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

Definition at line 765 of file Miic.cpp.

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

Referenced by _initiation(), and _iteration().

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

◆ _getUnshieldedTriples()

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

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

Definition at line 849 of file Miic.cpp.

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

Referenced by _orientation_3off2(), and _orientation_latents().

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

◆ _getUnshieldedTriplesMIIC()

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

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

Definition at line 891 of file Miic.cpp.

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

Referenced by _orientation_miic().

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

◆ _initiation()

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

Initiation phase.

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

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

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

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

◆ _iteration()

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

Iteration phase.

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

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

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

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

◆ _orientation_3off2()

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

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

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

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

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

◆ _orientation_latents()

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

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

varient trying to propagate both orientations in a bidirected arc

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

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

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

◆ _orientation_miic()

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

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

varient using the orientation protocol of MIIC

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

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

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

◆ _propagatesHead()

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

Propagates the orientation from a node to its neighbours.

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

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

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

Referenced by _getUnshieldedTriplesMIIC(), and _orientation_miic().

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

◆ addConstraints()

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

Set a ensemble of constraints for the orientation phase.

Definition at line 1067 of file Miic.cpp.

References __initial_marks.

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

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

◆ continueApproximationScheme()

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

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

Test the stopping criterion that are enabled.

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

Definition at line 227 of file approximationScheme_inl.h.

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

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

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

◆ currentTime()

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

Returns the current running time in second.

Returns
Returns the current running time in second.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 128 of file approximationScheme_inl.h.

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

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

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

◆ disableEpsilon()

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

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 54 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

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

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

◆ disableMaxIter()

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

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 105 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

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

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

◆ disableMaxTime()

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

Disable stopping criterion on timeout.

Returns
Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 131 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

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

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

◆ disableMinEpsilonRate()

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

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 79 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

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

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

◆ enableEpsilon()

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

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 57 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

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

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

◆ enableMaxIter()

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

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 108 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

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

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

◆ enableMaxTime()

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

Enable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 134 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

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

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

◆ enableMinEpsilonRate()

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

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 84 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

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

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

◆ epsilon()

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

Returns the value of epsilon.

Returns
Returns the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 51 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_eps.

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

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

◆ history()

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

Returns the scheme history.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 173 of file approximationScheme_inl.h.

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

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

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

◆ initApproximationScheme()

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

Initialise the scheme.

Definition at line 187 of file approximationScheme_inl.h.

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

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

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

◆ isEnabledEpsilon()

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

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

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 61 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_eps.

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

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

◆ isEnabledMaxIter()

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

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

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 112 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_iter.

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

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

◆ isEnabledMaxTime()

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

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

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 138 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_max_time.

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

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

◆ isEnabledMinEpsilonRate()

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

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

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 90 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_enabled_min_rate_eps.

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

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

◆ latentVariables()

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

get the list of arcs hiding latent variables

Definition at line 1049 of file Miic.cpp.

References __latent_couples.

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

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

◆ learnBN()

template<typename GUM_SCALAR , typename GRAPH_CHANGES_SELECTOR , typename PARAM_ESTIMATOR >
BayesNet< GUM_SCALAR > gum::learning::Miic::learnBN ( GRAPH_CHANGES_SELECTOR &  selector,
PARAM_ESTIMATOR &  estimator,
DAG  initial_dag = DAG() 
)

learns the structure and the parameters of a BN

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

Definition at line 1057 of file Miic.cpp.

References learnStructure().

1059  {
1060  return DAG2BNLearner<>::createBN< GUM_SCALAR >(
1061  estimator, learnStructure(selector, initial_dag));
1062  }
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:987
+ 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 113 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().

114  {
115  _timer.reset();
116  _current_step = 0;
117 
118  // clear the vector of latent arcs to be sure
119  __latent_couples.clear();
120 
122  Heap<
123  std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
124  double >,
125  GreaterPairOn2nd >
126  _rank;
127 
129  HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > sep_set;
130 
131  _initiation(I, graph, sep_set, _rank);
132 
133  _iteration(I, graph, sep_set, _rank);
134 
135  if (__usemiic) {
136  _orientation_miic(I, graph, sep_set);
137  } else {
138  _orientation_3off2(I, graph, sep_set);
139  }
140 
141  return graph;
142  }
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:189
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:586
bool __usemiic
wether to use the miic algorithm or not
Definition: Miic.h:359
void reset()
Reset the timer.
Definition: timer_inl.h:32
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:354
Size _current_step
The current step.
void _initiation(CorrectedMutualInformation<> &I, MixedGraph &graph, HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sep_set, Heap< std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double >, GreaterPairOn2nd > &_rank)
Initiation phase.
Definition: Miic.cpp:151
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:246
+ 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 987 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().

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

◆ maxIter()

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

Returns the criterion on number of iterations.

Returns
Returns the criterion on number of iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 102 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_max_iter.

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

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

◆ maxTime()

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

Returns the timeout (in seconds).

Returns
Returns the timeout (in seconds).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 125 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_max_time.

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

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

◆ messageApproximationScheme()

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

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 40 of file IApproximationSchemeConfiguration_inl.h.

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

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

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

◆ minEpsilonRate()

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

Returns the value of the minimal epsilon rate.

Returns
Returns the value of the minimal epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 74 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_min_rate_eps.

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

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

◆ nbrIterations()

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

Returns the number of iterations.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 163 of file approximationScheme_inl.h.

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

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

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

◆ operator=() [1/2]

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

copy operator

Definition at line 63 of file Miic.cpp.

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

◆ operator=() [2/2]

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

move operator

Definition at line 69 of file Miic.cpp.

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

69  {
70  ApproximationScheme::operator=(std::move(from));
71  return *this;
72  }
+ 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 149 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_period_size.

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

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

◆ remainingBurnIn()

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

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 210 of file approximationScheme_inl.h.

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

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

◆ set3off2Behaviour()

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

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

Definition at line 1065 of file Miic.cpp.

References __usemiic.

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

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

◆ setEpsilon()

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

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

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 43 of file approximationScheme_inl.h.

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

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

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

◆ setMaxIter()

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

Stopping criterion on number of iterations.

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 95 of file approximationScheme_inl.h.

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

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

95  {
96  if (max < 1) { GUM_ERROR(OutOfLowerBound, "max should be >=1"); }
97  _max_iter = max;
98  _enabled_max_iter = true;
99  }
bool _enabled_max_iter
If true, the maximum iterations stopping criterion is enabled.
Size _max_iter
The maximum iterations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ setMaxTime()

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

Stopping criterion on timeout.

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 118 of file approximationScheme_inl.h.

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

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

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

◆ setMiicBehaviour()

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

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

Definition at line 1064 of file Miic.cpp.

References __usemiic.

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

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

◆ setMinEpsilonRate()

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

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

If the criterion was disabled it will be enabled

Parameters
rateThe minimal epsilon rate.
Exceptions
OutOfLowerBoundif rate<0

Implements gum::IApproximationSchemeConfiguration.

Definition at line 66 of file approximationScheme_inl.h.

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

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

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

◆ setPeriodSize()

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

How many samples between two stopping is enable.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 143 of file approximationScheme_inl.h.

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

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

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

◆ setVerbosity()

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

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

Parameters
vIf true, then verbosity is turned on.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 152 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_verbosity.

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

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

◆ startOfPeriod()

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

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

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

Definition at line 197 of file approximationScheme_inl.h.

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

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

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

◆ stateApproximationScheme()

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

Returns the approximation scheme state.

Returns
Returns the approximation scheme state.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 158 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_current_state.

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

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

◆ stopApproximationScheme()

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

Stop the approximation scheme.

Definition at line 219 of file approximationScheme_inl.h.

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

Referenced by gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::learning::GreedyHillClimbing::learnStructure(), and gum::learning::LocalSearchWithTabuList::learnStructure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateApproximationScheme()

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

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

Parameters
incrThe new increment steps.

Definition at line 206 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_current_step.

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

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

◆ verbosity()

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

Returns true if verbosity is enabled.

Returns
Returns true if verbosity is enabled.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 154 of file approximationScheme_inl.h.

References gum::ApproximationScheme::_verbosity.

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

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

Member Data Documentation

◆ __arc_probas

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

Storing the propabilities for each arc set in the graph.

Definition at line 362 of file Miic.h.

Referenced by _orientation_miic().

◆ __empty_set

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

an empty conditioning set

Definition at line 352 of file Miic.h.

Referenced by _initiation().

◆ __initial_marks

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

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

Definition at line 365 of file Miic.h.

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

◆ __latent_couples

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

an empty vector of arcs

Definition at line 354 of file Miic.h.

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

◆ __maxLog

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

Fixes the maximum log that we accept in exponential computations.

Definition at line 350 of file Miic.h.

Referenced by _findBestContributor().

◆ __N

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

size of the database

Definition at line 357 of file Miic.h.

Referenced by _updateProbaTriples().

◆ __usemiic

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

wether to use the miic algorithm or not

Definition at line 359 of file Miic.h.

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

◆ _burn_in

◆ _current_epsilon

double gum::ApproximationScheme::_current_epsilon
protectedinherited

◆ _current_rate

double gum::ApproximationScheme::_current_rate
protectedinherited

◆ _current_state

◆ _current_step

◆ _enabled_eps

◆ _enabled_max_iter

bool gum::ApproximationScheme::_enabled_max_iter
protectedinherited

◆ _enabled_max_time

◆ _enabled_min_rate_eps

bool gum::ApproximationScheme::_enabled_min_rate_eps
protectedinherited

◆ _eps

double gum::ApproximationScheme::_eps
protectedinherited

◆ _history

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

◆ _last_epsilon

double gum::ApproximationScheme::_last_epsilon
protectedinherited

Last epsilon value.

Definition at line 372 of file approximationScheme.h.

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

◆ _max_iter

Size gum::ApproximationScheme::_max_iter
protectedinherited

◆ _max_time

double gum::ApproximationScheme::_max_time
protectedinherited

◆ _min_rate_eps

double gum::ApproximationScheme::_min_rate_eps
protectedinherited

◆ _period_size

Size gum::ApproximationScheme::_period_size
protectedinherited

◆ _timer

◆ _verbosity

bool gum::ApproximationScheme::_verbosity
protectedinherited

If true, verbosity is enabled.

Definition at line 420 of file approximationScheme.h.

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

◆ onProgress

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

◆ onStop

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

Criteria messageApproximationScheme.

Definition at line 62 of file IApproximationSchemeConfiguration.h.

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


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