Skip to content

Commit

Permalink
Mainly : adding ContinuousBayesianNetwork and ContinuousPC::learnJunc…
Browse files Browse the repository at this point in the history
…tionTree
  • Loading branch information
phwuil authored and jschueller committed Jul 25, 2019
1 parent 4c359ce commit 897085b
Show file tree
Hide file tree
Showing 30 changed files with 730 additions and 550 deletions.
992 changes: 496 additions & 496 deletions Doxyfile.in

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmake/Useotagr.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Use otagr in CMake files
#
# Copyright 2010-2018 Airbus-LIP6-Phimeca
# Copyright 2010-2019 Airbus-LIP6-Phimeca
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 1 addition & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

add_subdirectory ( include )
add_subdirectory ( src )
add_subdirectory ( test )

install ( FILES ${HEADERFILES}
DESTINATION ${OTAGRUM_INCLUDE_PATH}/${PACKAGE_NAME}
DESTINATION ${OTAGRUM_INCLUDE_PATH}/${PACKAGE_NAME}
)

2 changes: 1 addition & 1 deletion lib/include/otagrum/otagrum.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief The external header file of otagr
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down
2 changes: 2 additions & 0 deletions lib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ot_add_source_file ( StratifiedCache.cxx )
ot_add_source_file ( ContinuousTTest.cxx )
ot_add_source_file ( IndicesManip.cxx )
ot_add_source_file ( ContinuousPC.cxx )
ot_add_source_file ( ContinuousBayesianNetwork.cxx )
ot_add_source_file ( JunctionTreeBernsteinCopula.cxx )

ot_install_header_file ( MixedHistogramUserDefined.hxx )
Expand All @@ -18,6 +19,7 @@ ot_install_header_file ( StratifiedCache.hxx )
ot_install_header_file ( ContinuousTTest.hxx )
ot_install_header_file ( IndicesManip.hxx )
ot_install_header_file ( ContinuousPC.hxx )
ot_install_header_file ( ContinuousBayesianNetwwork.hxx )
ot_install_header_file ( JunctionTreeBernsteinCopula.hxx )

