[aGrUM] new method Potential.fillWith(pot,map)

parent 859f886e
......@@ -225,8 +225,7 @@ namespace gum {
/**
* @brief copy a Potential data using name of variables and labels (not
* necessarily
* the same variables in the same orders)
* necessarily the same variables in the same orders)
*
* @warning a strict control on names of variables and labels are made
*
......@@ -235,6 +234,26 @@ namespace gum {
const Potential< GUM_SCALAR >&
fillWith(const Potential< GUM_SCALAR >& src) const;
/**
* @brief copy a Potential data using the sequence of names in mapSrc to find
* the corresponding variables.
*
* For instance, to copy the potential P(A,B,C) in Q(D,E,A) with the mapping
* P.A<->Q.E, P.B<->Q.A, P.C<->Q.D (assuming that the corresponding variables
* have the same domain size and the order of labels):
*
* @code
* Q.fillWith(P,{"C","A","B"});
* @endcode
*
* @warning a strict control on names of variables and labels are made
*
* @throw InvalidArgument if the Potential is not compatible with this
* */
const Potential< GUM_SCALAR >&
fillWith(const Potential< GUM_SCALAR >& src,
const std::vector< std::string >& mapSrc) const;
/**
* @brief Automatically fills the potential with the values in
* v.
......
......@@ -235,12 +235,29 @@ namespace gum {
this->fill(v);
return *this;
}
template < typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR >&
Potential< GUM_SCALAR >::fillWith(const Potential< GUM_SCALAR >& src) const {
if (src.domainSize() != this->domainSize()) {
GUM_ERROR(InvalidArgument, "Potential to copy has not the same dimension.");
}
gum::Set< std::string > son; // set of names
for (const auto& v : src.variablesSequence()) {
son.insert(v->name());
}
for (const auto& v : this->variablesSequence()) {
if (!son.contains(v->name())) {
GUM_ERROR(InvalidArgument,
"Variable <" << v->name() << "> not present in src.");
}
// we check size, labels and order of labels in the same time
if (v->toString() != src.variable(v->name()).toString()) {
GUM_ERROR(InvalidArgument,
"Variables <" << v->name() << "> are not identical.");
}
}
Instantiation Isrc(src);
Instantiation Idst(*this);
for (Isrc.setFirst(); !Isrc.end(); ++Isrc) {
......@@ -253,6 +270,36 @@ namespace gum {
return *this;
}
template < typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR >& Potential< GUM_SCALAR >::fillWith(
const Potential< GUM_SCALAR >& src,
const std::vector< std::string >& mapSrc) const {
if (src.nbrDim() != this->nbrDim()) {
GUM_ERROR(InvalidArgument, "Potential to copy has not the same dimension.");
}
if (src.nbrDim() != mapSrc.size()) {
GUM_ERROR(InvalidArgument,
"Potential and vector have not the same dimension.");
}
Instantiation Isrc;
for (Idx i = 0; i < src.nbrDim(); i++) {
if (src.variable(mapSrc[i]).domainSize() != this->variable(i).domainSize()) {
GUM_ERROR(InvalidArgument,
"Variables " << mapSrc[i] << " (in the argument) and "
<< this->variable(i).name()
<< " have not the same dimension.");
} else {
Isrc.add(src.variable(mapSrc[i]));
}
}
Instantiation Idst(*this);
for (Isrc.setFirst(); !Isrc.end(); ++Isrc, ++Idst) {
this->set(Idst, src.get(Isrc));
}
return *this;
}
template < typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR >& Potential< GUM_SCALAR >::sq() const {
this->apply([](GUM_SCALAR x) { return x * x; });
......
......@@ -24,8 +24,8 @@
#include <agrum/variables/labelizedVariable.h>
#include <agrum/multidim/ICIModels/multiDimLogit.h>
#include <agrum/multidim/instantiation.h>
#include <agrum/multidim/implementations/multiDimArray.h>
#include <agrum/multidim/instantiation.h>
#include <agrum/multidim/potential.h>
namespace gum_tests {
......@@ -501,6 +501,7 @@ namespace gum_tests {
r.fillWith({3, 6, 9, 12, 15, 18, 21, 24, 27});
TS_ASSERT(pot.reorganize({&b, &c, &a}).extract(I) == r);
}
void testOperatorEqual() {
auto a = gum::LabelizedVariable("a", "afoo", 3);
auto b = gum::LabelizedVariable("b", "bfoo", 3);
......@@ -961,7 +962,6 @@ namespace gum_tests {
pp.add(ww);
pp.add(vv);
TS_ASSERT_EQUALS(p.domainSize(), gum::Size(6));
TS_ASSERT_EQUALS(pp.domainSize(), gum::Size(6));
......@@ -989,14 +989,38 @@ namespace gum_tests {
gum::Potential< int > bad_p2;
bad_p2.add(vvv);
bad_p2.add(www);
TS_ASSERT_THROWS(bad_p2.fillWith(p), gum::OutOfBounds);
TS_ASSERT_THROWS(bad_p2.fillWith(p), gum::InvalidArgument);
gum::Potential< int > bad_p3;
bad_p3.add(w);
bad_p3.add(z);
// TS_GUM_ASSERT_THROWS_NOTHING(bad_p3.fillWith(p));
TS_ASSERT_THROWS(bad_p3.fillWith(p), gum::NotFound);
TS_ASSERT_THROWS(bad_p3.fillWith(p), gum::InvalidArgument);
gum::Potential< int > bad_p4;
gum::LabelizedVariable badv("v", "v", 0);
badv.addLabel("3").addLabel("1");
bad_p4.add(w);
bad_p4.add(badv);
TS_ASSERT_THROWS(bad_p4.fillWith(p), gum::InvalidArgument);
}
void testFillWithPotentialAndMapMethod() {
gum::LabelizedVariable v("v", "v", 2), w("w", "w", 3);
gum::Potential< int > p;
p.add(v);
p.add(w);
gum::LabelizedVariable vv("vv", "vv", 2), ww("ww", "ww", 3);
gum::Potential< int > pp;
pp.add(ww);
pp.add(vv);
TS_ASSERT_EQUALS(p.domainSize(), gum::Size(6));
TS_ASSERT_EQUALS(pp.domainSize(), gum::Size(6));
p.fillWith({1, 2, 3, 4, 5, 6});
TS_GUM_ASSERT_THROWS_NOTHING(pp.fillWith(p, {"w", "v"}));
TS_ASSERT_THROWS(pp.fillWith(p, {"v", "w"}), gum::InvalidArgument);
}
};
}
......@@ -2020,9 +2020,9 @@ class GumException(Exception):
def __del__(self):
return None
def toString(self) -> "std::string const":
"""toString(self) -> std::string const"""
return _pyAgrum.GumException_toString(self)
def what(self) -> "std::string const":
"""what(self) -> std::string const"""
return _pyAgrum.GumException_what(self)
def errorContent(self) -> "std::string const":
......@@ -2090,6 +2090,7 @@ class IdError(GumException):
"""
__init__(self, aMsg, aType) -> IdError
__init__(self, aMsg) -> IdError
__init__(self, src) -> IdError
"""
this = _pyAgrum.new_IdError(*args)
try:
......@@ -2119,6 +2120,7 @@ class FatalError(GumException):
"""
__init__(self, aMsg, aType) -> FatalError
__init__(self, aMsg) -> FatalError
__init__(self, src) -> FatalError
"""
this = _pyAgrum.new_FatalError(*args)
try:
......@@ -2148,6 +2150,7 @@ class UndefinedIteratorValue(GumException):
"""
__init__(self, aMsg, aType) -> UndefinedIteratorValue
__init__(self, aMsg) -> UndefinedIteratorValue
__init__(self, src) -> UndefinedIteratorValue
"""
this = _pyAgrum.new_UndefinedIteratorValue(*args)
try:
......@@ -2177,6 +2180,7 @@ class UndefinedIteratorKey(GumException):
"""
__init__(self, aMsg, aType) -> UndefinedIteratorKey
__init__(self, aMsg) -> UndefinedIteratorKey
__init__(self, src) -> UndefinedIteratorKey
"""
this = _pyAgrum.new_UndefinedIteratorKey(*args)
try:
......@@ -2206,6 +2210,7 @@ class NullElement(GumException):
"""
__init__(self, aMsg, aType) -> NullElement
__init__(self, aMsg) -> NullElement
__init__(self, src) -> NullElement
"""
this = _pyAgrum.new_NullElement(*args)
try:
......@@ -2235,6 +2240,7 @@ class UndefinedElement(GumException):
"""
__init__(self, aMsg, aType) -> UndefinedElement
__init__(self, aMsg) -> UndefinedElement
__init__(self, src) -> UndefinedElement
"""
this = _pyAgrum.new_UndefinedElement(*args)
try:
......@@ -2264,6 +2270,7 @@ class SizeError(GumException):
"""
__init__(self, aMsg, aType) -> SizeError
__init__(self, aMsg) -> SizeError
__init__(self, src) -> SizeError
"""
this = _pyAgrum.new_SizeError(*args)
try:
......@@ -2293,6 +2300,7 @@ class EmptySet(GumException):
"""
__init__(self, aMsg, aType) -> EmptySet
__init__(self, aMsg) -> EmptySet
__init__(self, src) -> EmptySet
"""
this = _pyAgrum.new_EmptySet(*args)
try:
......@@ -2322,6 +2330,7 @@ class InvalidArgumentsNumber(GumException):
"""
__init__(self, aMsg, aType) -> InvalidArgumentsNumber
__init__(self, aMsg) -> InvalidArgumentsNumber
__init__(self, src) -> InvalidArgumentsNumber
"""
this = _pyAgrum.new_InvalidArgumentsNumber(*args)
try:
......@@ -2351,6 +2360,7 @@ class InvalidArgument(GumException):
"""
__init__(self, aMsg, aType) -> InvalidArgument
__init__(self, aMsg) -> InvalidArgument
__init__(self, src) -> InvalidArgument
"""
this = _pyAgrum.new_InvalidArgument(*args)
try:
......@@ -2380,6 +2390,7 @@ class IOError(GumException):
"""
__init__(self, aMsg, aType) -> IOError
__init__(self, aMsg) -> IOError
__init__(self, src) -> IOError
"""
this = _pyAgrum.new_IOError(*args)
try:
......@@ -2409,6 +2420,7 @@ class FormatNotFound(IOError):
"""
__init__(self, aMsg, aType) -> FormatNotFound
__init__(self, aMsg) -> FormatNotFound
__init__(self, src) -> FormatNotFound
"""
this = _pyAgrum.new_FormatNotFound(*args)
try:
......@@ -2438,6 +2450,7 @@ class OperationNotAllowed(GumException):
"""
__init__(self, aMsg, aType) -> OperationNotAllowed
__init__(self, aMsg) -> OperationNotAllowed
__init__(self, src) -> OperationNotAllowed
"""
this = _pyAgrum.new_OperationNotAllowed(*args)
try:
......@@ -2467,6 +2480,7 @@ class NotFound(GumException):
"""
__init__(self, aMsg, aType) -> NotFound
__init__(self, aMsg) -> NotFound
__init__(self, src) -> NotFound
"""
this = _pyAgrum.new_NotFound(*args)
try:
......@@ -2496,6 +2510,7 @@ class ReferenceError(GumException):
"""
__init__(self, aMsg, aType) -> ReferenceError
__init__(self, aMsg) -> ReferenceError
__init__(self, src) -> ReferenceError
"""
this = _pyAgrum.new_ReferenceError(*args)
try:
......@@ -2525,6 +2540,7 @@ class OutOfBounds(ReferenceError):
"""
__init__(self, aMsg, aType) -> OutOfBounds
__init__(self, aMsg) -> OutOfBounds
__init__(self, src) -> OutOfBounds
"""
this = _pyAgrum.new_OutOfBounds(*args)
try:
......@@ -2554,6 +2570,7 @@ class OutOfLowerBound(OutOfBounds):
"""
__init__(self, aMsg, aType) -> OutOfLowerBound
__init__(self, aMsg) -> OutOfLowerBound
__init__(self, src) -> OutOfLowerBound
"""
this = _pyAgrum.new_OutOfLowerBound(*args)
try:
......@@ -2583,6 +2600,7 @@ class OutOfUpperBound(OutOfBounds):
"""
__init__(self, aMsg, aType) -> OutOfUpperBound
__init__(self, aMsg) -> OutOfUpperBound
__init__(self, src) -> OutOfUpperBound
"""
this = _pyAgrum.new_OutOfUpperBound(*args)
try:
......@@ -2612,6 +2630,7 @@ class DuplicateElement(ReferenceError):
"""
__init__(self, aMsg, aType) -> DuplicateElement
__init__(self, aMsg) -> DuplicateElement
__init__(self, src) -> DuplicateElement
"""
this = _pyAgrum.new_DuplicateElement(*args)
try:
......@@ -2641,6 +2660,7 @@ class DuplicateLabel(ReferenceError):
"""
__init__(self, aMsg, aType) -> DuplicateLabel
__init__(self, aMsg) -> DuplicateLabel
__init__(self, src) -> DuplicateLabel
"""
this = _pyAgrum.new_DuplicateLabel(*args)
try:
......@@ -2670,6 +2690,7 @@ class GraphError(GumException):
"""
__init__(self, aMsg, aType) -> GraphError
__init__(self, aMsg) -> GraphError
__init__(self, src) -> GraphError
"""
this = _pyAgrum.new_GraphError(*args)
try:
......@@ -2699,6 +2720,7 @@ class NoNeighbour(GraphError):
"""
__init__(self, aMsg, aType) -> NoNeighbour
__init__(self, aMsg) -> NoNeighbour
__init__(self, src) -> NoNeighbour
"""
this = _pyAgrum.new_NoNeighbour(*args)
try:
......@@ -2728,6 +2750,7 @@ class NoParent(GraphError):
"""
__init__(self, aMsg, aType) -> NoParent
__init__(self, aMsg) -> NoParent
__init__(self, src) -> NoParent
"""
this = _pyAgrum.new_NoParent(*args)
try:
......@@ -2757,6 +2780,7 @@ class NoChild(GraphError):
"""
__init__(self, aMsg, aType) -> NoChild
__init__(self, aMsg) -> NoChild
__init__(self, src) -> NoChild
"""
this = _pyAgrum.new_NoChild(*args)
try:
......@@ -2786,6 +2810,7 @@ class InvalidEdge(GraphError):
"""
__init__(self, aMsg, aType) -> InvalidEdge
__init__(self, aMsg) -> InvalidEdge
__init__(self, src) -> InvalidEdge
"""
this = _pyAgrum.new_InvalidEdge(*args)
try:
......@@ -2815,6 +2840,7 @@ class InvalidArc(GraphError):
"""
__init__(self, aMsg, aType) -> InvalidArc
__init__(self, aMsg) -> InvalidArc
__init__(self, src) -> InvalidArc
"""
this = _pyAgrum.new_InvalidArc(*args)
try:
......@@ -2844,6 +2870,7 @@ class InvalidNode(GraphError):
"""
__init__(self, aMsg, aType) -> InvalidNode
__init__(self, aMsg) -> InvalidNode
__init__(self, src) -> InvalidNode
"""
this = _pyAgrum.new_InvalidNode(*args)
try:
......@@ -2873,6 +2900,7 @@ class EmptyBSTree(GraphError):
"""
__init__(self, aMsg, aType) -> EmptyBSTree
__init__(self, aMsg) -> EmptyBSTree
__init__(self, src) -> EmptyBSTree
"""
this = _pyAgrum.new_EmptyBSTree(*args)
try:
......@@ -2902,6 +2930,7 @@ class DefaultInLabel(GraphError):
"""
__init__(self, aMsg, aType) -> DefaultInLabel
__init__(self, aMsg) -> DefaultInLabel
__init__(self, src) -> DefaultInLabel
"""
this = _pyAgrum.new_DefaultInLabel(*args)
try:
......@@ -2931,6 +2960,7 @@ class InvalidDirectedCycle(GraphError):
"""
__init__(self, aMsg, aType) -> InvalidDirectedCycle
__init__(self, aMsg) -> InvalidDirectedCycle
__init__(self, src) -> InvalidDirectedCycle
"""
this = _pyAgrum.new_InvalidDirectedCycle(*args)
try:
......@@ -2960,6 +2990,7 @@ class CPTError(GumException):
"""
__init__(self, aMsg, aType) -> CPTError
__init__(self, aMsg) -> CPTError
__init__(self, src) -> CPTError
"""
this = _pyAgrum.new_CPTError(*args)
try:
......@@ -2989,6 +3020,7 @@ class CPTNoSumTo1(CPTError):
"""
__init__(self, aMsg, aType) -> CPTNoSumTo1
__init__(self, aMsg) -> CPTNoSumTo1
__init__(self, src) -> CPTNoSumTo1
"""
this = _pyAgrum.new_CPTNoSumTo1(*args)
try:
......@@ -3018,6 +3050,7 @@ class IncompatibleEvidence(GumException):
"""
__init__(self, aMsg, aType) -> IncompatibleEvidence
__init__(self, aMsg) -> IncompatibleEvidence
__init__(self, src) -> IncompatibleEvidence
"""
this = _pyAgrum.new_IncompatibleEvidence(*args)
try:
......@@ -3047,6 +3080,7 @@ class FactoryError(GumException):
"""
__init__(self, aMsg, aType) -> FactoryError
__init__(self, aMsg) -> FactoryError
__init__(self, src) -> FactoryError
"""
this = _pyAgrum.new_FactoryError(*args)
try:
......@@ -3076,6 +3110,7 @@ class FactoryInvalidState(FactoryError):
"""
__init__(self, aMsg, aType) -> FactoryInvalidState
__init__(self, aMsg) -> FactoryInvalidState
__init__(self, src) -> FactoryInvalidState
"""
this = _pyAgrum.new_FactoryInvalidState(*args)
try:
......@@ -3105,6 +3140,7 @@ class WrongType(FactoryError):
"""
__init__(self, aMsg, aType) -> WrongType
__init__(self, aMsg) -> WrongType
__init__(self, src) -> WrongType
"""
this = _pyAgrum.new_WrongType(*args)
try:
......@@ -3134,6 +3170,7 @@ class WrongClassElement(FactoryError):
"""
__init__(self, aMsg, aType) -> WrongClassElement
__init__(self, aMsg) -> WrongClassElement
__init__(self, src) -> WrongClassElement
"""
this = _pyAgrum.new_WrongClassElement(*args)
try:
......@@ -3163,6 +3200,7 @@ class TypeError(FactoryError):
"""
__init__(self, aMsg, aType) -> TypeError
__init__(self, aMsg) -> TypeError
__init__(self, src) -> TypeError
"""
this = _pyAgrum.new_TypeError(*args)
try:
......@@ -3192,6 +3230,7 @@ class LearningError(GumException):
"""
__init__(self, aMsg, aType) -> LearningError
__init__(self, aMsg) -> LearningError
__init__(self, src) -> LearningError
"""
this = _pyAgrum.new_LearningError(*args)
try:
......@@ -3221,6 +3260,7 @@ class IncompatibleScoreApriori(LearningError):
"""
__init__(self, aMsg, aType) -> IncompatibleScoreApriori
__init__(self, aMsg) -> IncompatibleScoreApriori
__init__(self, src) -> IncompatibleScoreApriori
"""
this = _pyAgrum.new_IncompatibleScoreApriori(*args)
try:
......@@ -3250,6 +3290,7 @@ class PossiblyIncompatibleScoreApriori(LearningError):
"""
__init__(self, aMsg, aType) -> PossiblyIncompatibleScoreApriori
__init__(self, aMsg) -> PossiblyIncompatibleScoreApriori
__init__(self, src) -> PossiblyIncompatibleScoreApriori
"""
this = _pyAgrum.new_PossiblyIncompatibleScoreApriori(*args)
try:
......@@ -3279,6 +3320,7 @@ class DatabaseError(LearningError):
"""
__init__(self, aMsg, aType) -> DatabaseError
__init__(self, aMsg) -> DatabaseError
__init__(self, src) -> DatabaseError
"""
this = _pyAgrum.new_DatabaseError(*args)
try:
......@@ -3308,6 +3350,7 @@ class MissingVariableInDatabase(LearningError):
"""
__init__(self, aMsg, aType) -> MissingVariableInDatabase
__init__(self, aMsg) -> MissingVariableInDatabase
__init__(self, src) -> MissingVariableInDatabase
"""
this = _pyAgrum.new_MissingVariableInDatabase(*args)
try:
......@@ -3337,6 +3380,7 @@ class UnknownLabelInDatabase(LearningError):
"""
__init__(self, aMsg, aType) -> UnknownLabelInDatabase
__init__(self, aMsg) -> UnknownLabelInDatabase
__init__(self, src) -> UnknownLabelInDatabase
"""
this = _pyAgrum.new_UnknownLabelInDatabase(*args)
try:
......@@ -8937,6 +8981,7 @@ class Potential_double(_object):
def fillWith(self, *args) -> "gum::Potential< double > const &":
"""
fillWith(self, src) -> Potential_double
fillWith(self, src, mapSrc) -> Potential_double
fillWith(self, v) -> Potential_double
fillWith(self, v) -> Potential_double
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -556,8 +556,23 @@ def _reprPotential(pot, digits=4, withColors=True, varnames=None, asString=False
else:
return HTML("".join(html))
def __isKindOfProba(pot):
"""
check if pot is a joint proba or a CPT
:param pot: the potential
:return: True or False
"""
if abs(pot.sum()-1)<1e-2:
return True
q=pot.margSumOut([pot.variable(0).name()])
if abs(q.max()-1)>1e-2:
return False
if abs(q.min()-1)>1e-2:
return False
return True
def showPotential(pot, digits=4, withColors=True, varnames=None):
def showPotential(pot, digits=4, withColors=None, varnames=None):
"""
show a gum.Potential as a HTML table.
The first dimension is special (horizontal) due to the representation of conditional probability table
......@@ -568,10 +583,13 @@ def showPotential(pot, digits=4, withColors=True, varnames=None):
:param list of strings varnames: the aliases for variables name in the table
:return: the display of the potential
"""
if withColors is None:
withColors=__isKindOfProba
display(_reprPotential(pot, digits, withColors, varnames, asString=False))
def getPotential(pot, digits=4, withColors=True, varnames=None):
def getPotential(pot, digits=4, withColors=None, varnames=None):
"""
return a HTML string of a gum.Potential as a HTML table.
The first dimension is special (horizontal) due to the representation of conditional probability table
......@@ -582,6 +600,9 @@ def getPotential(pot, digits=4, withColors=True, varnames=None):
:param list of strings varnames: the aliases for variables name in the table
:return: the HTML string
"""
if withColors is None:
withColors=__isKindOfProba(pot)
return _reprPotential(pot, digits, withColors, varnames, asString=True)
......
......@@ -30,7 +30,6 @@ CHANGE_THEN_RETURN_SELF(sq)
CHANGE_THEN_RETURN_SELF(scale)
CHANGE_THEN_RETURN_SELF(translate)
CHANGE_THEN_RETURN_SELF(normalizeAsCPT)
CHANGE_THEN_RETURN_SELF(fillWith)
CHANGE_THEN_RETURN_SELF(set)
%rename ("$ignore", fullname=1) gum::Potential<double>::margSumOut(const Set<const DiscreteVariable*>& del_vars) const;
......
......@@ -32,7 +32,7 @@ class BNDatabaseGeneratorTestCase(pyAgrumTestCase):
with self.assertRaises(gum.FatalError):
dbgen.setVarOrder(["A", "O", "R", "S", "T"])
with self.assertRaises(IndexError):
with self.assertRaises(gum.NotFound):
dbgen.setVarOrder(["A", "O", "R", "S", "T", "X"])
def testDrawSamples(self):
......
......@@ -655,7 +655,7 @@ class TestOperators(pyAgrumTestCase):
self.assertNotEqual(p.variable(1), p.variable('v'))
self.assertNotEqual(p.variable(0), p.variable('w'))
with self.assertRaises(IndexError):
with self.assertRaises(gum.NotFound):
x = p.variable("zz")
def testFillWithPotential(self):
......@@ -673,6 +673,24 @@ class TestOperators(pyAgrumTestCase):
self.assertAlmostEquals(np.max(pABC.reorganize(['A', 'B', 'C']).toarray() -
pABC2.reorganize(['A', 'B', 'C']).toarray()), 0)
def testFillWithPotentialAndMap(self):
v = gum.LabelizedVariable("v", "v", 2)
w = gum.LabelizedVariable("w", "w", 3)
p = gum.Potential().add(v).add(w)
p.fillWith([1, 2, 3, 4, 5, 6])
vv = gum.LabelizedVariable("vv", "vv", 2)
ww = gum.LabelizedVariable("ww", "ww", 3)
pp = gum.Potential().add(ww).add(vv)
pp.fillWith(p, ["w", "v"])
self.assertAlmostEquals(np.max(p.reorganize(['v', 'w']).toarray() -
pp.reorganize(['vv', 'ww']).toarray()), 0)
vvv = gum.LabelizedVariable("vvv", "vvv", 2)
www = gum.LabelizedVariable("www", "www", 2)
ppp = gum.Potential().add(vvv).add(www)
with self.assertRaises(gum.InvalidArgument):
ppp.fillWith(p, ["w", "v"])
ts = unittest.TestSuite()
addTests(ts, TestInsertions)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment