partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | WeightedMinFill.cost | Cost function for WeightedMinFill.
The cost of eliminating a node is the sum of weights of the edges that need to
be added to the graph due to its elimination, where a weight of an edge is the
product of the weights, domain cardinality, of its constituent vertices. | pgmpy/inference/EliminationOrder.py | def cost(self, node):
"""
Cost function for WeightedMinFill.
The cost of eliminating a node is the sum of weights of the edges that need to
be added to the graph due to its elimination, where a weight of an edge is the
product of the weights, domain cardinality, of its constituen... | def cost(self, node):
"""
Cost function for WeightedMinFill.
The cost of eliminating a node is the sum of weights of the edges that need to
be added to the graph due to its elimination, where a weight of an edge is the
product of the weights, domain cardinality, of its constituen... | [
"Cost",
"function",
"for",
"WeightedMinFill",
".",
"The",
"cost",
"of",
"eliminating",
"a",
"node",
"is",
"the",
"sum",
"of",
"weights",
"of",
"the",
"edges",
"that",
"need",
"to",
"be",
"added",
"to",
"the",
"graph",
"due",
"to",
"its",
"elimination",
"... | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/EliminationOrder.py#L108-L117 | [
"def",
"cost",
"(",
"self",
",",
"node",
")",
":",
"edges",
"=",
"combinations",
"(",
"self",
".",
"moralized_model",
".",
"neighbors",
"(",
"node",
")",
",",
"2",
")",
"return",
"sum",
"(",
"[",
"self",
".",
"bayesian_model",
".",
"get_cardinality",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | MinWeight.cost | The cost of a eliminating a node is the product of weights, domain cardinality,
of its neighbors. | pgmpy/inference/EliminationOrder.py | def cost(self, node):
"""
The cost of a eliminating a node is the product of weights, domain cardinality,
of its neighbors.
"""
return np.prod([self.bayesian_model.get_cardinality(neig_node) for neig_node in
self.moralized_model.neighbors(node)]) | def cost(self, node):
"""
The cost of a eliminating a node is the product of weights, domain cardinality,
of its neighbors.
"""
return np.prod([self.bayesian_model.get_cardinality(neig_node) for neig_node in
self.moralized_model.neighbors(node)]) | [
"The",
"cost",
"of",
"a",
"eliminating",
"a",
"node",
"is",
"the",
"product",
"of",
"weights",
"domain",
"cardinality",
"of",
"its",
"neighbors",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/EliminationOrder.py#L130-L136 | [
"def",
"cost",
"(",
"self",
",",
"node",
")",
":",
"return",
"np",
".",
"prod",
"(",
"[",
"self",
".",
"bayesian_model",
".",
"get_cardinality",
"(",
"neig_node",
")",
"for",
"neig_node",
"in",
"self",
".",
"moralized_model",
".",
"neighbors",
"(",
"node... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNReader.get_static_properties | Returns a dictionary of STATICPROPERTIES
Examples
--------
>>> reader = XBNReader('xbn_test.xml')
>>> reader.get_static_properties()
{'FORMAT': 'MSR DTAS XML', 'VERSION': '0.2', 'CREATOR': 'Microsoft Research DTAS'} | pgmpy/readwrite/XMLBeliefNetwork.py | def get_static_properties(self):
"""
Returns a dictionary of STATICPROPERTIES
Examples
--------
>>> reader = XBNReader('xbn_test.xml')
>>> reader.get_static_properties()
{'FORMAT': 'MSR DTAS XML', 'VERSION': '0.2', 'CREATOR': 'Microsoft Research DTAS'}
""... | def get_static_properties(self):
"""
Returns a dictionary of STATICPROPERTIES
Examples
--------
>>> reader = XBNReader('xbn_test.xml')
>>> reader.get_static_properties()
{'FORMAT': 'MSR DTAS XML', 'VERSION': '0.2', 'CREATOR': 'Microsoft Research DTAS'}
""... | [
"Returns",
"a",
"dictionary",
"of",
"STATICPROPERTIES"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L85-L95 | [
"def",
"get_static_properties",
"(",
"self",
")",
":",
"return",
"{",
"tags",
".",
"tag",
":",
"tags",
".",
"get",
"(",
"'VALUE'",
")",
"for",
"tags",
"in",
"self",
".",
"bnmodel",
".",
"find",
"(",
"'STATICPROPERTIES'",
")",
"}"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNReader.get_variables | Returns a list of variables.
Examples
--------
>>> reader = XBNReader('xbn_test.xml')
>>> reader.get_variables()
{'a': {'TYPE': 'discrete', 'XPOS': '13495',
'YPOS': '10465', 'DESCRIPTION': '(a) Metastatic Cancer',
'STATES': ['Present', 'Absent']}
... | pgmpy/readwrite/XMLBeliefNetwork.py | def get_variables(self):
"""
Returns a list of variables.
Examples
--------
>>> reader = XBNReader('xbn_test.xml')
>>> reader.get_variables()
{'a': {'TYPE': 'discrete', 'XPOS': '13495',
'YPOS': '10465', 'DESCRIPTION': '(a) Metastatic Cancer',
... | def get_variables(self):
"""
Returns a list of variables.
Examples
--------
>>> reader = XBNReader('xbn_test.xml')
>>> reader.get_variables()
{'a': {'TYPE': 'discrete', 'XPOS': '13495',
'YPOS': '10465', 'DESCRIPTION': '(a) Metastatic Cancer',
... | [
"Returns",
"a",
"list",
"of",
"variables",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L97-L123 | [
"def",
"get_variables",
"(",
"self",
")",
":",
"variables",
"=",
"{",
"}",
"for",
"variable",
"in",
"self",
".",
"bnmodel",
".",
"find",
"(",
"'VARIABLES'",
")",
":",
"variables",
"[",
"variable",
".",
"get",
"(",
"'NAME'",
")",
"]",
"=",
"{",
"'TYPE... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNReader.get_edges | Returns a list of tuples. Each tuple contains two elements (parent, child) for each edge.
Examples
--------
>>> reader = XBNReader('xbn_test.xml')
>>> reader.get_edges()
[('a', 'b'), ('a', 'c'), ('b', 'd'), ('c', 'd'), ('c', 'e')] | pgmpy/readwrite/XMLBeliefNetwork.py | def get_edges(self):
"""
Returns a list of tuples. Each tuple contains two elements (parent, child) for each edge.
Examples
--------
>>> reader = XBNReader('xbn_test.xml')
>>> reader.get_edges()
[('a', 'b'), ('a', 'c'), ('b', 'd'), ('c', 'd'), ('c', 'e')]
... | def get_edges(self):
"""
Returns a list of tuples. Each tuple contains two elements (parent, child) for each edge.
Examples
--------
>>> reader = XBNReader('xbn_test.xml')
>>> reader.get_edges()
[('a', 'b'), ('a', 'c'), ('b', 'd'), ('c', 'd'), ('c', 'e')]
... | [
"Returns",
"a",
"list",
"of",
"tuples",
".",
"Each",
"tuple",
"contains",
"two",
"elements",
"(",
"parent",
"child",
")",
"for",
"each",
"edge",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L125-L135 | [
"def",
"get_edges",
"(",
"self",
")",
":",
"return",
"[",
"(",
"arc",
".",
"get",
"(",
"'PARENT'",
")",
",",
"arc",
".",
"get",
"(",
"'CHILD'",
")",
")",
"for",
"arc",
"in",
"self",
".",
"bnmodel",
".",
"find",
"(",
"'STRUCTURE'",
")",
"]"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNReader.get_distributions | Returns a dictionary of name and its distribution. Distribution is a ndarray.
The ndarray is stored in the standard way such that the rightmost variable changes most often.
Consider a CPD of variable 'd' which has parents 'b' and 'c' (distribution['CONDSET'] = ['b', 'c'])
| d_0 ... | pgmpy/readwrite/XMLBeliefNetwork.py | def get_distributions(self):
"""
Returns a dictionary of name and its distribution. Distribution is a ndarray.
The ndarray is stored in the standard way such that the rightmost variable changes most often.
Consider a CPD of variable 'd' which has parents 'b' and 'c' (distribution['CONDS... | def get_distributions(self):
"""
Returns a dictionary of name and its distribution. Distribution is a ndarray.
The ndarray is stored in the standard way such that the rightmost variable changes most often.
Consider a CPD of variable 'd' which has parents 'b' and 'c' (distribution['CONDS... | [
"Returns",
"a",
"dictionary",
"of",
"name",
"and",
"its",
"distribution",
".",
"Distribution",
"is",
"a",
"ndarray",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L137-L184 | [
"def",
"get_distributions",
"(",
"self",
")",
":",
"distribution",
"=",
"{",
"}",
"for",
"dist",
"in",
"self",
".",
"bnmodel",
".",
"find",
"(",
"'DISTRIBUTIONS'",
")",
":",
"variable_name",
"=",
"dist",
".",
"find",
"(",
"'PRIVATE'",
")",
".",
"get",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNReader.get_model | Returns an instance of Bayesian Model. | pgmpy/readwrite/XMLBeliefNetwork.py | def get_model(self):
"""
Returns an instance of Bayesian Model.
"""
model = BayesianModel()
model.add_nodes_from(self.variables)
model.add_edges_from(self.edges)
model.name = self.model_name
tabular_cpds = []
for var, values in self.variable_CPD.i... | def get_model(self):
"""
Returns an instance of Bayesian Model.
"""
model = BayesianModel()
model.add_nodes_from(self.variables)
model.add_edges_from(self.edges)
model.name = self.model_name
tabular_cpds = []
for var, values in self.variable_CPD.i... | [
"Returns",
"an",
"instance",
"of",
"Bayesian",
"Model",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L186-L215 | [
"def",
"get_model",
"(",
"self",
")",
":",
"model",
"=",
"BayesianModel",
"(",
")",
"model",
".",
"add_nodes_from",
"(",
"self",
".",
"variables",
")",
"model",
".",
"add_edges_from",
"(",
"self",
".",
"edges",
")",
"model",
".",
"name",
"=",
"self",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNWriter.set_analysisnotebook | Set attributes for ANALYSISNOTEBOOK tag
Parameters
----------
**data: dict
{name: value} for the attributes to be set.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter()
>>> writer.set_analys... | pgmpy/readwrite/XMLBeliefNetwork.py | def set_analysisnotebook(self, **data):
"""
Set attributes for ANALYSISNOTEBOOK tag
Parameters
----------
**data: dict
{name: value} for the attributes to be set.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
... | def set_analysisnotebook(self, **data):
"""
Set attributes for ANALYSISNOTEBOOK tag
Parameters
----------
**data: dict
{name: value} for the attributes to be set.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
... | [
"Set",
"attributes",
"for",
"ANALYSISNOTEBOOK",
"tag"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L285-L302 | [
"def",
"set_analysisnotebook",
"(",
"self",
",",
"*",
"*",
"data",
")",
":",
"for",
"key",
",",
"value",
"in",
"data",
".",
"items",
"(",
")",
":",
"self",
".",
"network",
".",
"set",
"(",
"str",
"(",
"key",
")",
",",
"str",
"(",
"value",
")",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNWriter.set_static_properties | Set STATICPROPERTIES tag for the network
Parameters
----------
**data: dict
{name: value} for name and value of the property.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter()
>>> writer.set... | pgmpy/readwrite/XMLBeliefNetwork.py | def set_static_properties(self, **data):
"""
Set STATICPROPERTIES tag for the network
Parameters
----------
**data: dict
{name: value} for name and value of the property.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNW... | def set_static_properties(self, **data):
"""
Set STATICPROPERTIES tag for the network
Parameters
----------
**data: dict
{name: value} for name and value of the property.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNW... | [
"Set",
"STATICPROPERTIES",
"tag",
"for",
"the",
"network"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L321-L338 | [
"def",
"set_static_properties",
"(",
"self",
",",
"*",
"*",
"data",
")",
":",
"static_prop",
"=",
"etree",
".",
"SubElement",
"(",
"self",
".",
"bnmodel",
",",
"'STATICPROPERTIES'",
")",
"for",
"key",
",",
"value",
"in",
"data",
".",
"items",
"(",
")",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNWriter.set_variables | Set variables for the network.
Parameters
----------
data: dict
dict for variable in the form of example as shown.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter()
>>> writer.set_variables(... | pgmpy/readwrite/XMLBeliefNetwork.py | def set_variables(self, data):
"""
Set variables for the network.
Parameters
----------
data: dict
dict for variable in the form of example as shown.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> wri... | def set_variables(self, data):
"""
Set variables for the network.
Parameters
----------
data: dict
dict for variable in the form of example as shown.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> wri... | [
"Set",
"variables",
"for",
"the",
"network",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L340-L366 | [
"def",
"set_variables",
"(",
"self",
",",
"data",
")",
":",
"variables",
"=",
"etree",
".",
"SubElement",
"(",
"self",
".",
"bnmodel",
",",
"\"VARIABLES\"",
")",
"for",
"var",
"in",
"sorted",
"(",
"data",
")",
":",
"variable",
"=",
"etree",
".",
"SubEl... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNWriter.set_edges | Set edges/arc in the network.
Parameters
----------
edge_list: array_like
list, tuple, dict or set whose each elements has two values (parent, child).
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter... | pgmpy/readwrite/XMLBeliefNetwork.py | def set_edges(self, edge_list):
"""
Set edges/arc in the network.
Parameters
----------
edge_list: array_like
list, tuple, dict or set whose each elements has two values (parent, child).
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNet... | def set_edges(self, edge_list):
"""
Set edges/arc in the network.
Parameters
----------
edge_list: array_like
list, tuple, dict or set whose each elements has two values (parent, child).
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNet... | [
"Set",
"edges",
"/",
"arc",
"in",
"the",
"network",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L368-L385 | [
"def",
"set_edges",
"(",
"self",
",",
"edge_list",
")",
":",
"structure",
"=",
"etree",
".",
"SubElement",
"(",
"self",
".",
"bnmodel",
",",
"'STRUCTURE'",
")",
"for",
"edge",
"in",
"edge_list",
":",
"etree",
".",
"SubElement",
"(",
"structure",
",",
"'A... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XBNWriter.set_distributions | Set distributions in the network.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer =XBNWriter()
>>> writer.set_distributions() | pgmpy/readwrite/XMLBeliefNetwork.py | def set_distributions(self):
"""
Set distributions in the network.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer =XBNWriter()
>>> writer.set_distributions()
"""
distributions = etree.SubElement(self.bnmode... | def set_distributions(self):
"""
Set distributions in the network.
Examples
--------
>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer =XBNWriter()
>>> writer.set_distributions()
"""
distributions = etree.SubElement(self.bnmode... | [
"Set",
"distributions",
"in",
"the",
"network",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L387-L417 | [
"def",
"set_distributions",
"(",
"self",
")",
":",
"distributions",
"=",
"etree",
".",
"SubElement",
"(",
"self",
".",
"bnmodel",
",",
"'DISTRIBUTIONS'",
")",
"cpds",
"=",
"self",
".",
"model",
".",
"get_cpds",
"(",
")",
"cpds",
".",
"sort",
"(",
"key",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | FactorGraph.add_edge | Add an edge between variable_node and factor_node.
Parameters
----------
u, v: nodes
Nodes can be any hashable Python object.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> G = FactorGraph()
>>> G.add_nodes_from(['a', 'b', 'c'... | pgmpy/models/FactorGraph.py | def add_edge(self, u, v, **kwargs):
"""
Add an edge between variable_node and factor_node.
Parameters
----------
u, v: nodes
Nodes can be any hashable Python object.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> G = F... | def add_edge(self, u, v, **kwargs):
"""
Add an edge between variable_node and factor_node.
Parameters
----------
u, v: nodes
Nodes can be any hashable Python object.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> G = F... | [
"Add",
"an",
"edge",
"between",
"variable_node",
"and",
"factor_node",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/FactorGraph.py#L72-L93 | [
"def",
"add_edge",
"(",
"self",
",",
"u",
",",
"v",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"u",
"!=",
"v",
":",
"super",
"(",
"FactorGraph",
",",
"self",
")",
".",
"add_edge",
"(",
"u",
",",
"v",
",",
"*",
"*",
"kwargs",
")",
"else",
":",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | FactorGraph.check_model | Check the model for various errors. This method checks for the following
errors. In the same time it also updates the cardinalities of all the
random variables.
* Check whether bipartite property of factor graph is still maintained
or not.
* Check whether factors are associate... | pgmpy/models/FactorGraph.py | def check_model(self):
"""
Check the model for various errors. This method checks for the following
errors. In the same time it also updates the cardinalities of all the
random variables.
* Check whether bipartite property of factor graph is still maintained
or not.
... | def check_model(self):
"""
Check the model for various errors. This method checks for the following
errors. In the same time it also updates the cardinalities of all the
random variables.
* Check whether bipartite property of factor graph is still maintained
or not.
... | [
"Check",
"the",
"model",
"for",
"various",
"errors",
".",
"This",
"method",
"checks",
"for",
"the",
"following",
"errors",
".",
"In",
"the",
"same",
"time",
"it",
"also",
"updates",
"the",
"cardinalities",
"of",
"all",
"the",
"random",
"variables",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/FactorGraph.py#L190-L227 | [
"def",
"check_model",
"(",
"self",
")",
":",
"variable_nodes",
"=",
"set",
"(",
"[",
"x",
"for",
"factor",
"in",
"self",
".",
"factors",
"for",
"x",
"in",
"factor",
".",
"scope",
"(",
")",
"]",
")",
"factor_nodes",
"=",
"set",
"(",
"self",
".",
"no... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | FactorGraph.get_variable_nodes | Returns variable nodes present in the graph.
Before calling this method make sure that all the factors are added
properly.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> G = FactorGraph()
... | pgmpy/models/FactorGraph.py | def get_variable_nodes(self):
"""
Returns variable nodes present in the graph.
Before calling this method make sure that all the factors are added
properly.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgmpy.factors.discrete import... | def get_variable_nodes(self):
"""
Returns variable nodes present in the graph.
Before calling this method make sure that all the factors are added
properly.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgmpy.factors.discrete import... | [
"Returns",
"variable",
"nodes",
"present",
"in",
"the",
"graph",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/FactorGraph.py#L229-L254 | [
"def",
"get_variable_nodes",
"(",
"self",
")",
":",
"self",
".",
"check_model",
"(",
")",
"variable_nodes",
"=",
"set",
"(",
"[",
"x",
"for",
"factor",
"in",
"self",
".",
"factors",
"for",
"x",
"in",
"factor",
".",
"scope",
"(",
")",
"]",
")",
"retur... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | FactorGraph.get_factor_nodes | Returns factors nodes present in the graph.
Before calling this method make sure that all the factors are added
properly.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> G = FactorGraph()
... | pgmpy/models/FactorGraph.py | def get_factor_nodes(self):
"""
Returns factors nodes present in the graph.
Before calling this method make sure that all the factors are added
properly.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgmpy.factors.discrete import Di... | def get_factor_nodes(self):
"""
Returns factors nodes present in the graph.
Before calling this method make sure that all the factors are added
properly.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgmpy.factors.discrete import Di... | [
"Returns",
"factors",
"nodes",
"present",
"in",
"the",
"graph",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/FactorGraph.py#L256-L283 | [
"def",
"get_factor_nodes",
"(",
"self",
")",
":",
"self",
".",
"check_model",
"(",
")",
"variable_nodes",
"=",
"self",
".",
"get_variable_nodes",
"(",
")",
"factor_nodes",
"=",
"set",
"(",
"self",
".",
"nodes",
"(",
")",
")",
"-",
"set",
"(",
"variable_n... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | FactorGraph.to_markov_model | Converts the factor graph into markov model.
A markov model contains nodes as random variables and edge between
two nodes imply interaction between them.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgmpy.factors.discrete import DiscreteFactor
... | pgmpy/models/FactorGraph.py | def to_markov_model(self):
"""
Converts the factor graph into markov model.
A markov model contains nodes as random variables and edge between
two nodes imply interaction between them.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from p... | def to_markov_model(self):
"""
Converts the factor graph into markov model.
A markov model contains nodes as random variables and edge between
two nodes imply interaction between them.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from p... | [
"Converts",
"the",
"factor",
"graph",
"into",
"markov",
"model",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/FactorGraph.py#L285-L319 | [
"def",
"to_markov_model",
"(",
"self",
")",
":",
"mm",
"=",
"MarkovModel",
"(",
")",
"variable_nodes",
"=",
"self",
".",
"get_variable_nodes",
"(",
")",
"if",
"len",
"(",
"set",
"(",
"self",
".",
"nodes",
"(",
")",
")",
"-",
"set",
"(",
"variable_nodes... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | FactorGraph.get_factors | Returns the factors that have been added till now to the graph.
If node is not None, it would return the factor corresponding to the
given node.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> ... | pgmpy/models/FactorGraph.py | def get_factors(self, node=None):
"""
Returns the factors that have been added till now to the graph.
If node is not None, it would return the factor corresponding to the
given node.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgm... | def get_factors(self, node=None):
"""
Returns the factors that have been added till now to the graph.
If node is not None, it would return the factor corresponding to the
given node.
Examples
--------
>>> from pgmpy.models import FactorGraph
>>> from pgm... | [
"Returns",
"the",
"factors",
"that",
"have",
"been",
"added",
"till",
"now",
"to",
"the",
"graph",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/FactorGraph.py#L347-L378 | [
"def",
"get_factors",
"(",
"self",
",",
"node",
"=",
"None",
")",
":",
"if",
"node",
"is",
"None",
":",
"return",
"self",
".",
"factors",
"else",
":",
"factor_nodes",
"=",
"self",
".",
"get_factor_nodes",
"(",
")",
"if",
"node",
"not",
"in",
"factor_no... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | BdeuScore.local_score | Computes a score that measures how much a \
given variable is \"influenced\" by a given list of potential parents. | pgmpy/estimators/BdeuScore.py | def local_score(self, variable, parents):
"Computes a score that measures how much a \
given variable is \"influenced\" by a given list of potential parents."
var_states = self.state_names[variable]
var_cardinality = len(var_states)
state_counts = self.state_counts(variable, par... | def local_score(self, variable, parents):
"Computes a score that measures how much a \
given variable is \"influenced\" by a given list of potential parents."
var_states = self.state_names[variable]
var_cardinality = len(var_states)
state_counts = self.state_counts(variable, par... | [
"Computes",
"a",
"score",
"that",
"measures",
"how",
"much",
"a",
"\\",
"given",
"variable",
"is",
"\\",
"influenced",
"\\",
"by",
"a",
"given",
"list",
"of",
"potential",
"parents",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/estimators/BdeuScore.py#L47-L68 | [
"def",
"local_score",
"(",
"self",
",",
"variable",
",",
"parents",
")",
":",
"var_states",
"=",
"self",
".",
"state_names",
"[",
"variable",
"]",
"var_cardinality",
"=",
"len",
"(",
"var_states",
")",
"state_counts",
"=",
"self",
".",
"state_counts",
"(",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DBNInference._get_clique | Extracting the cliques from the junction tree which are a subset of
the given nodes.
Parameters:
----------
junction_tree: Junction tree
from which the nodes are to be extracted.
nodes: iterable container
A container of nodes (list, dict, set, etc.). | pgmpy/inference/dbn_inference.py | def _get_clique(self, junction_tree, nodes):
"""
Extracting the cliques from the junction tree which are a subset of
the given nodes.
Parameters:
----------
junction_tree: Junction tree
from which the nodes are to be extracted.
nodes: iterable contai... | def _get_clique(self, junction_tree, nodes):
"""
Extracting the cliques from the junction tree which are a subset of
the given nodes.
Parameters:
----------
junction_tree: Junction tree
from which the nodes are to be extracted.
nodes: iterable contai... | [
"Extracting",
"the",
"cliques",
"from",
"the",
"junction",
"tree",
"which",
"are",
"a",
"subset",
"of",
"the",
"given",
"nodes",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/dbn_inference.py#L101-L115 | [
"def",
"_get_clique",
"(",
"self",
",",
"junction_tree",
",",
"nodes",
")",
":",
"return",
"[",
"clique",
"for",
"clique",
"in",
"junction_tree",
".",
"nodes",
"(",
")",
"if",
"set",
"(",
"nodes",
")",
".",
"issubset",
"(",
"clique",
")",
"]",
"[",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DBNInference._get_evidence | Getting the evidence belonging to a particular timeslice.
Parameters:
----------
evidence: dict
a dict key, value pair as {var: state_of_var_observed}
None if no evidence
time: int
the evidence corresponding to the time slice
shift: int
... | pgmpy/inference/dbn_inference.py | def _get_evidence(self, evidence_dict, time_slice, shift):
"""
Getting the evidence belonging to a particular timeslice.
Parameters:
----------
evidence: dict
a dict key, value pair as {var: state_of_var_observed}
None if no evidence
time: int
... | def _get_evidence(self, evidence_dict, time_slice, shift):
"""
Getting the evidence belonging to a particular timeslice.
Parameters:
----------
evidence: dict
a dict key, value pair as {var: state_of_var_observed}
None if no evidence
time: int
... | [
"Getting",
"the",
"evidence",
"belonging",
"to",
"a",
"particular",
"timeslice",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/dbn_inference.py#L117-L134 | [
"def",
"_get_evidence",
"(",
"self",
",",
"evidence_dict",
",",
"time_slice",
",",
"shift",
")",
":",
"if",
"evidence_dict",
":",
"return",
"{",
"(",
"node",
"[",
"0",
"]",
",",
"shift",
")",
":",
"evidence_dict",
"[",
"node",
"]",
"for",
"node",
"in",... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DBNInference._marginalize_factor | Marginalizing the factor selectively for a set of variables.
Parameters:
----------
nodes: list, array-like
A container of nodes (list, dict, set, etc.).
factor: factor
factor which is to be marginalized. | pgmpy/inference/dbn_inference.py | def _marginalize_factor(self, nodes, factor):
"""
Marginalizing the factor selectively for a set of variables.
Parameters:
----------
nodes: list, array-like
A container of nodes (list, dict, set, etc.).
factor: factor
factor which is to be margi... | def _marginalize_factor(self, nodes, factor):
"""
Marginalizing the factor selectively for a set of variables.
Parameters:
----------
nodes: list, array-like
A container of nodes (list, dict, set, etc.).
factor: factor
factor which is to be margi... | [
"Marginalizing",
"the",
"factor",
"selectively",
"for",
"a",
"set",
"of",
"variables",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/dbn_inference.py#L136-L149 | [
"def",
"_marginalize_factor",
"(",
"self",
",",
"nodes",
",",
"factor",
")",
":",
"marginalizing_nodes",
"=",
"list",
"(",
"set",
"(",
"factor",
".",
"scope",
"(",
")",
")",
".",
"difference",
"(",
"nodes",
")",
")",
"return",
"factor",
".",
"marginalize... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DBNInference._update_belief | Method for updating the belief.
Parameters:
----------
belief_prop: Belief Propagation
Belief Propagation which needs to be updated.
in_clique: clique
The factor which needs to be updated corresponding to the input clique.
out_clique_potential: factor
... | pgmpy/inference/dbn_inference.py | def _update_belief(self, belief_prop, clique, clique_potential, message=None):
"""
Method for updating the belief.
Parameters:
----------
belief_prop: Belief Propagation
Belief Propagation which needs to be updated.
in_clique: clique
The factor w... | def _update_belief(self, belief_prop, clique, clique_potential, message=None):
"""
Method for updating the belief.
Parameters:
----------
belief_prop: Belief Propagation
Belief Propagation which needs to be updated.
in_clique: clique
The factor w... | [
"Method",
"for",
"updating",
"the",
"belief",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/dbn_inference.py#L151-L177 | [
"def",
"_update_belief",
"(",
"self",
",",
"belief_prop",
",",
"clique",
",",
"clique_potential",
",",
"message",
"=",
"None",
")",
":",
"old_factor",
"=",
"belief_prop",
".",
"junction_tree",
".",
"get_factors",
"(",
"clique",
")",
"belief_prop",
".",
"juncti... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DBNInference._get_factor | Extracts the required factor from the junction tree.
Parameters:
----------
belief_prop: Belief Propagation
Belief Propagation which needs to be updated.
evidence: dict
a dict key, value pair as {var: state_of_var_observed} | pgmpy/inference/dbn_inference.py | def _get_factor(self, belief_prop, evidence):
"""
Extracts the required factor from the junction tree.
Parameters:
----------
belief_prop: Belief Propagation
Belief Propagation which needs to be updated.
evidence: dict
a dict key, value pair as {... | def _get_factor(self, belief_prop, evidence):
"""
Extracts the required factor from the junction tree.
Parameters:
----------
belief_prop: Belief Propagation
Belief Propagation which needs to be updated.
evidence: dict
a dict key, value pair as {... | [
"Extracts",
"the",
"required",
"factor",
"from",
"the",
"junction",
"tree",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/dbn_inference.py#L179-L196 | [
"def",
"_get_factor",
"(",
"self",
",",
"belief_prop",
",",
"evidence",
")",
":",
"final_factor",
"=",
"factor_product",
"(",
"*",
"belief_prop",
".",
"junction_tree",
".",
"get_factors",
"(",
")",
")",
"if",
"evidence",
":",
"for",
"var",
"in",
"evidence",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DBNInference._shift_factor | Shifting the factor to a certain required time slice.
Parameters:
----------
factor: DiscreteFactor
The factor which needs to be shifted.
shift: int
The new timeslice to which the factor should belong to. | pgmpy/inference/dbn_inference.py | def _shift_factor(self, factor, shift):
"""
Shifting the factor to a certain required time slice.
Parameters:
----------
factor: DiscreteFactor
The factor which needs to be shifted.
shift: int
The new timeslice to which the factor should belong to.... | def _shift_factor(self, factor, shift):
"""
Shifting the factor to a certain required time slice.
Parameters:
----------
factor: DiscreteFactor
The factor which needs to be shifted.
shift: int
The new timeslice to which the factor should belong to.... | [
"Shifting",
"the",
"factor",
"to",
"a",
"certain",
"required",
"time",
"slice",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/dbn_inference.py#L198-L211 | [
"def",
"_shift_factor",
"(",
"self",
",",
"factor",
",",
"shift",
")",
":",
"new_scope",
"=",
"self",
".",
"_shift_nodes",
"(",
"factor",
".",
"scope",
"(",
")",
",",
"shift",
")",
"return",
"DiscreteFactor",
"(",
"new_scope",
",",
"factor",
".",
"cardin... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DBNInference.forward_inference | Forward inference method using belief propagation.
Parameters:
----------
variables: list
list of variables for which you want to compute the probability
evidence: dict
a dict key, value pair as {var: state_of_var_observed}
None if no evidence
... | pgmpy/inference/dbn_inference.py | def forward_inference(self, variables, evidence=None, args=None):
"""
Forward inference method using belief propagation.
Parameters:
----------
variables: list
list of variables for which you want to compute the probability
evidence: dict
a dict ... | def forward_inference(self, variables, evidence=None, args=None):
"""
Forward inference method using belief propagation.
Parameters:
----------
variables: list
list of variables for which you want to compute the probability
evidence: dict
a dict ... | [
"Forward",
"inference",
"method",
"using",
"belief",
"propagation",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/dbn_inference.py#L213-L310 | [
"def",
"forward_inference",
"(",
"self",
",",
"variables",
",",
"evidence",
"=",
"None",
",",
"args",
"=",
"None",
")",
":",
"variable_dict",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"var",
"in",
"variables",
":",
"variable_dict",
"[",
"var",
"[",
"1... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DBNInference.backward_inference | Backward inference method using belief propagation.
Parameters:
----------
variables: list
list of variables for which you want to compute the probability
evidence: dict
a dict key, value pair as {var: state_of_var_observed}
None if no evidence
... | pgmpy/inference/dbn_inference.py | def backward_inference(self, variables, evidence=None):
"""
Backward inference method using belief propagation.
Parameters:
----------
variables: list
list of variables for which you want to compute the probability
evidence: dict
a dict key, value... | def backward_inference(self, variables, evidence=None):
"""
Backward inference method using belief propagation.
Parameters:
----------
variables: list
list of variables for which you want to compute the probability
evidence: dict
a dict key, value... | [
"Backward",
"inference",
"method",
"using",
"belief",
"propagation",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/dbn_inference.py#L312-L395 | [
"def",
"backward_inference",
"(",
"self",
",",
"variables",
",",
"evidence",
"=",
"None",
")",
":",
"variable_dict",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"var",
"in",
"variables",
":",
"variable_dict",
"[",
"var",
"[",
"1",
"]",
"]",
".",
"append... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DBNInference.query | Query method for Dynamic Bayesian Network using Interface Algorithm.
Parameters:
----------
variables: list
list of variables for which you want to compute the probability
evidence: dict
a dict key, value pair as {var: state_of_var_observed}
None if ... | pgmpy/inference/dbn_inference.py | def query(self, variables, evidence=None, args='exact'):
"""
Query method for Dynamic Bayesian Network using Interface Algorithm.
Parameters:
----------
variables: list
list of variables for which you want to compute the probability
evidence: dict
... | def query(self, variables, evidence=None, args='exact'):
"""
Query method for Dynamic Bayesian Network using Interface Algorithm.
Parameters:
----------
variables: list
list of variables for which you want to compute the probability
evidence: dict
... | [
"Query",
"method",
"for",
"Dynamic",
"Bayesian",
"Network",
"using",
"Interface",
"Algorithm",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/inference/dbn_inference.py#L397-L438 | [
"def",
"query",
"(",
"self",
",",
"variables",
",",
"evidence",
"=",
"None",
",",
"args",
"=",
"'exact'",
")",
":",
"if",
"args",
"==",
"'exact'",
":",
"return",
"self",
".",
"backward_inference",
"(",
"variables",
",",
"evidence",
")"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.add_node | Adds a single node to the Graph.
Parameters
----------
node: str, int, or any hashable python object.
The node to add to the graph.
weight: int, float
The weight of the node.
Examples
--------
>>> from pgmpy.base import DAG
>>> G... | pgmpy/base/DAG.py | def add_node(self, node, weight=None):
"""
Adds a single node to the Graph.
Parameters
----------
node: str, int, or any hashable python object.
The node to add to the graph.
weight: int, float
The weight of the node.
Examples
--... | def add_node(self, node, weight=None):
"""
Adds a single node to the Graph.
Parameters
----------
node: str, int, or any hashable python object.
The node to add to the graph.
weight: int, float
The weight of the node.
Examples
--... | [
"Adds",
"a",
"single",
"node",
"to",
"the",
"Graph",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L87-L125 | [
"def",
"add_node",
"(",
"self",
",",
"node",
",",
"weight",
"=",
"None",
")",
":",
"# Check for networkx 2.0 syntax",
"if",
"isinstance",
"(",
"node",
",",
"tuple",
")",
"and",
"len",
"(",
"node",
")",
"==",
"2",
"and",
"isinstance",
"(",
"node",
"[",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.add_nodes_from | Add multiple nodes to the Graph.
**The behviour of adding weights is different than in networkx.
Parameters
----------
nodes: iterable container
A container of nodes (list, dict, set, or any hashable python
object).
weights: list, tuple (default=None)
... | pgmpy/base/DAG.py | def add_nodes_from(self, nodes, weights=None):
"""
Add multiple nodes to the Graph.
**The behviour of adding weights is different than in networkx.
Parameters
----------
nodes: iterable container
A container of nodes (list, dict, set, or any hashable python
... | def add_nodes_from(self, nodes, weights=None):
"""
Add multiple nodes to the Graph.
**The behviour of adding weights is different than in networkx.
Parameters
----------
nodes: iterable container
A container of nodes (list, dict, set, or any hashable python
... | [
"Add",
"multiple",
"nodes",
"to",
"the",
"Graph",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L127-L170 | [
"def",
"add_nodes_from",
"(",
"self",
",",
"nodes",
",",
"weights",
"=",
"None",
")",
":",
"nodes",
"=",
"list",
"(",
"nodes",
")",
"if",
"weights",
":",
"if",
"len",
"(",
"nodes",
")",
"!=",
"len",
"(",
"weights",
")",
":",
"raise",
"ValueError",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.add_edge | Add an edge between u and v.
The nodes u and v will be automatically added if they are
not already in the graph.
Parameters
----------
u, v : nodes
Nodes can be any hashable Python object.
weight: int, float (default=None)
The weight of the edge... | pgmpy/base/DAG.py | def add_edge(self, u, v, weight=None):
"""
Add an edge between u and v.
The nodes u and v will be automatically added if they are
not already in the graph.
Parameters
----------
u, v : nodes
Nodes can be any hashable Python object.
weight: i... | def add_edge(self, u, v, weight=None):
"""
Add an edge between u and v.
The nodes u and v will be automatically added if they are
not already in the graph.
Parameters
----------
u, v : nodes
Nodes can be any hashable Python object.
weight: i... | [
"Add",
"an",
"edge",
"between",
"u",
"and",
"v",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L172-L210 | [
"def",
"add_edge",
"(",
"self",
",",
"u",
",",
"v",
",",
"weight",
"=",
"None",
")",
":",
"super",
"(",
"DAG",
",",
"self",
")",
".",
"add_edge",
"(",
"u",
",",
"v",
",",
"weight",
"=",
"weight",
")"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.add_edges_from | Add all the edges in ebunch.
If nodes referred in the ebunch are not already present, they
will be automatically added. Node names can be any hashable python
object.
**The behavior of adding weights is different than networkx.
Parameters
----------
ebunch : con... | pgmpy/base/DAG.py | def add_edges_from(self, ebunch, weights=None):
"""
Add all the edges in ebunch.
If nodes referred in the ebunch are not already present, they
will be automatically added. Node names can be any hashable python
object.
**The behavior of adding weights is different than n... | def add_edges_from(self, ebunch, weights=None):
"""
Add all the edges in ebunch.
If nodes referred in the ebunch are not already present, they
will be automatically added. Node names can be any hashable python
object.
**The behavior of adding weights is different than n... | [
"Add",
"all",
"the",
"edges",
"in",
"ebunch",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L212-L269 | [
"def",
"add_edges_from",
"(",
"self",
",",
"ebunch",
",",
"weights",
"=",
"None",
")",
":",
"ebunch",
"=",
"list",
"(",
"ebunch",
")",
"if",
"weights",
":",
"if",
"len",
"(",
"ebunch",
")",
"!=",
"len",
"(",
"weights",
")",
":",
"raise",
"ValueError"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.moralize | Removes all the immoralities in the DAG and creates a moral
graph (UndirectedGraph).
A v-structure X->Z<-Y is an immorality if there is no directed edge
between X and Y.
Examples
--------
>>> from pgmpy.base import DAG
>>> G = DAG(ebunch=[('diff', 'grade'), ('in... | pgmpy/base/DAG.py | def moralize(self):
"""
Removes all the immoralities in the DAG and creates a moral
graph (UndirectedGraph).
A v-structure X->Z<-Y is an immorality if there is no directed edge
between X and Y.
Examples
--------
>>> from pgmpy.base import DAG
>>>... | def moralize(self):
"""
Removes all the immoralities in the DAG and creates a moral
graph (UndirectedGraph).
A v-structure X->Z<-Y is an immorality if there is no directed edge
between X and Y.
Examples
--------
>>> from pgmpy.base import DAG
>>>... | [
"Removes",
"all",
"the",
"immoralities",
"in",
"the",
"DAG",
"and",
"creates",
"a",
"moral",
"graph",
"(",
"UndirectedGraph",
")",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L291-L313 | [
"def",
"moralize",
"(",
"self",
")",
":",
"moral_graph",
"=",
"UndirectedGraph",
"(",
"self",
".",
"to_undirected",
"(",
")",
".",
"edges",
"(",
")",
")",
"for",
"node",
"in",
"self",
".",
"nodes",
"(",
")",
":",
"moral_graph",
".",
"add_edges_from",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.get_roots | Returns a list of roots of the graph.
Examples
--------
>>> from pgmpy.base import DAG
>>> graph = DAG([('A', 'B'), ('B', 'C'), ('B', 'D'), ('E', 'B')])
>>> graph.get_roots()
['A', 'E'] | pgmpy/base/DAG.py | def get_roots(self):
"""
Returns a list of roots of the graph.
Examples
--------
>>> from pgmpy.base import DAG
>>> graph = DAG([('A', 'B'), ('B', 'C'), ('B', 'D'), ('E', 'B')])
>>> graph.get_roots()
['A', 'E']
"""
return [node for node, i... | def get_roots(self):
"""
Returns a list of roots of the graph.
Examples
--------
>>> from pgmpy.base import DAG
>>> graph = DAG([('A', 'B'), ('B', 'C'), ('B', 'D'), ('E', 'B')])
>>> graph.get_roots()
['A', 'E']
"""
return [node for node, i... | [
"Returns",
"a",
"list",
"of",
"roots",
"of",
"the",
"graph",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L341-L352 | [
"def",
"get_roots",
"(",
"self",
")",
":",
"return",
"[",
"node",
"for",
"node",
",",
"in_degree",
"in",
"dict",
"(",
"self",
".",
"in_degree",
"(",
")",
")",
".",
"items",
"(",
")",
"if",
"in_degree",
"==",
"0",
"]"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.get_independencies | Computes independencies in the DAG, by checking d-seperation.
Parameters
----------
latex: boolean
If latex=True then latex string of the independence assertion
would be created.
Examples
--------
>>> from pgmpy.base import DAG
>>> chain ... | pgmpy/base/DAG.py | def get_independencies(self, latex=False):
"""
Computes independencies in the DAG, by checking d-seperation.
Parameters
----------
latex: boolean
If latex=True then latex string of the independence assertion
would be created.
Examples
---... | def get_independencies(self, latex=False):
"""
Computes independencies in the DAG, by checking d-seperation.
Parameters
----------
latex: boolean
If latex=True then latex string of the independence assertion
would be created.
Examples
---... | [
"Computes",
"independencies",
"in",
"the",
"DAG",
"by",
"checking",
"d",
"-",
"seperation",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L374-L407 | [
"def",
"get_independencies",
"(",
"self",
",",
"latex",
"=",
"False",
")",
":",
"independencies",
"=",
"Independencies",
"(",
")",
"for",
"start",
"in",
"(",
"self",
".",
"nodes",
"(",
")",
")",
":",
"rest",
"=",
"set",
"(",
"self",
".",
"nodes",
"("... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.local_independencies | Returns an instance of Independencies containing the local independencies
of each of the variables.
Parameters
----------
variables: str or array like
variables whose local independencies are to be found.
Examples
--------
>>> from pgmpy.models impor... | pgmpy/base/DAG.py | def local_independencies(self, variables):
"""
Returns an instance of Independencies containing the local independencies
of each of the variables.
Parameters
----------
variables: str or array like
variables whose local independencies are to be found.
... | def local_independencies(self, variables):
"""
Returns an instance of Independencies containing the local independencies
of each of the variables.
Parameters
----------
variables: str or array like
variables whose local independencies are to be found.
... | [
"Returns",
"an",
"instance",
"of",
"Independencies",
"containing",
"the",
"local",
"independencies",
"of",
"each",
"of",
"the",
"variables",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L409-L451 | [
"def",
"local_independencies",
"(",
"self",
",",
"variables",
")",
":",
"def",
"dfs",
"(",
"node",
")",
":",
"\"\"\"\n Returns the descendents of node.\n\n This is a very simple dfs\n which does not remember which nodes it has visited.\n \"\"\"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.is_iequivalent | Checks whether the given model is I-equivalent
Two graphs G1 and G2 are said to be I-equivalent if they have same skeleton
and have same set of immoralities.
Note: For same skeleton different names of nodes can work but for immoralities
names of nodes must be same
Parameters
... | pgmpy/base/DAG.py | def is_iequivalent(self, model):
"""
Checks whether the given model is I-equivalent
Two graphs G1 and G2 are said to be I-equivalent if they have same skeleton
and have same set of immoralities.
Note: For same skeleton different names of nodes can work but for immoralities
... | def is_iequivalent(self, model):
"""
Checks whether the given model is I-equivalent
Two graphs G1 and G2 are said to be I-equivalent if they have same skeleton
and have same set of immoralities.
Note: For same skeleton different names of nodes can work but for immoralities
... | [
"Checks",
"whether",
"the",
"given",
"model",
"is",
"I",
"-",
"equivalent"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L453-L489 | [
"def",
"is_iequivalent",
"(",
"self",
",",
"model",
")",
":",
"if",
"not",
"isinstance",
"(",
"model",
",",
"DAG",
")",
":",
"raise",
"TypeError",
"(",
"'model must be an instance of DAG'",
")",
"skeleton",
"=",
"nx",
".",
"algorithms",
".",
"isomorphism",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.get_immoralities | Finds all the immoralities in the model
A v-structure X -> Z <- Y is an immorality if there is no direct edge between X and Y .
Returns
-------
set: A set of all the immoralities in the model
Examples
---------
>>> from pgmpy.base import DAG
>>> student ... | pgmpy/base/DAG.py | def get_immoralities(self):
"""
Finds all the immoralities in the model
A v-structure X -> Z <- Y is an immorality if there is no direct edge between X and Y .
Returns
-------
set: A set of all the immoralities in the model
Examples
---------
>>>... | def get_immoralities(self):
"""
Finds all the immoralities in the model
A v-structure X -> Z <- Y is an immorality if there is no direct edge between X and Y .
Returns
-------
set: A set of all the immoralities in the model
Examples
---------
>>>... | [
"Finds",
"all",
"the",
"immoralities",
"in",
"the",
"model",
"A",
"v",
"-",
"structure",
"X",
"-",
">",
"Z",
"<",
"-",
"Y",
"is",
"an",
"immorality",
"if",
"there",
"is",
"no",
"direct",
"edge",
"between",
"X",
"and",
"Y",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L491-L514 | [
"def",
"get_immoralities",
"(",
"self",
")",
":",
"immoralities",
"=",
"set",
"(",
")",
"for",
"node",
"in",
"self",
".",
"nodes",
"(",
")",
":",
"for",
"parents",
"in",
"itertools",
".",
"combinations",
"(",
"self",
".",
"predecessors",
"(",
"node",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.is_active_trail | Returns True if there is any active trail between start and end node
Parameters
----------
start : Graph Node
end : Graph Node
observed : List of nodes (optional)
If given the active trail would be computed assuming these nodes to be observed.
additional_obser... | pgmpy/base/DAG.py | def is_active_trail(self, start, end, observed=None):
"""
Returns True if there is any active trail between start and end node
Parameters
----------
start : Graph Node
end : Graph Node
observed : List of nodes (optional)
If given the active trail would... | def is_active_trail(self, start, end, observed=None):
"""
Returns True if there is any active trail between start and end node
Parameters
----------
start : Graph Node
end : Graph Node
observed : List of nodes (optional)
If given the active trail would... | [
"Returns",
"True",
"if",
"there",
"is",
"any",
"active",
"trail",
"between",
"start",
"and",
"end",
"node",
"Parameters",
"----------",
"start",
":",
"Graph",
"Node",
"end",
":",
"Graph",
"Node",
"observed",
":",
"List",
"of",
"nodes",
"(",
"optional",
")"... | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L516-L543 | [
"def",
"is_active_trail",
"(",
"self",
",",
"start",
",",
"end",
",",
"observed",
"=",
"None",
")",
":",
"if",
"end",
"in",
"self",
".",
"active_trail_nodes",
"(",
"start",
",",
"observed",
")",
"[",
"start",
"]",
":",
"return",
"True",
"else",
":",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.get_markov_blanket | Returns a markov blanket for a random variable. In the case
of Bayesian Networks, the markov blanket is the set of
node's parents, its children and its children's other parents.
Returns
-------
list(blanket_nodes): List of nodes contained in Markov Blanket
Parameters
... | pgmpy/base/DAG.py | def get_markov_blanket(self, node):
"""
Returns a markov blanket for a random variable. In the case
of Bayesian Networks, the markov blanket is the set of
node's parents, its children and its children's other parents.
Returns
-------
list(blanket_nodes): List of ... | def get_markov_blanket(self, node):
"""
Returns a markov blanket for a random variable. In the case
of Bayesian Networks, the markov blanket is the set of
node's parents, its children and its children's other parents.
Returns
-------
list(blanket_nodes): List of ... | [
"Returns",
"a",
"markov",
"blanket",
"for",
"a",
"random",
"variable",
".",
"In",
"the",
"case",
"of",
"Bayesian",
"Networks",
"the",
"markov",
"blanket",
"is",
"the",
"set",
"of",
"node",
"s",
"parents",
"its",
"children",
"and",
"its",
"children",
"s",
... | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L545-L576 | [
"def",
"get_markov_blanket",
"(",
"self",
",",
"node",
")",
":",
"children",
"=",
"self",
".",
"get_children",
"(",
"node",
")",
"parents",
"=",
"self",
".",
"get_parents",
"(",
"node",
")",
"blanket_nodes",
"=",
"children",
"+",
"parents",
"for",
"child_n... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG.active_trail_nodes | Returns a dictionary with the given variables as keys and all the nodes reachable
from that respective variable as values.
Parameters
----------
variables: str or array like
variables whose active trails are to be found.
observed : List of nodes (optional)
... | pgmpy/base/DAG.py | def active_trail_nodes(self, variables, observed=None):
"""
Returns a dictionary with the given variables as keys and all the nodes reachable
from that respective variable as values.
Parameters
----------
variables: str or array like
variables whose active tra... | def active_trail_nodes(self, variables, observed=None):
"""
Returns a dictionary with the given variables as keys and all the nodes reachable
from that respective variable as values.
Parameters
----------
variables: str or array like
variables whose active tra... | [
"Returns",
"a",
"dictionary",
"with",
"the",
"given",
"variables",
"as",
"keys",
"and",
"all",
"the",
"nodes",
"reachable",
"from",
"that",
"respective",
"variable",
"as",
"values",
".",
"Parameters",
"----------",
"variables",
":",
"str",
"or",
"array",
"like... | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L578-L639 | [
"def",
"active_trail_nodes",
"(",
"self",
",",
"variables",
",",
"observed",
"=",
"None",
")",
":",
"if",
"observed",
":",
"observed_list",
"=",
"observed",
"if",
"isinstance",
"(",
"observed",
",",
"(",
"list",
",",
"tuple",
")",
")",
"else",
"[",
"obse... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DAG._get_ancestors_of | Returns a dictionary of all ancestors of all the observed nodes including the
node itself.
Parameters
----------
obs_nodes_list: string, list-type
name of all the observed nodes
Examples
--------
>>> from pgmpy.base import DAG
>>> model = DAG([... | pgmpy/base/DAG.py | def _get_ancestors_of(self, obs_nodes_list):
"""
Returns a dictionary of all ancestors of all the observed nodes including the
node itself.
Parameters
----------
obs_nodes_list: string, list-type
name of all the observed nodes
Examples
--------... | def _get_ancestors_of(self, obs_nodes_list):
"""
Returns a dictionary of all ancestors of all the observed nodes including the
node itself.
Parameters
----------
obs_nodes_list: string, list-type
name of all the observed nodes
Examples
--------... | [
"Returns",
"a",
"dictionary",
"of",
"all",
"ancestors",
"of",
"all",
"the",
"observed",
"nodes",
"including",
"the",
"node",
"itself",
".",
"Parameters",
"----------",
"obs_nodes_list",
":",
"string",
"list",
"-",
"type",
"name",
"of",
"all",
"the",
"observed"... | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/base/DAG.py#L641-L673 | [
"def",
"_get_ancestors_of",
"(",
"self",
",",
"obs_nodes_list",
")",
":",
"if",
"not",
"isinstance",
"(",
"obs_nodes_list",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"obs_nodes_list",
"=",
"[",
"obs_nodes_list",
"]",
"for",
"node",
"in",
"obs_nodes_list... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | JunctionTree.add_edge | Add an edge between two clique nodes.
Parameters
----------
u, v: nodes
Nodes can be any list or set or tuple of nodes forming a clique.
Examples
--------
>>> from pgmpy.models import JunctionTree
>>> G = JunctionTree()
>>> G.add_nodes_from([... | pgmpy/models/JunctionTree.py | def add_edge(self, u, v, **kwargs):
"""
Add an edge between two clique nodes.
Parameters
----------
u, v: nodes
Nodes can be any list or set or tuple of nodes forming a clique.
Examples
--------
>>> from pgmpy.models import JunctionTree
... | def add_edge(self, u, v, **kwargs):
"""
Add an edge between two clique nodes.
Parameters
----------
u, v: nodes
Nodes can be any list or set or tuple of nodes forming a clique.
Examples
--------
>>> from pgmpy.models import JunctionTree
... | [
"Add",
"an",
"edge",
"between",
"two",
"clique",
"nodes",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/JunctionTree.py#L56-L77 | [
"def",
"add_edge",
"(",
"self",
",",
"u",
",",
"v",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"u",
"in",
"self",
".",
"nodes",
"(",
")",
"and",
"v",
"in",
"self",
".",
"nodes",
"(",
")",
"and",
"nx",
".",
"has_path",
"(",
"self",
",",
"u",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | JunctionTree.check_model | Check the model for various errors. This method checks for the following
errors. In the same time also updates the cardinalities of all the random
variables.
* Checks if clique potentials are defined for all the cliques or not.
* Check for running intersection property is not done expli... | pgmpy/models/JunctionTree.py | def check_model(self):
"""
Check the model for various errors. This method checks for the following
errors. In the same time also updates the cardinalities of all the random
variables.
* Checks if clique potentials are defined for all the cliques or not.
* Check for runn... | def check_model(self):
"""
Check the model for various errors. This method checks for the following
errors. In the same time also updates the cardinalities of all the random
variables.
* Checks if clique potentials are defined for all the cliques or not.
* Check for runn... | [
"Check",
"the",
"model",
"for",
"various",
"errors",
".",
"This",
"method",
"checks",
"for",
"the",
"following",
"errors",
".",
"In",
"the",
"same",
"time",
"also",
"updates",
"the",
"cardinalities",
"of",
"all",
"the",
"random",
"variables",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/JunctionTree.py#L79-L97 | [
"def",
"check_model",
"(",
"self",
")",
":",
"if",
"not",
"nx",
".",
"is_connected",
"(",
"self",
")",
":",
"raise",
"ValueError",
"(",
"'The Junction Tree defined is not fully connected.'",
")",
"return",
"super",
"(",
"JunctionTree",
",",
"self",
")",
".",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | JunctionTree.copy | Returns a copy of JunctionTree.
Returns
-------
JunctionTree : copy of JunctionTree
Examples
--------
>>> import numpy as np
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> from pgmpy.models import JunctionTree
>>> G = JunctionTree()
... | pgmpy/models/JunctionTree.py | def copy(self):
"""
Returns a copy of JunctionTree.
Returns
-------
JunctionTree : copy of JunctionTree
Examples
--------
>>> import numpy as np
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> from pgmpy.models import JunctionTr... | def copy(self):
"""
Returns a copy of JunctionTree.
Returns
-------
JunctionTree : copy of JunctionTree
Examples
--------
>>> import numpy as np
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> from pgmpy.models import JunctionTr... | [
"Returns",
"a",
"copy",
"of",
"JunctionTree",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/JunctionTree.py#L99-L133 | [
"def",
"copy",
"(",
"self",
")",
":",
"copy",
"=",
"JunctionTree",
"(",
"self",
".",
"edges",
"(",
")",
")",
"copy",
".",
"add_nodes_from",
"(",
"self",
".",
"nodes",
"(",
")",
")",
"if",
"self",
".",
"factors",
":",
"factors_copy",
"=",
"[",
"fact... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | generate_probmodelxml | Generate ProbModelXML lines for model.
Parameters
----------
model : Graph
The Bayesian or Markov Model
encoding : string (optional)
Encoding for text data
prettyprint: bool (optional)
If True uses line breaks and indenting in output XML.
Examples
--------
>>> G... | pgmpy/readwrite/ProbModelXML.py | def generate_probmodelxml(model, encoding='utf-8', prettyprint=True):
"""
Generate ProbModelXML lines for model.
Parameters
----------
model : Graph
The Bayesian or Markov Model
encoding : string (optional)
Encoding for text data
prettyprint: bool (optional)
If True ... | def generate_probmodelxml(model, encoding='utf-8', prettyprint=True):
"""
Generate ProbModelXML lines for model.
Parameters
----------
model : Graph
The Bayesian or Markov Model
encoding : string (optional)
Encoding for text data
prettyprint: bool (optional)
If True ... | [
"Generate",
"ProbModelXML",
"lines",
"for",
"model",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L134-L156 | [
"def",
"generate_probmodelxml",
"(",
"model",
",",
"encoding",
"=",
"'utf-8'",
",",
"prettyprint",
"=",
"True",
")",
":",
"writer",
"=",
"ProbModelXMLWriter",
"(",
"G",
",",
"encoding",
"=",
"encoding",
",",
"prettyprint",
"=",
"prettyprint",
")",
"for",
"li... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | write_probmodelxml | Write model in ProbModelXML format to path.
Parameters
----------
model : A NetworkX graph
Bayesian network or Markov network
path : file or string
File or filename to write.
Filenames ending in .gz or .bz2 will be compressed.
encoding : string (optional)
... | pgmpy/readwrite/ProbModelXML.py | def write_probmodelxml(model, path, encoding='utf-8', prettyprint=True):
"""
Write model in ProbModelXML format to path.
Parameters
----------
model : A NetworkX graph
Bayesian network or Markov network
path : file or string
File or filename to write.
Filenam... | def write_probmodelxml(model, path, encoding='utf-8', prettyprint=True):
"""
Write model in ProbModelXML format to path.
Parameters
----------
model : A NetworkX graph
Bayesian network or Markov network
path : file or string
File or filename to write.
Filenam... | [
"Write",
"model",
"in",
"ProbModelXML",
"format",
"to",
"path",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L160-L183 | [
"def",
"write_probmodelxml",
"(",
"model",
",",
"path",
",",
"encoding",
"=",
"'utf-8'",
",",
"prettyprint",
"=",
"True",
")",
":",
"writer",
"=",
"ProbModelXMLWriter",
"(",
"model",
",",
"path",
",",
"encoding",
"=",
"encoding",
",",
"prettyprint",
"=",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | get_probmodel_data | Returns the model_data based on the given model.
Parameters
----------
model: BayesianModel instance
Model to write
Return
------
model_data: dict
dictionary containing model data of the given model.
Examples
--------
>>> model_data = pgmpy.readwrite.get_model_data... | pgmpy/readwrite/ProbModelXML.py | def get_probmodel_data(model):
"""
Returns the model_data based on the given model.
Parameters
----------
model: BayesianModel instance
Model to write
Return
------
model_data: dict
dictionary containing model data of the given model.
Examples
--------
>>> ... | def get_probmodel_data(model):
"""
Returns the model_data based on the given model.
Parameters
----------
model: BayesianModel instance
Model to write
Return
------
model_data: dict
dictionary containing model data of the given model.
Examples
--------
>>> ... | [
"Returns",
"the",
"model_data",
"based",
"on",
"the",
"given",
"model",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L236-L283 | [
"def",
"get_probmodel_data",
"(",
"model",
")",
":",
"if",
"not",
"isinstance",
"(",
"model",
",",
"BayesianModel",
")",
":",
"raise",
"TypeError",
"(",
"\"Model must an instance of BayesianModel.\"",
")",
"model_data",
"=",
"{",
"'probnet'",
":",
"{",
"'type'",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLWriter._add_additional_properties | Sets AdditionalProperties of the ProbModelXML. | pgmpy/readwrite/ProbModelXML.py | def _add_additional_properties(position, properties_dict):
"""
Sets AdditionalProperties of the ProbModelXML.
"""
add_prop = etree.SubElement(position, 'AdditionalProperties')
for key, value in properties_dict.items():
etree.SubElement(add_prop, 'Property', attrib={'n... | def _add_additional_properties(position, properties_dict):
"""
Sets AdditionalProperties of the ProbModelXML.
"""
add_prop = etree.SubElement(position, 'AdditionalProperties')
for key, value in properties_dict.items():
etree.SubElement(add_prop, 'Property', attrib={'n... | [
"Sets",
"AdditionalProperties",
"of",
"the",
"ProbModelXML",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L370-L376 | [
"def",
"_add_additional_properties",
"(",
"position",
",",
"properties_dict",
")",
":",
"add_prop",
"=",
"etree",
".",
"SubElement",
"(",
"position",
",",
"'AdditionalProperties'",
")",
"for",
"key",
",",
"value",
"in",
"properties_dict",
".",
"items",
"(",
")",... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLWriter._add_variable | Adds a node to the ProbModelXML. | pgmpy/readwrite/ProbModelXML.py | def _add_variable(self, variable):
"""
Adds a node to the ProbModelXML.
"""
# TODO: Add feature for accepting additional properties of states.
variable_data = self.data['probnet']['Variables'][variable]
variable_element = etree.SubElement(self.variables, 'Variable', attri... | def _add_variable(self, variable):
"""
Adds a node to the ProbModelXML.
"""
# TODO: Add feature for accepting additional properties of states.
variable_data = self.data['probnet']['Variables'][variable]
variable_element = etree.SubElement(self.variables, 'Variable', attri... | [
"Adds",
"a",
"node",
"to",
"the",
"ProbModelXML",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L378-L408 | [
"def",
"_add_variable",
"(",
"self",
",",
"variable",
")",
":",
"# TODO: Add feature for accepting additional properties of states.",
"variable_data",
"=",
"self",
".",
"data",
"[",
"'probnet'",
"]",
"[",
"'Variables'",
"]",
"[",
"variable",
"]",
"variable_element",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLWriter._add_link | Adds an edge to the ProbModelXML. | pgmpy/readwrite/ProbModelXML.py | def _add_link(self, edge):
"""
Adds an edge to the ProbModelXML.
"""
edge_data = self.data['probnet']['edges'][edge]
if isinstance(edge, six.string_types):
edge = eval(edge)
link = etree.SubElement(self.links, 'Link', attrib={'var1': edge[0], 'var2': edge[1],
... | def _add_link(self, edge):
"""
Adds an edge to the ProbModelXML.
"""
edge_data = self.data['probnet']['edges'][edge]
if isinstance(edge, six.string_types):
edge = eval(edge)
link = etree.SubElement(self.links, 'Link', attrib={'var1': edge[0], 'var2': edge[1],
... | [
"Adds",
"an",
"edge",
"to",
"the",
"ProbModelXML",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L410-L430 | [
"def",
"_add_link",
"(",
"self",
",",
"edge",
")",
":",
"edge_data",
"=",
"self",
".",
"data",
"[",
"'probnet'",
"]",
"[",
"'edges'",
"]",
"[",
"edge",
"]",
"if",
"isinstance",
"(",
"edge",
",",
"six",
".",
"string_types",
")",
":",
"edge",
"=",
"e... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLWriter._add_constraint | Adds constraint to the ProbModelXML. | pgmpy/readwrite/ProbModelXML.py | def _add_constraint(self, constraint):
"""
Adds constraint to the ProbModelXML.
"""
constraint_data = self.data['probnet']['AdditionalConstraints'][constraint]
constraint_element = etree.SubElement(
self.additional_constraints, 'Constraint', attrib={'name': constraint... | def _add_constraint(self, constraint):
"""
Adds constraint to the ProbModelXML.
"""
constraint_data = self.data['probnet']['AdditionalConstraints'][constraint]
constraint_element = etree.SubElement(
self.additional_constraints, 'Constraint', attrib={'name': constraint... | [
"Adds",
"constraint",
"to",
"the",
"ProbModelXML",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L432-L442 | [
"def",
"_add_constraint",
"(",
"self",
",",
"constraint",
")",
":",
"constraint_data",
"=",
"self",
".",
"data",
"[",
"'probnet'",
"]",
"[",
"'AdditionalConstraints'",
"]",
"[",
"constraint",
"]",
"constraint_element",
"=",
"etree",
".",
"SubElement",
"(",
"se... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLWriter._add_decision_criteria | Adds Decision Criteria to the ProbModelXML.
Parameters
----------
criteria_dict: dict
Dictionary containing Deecision Criteria data.
For example: {'effectiveness': {}, 'cost': {}}
Examples
-------
>>> writer = ProbModelXMLWriter(model)
>>... | pgmpy/readwrite/ProbModelXML.py | def _add_decision_criteria(self, criteria_dict):
"""
Adds Decision Criteria to the ProbModelXML.
Parameters
----------
criteria_dict: dict
Dictionary containing Deecision Criteria data.
For example: {'effectiveness': {}, 'cost': {}}
Examples
... | def _add_decision_criteria(self, criteria_dict):
"""
Adds Decision Criteria to the ProbModelXML.
Parameters
----------
criteria_dict: dict
Dictionary containing Deecision Criteria data.
For example: {'effectiveness': {}, 'cost': {}}
Examples
... | [
"Adds",
"Decision",
"Criteria",
"to",
"the",
"ProbModelXML",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L444-L462 | [
"def",
"_add_decision_criteria",
"(",
"self",
",",
"criteria_dict",
")",
":",
"decision_tag",
"=",
"etree",
".",
"SubElement",
"(",
"self",
".",
"xml",
",",
"'DecisionCriteria'",
",",
"attrib",
"=",
"{",
"}",
")",
"for",
"criteria",
"in",
"sorted",
"(",
"c... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLWriter._add_potential | Adds Potentials to the ProbModelXML.
Parameters
----------
potential: dict
Dictionary containing Potential data.
For example: {'role': 'Utility',
'Variables': ['D0', 'D1', 'C0', 'C1'],
'type': 'Tree/ADD',
... | pgmpy/readwrite/ProbModelXML.py | def _add_potential(self, potential, parent_tag):
"""
Adds Potentials to the ProbModelXML.
Parameters
----------
potential: dict
Dictionary containing Potential data.
For example: {'role': 'Utility',
'Variables': ['D0', 'D1', 'C0'... | def _add_potential(self, potential, parent_tag):
"""
Adds Potentials to the ProbModelXML.
Parameters
----------
potential: dict
Dictionary containing Potential data.
For example: {'role': 'Utility',
'Variables': ['D0', 'D1', 'C0'... | [
"Adds",
"Potentials",
"to",
"the",
"ProbModelXML",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L464-L559 | [
"def",
"_add_potential",
"(",
"self",
",",
"potential",
",",
"parent_tag",
")",
":",
"potential_type",
"=",
"potential",
"[",
"'type'",
"]",
"try",
":",
"potential_tag",
"=",
"etree",
".",
"SubElement",
"(",
"parent_tag",
",",
"'Potential'",
",",
"attrib",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLWriter._add_element | Helper function to add variable tag to the potential_tag
Parameters
----------
potential: dict
Dictionary containing Potential data.
For example: {'role': 'Utility',
'Variables': ['D0', 'D1', 'C0', 'C1'],
'type': 'Tree/... | pgmpy/readwrite/ProbModelXML.py | def _add_element(potential, var, potential_tag):
"""
Helper function to add variable tag to the potential_tag
Parameters
----------
potential: dict
Dictionary containing Potential data.
For example: {'role': 'Utility',
'Variables... | def _add_element(potential, var, potential_tag):
"""
Helper function to add variable tag to the potential_tag
Parameters
----------
potential: dict
Dictionary containing Potential data.
For example: {'role': 'Utility',
'Variables... | [
"Helper",
"function",
"to",
"add",
"variable",
"tag",
"to",
"the",
"potential_tag"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L562-L590 | [
"def",
"_add_element",
"(",
"potential",
",",
"var",
",",
"potential_tag",
")",
":",
"if",
"var",
"in",
"potential",
":",
"etree",
".",
"SubElement",
"(",
"potential_tag",
",",
"var",
")",
".",
"text",
"=",
"potential",
"[",
"var",
"]"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLWriter.dump | Dumps the data to stream after appending header. | pgmpy/readwrite/ProbModelXML.py | def dump(self, stream):
"""
Dumps the data to stream after appending header.
"""
if self.prettyprint:
self.indent(self.xml)
document = etree.ElementTree(self.xml)
header = '<?xml version="1.0" encoding="%s"?>' % self.encoding
stream.write(header.encode... | def dump(self, stream):
"""
Dumps the data to stream after appending header.
"""
if self.prettyprint:
self.indent(self.xml)
document = etree.ElementTree(self.xml)
header = '<?xml version="1.0" encoding="%s"?>' % self.encoding
stream.write(header.encode... | [
"Dumps",
"the",
"data",
"to",
"stream",
"after",
"appending",
"header",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L592-L601 | [
"def",
"dump",
"(",
"self",
",",
"stream",
")",
":",
"if",
"self",
".",
"prettyprint",
":",
"self",
".",
"indent",
"(",
"self",
".",
"xml",
")",
"document",
"=",
"etree",
".",
"ElementTree",
"(",
"self",
".",
"xml",
")",
"header",
"=",
"'<?xml versio... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLWriter.write_file | Write the xml data into the file.
Parameters
----------
filename: Name of the file.
Examples
-------
>>> writer = ProbModelXMLWriter(model)
>>> writer.write_file(test_file) | pgmpy/readwrite/ProbModelXML.py | def write_file(self, filename):
"""
Write the xml data into the file.
Parameters
----------
filename: Name of the file.
Examples
-------
>>> writer = ProbModelXMLWriter(model)
>>> writer.write_file(test_file)
"""
writer = self.__s... | def write_file(self, filename):
"""
Write the xml data into the file.
Parameters
----------
filename: Name of the file.
Examples
-------
>>> writer = ProbModelXMLWriter(model)
>>> writer.write_file(test_file)
"""
writer = self.__s... | [
"Write",
"the",
"xml",
"data",
"into",
"the",
"file",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L621-L636 | [
"def",
"write_file",
"(",
"self",
",",
"filename",
")",
":",
"writer",
"=",
"self",
".",
"__str__",
"(",
")",
"[",
":",
"-",
"1",
"]",
".",
"decode",
"(",
"'utf-8'",
")",
"with",
"open",
"(",
"filename",
",",
"'w'",
")",
"as",
"fout",
":",
"fout"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLReader.create_probnet | Returns a BayesianModel or MarkovModel object depending on the
type of ProbModelXML passed to ProbModelXMLReader class. | pgmpy/readwrite/ProbModelXML.py | def create_probnet(self):
"""
Returns a BayesianModel or MarkovModel object depending on the
type of ProbModelXML passed to ProbModelXMLReader class.
"""
self.probnet = {}
# Add general properties
probnet_elem = self.xml.find('ProbNet')
self.probnet['type'... | def create_probnet(self):
"""
Returns a BayesianModel or MarkovModel object depending on the
type of ProbModelXML passed to ProbModelXMLReader class.
"""
self.probnet = {}
# Add general properties
probnet_elem = self.xml.find('ProbNet')
self.probnet['type'... | [
"Returns",
"a",
"BayesianModel",
"or",
"MarkovModel",
"object",
"depending",
"on",
"the",
"type",
"of",
"ProbModelXML",
"passed",
"to",
"ProbModelXMLReader",
"class",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L723-L766 | [
"def",
"create_probnet",
"(",
"self",
")",
":",
"self",
".",
"probnet",
"=",
"{",
"}",
"# Add general properties",
"probnet_elem",
"=",
"self",
".",
"xml",
".",
"find",
"(",
"'ProbNet'",
")",
"self",
".",
"probnet",
"[",
"'type'",
"]",
"=",
"probnet_elem",... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLReader.add_probnet_additionalconstraints | Adds Additional Constraints to the probnet dict.
Parameters
----------
criterion: <Element Constraint at AdditionalConstraints Node in XML>
etree Element consisting Constraint tag.
Examples
-------
>>> reader = ProbModelXMLReader()
>>> reader.add_add... | pgmpy/readwrite/ProbModelXML.py | def add_probnet_additionalconstraints(self, constraint):
"""
Adds Additional Constraints to the probnet dict.
Parameters
----------
criterion: <Element Constraint at AdditionalConstraints Node in XML>
etree Element consisting Constraint tag.
Examples
... | def add_probnet_additionalconstraints(self, constraint):
"""
Adds Additional Constraints to the probnet dict.
Parameters
----------
criterion: <Element Constraint at AdditionalConstraints Node in XML>
etree Element consisting Constraint tag.
Examples
... | [
"Adds",
"Additional",
"Constraints",
"to",
"the",
"probnet",
"dict",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L768-L787 | [
"def",
"add_probnet_additionalconstraints",
"(",
"self",
",",
"constraint",
")",
":",
"constraint_name",
"=",
"constraint",
".",
"attrib",
"[",
"'name'",
"]",
"self",
".",
"probnet",
"[",
"'AdditionalConstraints'",
"]",
"[",
"constraint_name",
"]",
"=",
"{",
"}"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLReader.add_criterion | Adds Decision Criteria to the probnet dict.
Parameters
----------
criterion: <Element Criterion at Decision Criteria Node in XML>
etree Element consisting DecisionCritera tag.
Examples
-------
>>> reader = ProbModelXMLReader()
>>> reader.add_criterio... | pgmpy/readwrite/ProbModelXML.py | def add_criterion(self, criterion):
"""
Adds Decision Criteria to the probnet dict.
Parameters
----------
criterion: <Element Criterion at Decision Criteria Node in XML>
etree Element consisting DecisionCritera tag.
Examples
-------
>>> reade... | def add_criterion(self, criterion):
"""
Adds Decision Criteria to the probnet dict.
Parameters
----------
criterion: <Element Criterion at Decision Criteria Node in XML>
etree Element consisting DecisionCritera tag.
Examples
-------
>>> reade... | [
"Adds",
"Decision",
"Criteria",
"to",
"the",
"probnet",
"dict",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L789-L809 | [
"def",
"add_criterion",
"(",
"self",
",",
"criterion",
")",
":",
"criterion_name",
"=",
"criterion",
".",
"attrib",
"[",
"'name'",
"]",
"self",
".",
"probnet",
"[",
"'DecisionCriteria'",
"]",
"[",
"criterion_name",
"]",
"=",
"{",
"}",
"if",
"criterion",
".... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLReader.add_node | Adds Variables to the probnet dict.
Parameters
----------
variable: <Element Variable at Variables Node in XML>
etree Element consisting Variable tag.
Examples
-------
>>> reader = ProbModelXMLReader()
>>> reader.add_node(variable) | pgmpy/readwrite/ProbModelXML.py | def add_node(self, variable):
"""
Adds Variables to the probnet dict.
Parameters
----------
variable: <Element Variable at Variables Node in XML>
etree Element consisting Variable tag.
Examples
-------
>>> reader = ProbModelXMLReader()
... | def add_node(self, variable):
"""
Adds Variables to the probnet dict.
Parameters
----------
variable: <Element Variable at Variables Node in XML>
etree Element consisting Variable tag.
Examples
-------
>>> reader = ProbModelXMLReader()
... | [
"Adds",
"Variables",
"to",
"the",
"probnet",
"dict",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L847-L881 | [
"def",
"add_node",
"(",
"self",
",",
"variable",
")",
":",
"# TODO: Do some checks with variable type and roles. Right now I don't know when they are to be used.",
"variable_name",
"=",
"variable",
".",
"attrib",
"[",
"'name'",
"]",
"self",
".",
"probnet",
"[",
"'Variables'... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLReader.add_edge | Adds Edges to the probnet dict.
Parameters
----------
edge: <Element Link at Links Node in XML>
etree Element consisting Variable tag.
Examples
-------
>>> reader = ProbModelXMLReader()
>>> reader.add_edge(edge) | pgmpy/readwrite/ProbModelXML.py | def add_edge(self, edge):
"""
Adds Edges to the probnet dict.
Parameters
----------
edge: <Element Link at Links Node in XML>
etree Element consisting Variable tag.
Examples
-------
>>> reader = ProbModelXMLReader()
>>> reader.add_edg... | def add_edge(self, edge):
"""
Adds Edges to the probnet dict.
Parameters
----------
edge: <Element Link at Links Node in XML>
etree Element consisting Variable tag.
Examples
-------
>>> reader = ProbModelXMLReader()
>>> reader.add_edg... | [
"Adds",
"Edges",
"to",
"the",
"probnet",
"dict",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L883-L909 | [
"def",
"add_edge",
"(",
"self",
",",
"edge",
")",
":",
"var1",
"=",
"edge",
".",
"findall",
"(",
"'Variable'",
")",
"[",
"0",
"]",
".",
"attrib",
"[",
"'name'",
"]",
"var2",
"=",
"edge",
".",
"findall",
"(",
"'Variable'",
")",
"[",
"1",
"]",
".",... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLReader.add_potential | Adds Potential to the potential dict.
Parameters
----------
potential: <Element Potential at Potentials node in XML>
etree Element consisting Potential tag.
potential_dict: dict{}
Dictionary to parse Potential tag.
Examples
-------
>>> re... | pgmpy/readwrite/ProbModelXML.py | def add_potential(self, potential, potential_dict):
"""
Adds Potential to the potential dict.
Parameters
----------
potential: <Element Potential at Potentials node in XML>
etree Element consisting Potential tag.
potential_dict: dict{}
Dictionary ... | def add_potential(self, potential, potential_dict):
"""
Adds Potential to the potential dict.
Parameters
----------
potential: <Element Potential at Potentials node in XML>
etree Element consisting Potential tag.
potential_dict: dict{}
Dictionary ... | [
"Adds",
"Potential",
"to",
"the",
"potential",
"dict",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L911-L1017 | [
"def",
"add_potential",
"(",
"self",
",",
"potential",
",",
"potential_dict",
")",
":",
"potential_type",
"=",
"potential",
".",
"attrib",
"[",
"'type'",
"]",
"potential_dict",
"[",
"'type'",
"]",
"=",
"potential_type",
"try",
":",
"potential_dict",
"[",
"'rol... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ProbModelXMLReader.get_model | Returns the model instance of the ProbModel.
Return
---------------
model: an instance of BayesianModel.
Examples
-------
>>> reader = ProbModelXMLReader()
>>> reader.get_model() | pgmpy/readwrite/ProbModelXML.py | def get_model(self):
"""
Returns the model instance of the ProbModel.
Return
---------------
model: an instance of BayesianModel.
Examples
-------
>>> reader = ProbModelXMLReader()
>>> reader.get_model()
"""
if self.probnet.get('t... | def get_model(self):
"""
Returns the model instance of the ProbModel.
Return
---------------
model: an instance of BayesianModel.
Examples
-------
>>> reader = ProbModelXMLReader()
>>> reader.get_model()
"""
if self.probnet.get('t... | [
"Returns",
"the",
"model",
"instance",
"of",
"the",
"ProbModel",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/ProbModelXML.py#L1019-L1068 | [
"def",
"get_model",
"(",
"self",
")",
":",
"if",
"self",
".",
"probnet",
".",
"get",
"(",
"'type'",
")",
"==",
"\"BayesianNetwork\"",
":",
"model",
"=",
"BayesianModel",
"(",
")",
"model",
".",
"add_nodes_from",
"(",
"self",
".",
"probnet",
"[",
"'Variab... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ExhaustiveSearch.all_dags | Computes all possible directed acyclic graphs with a given set of nodes,
sparse ones first. `2**(n*(n-1))` graphs need to be searched, given `n` nodes,
so this is likely not feasible for n>6. This is a generator.
Parameters
----------
nodes: list of nodes for the DAGs (optional)... | pgmpy/estimators/ExhaustiveSearch.py | def all_dags(self, nodes=None):
"""
Computes all possible directed acyclic graphs with a given set of nodes,
sparse ones first. `2**(n*(n-1))` graphs need to be searched, given `n` nodes,
so this is likely not feasible for n>6. This is a generator.
Parameters
----------
... | def all_dags(self, nodes=None):
"""
Computes all possible directed acyclic graphs with a given set of nodes,
sparse ones first. `2**(n*(n-1))` graphs need to be searched, given `n` nodes,
so this is likely not feasible for n>6. This is a generator.
Parameters
----------
... | [
"Computes",
"all",
"possible",
"directed",
"acyclic",
"graphs",
"with",
"a",
"given",
"set",
"of",
"nodes",
"sparse",
"ones",
"first",
".",
"2",
"**",
"(",
"n",
"*",
"(",
"n",
"-",
"1",
"))",
"graphs",
"need",
"to",
"be",
"searched",
"given",
"n",
"n... | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/estimators/ExhaustiveSearch.py#L49-L99 | [
"def",
"all_dags",
"(",
"self",
",",
"nodes",
"=",
"None",
")",
":",
"if",
"nodes",
"is",
"None",
":",
"nodes",
"=",
"sorted",
"(",
"self",
".",
"state_names",
".",
"keys",
"(",
")",
")",
"if",
"len",
"(",
"nodes",
")",
">",
"6",
":",
"warn",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ExhaustiveSearch.all_scores | Computes a list of DAGs and their structure scores, ordered by score.
Returns
-------
list: a list of (score, dag) pairs
A list of (score, dag)-tuples, where score is a float and model a acyclic nx.DiGraph.
The list is ordered by score values.
Examples
-... | pgmpy/estimators/ExhaustiveSearch.py | def all_scores(self):
"""
Computes a list of DAGs and their structure scores, ordered by score.
Returns
-------
list: a list of (score, dag) pairs
A list of (score, dag)-tuples, where score is a float and model a acyclic nx.DiGraph.
The list is ordered by... | def all_scores(self):
"""
Computes a list of DAGs and their structure scores, ordered by score.
Returns
-------
list: a list of (score, dag) pairs
A list of (score, dag)-tuples, where score is a float and model a acyclic nx.DiGraph.
The list is ordered by... | [
"Computes",
"a",
"list",
"of",
"DAGs",
"and",
"their",
"structure",
"scores",
"ordered",
"by",
"score",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/estimators/ExhaustiveSearch.py#L101-L151 | [
"def",
"all_scores",
"(",
"self",
")",
":",
"scored_dags",
"=",
"sorted",
"(",
"[",
"(",
"self",
".",
"scoring_method",
".",
"score",
"(",
"dag",
")",
",",
"dag",
")",
"for",
"dag",
"in",
"self",
".",
"all_dags",
"(",
")",
"]",
",",
"key",
"=",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | ExhaustiveSearch.estimate | Estimates the `DAG` structure that fits best to the given data set,
according to the scoring method supplied in the constructor.
Exhaustively searches through all models. Only estimates network structure, no parametrization.
Returns
-------
model: `DAG` instance
A `D... | pgmpy/estimators/ExhaustiveSearch.py | def estimate(self):
"""
Estimates the `DAG` structure that fits best to the given data set,
according to the scoring method supplied in the constructor.
Exhaustively searches through all models. Only estimates network structure, no parametrization.
Returns
-------
... | def estimate(self):
"""
Estimates the `DAG` structure that fits best to the given data set,
according to the scoring method supplied in the constructor.
Exhaustively searches through all models. Only estimates network structure, no parametrization.
Returns
-------
... | [
"Estimates",
"the",
"DAG",
"structure",
"that",
"fits",
"best",
"to",
"the",
"given",
"data",
"set",
"according",
"to",
"the",
"scoring",
"method",
"supplied",
"in",
"the",
"constructor",
".",
"Exhaustively",
"searches",
"through",
"all",
"models",
".",
"Only"... | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/estimators/ExhaustiveSearch.py#L153-L185 | [
"def",
"estimate",
"(",
"self",
")",
":",
"best_dag",
"=",
"max",
"(",
"self",
".",
"all_dags",
"(",
")",
",",
"key",
"=",
"self",
".",
"scoring_method",
".",
"score",
")",
"best_model",
"=",
"DAG",
"(",
")",
"best_model",
".",
"add_nodes_from",
"(",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | NoisyOrModel.add_variables | Adds variables to the NoisyOrModel.
Parameters
----------
variables: list, tuple, dict (array like)
array containing names of the variables that are to be added.
cardinality: list, tuple, dict (array like)
array containing integers representing the cardinality
... | pgmpy/models/NoisyOrModel.py | def add_variables(self, variables, cardinality, inhibitor_probability):
"""
Adds variables to the NoisyOrModel.
Parameters
----------
variables: list, tuple, dict (array like)
array containing names of the variables that are to be added.
cardinality: list, t... | def add_variables(self, variables, cardinality, inhibitor_probability):
"""
Adds variables to the NoisyOrModel.
Parameters
----------
variables: list, tuple, dict (array like)
array containing names of the variables that are to be added.
cardinality: list, t... | [
"Adds",
"variables",
"to",
"the",
"NoisyOrModel",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/NoisyOrModel.py#L51-L89 | [
"def",
"add_variables",
"(",
"self",
",",
"variables",
",",
"cardinality",
",",
"inhibitor_probability",
")",
":",
"if",
"len",
"(",
"variables",
")",
"==",
"1",
":",
"if",
"not",
"isinstance",
"(",
"inhibitor_probability",
"[",
"0",
"]",
",",
"(",
"list",... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | NoisyOrModel.del_variables | Deletes variables from the NoisyOrModel.
Parameters
----------
variables: list, tuple, dict (array like)
list of variables to be deleted.
Examples
--------
>>> from pgmpy.models import NoisyOrModel
>>> model = NoisyOrModel(['x1', 'x2', 'x3'], [2, 3, ... | pgmpy/models/NoisyOrModel.py | def del_variables(self, variables):
"""
Deletes variables from the NoisyOrModel.
Parameters
----------
variables: list, tuple, dict (array like)
list of variables to be deleted.
Examples
--------
>>> from pgmpy.models import NoisyOrModel
... | def del_variables(self, variables):
"""
Deletes variables from the NoisyOrModel.
Parameters
----------
variables: list, tuple, dict (array like)
list of variables to be deleted.
Examples
--------
>>> from pgmpy.models import NoisyOrModel
... | [
"Deletes",
"variables",
"from",
"the",
"NoisyOrModel",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/models/NoisyOrModel.py#L91-L113 | [
"def",
"del_variables",
"(",
"self",
",",
"variables",
")",
":",
"variables",
"=",
"[",
"variables",
"]",
"if",
"isinstance",
"(",
"variables",
",",
"six",
".",
"string_types",
")",
"else",
"set",
"(",
"variables",
")",
"indices",
"=",
"[",
"index",
"for... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | _return_samples | A utility function to return samples according to type | pgmpy/sampling/base.py | def _return_samples(return_type, samples):
"""
A utility function to return samples according to type
"""
if return_type.lower() == "dataframe":
if HAS_PANDAS:
return pandas.DataFrame.from_records(samples)
else:
warn("Pandas installation not found. Returning n... | def _return_samples(return_type, samples):
"""
A utility function to return samples according to type
"""
if return_type.lower() == "dataframe":
if HAS_PANDAS:
return pandas.DataFrame.from_records(samples)
else:
warn("Pandas installation not found. Returning n... | [
"A",
"utility",
"function",
"to",
"return",
"samples",
"according",
"to",
"type"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/sampling/base.py#L409-L420 | [
"def",
"_return_samples",
"(",
"return_type",
",",
"samples",
")",
":",
"if",
"return_type",
".",
"lower",
"(",
")",
"==",
"\"dataframe\"",
":",
"if",
"HAS_PANDAS",
":",
"return",
"pandas",
".",
"DataFrame",
".",
"from_records",
"(",
"samples",
")",
"else",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | GradLogPDFGaussian._get_gradient_log_pdf | Method that finds gradient and its log at position | pgmpy/sampling/base.py | def _get_gradient_log_pdf(self):
"""
Method that finds gradient and its log at position
"""
sub_vec = self.variable_assignments - self.model.mean.flatten()
grad = - np.dot(self.model.precision_matrix, sub_vec)
log_pdf = 0.5 * np.dot(sub_vec, grad)
return grad, lo... | def _get_gradient_log_pdf(self):
"""
Method that finds gradient and its log at position
"""
sub_vec = self.variable_assignments - self.model.mean.flatten()
grad = - np.dot(self.model.precision_matrix, sub_vec)
log_pdf = 0.5 * np.dot(sub_vec, grad)
return grad, lo... | [
"Method",
"that",
"finds",
"gradient",
"and",
"its",
"log",
"at",
"position"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/sampling/base.py#L130-L138 | [
"def",
"_get_gradient_log_pdf",
"(",
"self",
")",
":",
"sub_vec",
"=",
"self",
".",
"variable_assignments",
"-",
"self",
".",
"model",
".",
"mean",
".",
"flatten",
"(",
")",
"grad",
"=",
"-",
"np",
".",
"dot",
"(",
"self",
".",
"model",
".",
"precision... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | LeapFrog._get_proposed_values | Method to perform time splitting using leapfrog | pgmpy/sampling/base.py | def _get_proposed_values(self):
"""
Method to perform time splitting using leapfrog
"""
# Take half step in time for updating momentum
momentum_bar = self.momentum + 0.5 * self.stepsize * self.grad_log_position
# Take full step in time for updating position position
... | def _get_proposed_values(self):
"""
Method to perform time splitting using leapfrog
"""
# Take half step in time for updating momentum
momentum_bar = self.momentum + 0.5 * self.stepsize * self.grad_log_position
# Take full step in time for updating position position
... | [
"Method",
"to",
"perform",
"time",
"splitting",
"using",
"leapfrog"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/sampling/base.py#L322-L337 | [
"def",
"_get_proposed_values",
"(",
"self",
")",
":",
"# Take half step in time for updating momentum",
"momentum_bar",
"=",
"self",
".",
"momentum",
"+",
"0.5",
"*",
"self",
".",
"stepsize",
"*",
"self",
".",
"grad_log_position",
"# Take full step in time for updating po... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor.get_cardinality | Returns cardinality of a given variable
Parameters
----------
variables: list, array-like
A list of variable names.
Returns
-------
dict: Dictionary of the form {variable: variable_cardinality}
Examples
--------
>>> from pgmpy.fa... | pgmpy/factors/discrete/DiscreteFactor.py | def get_cardinality(self, variables):
"""
Returns cardinality of a given variable
Parameters
----------
variables: list, array-like
A list of variable names.
Returns
-------
dict: Dictionary of the form {variable: variable_cardinality}
... | def get_cardinality(self, variables):
"""
Returns cardinality of a given variable
Parameters
----------
variables: list, array-like
A list of variable names.
Returns
-------
dict: Dictionary of the form {variable: variable_cardinality}
... | [
"Returns",
"cardinality",
"of",
"a",
"given",
"variable"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L131-L159 | [
"def",
"get_cardinality",
"(",
"self",
",",
"variables",
")",
":",
"if",
"isinstance",
"(",
"variables",
",",
"six",
".",
"string_types",
")",
":",
"raise",
"TypeError",
"(",
"\"variables: Expected type list or array-like, got type str\"",
")",
"if",
"not",
"all",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor.assignment | Returns a list of assignments for the corresponding index.
Parameters
----------
index: list, array-like
List of indices whose assignment is to be computed
Returns
-------
list: Returns a list of full assignments of all the variables of the factor.
... | pgmpy/factors/discrete/DiscreteFactor.py | def assignment(self, index):
"""
Returns a list of assignments for the corresponding index.
Parameters
----------
index: list, array-like
List of indices whose assignment is to be computed
Returns
-------
list: Returns a list of full assignme... | def assignment(self, index):
"""
Returns a list of assignments for the corresponding index.
Parameters
----------
index: list, array-like
List of indices whose assignment is to be computed
Returns
-------
list: Returns a list of full assignme... | [
"Returns",
"a",
"list",
"of",
"assignments",
"for",
"the",
"corresponding",
"index",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L162-L197 | [
"def",
"assignment",
"(",
"self",
",",
"index",
")",
":",
"index",
"=",
"np",
".",
"array",
"(",
"index",
")",
"max_possible_index",
"=",
"np",
".",
"prod",
"(",
"self",
".",
"cardinality",
")",
"-",
"1",
"if",
"not",
"all",
"(",
"i",
"<=",
"max_po... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor.identity_factor | Returns the identity factor.
Def: The identity factor of a factor has the same scope and cardinality as the original factor,
but the values for all the assignments is 1. When the identity factor is multiplied with
the factor it returns the factor itself.
Returns
-----... | pgmpy/factors/discrete/DiscreteFactor.py | def identity_factor(self):
"""
Returns the identity factor.
Def: The identity factor of a factor has the same scope and cardinality as the original factor,
but the values for all the assignments is 1. When the identity factor is multiplied with
the factor it returns th... | def identity_factor(self):
"""
Returns the identity factor.
Def: The identity factor of a factor has the same scope and cardinality as the original factor,
but the values for all the assignments is 1. When the identity factor is multiplied with
the factor it returns th... | [
"Returns",
"the",
"identity",
"factor",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L199-L227 | [
"def",
"identity_factor",
"(",
"self",
")",
":",
"return",
"DiscreteFactor",
"(",
"self",
".",
"variables",
",",
"self",
".",
"cardinality",
",",
"np",
".",
"ones",
"(",
"self",
".",
"values",
".",
"size",
")",
")"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor.marginalize | Modifies the factor with marginalized values.
Parameters
----------
variables: list, array-like
List of variables over which to marginalize.
inplace: boolean
If inplace=True it will modify the factor itself, else would return
a new factor.
R... | pgmpy/factors/discrete/DiscreteFactor.py | def marginalize(self, variables, inplace=True):
"""
Modifies the factor with marginalized values.
Parameters
----------
variables: list, array-like
List of variables over which to marginalize.
inplace: boolean
If inplace=True it will modify the f... | def marginalize(self, variables, inplace=True):
"""
Modifies the factor with marginalized values.
Parameters
----------
variables: list, array-like
List of variables over which to marginalize.
inplace: boolean
If inplace=True it will modify the f... | [
"Modifies",
"the",
"factor",
"with",
"marginalized",
"values",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L229-L276 | [
"def",
"marginalize",
"(",
"self",
",",
"variables",
",",
"inplace",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"variables",
",",
"six",
".",
"string_types",
")",
":",
"raise",
"TypeError",
"(",
"\"variables: Expected type list or array-like, got type str\"",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor.normalize | Normalizes the values of factor so that they sum to 1.
Parameters
----------
inplace: boolean
If inplace=True it will modify the factor itself, else would return
a new factor
Returns
-------
DiscreteFactor or None: if inplace=True (default) retur... | pgmpy/factors/discrete/DiscreteFactor.py | def normalize(self, inplace=True):
"""
Normalizes the values of factor so that they sum to 1.
Parameters
----------
inplace: boolean
If inplace=True it will modify the factor itself, else would return
a new factor
Returns
-------
... | def normalize(self, inplace=True):
"""
Normalizes the values of factor so that they sum to 1.
Parameters
----------
inplace: boolean
If inplace=True it will modify the factor itself, else would return
a new factor
Returns
-------
... | [
"Normalizes",
"the",
"values",
"of",
"factor",
"so",
"that",
"they",
"sum",
"to",
"1",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L333-L380 | [
"def",
"normalize",
"(",
"self",
",",
"inplace",
"=",
"True",
")",
":",
"phi",
"=",
"self",
"if",
"inplace",
"else",
"self",
".",
"copy",
"(",
")",
"phi",
".",
"values",
"=",
"phi",
".",
"values",
"/",
"phi",
".",
"values",
".",
"sum",
"(",
")",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor.reduce | Reduces the factor to the context of given variable values.
Parameters
----------
values: list, array-like
A list of tuples of the form (variable_name, variable_state).
inplace: boolean
If inplace=True it will modify the factor itself, else would return
... | pgmpy/factors/discrete/DiscreteFactor.py | def reduce(self, values, inplace=True):
"""
Reduces the factor to the context of given variable values.
Parameters
----------
values: list, array-like
A list of tuples of the form (variable_name, variable_state).
inplace: boolean
If inplace=True ... | def reduce(self, values, inplace=True):
"""
Reduces the factor to the context of given variable values.
Parameters
----------
values: list, array-like
A list of tuples of the form (variable_name, variable_state).
inplace: boolean
If inplace=True ... | [
"Reduces",
"the",
"factor",
"to",
"the",
"context",
"of",
"given",
"variable",
"values",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L383-L437 | [
"def",
"reduce",
"(",
"self",
",",
"values",
",",
"inplace",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"values",
",",
"six",
".",
"string_types",
")",
":",
"raise",
"TypeError",
"(",
"\"values: Expected type list or array-like, got type str\"",
")",
"if",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor.sum | DiscreteFactor sum with `phi1`.
Parameters
----------
phi1: `DiscreteFactor` instance.
DiscreteFactor to be added.
inplace: boolean
If inplace=True it will modify the factor itself, else would return
a new factor.
Returns
-------
... | pgmpy/factors/discrete/DiscreteFactor.py | def sum(self, phi1, inplace=True):
"""
DiscreteFactor sum with `phi1`.
Parameters
----------
phi1: `DiscreteFactor` instance.
DiscreteFactor to be added.
inplace: boolean
If inplace=True it will modify the factor itself, else would return
... | def sum(self, phi1, inplace=True):
"""
DiscreteFactor sum with `phi1`.
Parameters
----------
phi1: `DiscreteFactor` instance.
DiscreteFactor to be added.
inplace: boolean
If inplace=True it will modify the factor itself, else would return
... | [
"DiscreteFactor",
"sum",
"with",
"phi1",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L439-L525 | [
"def",
"sum",
"(",
"self",
",",
"phi1",
",",
"inplace",
"=",
"True",
")",
":",
"phi",
"=",
"self",
"if",
"inplace",
"else",
"self",
".",
"copy",
"(",
")",
"if",
"isinstance",
"(",
"phi1",
",",
"(",
"int",
",",
"float",
")",
")",
":",
"phi",
"."... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor.divide | DiscreteFactor division by `phi1`.
Parameters
----------
phi1 : `DiscreteFactor` instance
The denominator for division.
inplace: boolean
If inplace=True it will modify the factor itself, else would return
a new factor.
Returns
------... | pgmpy/factors/discrete/DiscreteFactor.py | def divide(self, phi1, inplace=True):
"""
DiscreteFactor division by `phi1`.
Parameters
----------
phi1 : `DiscreteFactor` instance
The denominator for division.
inplace: boolean
If inplace=True it will modify the factor itself, else would return... | def divide(self, phi1, inplace=True):
"""
DiscreteFactor division by `phi1`.
Parameters
----------
phi1 : `DiscreteFactor` instance
The denominator for division.
inplace: boolean
If inplace=True it will modify the factor itself, else would return... | [
"DiscreteFactor",
"division",
"by",
"phi1",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L615-L680 | [
"def",
"divide",
"(",
"self",
",",
"phi1",
",",
"inplace",
"=",
"True",
")",
":",
"phi",
"=",
"self",
"if",
"inplace",
"else",
"self",
".",
"copy",
"(",
")",
"phi1",
"=",
"phi1",
".",
"copy",
"(",
")",
"if",
"set",
"(",
"phi1",
".",
"variables",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor.copy | Returns a copy of the factor.
Returns
-------
DiscreteFactor: copy of the factor
Examples
--------
>>> import numpy as np
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> phi = DiscreteFactor(['x1', 'x2', 'x3'], [2, 3, 3], np.arange(18))
... | pgmpy/factors/discrete/DiscreteFactor.py | def copy(self):
"""
Returns a copy of the factor.
Returns
-------
DiscreteFactor: copy of the factor
Examples
--------
>>> import numpy as np
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> phi = DiscreteFactor(['x1', 'x2', 'x3'... | def copy(self):
"""
Returns a copy of the factor.
Returns
-------
DiscreteFactor: copy of the factor
Examples
--------
>>> import numpy as np
>>> from pgmpy.factors.discrete import DiscreteFactor
>>> phi = DiscreteFactor(['x1', 'x2', 'x3'... | [
"Returns",
"a",
"copy",
"of",
"the",
"factor",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L682-L711 | [
"def",
"copy",
"(",
"self",
")",
":",
"# not creating a new copy of self.values and self.cardinality",
"# because __init__ methods does that.",
"return",
"DiscreteFactor",
"(",
"self",
".",
"scope",
"(",
")",
",",
"self",
".",
"cardinality",
",",
"self",
".",
"values",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | DiscreteFactor._str | Generate the string from `__str__` method.
Parameters
----------
phi_or_p: 'phi' | 'p'
'phi': When used for Factors.
'p': When used for CPDs.
print_state_names: boolean
If True, the user defined state names are displayed. | pgmpy/factors/discrete/DiscreteFactor.py | def _str(self, phi_or_p="phi", tablefmt="grid", print_state_names=True):
"""
Generate the string from `__str__` method.
Parameters
----------
phi_or_p: 'phi' | 'p'
'phi': When used for Factors.
'p': When used for CPDs.
print_state_names:... | def _str(self, phi_or_p="phi", tablefmt="grid", print_state_names=True):
"""
Generate the string from `__str__` method.
Parameters
----------
phi_or_p: 'phi' | 'p'
'phi': When used for Factors.
'p': When used for CPDs.
print_state_names:... | [
"Generate",
"the",
"string",
"from",
"__str__",
"method",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/DiscreteFactor.py#L721-L753 | [
"def",
"_str",
"(",
"self",
",",
"phi_or_p",
"=",
"\"phi\"",
",",
"tablefmt",
"=",
"\"grid\"",
",",
"print_state_names",
"=",
"True",
")",
":",
"string_header",
"=",
"list",
"(",
"map",
"(",
"lambda",
"x",
":",
"six",
".",
"text_type",
"(",
"x",
")",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | _check_1d_array_object | Checks whether given parameter is a 1d array like object, and returns a numpy array object | pgmpy/utils/check_functions.py | def _check_1d_array_object(parameter, name_param):
"""
Checks whether given parameter is a 1d array like object, and returns a numpy array object
"""
if isinstance(parameter, (np.ndarray, list, tuple, np.matrix)):
parameter = np.array(parameter)
if parameter.ndim != 1:
raise ... | def _check_1d_array_object(parameter, name_param):
"""
Checks whether given parameter is a 1d array like object, and returns a numpy array object
"""
if isinstance(parameter, (np.ndarray, list, tuple, np.matrix)):
parameter = np.array(parameter)
if parameter.ndim != 1:
raise ... | [
"Checks",
"whether",
"given",
"parameter",
"is",
"a",
"1d",
"array",
"like",
"object",
"and",
"returns",
"a",
"numpy",
"array",
"object"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/utils/check_functions.py#L7-L18 | [
"def",
"_check_1d_array_object",
"(",
"parameter",
",",
"name_param",
")",
":",
"if",
"isinstance",
"(",
"parameter",
",",
"(",
"np",
".",
"ndarray",
",",
"list",
",",
"tuple",
",",
"np",
".",
"matrix",
")",
")",
":",
"parameter",
"=",
"np",
".",
"arra... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | _check_length_equal | Raises an error when the length of given two arguments is not equal | pgmpy/utils/check_functions.py | def _check_length_equal(param_1, param_2, name_param_1, name_param_2):
"""
Raises an error when the length of given two arguments is not equal
"""
if len(param_1) != len(param_2):
raise ValueError("Length of {} must be same as Length of {}".format(name_param_1, name_param_2)) | def _check_length_equal(param_1, param_2, name_param_1, name_param_2):
"""
Raises an error when the length of given two arguments is not equal
"""
if len(param_1) != len(param_2):
raise ValueError("Length of {} must be same as Length of {}".format(name_param_1, name_param_2)) | [
"Raises",
"an",
"error",
"when",
"the",
"length",
"of",
"given",
"two",
"arguments",
"is",
"not",
"equal"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/utils/check_functions.py#L21-L26 | [
"def",
"_check_length_equal",
"(",
"param_1",
",",
"param_2",
",",
"name_param_1",
",",
"name_param_2",
")",
":",
"if",
"len",
"(",
"param_1",
")",
"!=",
"len",
"(",
"param_2",
")",
":",
"raise",
"ValueError",
"(",
"\"Length of {} must be same as Length of {}\"",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFReader.get_variables | Returns list of variables of the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_variables()
['light-on', 'bowel-problem', 'dog-out', 'hear-bark', 'family-out'] | pgmpy/readwrite/XMLBIF.py | def get_variables(self):
"""
Returns list of variables of the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_variables()
['light-on', 'bowel-problem', 'dog-out', 'hear-bark', 'family-out']
"""
variable... | def get_variables(self):
"""
Returns list of variables of the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_variables()
['light-on', 'bowel-problem', 'dog-out', 'hear-bark', 'family-out']
"""
variable... | [
"Returns",
"list",
"of",
"variables",
"of",
"the",
"network"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L66-L77 | [
"def",
"get_variables",
"(",
"self",
")",
":",
"variables",
"=",
"[",
"variable",
".",
"find",
"(",
"'NAME'",
")",
".",
"text",
"for",
"variable",
"in",
"self",
".",
"network",
".",
"findall",
"(",
"'VARIABLE'",
")",
"]",
"return",
"variables"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFReader.get_edges | Returns the edges of the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_edges()
[['family-out', 'light-on'],
['family-out', 'dog-out'],
['bowel-problem', 'dog-out'],
['dog-out', 'hear-bark']] | pgmpy/readwrite/XMLBIF.py | def get_edges(self):
"""
Returns the edges of the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_edges()
[['family-out', 'light-on'],
['family-out', 'dog-out'],
['bowel-problem', 'dog-out'],
... | def get_edges(self):
"""
Returns the edges of the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_edges()
[['family-out', 'light-on'],
['family-out', 'dog-out'],
['bowel-problem', 'dog-out'],
... | [
"Returns",
"the",
"edges",
"of",
"the",
"network"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L79-L94 | [
"def",
"get_edges",
"(",
"self",
")",
":",
"edge_list",
"=",
"[",
"[",
"value",
",",
"key",
"]",
"for",
"key",
"in",
"self",
".",
"variable_parents",
"for",
"value",
"in",
"self",
".",
"variable_parents",
"[",
"key",
"]",
"]",
"return",
"edge_list"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFReader.get_states | Returns the states of variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_states()
{'bowel-problem': ['true', 'false'],
'dog-out': ['true', 'false'],
'family-out': ['true', 'false'],
'he... | pgmpy/readwrite/XMLBIF.py | def get_states(self):
"""
Returns the states of variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_states()
{'bowel-problem': ['true', 'false'],
'dog-out': ['true', 'false'],
'fa... | def get_states(self):
"""
Returns the states of variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_states()
{'bowel-problem': ['true', 'false'],
'dog-out': ['true', 'false'],
'fa... | [
"Returns",
"the",
"states",
"of",
"variables",
"present",
"in",
"the",
"network"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L96-L112 | [
"def",
"get_states",
"(",
"self",
")",
":",
"variable_states",
"=",
"{",
"variable",
".",
"find",
"(",
"'NAME'",
")",
".",
"text",
":",
"[",
"outcome",
".",
"text",
"for",
"outcome",
"in",
"variable",
".",
"findall",
"(",
"'OUTCOME'",
")",
"]",
"for",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFReader.get_parents | Returns the parents of the variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_parents()
{'bowel-problem': [],
'dog-out': ['family-out', 'bowel-problem'],
'family-out': [],
'hear-bark': ... | pgmpy/readwrite/XMLBIF.py | def get_parents(self):
"""
Returns the parents of the variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_parents()
{'bowel-problem': [],
'dog-out': ['family-out', 'bowel-problem'],
... | def get_parents(self):
"""
Returns the parents of the variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_parents()
{'bowel-problem': [],
'dog-out': ['family-out', 'bowel-problem'],
... | [
"Returns",
"the",
"parents",
"of",
"the",
"variables",
"present",
"in",
"the",
"network"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L114-L130 | [
"def",
"get_parents",
"(",
"self",
")",
":",
"variable_parents",
"=",
"{",
"definition",
".",
"find",
"(",
"'FOR'",
")",
".",
"text",
":",
"[",
"edge",
".",
"text",
"for",
"edge",
"in",
"definition",
".",
"findall",
"(",
"'GIVEN'",
")",
"]",
"for",
"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFReader.get_values | Returns the CPD of the variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_values()
{'bowel-problem': array([[ 0.01],
[ 0.99]]),
'dog-out': array([[ 0.99, 0.01, 0.97, 0... | pgmpy/readwrite/XMLBIF.py | def get_values(self):
"""
Returns the CPD of the variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_values()
{'bowel-problem': array([[ 0.01],
[ 0.99]]),
... | def get_values(self):
"""
Returns the CPD of the variables present in the network
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_values()
{'bowel-problem': array([[ 0.01],
[ 0.99]]),
... | [
"Returns",
"the",
"CPD",
"of",
"the",
"variables",
"present",
"in",
"the",
"network"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L132-L159 | [
"def",
"get_values",
"(",
"self",
")",
":",
"variable_CPD",
"=",
"{",
"definition",
".",
"find",
"(",
"'FOR'",
")",
".",
"text",
":",
"list",
"(",
"map",
"(",
"float",
",",
"table",
".",
"text",
".",
"split",
"(",
")",
")",
")",
"for",
"definition"... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFReader.get_property | Returns the property of the variable
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_property()
{'bowel-problem': ['position = (190, 69)'],
'dog-out': ['position = (155, 165)'],
'family-out': ['position = (112, 69)'],
... | pgmpy/readwrite/XMLBIF.py | def get_property(self):
"""
Returns the property of the variable
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_property()
{'bowel-problem': ['position = (190, 69)'],
'dog-out': ['position = (155, 165)'],
'f... | def get_property(self):
"""
Returns the property of the variable
Examples
--------
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml")
>>> reader.get_property()
{'bowel-problem': ['position = (190, 69)'],
'dog-out': ['position = (155, 165)'],
'f... | [
"Returns",
"the",
"property",
"of",
"the",
"variable"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L161-L177 | [
"def",
"get_property",
"(",
"self",
")",
":",
"variable_property",
"=",
"{",
"variable",
".",
"find",
"(",
"'NAME'",
")",
".",
"text",
":",
"[",
"property",
".",
"text",
"for",
"property",
"in",
"variable",
".",
"findall",
"(",
"'PROPERTY'",
")",
"]",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFWriter.get_variables | Add variables to XMLBIF
Return
------
dict: dict of type {variable: variable tags}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_variables()
{'bowel-problem': <Element VARIABLE at 0x7fe28607dd88>,
'family-out': <Element VARIA... | pgmpy/readwrite/XMLBIF.py | def get_variables(self):
"""
Add variables to XMLBIF
Return
------
dict: dict of type {variable: variable tags}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_variables()
{'bowel-problem': <Element VARIABLE at 0x7fe2860... | def get_variables(self):
"""
Add variables to XMLBIF
Return
------
dict: dict of type {variable: variable tags}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_variables()
{'bowel-problem': <Element VARIABLE at 0x7fe2860... | [
"Add",
"variables",
"to",
"XMLBIF"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L275-L298 | [
"def",
"get_variables",
"(",
"self",
")",
":",
"variables",
"=",
"self",
".",
"model",
".",
"nodes",
"(",
")",
"variable_tag",
"=",
"{",
"}",
"for",
"var",
"in",
"sorted",
"(",
"variables",
")",
":",
"variable_tag",
"[",
"var",
"]",
"=",
"etree",
"."... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFWriter.get_states | Add outcome to variables of XMLBIF
Return
------
dict: dict of type {variable: outcome tags}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_states()
{'dog-out': [<Element OUTCOME at 0x7ffbabfcdec8>, <Element OUTCOME at 0x7ffbabfcdf08>]... | pgmpy/readwrite/XMLBIF.py | def get_states(self):
"""
Add outcome to variables of XMLBIF
Return
------
dict: dict of type {variable: outcome tags}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_states()
{'dog-out': [<Element OUTCOME at 0x7ffbabfcd... | def get_states(self):
"""
Add outcome to variables of XMLBIF
Return
------
dict: dict of type {variable: outcome tags}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_states()
{'dog-out': [<Element OUTCOME at 0x7ffbabfcd... | [
"Add",
"outcome",
"to",
"variables",
"of",
"XMLBIF"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L300-L332 | [
"def",
"get_states",
"(",
"self",
")",
":",
"outcome_tag",
"=",
"{",
"}",
"cpds",
"=",
"self",
".",
"model",
".",
"get_cpds",
"(",
")",
"for",
"cpd",
"in",
"cpds",
":",
"var",
"=",
"cpd",
".",
"variable",
"outcome_tag",
"[",
"var",
"]",
"=",
"[",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFWriter._make_valid_state_name | Transform the input state_name into a valid state in XMLBIF.
XMLBIF states must start with a letter an only contain letters,
numbers and underscores. | pgmpy/readwrite/XMLBIF.py | def _make_valid_state_name(self, state_name):
"""Transform the input state_name into a valid state in XMLBIF.
XMLBIF states must start with a letter an only contain letters,
numbers and underscores.
"""
s = str(state_name)
s_fixed = pp.CharsNotIn(pp.alphanums + "_").setPa... | def _make_valid_state_name(self, state_name):
"""Transform the input state_name into a valid state in XMLBIF.
XMLBIF states must start with a letter an only contain letters,
numbers and underscores.
"""
s = str(state_name)
s_fixed = pp.CharsNotIn(pp.alphanums + "_").setPa... | [
"Transform",
"the",
"input",
"state_name",
"into",
"a",
"valid",
"state",
"in",
"XMLBIF",
".",
"XMLBIF",
"states",
"must",
"start",
"with",
"a",
"letter",
"an",
"only",
"contain",
"letters",
"numbers",
"and",
"underscores",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L334-L343 | [
"def",
"_make_valid_state_name",
"(",
"self",
",",
"state_name",
")",
":",
"s",
"=",
"str",
"(",
"state_name",
")",
"s_fixed",
"=",
"pp",
".",
"CharsNotIn",
"(",
"pp",
".",
"alphanums",
"+",
"\"_\"",
")",
".",
"setParseAction",
"(",
"pp",
".",
"replaceWi... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFWriter.get_properties | Add property to variables in XMLBIF
Return
------
dict: dict of type {variable: property tag}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_property()
{'light-on': <Element PROPERTY at 0x7f7a2ffac1c8>,
'family-out': <Element ... | pgmpy/readwrite/XMLBIF.py | def get_properties(self):
"""
Add property to variables in XMLBIF
Return
------
dict: dict of type {variable: property tag}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_property()
{'light-on': <Element PROPERTY at 0x7... | def get_properties(self):
"""
Add property to variables in XMLBIF
Return
------
dict: dict of type {variable: property tag}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_property()
{'light-on': <Element PROPERTY at 0x7... | [
"Add",
"property",
"to",
"variables",
"in",
"XMLBIF"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L345-L370 | [
"def",
"get_properties",
"(",
"self",
")",
":",
"variables",
"=",
"self",
".",
"model",
".",
"nodes",
"(",
")",
"property_tag",
"=",
"{",
"}",
"for",
"var",
"in",
"sorted",
"(",
"variables",
")",
":",
"properties",
"=",
"self",
".",
"model",
".",
"no... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFWriter.get_definition | Add Definition to XMLBIF
Return
------
dict: dict of type {variable: definition tag}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_definition()
{'hear-bark': <Element DEFINITION at 0x7f1d48977408>,
'family-out': <Element DEFI... | pgmpy/readwrite/XMLBIF.py | def get_definition(self):
"""
Add Definition to XMLBIF
Return
------
dict: dict of type {variable: definition tag}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_definition()
{'hear-bark': <Element DEFINITION at 0x7f1d4... | def get_definition(self):
"""
Add Definition to XMLBIF
Return
------
dict: dict of type {variable: definition tag}
Examples
--------
>>> writer = XMLBIFWriter(model)
>>> writer.get_definition()
{'hear-bark': <Element DEFINITION at 0x7f1d4... | [
"Add",
"Definition",
"to",
"XMLBIF"
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L372-L399 | [
"def",
"get_definition",
"(",
"self",
")",
":",
"cpds",
"=",
"self",
".",
"model",
".",
"get_cpds",
"(",
")",
"cpds",
".",
"sort",
"(",
"key",
"=",
"lambda",
"x",
":",
"x",
".",
"variable",
")",
"definition_tag",
"=",
"{",
"}",
"for",
"cpd",
"in",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFWriter.get_values | Add Table to XMLBIF.
Return
---------------
dict: dict of type {variable: table tag}
Examples
-------
>>> writer = XMLBIFWriter(model)
>>> writer.get_values()
{'dog-out': <Element TABLE at 0x7f240726f3c8>,
'light-on': <Element TABLE at 0x7f24072... | pgmpy/readwrite/XMLBIF.py | def get_values(self):
"""
Add Table to XMLBIF.
Return
---------------
dict: dict of type {variable: table tag}
Examples
-------
>>> writer = XMLBIFWriter(model)
>>> writer.get_values()
{'dog-out': <Element TABLE at 0x7f240726f3c8>,
... | def get_values(self):
"""
Add Table to XMLBIF.
Return
---------------
dict: dict of type {variable: table tag}
Examples
-------
>>> writer = XMLBIFWriter(model)
>>> writer.get_values()
{'dog-out': <Element TABLE at 0x7f240726f3c8>,
... | [
"Add",
"Table",
"to",
"XMLBIF",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L401-L428 | [
"def",
"get_values",
"(",
"self",
")",
":",
"cpds",
"=",
"self",
".",
"model",
".",
"get_cpds",
"(",
")",
"definition_tag",
"=",
"self",
".",
"definition",
"table_tag",
"=",
"{",
"}",
"for",
"cpd",
"in",
"cpds",
":",
"table_tag",
"[",
"cpd",
".",
"va... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | XMLBIFWriter.write_xmlbif | Write the xml data into the file.
Parameters
----------
filename: Name of the file.
Examples
-------
>>> writer = XMLBIFWriter(model)
>>> writer.write_xmlbif(test_file) | pgmpy/readwrite/XMLBIF.py | def write_xmlbif(self, filename):
"""
Write the xml data into the file.
Parameters
----------
filename: Name of the file.
Examples
-------
>>> writer = XMLBIFWriter(model)
>>> writer.write_xmlbif(test_file)
"""
with open(filename,... | def write_xmlbif(self, filename):
"""
Write the xml data into the file.
Parameters
----------
filename: Name of the file.
Examples
-------
>>> writer = XMLBIFWriter(model)
>>> writer.write_xmlbif(test_file)
"""
with open(filename,... | [
"Write",
"the",
"xml",
"data",
"into",
"the",
"file",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBIF.py#L430-L444 | [
"def",
"write_xmlbif",
"(",
"self",
",",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'w'",
")",
"as",
"fout",
":",
"fout",
".",
"write",
"(",
"self",
".",
"__str__",
"(",
")",
")"
] | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | JointProbabilityDistribution.marginal_distribution | Returns the marginal distribution over variables.
Parameters
----------
variables: string, list, tuple, set, dict
Variable or list of variables over which marginal distribution needs
to be calculated
inplace: Boolean (default True)
If Fals... | pgmpy/factors/discrete/JointProbabilityDistribution.py | def marginal_distribution(self, variables, inplace=True):
"""
Returns the marginal distribution over variables.
Parameters
----------
variables: string, list, tuple, set, dict
Variable or list of variables over which marginal distribution needs
to... | def marginal_distribution(self, variables, inplace=True):
"""
Returns the marginal distribution over variables.
Parameters
----------
variables: string, list, tuple, set, dict
Variable or list of variables over which marginal distribution needs
to... | [
"Returns",
"the",
"marginal",
"distribution",
"over",
"variables",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/JointProbabilityDistribution.py#L101-L133 | [
"def",
"marginal_distribution",
"(",
"self",
",",
"variables",
",",
"inplace",
"=",
"True",
")",
":",
"return",
"self",
".",
"marginalize",
"(",
"list",
"(",
"set",
"(",
"list",
"(",
"self",
".",
"variables",
")",
")",
"-",
"set",
"(",
"variables",
"if... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | JointProbabilityDistribution.check_independence | Check if the Joint Probability Distribution satisfies the given independence condition.
Parameters
----------
event1: list
random variable whose independence is to be checked.
event2: list
random variable from which event1 is independent.
values: 2D array... | pgmpy/factors/discrete/JointProbabilityDistribution.py | def check_independence(self, event1, event2, event3=None, condition_random_variable=False):
"""
Check if the Joint Probability Distribution satisfies the given independence condition.
Parameters
----------
event1: list
random variable whose independence is to be chec... | def check_independence(self, event1, event2, event3=None, condition_random_variable=False):
"""
Check if the Joint Probability Distribution satisfies the given independence condition.
Parameters
----------
event1: list
random variable whose independence is to be chec... | [
"Check",
"if",
"the",
"Joint",
"Probability",
"Distribution",
"satisfies",
"the",
"given",
"independence",
"condition",
"."
] | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/JointProbabilityDistribution.py#L135-L204 | [
"def",
"check_independence",
"(",
"self",
",",
"event1",
",",
"event2",
",",
"event3",
"=",
"None",
",",
"condition_random_variable",
"=",
"False",
")",
":",
"JPD",
"=",
"self",
".",
"copy",
"(",
")",
"if",
"isinstance",
"(",
"event1",
",",
"six",
".",
... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
train | JointProbabilityDistribution.get_independencies | Returns the independent variables in the joint probability distribution.
Returns marginally independent variables if condition=None.
Returns conditionally independent variables if condition!=None
Parameter
---------
condition: array_like
Random Variable on which ... | pgmpy/factors/discrete/JointProbabilityDistribution.py | def get_independencies(self, condition=None):
"""
Returns the independent variables in the joint probability distribution.
Returns marginally independent variables if condition=None.
Returns conditionally independent variables if condition!=None
Parameter
---------
... | def get_independencies(self, condition=None):
"""
Returns the independent variables in the joint probability distribution.
Returns marginally independent variables if condition=None.
Returns conditionally independent variables if condition!=None
Parameter
---------
... | [
"Returns",
"the",
"independent",
"variables",
"in",
"the",
"joint",
"probability",
"distribution",
".",
"Returns",
"marginally",
"independent",
"variables",
"if",
"condition",
"=",
"None",
".",
"Returns",
"conditionally",
"independent",
"variables",
"if",
"condition!"... | pgmpy/pgmpy | python | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/JointProbabilityDistribution.py#L206-L236 | [
"def",
"get_independencies",
"(",
"self",
",",
"condition",
"=",
"None",
")",
":",
"JPD",
"=",
"self",
".",
"copy",
"(",
")",
"if",
"condition",
":",
"JPD",
".",
"conditional_distribution",
"(",
"condition",
")",
"independencies",
"=",
"Independencies",
"(",... | 9381a66aba3c3871d3ccd00672b148d17d63239e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.