include_directories (${INTERNAL_INCLUDE_DIRS})
Expand Down
76 changes: 76 additions & 0 deletions lib/src/ContinuousBayesianNetwork.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// -*- C++ -*-
/**
* @brief ContinuousPC
*
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <algorithm>
#include <vector>

#include "otagrum/ContinuousBayesianNetwork.hxx"
#include "otagrum/Utils.hxx"

namespace OTAGRUM
{
ContinuousBayesianNetwork::ContinuousBayesianNetwork(
const gum::BayesNet<double> &bn)
: dag_(bn.dag()), map_(bn.size())
{
std::transform(bn.nodes().begin(), bn.nodes().end(), map_.begin(),
[&bn](const gum::NodeId nod) -> std::string
{
return bn.variable(nod).name();
});
}

ContinuousBayesianNetwork::ContinuousBayesianNetwork(
const gum::DAG &dag, const std::vector<std::string> &names)
: dag_(dag), map_(dag.size())
{
for (const auto &name : names)
{
map_.add(name);
}
}

OT::UnsignedInteger ContinuousBayesianNetwork::getSize() const
{
return map_.getSize();
}

OT::Description ContinuousBayesianNetwork::getDescription() const
{
return map_;
}

OT::Indices ContinuousBayesianNetwork::getParents(const gum::NodeId nod) const
{
return Utils::FromNodeSet(dag_.parents(nod));
}

OT::Indices
ContinuousBayesianNetwork::getChildren(const gum::NodeId nod) const
{
return Utils::FromNodeSet(dag_.children(nod));
}

OT::Indices ContinuousBayesianNetwork::getNodes() const
{
return Utils::FromNodeSet(dag_.nodes().asNodeSet());
}
} // namespace OTAGRUM
27 changes: 15 additions & 12 deletions lib/src/ContinuousPC.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief ContinuousPC
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -239,7 +239,7 @@ bool ContinuousPC::testCondSetWithSize(gum::UndiGraph &g,
// From complete graph g, remove as much as possible edge (y,z) in g
// if (y,z) is removed, it means that sepset_[Edge(y,z)] contains X, set of
// nodes, such that y and z are tested as independent given X.
gum::UndiGraph ContinuousPC::getSkeleton()
gum::UndiGraph ContinuousPC::learnSkeleton()
{
gum::UndiGraph g;
tester_.clearCache();
Expand Down Expand Up @@ -274,10 +274,15 @@ gum::UndiGraph ContinuousPC::getSkeleton()
return g;
}

NamedJunctionTree ContinuousPC::learnJunctionTree()
{
return getJunctionTree(getMoralGraph(learnPDAG(learnSkeleton())));
}

// for all triplet x-y-z (no edge between x and z), if y is in sepset[x,z]
// then x->y<-z.
// the ordering process uses the size of the p-value as a priority.
gum::MixedGraph ContinuousPC::getPDAG(const gum::UndiGraph &g) const
gum::MixedGraph ContinuousPC::learnPDAG(const gum::UndiGraph &g) const
{
gum::MixedGraph cpdag;

Expand All @@ -291,15 +296,12 @@ gum::MixedGraph ContinuousPC::getPDAG(const gum::UndiGraph &g) const
IndicesCombinationIterator couple(Utils::FromNodeSet(g.neighbours(x)), 2);
for (couple.setFirst(); !couple.isLast(); couple.next())
{
bool ok = false;
double t = 0.0, p = 0.0;
const gum::NodeId y = couple.current()[0];
const gum::NodeId z = couple.current()[1];
if (!g.existsEdge(y, z)) // maybe unshielded collider
{
// if (OTAGR::isIn(sepset_[gum::Edge(x, z)], y)) {
// queue.insert(Triplet{x, y, z}, pvalues_[gum::Edge(x, z)]);
//}
bool ok = false;
double t = 0.0, p = 0.0;
OT::Indices indX;
indX = indX + OT::UnsignedInteger(x);
std::tie(t, p, ok) = tester_.isIndep(y, z, indX);
Expand Down Expand Up @@ -362,15 +364,16 @@ gum::UndiGraph ContinuousPC::getMoralGraph(const gum::MixedGraph &g) const
NamedJunctionTree ContinuousPC::getJunctionTree(const gum::UndiGraph &g) const
{
gum::DefaultTriangulation triangulation;
gum::NodeProperty <gum::Size> mods;
gum::NodeProperty<gum::Size> mods;
std::vector<std::string> names;

const auto& description = tester_.getDataDescription();
const auto &description = tester_.getDataDescription();
for (int i = 0; i < description.getSize(); i++)
{
mods.insert(i, 2);
names.push_back(description.at(i)); // triangulation needs modalities. We just say that mods
// triangulation needs modalities. We just say that mods
// are all the same
mods.insert(i, 2);
names.push_back(description.at(i));
}
triangulation.setGraph(&g, &mods);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/ContinuousTTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief ContinuousTTest
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion lib/src/IndicesManip.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief IndicesCombinationIterator
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions lib/src/JunctionTreeBernsteinCopula.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief The JunctionTreeBernsteinCopula distribution
*
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -94,7 +94,7 @@ JunctionTreeBernsteinCopula::JunctionTreeBernsteinCopula(const NamedJunctionTree
}

/* Set the order according to which the cliques are traversed */
void JunctionTreeBernsteinCopula::setCliquesOrder(const OT::Indices & cliquesOrder)
void JunctionTreeBernsteinCopula::setCliquesOrder(const OT::Indices & cliquesOrder)
{
const unsigned int size = cliquesOrder.getSize();
if (size != junctionTree_.getCliquesCollection().getSize()) throw OT::InvalidArgumentException(HERE) << "Error: expected a cliques order of size=" << junctionTree_.getCliquesCollection().getSize() << ", got size=" << size;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/MixedHistogramUserDefined.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief The MixedHistogramUserDefined distribution
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down
5 changes: 3 additions & 2 deletions lib/src/NamedJunctionTree.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief NamedJunctionTree
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -27,7 +27,8 @@

namespace OTAGRUM
{
NamedJunctionTree::NamedJunctionTree() { /* Nothing to do */ };
NamedJunctionTree::NamedJunctionTree() {};

NamedJunctionTree::NamedJunctionTree(const gum::CliqueGraph &jt,
const gum::BayesNet<double> &bn)
: OT::Object(), jt_(jt), map_(bn.size())
Expand Down
2 changes: 1 addition & 1 deletion lib/src/StratifiedCache.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief The StratifiedCache is a cache for TTest with level
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief Utils
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down
58 changes: 58 additions & 0 deletions lib/src/otagrum/ContinuousBayesianNetwork.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// -*- C++ -*-
/**
* @brief ContinuousBayesianNetworks
*
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef OTAGRUM_CONTINUOUSBAYESIANNETWORK_HXX
#define OTAGRUM_CONTINUOUSBAYESIANNETWORK_HXX
#include <string>
#include <vector>

#include <agrum/BN/BayesNet.h>
#include <agrum/graphs/DAG.h>

#include <openturns/Description.hxx>
#include <openturns/Indices.hxx>

#include "otagrum/otagrumprivate.hxx"

namespace OTAGRUM
{
class OTAGRUM_API ContinuousBayesianNetwork : public OT::Object
{
public:
ContinuousBayesianNetwork() = delete;
ContinuousBayesianNetwork(const gum::BayesNet<double> &bn);
ContinuousBayesianNetwork(const gum::DAG &dag,
const std::vector<std::string> &names);

OT::UnsignedInteger getSize() const;
OT::Description getDescription() const;

OT::Indices getParents(const gum::NodeId nod) const;
OT::Indices getChildren(const gum::NodeId nod) const;
OT::Indices getNodes() const;

private:
gum::DAG dag_;
OT::Description map_;
};

} // namespace OTAGRUM
#endif // OTAGRUM_CONTINUOUSBAYESIANNETWORK_HXX
14 changes: 8 additions & 6 deletions lib/src/otagrum/ContinuousPC.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief ContinuousPC
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -22,11 +22,11 @@
#ifndef OTAGRUM_CONTINUOUSPC_HXX
#define OTAGRUM_CONTINUOUSPC_HXX

#include <agrum/graphs/mixedGraph.h>
#include <agrum/graphs/undiGraph.h>
#include <agrum/graphs/cliqueGraph.h>
#include <agrum/graphs/algorithms/triangulations/defaultTriangulation.h>
#include <agrum/graphs/algorithms/triangulations/junctionTreeStrategies/defaultJunctionTreeStrategy.h>
#include <agrum/graphs/cliqueGraph.h>
#include <agrum/graphs/mixedGraph.h>
#include <agrum/graphs/undiGraph.h>

#include <openturns/Sample.hxx>

Expand All @@ -43,8 +43,10 @@ public:
const OT::UnsignedInteger maxParents = 5,
const double alpha = 0.1);

gum::UndiGraph getSkeleton();
gum::MixedGraph getPDAG(const gum::UndiGraph &g) const;
gum::UndiGraph learnSkeleton();
NamedJunctionTree learnJunctionTree();

gum::MixedGraph learnPDAG(const gum::UndiGraph &g) const;
gum::UndiGraph getMoralGraph(const gum::MixedGraph &g) const;
NamedJunctionTree getJunctionTree(const gum::UndiGraph &g) const;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/otagrum/ContinuousTTest.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief ContinuousTTest
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion lib/src/otagrum/IndicesManip.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @brief IndicesCombinationIterator
*
* Copyright 2010-2018 Airbus-LIP6-Phimeca
* Copyright 2010-2019 Airbus-LIP6-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down
Loading

0 comments on commit 897085b

Please sign in to comment.