Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PRIMO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Social Cognitive Systems
PRIMO
Commits
a0e4c0eb
Commit
a0e4c0eb
authored
11 years ago
by
Denis John PC
Browse files
Options
Downloads
Patches
Plain Diff
Working on FactorTree
parent
30b6c912
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
primo/reasoning/factorelemination/Factor.py
+11
-6
11 additions, 6 deletions
primo/reasoning/factorelemination/Factor.py
primo/reasoning/factorelemination/FactorTree.py
+27
-0
27 additions, 0 deletions
primo/reasoning/factorelemination/FactorTree.py
with
38 additions
and
6 deletions
primo/reasoning/factorelemination/Factor.py
+
11
−
6
View file @
a0e4c0eb
...
...
@@ -3,24 +3,26 @@ from primo.core import Node
class
Factor
(
object
):
evidence
=
""
cluster
=
set
()
isEvidence
=
False
def
__init__
(
self
,
node
):
self
.
node
=
node
self
.
calCPD
=
node
.
get_cpd
()
self
.
calCPD
=
node
.
get_cpd
()
.
copy
()
def
__str__
(
self
):
return
self
.
node
.
name
def
set_evidence
(
self
,
evd
):
#TODO: copy from originalCPD
# setCPD
self
.
e
viden
c
e
=
evd
self
.
calCPD
=
self
.
node
.
get_cpd
().
copy
()
self
.
calCPD
=
self
.
calCPD
.
setEvidence
(
evd
)
self
.
isE
videne
=
True
def
clear_evidence
(
self
):
self
.
evidence
=
""
self
.
calCPD
=
self
.
node
.
get_cpd
().
copy
()
self
.
isEvidence
=
False
def
set_cluster
(
self
,
cluster
):
self
.
cluster
=
cluster
...
...
@@ -33,5 +35,8 @@ class Factor(object):
def
get_node
(
self
):
return
self
.
node
def
contains_node
(
self
,
node
):
return
self
.
node
==
node
This diff is collapsed.
Click to expand it.
primo/reasoning/factorelemination/FactorTree.py
+
27
−
0
View file @
a0e4c0eb
...
...
@@ -12,6 +12,33 @@ class FactorTree(object):
self
.
rootNode
=
rootNode
self
.
graph
[
'
messagesValid
'
]
=
False
def
calculate_marginal
(
self
,
variables
):
if
not
self
.
graph
[
'
messagesValid
'
]:
self
.
calculateMessages
()
resPT
=
ProbabilityTable
()
for
f
in
self
.
graph
.
nodes
():
if
f
.
get_node
()
in
variables
:
resPT
=
resPT
.
multiplication
.
calculate_marginal_forOne
(
f
)
return
resPT
def
calculate_marginal_forOne
(
self
,
factor
):
curCPD
=
factor
.
get_calculation_CDP
().
copy
()
for
p
in
self
.
graph
.
predecessors
(
factor
):
curCPD
=
curCPD
.
multiplication
(
self
.
graph
[
p
][
factor
][
'
inMessage
'
])
for
p
in
self
.
graph
.
neighbors
(
factor
):
curCPD
=
curCPD
.
multiplication
(
self
.
graph
[
factor
][
p
][
'
outMessage
'
])
for
v
in
curCPD
.
get_variables
()[:]:
if
v
!=
factor
.
get_node
():
curCPD
=
curCPD
.
marginalization
(
v
)
return
curCPD
def
draw
(
self
):
import
matplotlib.pyplot
as
plt
nx
.
draw_circular
(
self
.
graph
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment