Commit b4928f2b authored by Hendrik Buschmeier's avatar Hendrik Buschmeier
Browse files

Refactoring: Adapted imports.

parent d52cc730
......@@ -7,8 +7,7 @@ import random
import numpy
from scipy.stats
from primo.nodes import ContinuousNode
from primo.nodes
class Density(object):
'''TODO: write doc'''
......@@ -46,6 +45,7 @@ class ExponentialParameters(object):
#a dict (node,coefficient) that holds the weights that define the depency on each node
self.b=b
class GaussParameters(object):
'''
This represents the parameters for the Gauss-density class.
......@@ -58,6 +58,7 @@ class GaussParameters(object):
#the variance
self.var=var
class NDGaussParameters(object):
def __init__(self, mu, cov):
self.mu=mu
......@@ -591,7 +592,7 @@ class Gauss(Density):
def add_variable(self, variable):
if not isinstance(variable, ContinuousNode):
if not isinstance(variable, primo.nodes.ContinuousNode):
raise Exception("Tried to add Variable into Gaussian densitiy, but variable is not continuous")
self.b[variable]=0.0
......
......@@ -2,7 +2,7 @@ import networkx as nx
import primo.nodes
class BayesNet(object):
class BayesianNetwork(object):
def __init__(self):
self.graph = nx.DiGraph()
......@@ -15,7 +15,7 @@ class BayesNet(object):
self.node_lookup[node.name]=node
self.graph.add_node(node)
else:
raise Exception("Can only add 'Node' and its subclasses as nodes into the BayesNet")
raise Exception("Can only add 'Node' and its subclasses as nodes into the BayesianNetwork")
def add_edge(self, node_from, node_to):
if node_from in self.graph.nodes() and node_to in self.graph.nodes():
......@@ -38,14 +38,14 @@ class BayesNet(object):
try:
self.graph.remove_edge(node_from, node_to)
except nx.exception.NetworkXError:
raise Exception("Tried to remove an edge which does not exist in the BayesNet")
raise Exception("Tried to remove an edge which does not exist in the BayesianNetwork")
#raise Exception("Fixme: Adapt CPD of child-node")
def get_node(self, node_name):
try:
return self.node_lookup[node_name]
except KeyError:
raise Exception("There is no node with name "+node_name+" in the BayesNet")
raise Exception("There is no node with name "+node_name+" in the BayesianNetwork")
def get_all_nodes(self):
return self.graph.nodes()
......@@ -137,7 +137,7 @@ class BayesNet(object):
return len(self.graph)
class BayesianDecisionNetwork(BayesNet):
class BayesianDecisionNetwork(BayesianNetwork):
def __init__(self):
super(BayesianDecisionNetwork, self).__init__()
......@@ -180,7 +180,7 @@ class BayesianDecisionNetwork(BayesNet):
self.node_lookup[node.name]=node
self.graph.add_node(node)
else:
raise Exception("Can only add 'Node' and its subclasses as nodes into the BayesNet")
raise Exception("Can only add 'Node' and its subclasses as nodes into the BayesianNetwork")
def get_all_nodes(self):
'''Returns all RandomNodes'''
......@@ -234,7 +234,7 @@ class BayesianDecisionNetwork(BayesNet):
self.partialOrdering = partialOrder
class DynamicBayesNet(BayesNet):
class DynamicBayesianNetwork(BayesianNetwork):
''' This is the implementation of a dynamic Bayesian network (also called
temporal Bayesian network).
......@@ -248,8 +248,8 @@ class DynamicBayesNet(BayesNet):
'''
def __init__(self):
super(DynamicBayesNet, self).__init__()
self._B0 = BayesNet()
super(DynamicBayesianNetwork, self).__init__()
self._B0 = BayesianNetwork()
self._twoTBN = TwoTBN()
@property
......@@ -260,12 +260,12 @@ class DynamicBayesNet(BayesNet):
@B0.setter
def B0(self, value):
''' Set the Bayesian network representing the initial distribution.'''
if isinstance(value, BayesNet):
if isinstance(value, BayesianNetwork):
if not value.is_valid():
raise Exception("BayesNet is not valid.")
raise Exception("BayesianNetwork is not valid.")
self._B0 = value
else:
raise Exception("Can only set 'BayesNet' and its subclasses as " +
raise Exception("Can only set 'BayesianNetwork' and its subclasses as " +
"B0 of a DBN.")
@property
......@@ -278,7 +278,7 @@ class DynamicBayesNet(BayesNet):
''' Set the 2-time-slice Bayesian network.'''
if isinstance(value, TwoTBN):
if not value.is_valid():
raise Exception("BayesNet is not valid.")
raise Exception("BayesianNetwork is not valid.")
self._twoTBN = value
else:
raise Exception("Can only set 'TwoTBN' and its subclasses as " +
......@@ -294,18 +294,18 @@ class DynamicBayesNet(BayesNet):
" not found in TwoTBN!")
return False;
return super(DynamicBayesNet, self).is_valid()
return super(DynamicBayesianNetwork, self).is_valid()
class TwoTBN(BayesNet):
class TwoTBN(BayesianNetwork):
''' This is the implementation of a 2-time-slice Bayesian network (2-TBN).
'''
def __init__(self, bayesnet=None):
BayesNet.__init__(self)
BayesianNetwork.__init__(self)
if bayesnet:
if not isinstance(bayesnet, BayesNet):
raise Exception("Parameter 'bayesnet' is not a instance of class BayesNet.")
if not isinstance(bayesnet, BayesianNetwork):
raise Exception("Parameter 'bayesnet' is not a instance of class BayesianNetwork.")
self.graph = bayesnet.graph
self.node_lookup = bayesnet.node_lookup
self.__initial_nodes = []
......
......@@ -2,10 +2,9 @@ import abc
import random
import re
import scipy
import scipy.stats
from primo.decision.UtilityTable import UtilityTable
import primo.reasoning.density
import primo.reasoning.densities
class Node(object):
......@@ -99,7 +98,7 @@ class DiscreteNode(RandomNode):
super(DiscreteNode, self).__init__(name)
self.value_range = value_range
self.cpd = primo.reasoning.density.ProbabilityTable()
self.cpd = primo.reasoning.densities.ProbabilityTable()
self.cpd.add_variable(self)
def __str__(self):
......@@ -280,7 +279,7 @@ class ContinuousNodeFactory(object):
name,
(-float("Inf"),
float("Inf")),
primo.reasoning.density.Gauss)
primo.reasoning.densities.Gauss)
def createExponentialNode(self, name):
'''
......@@ -291,7 +290,7 @@ class ContinuousNodeFactory(object):
return self.createContinuousNode(
name,
(0,float("Inf")),
primo.reasoning.density.Exponential)
primo.reasoning.densities.Exponential)
def createBetaNode(self, name):
'''
......@@ -302,7 +301,7 @@ class ContinuousNodeFactory(object):
return self.createContinuousNode(
name,
(0, 1),
primo.reasoning.density.Beta)
primo.reasoning.densities.Beta)
def createContinuousNode(self,name,value_range,density_class):
'''
......
......@@ -4,8 +4,7 @@ import copy
import random
import time
from primo.networks import BayesNet
from primo.networks import DynamicBayesNet
import primo.networks
class Particle(object):
'''
......@@ -91,7 +90,7 @@ def weighted_sample(network, evidence = {}):
'''
w = 1.0
state = {}
if not isinstance(network, BayesNet):
if not isinstance(network, primo.network.BayesianNetwork):
raise Exception("The given network is not an instance of BayesNet.")
nodes = network.get_nodes_in_topological_sort()
......@@ -132,7 +131,7 @@ def particle_filtering_DBN(network, N, T, get_evidence_function, particle_class
Returns a list of N samples
'''
if not isinstance(network, DynamicBayesNet):
if not isinstance(network, primo.networks.DynamicBayesianNetwork):
raise Exception("The given network is not an instance of DynamicBayesNet.")
if not network.is_valid():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment