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
d0b043bb
Commit
d0b043bb
authored
12 years ago
by
Denis John
Browse files
Options
Downloads
Patches
Plain Diff
Working on factorgraphfactory
parent
efa8a757
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
+15
-0
15 additions, 0 deletions
primo/reasoning/factorelemination/Factor.py
primo/reasoning/factorelemination/FactorTreeFactory.py
+50
-0
50 additions, 0 deletions
primo/reasoning/factorelemination/FactorTreeFactory.py
with
65 additions
and
0 deletions
primo/reasoning/factorelemination/Factor.py
+
15
−
0
View file @
d0b043bb
...
...
@@ -4,6 +4,7 @@ from primo.core import Node
class
Factor
(
object
):
evidence
=
""
cluster
=
set
()
def
__init__
(
self
,
node
):
...
...
@@ -13,5 +14,19 @@ class Factor(object):
def
__str__
(
self
):
return
self
.
node
.
name
def
set_evidence
(
self
,
evd
):
self
.
evidence
=
evd
def
clear_evidence
(
self
):
self
.
evidence
=
""
def
set_cluster
(
self
,
cluster
):
self
.
cluster
=
cluster
def
add_to_cluster
(
self
,
node
):
self
.
cluster
.
add
(
node
)
def
get_variables
(
self
):
return
self
.
node
.
get_cpd
().
variables
This diff is collapsed.
Click to expand it.
primo/reasoning/factorelemination/FactorTreeFactory.py
+
50
−
0
View file @
d0b043bb
import
networkx
as
nx
import
copy
from
primo.core
import
Node
from
primo.reasoning.factorelemination
import
Factor
from
primo.reasoning.factorelemination
import
FactorTree
...
...
@@ -30,6 +31,55 @@ class FactorTreeFactory(object):
return
FactorTree
(
graph
,
rootFactor
)
def
calculate_seperators_pull
(
self
,
factor
,
graph
):
s
=
set
()
pullSet
=
set
()
#find all variables in outgoing edges for factor
for
child
in
graph
.
neighbors
(
factor
):
s
=
self
.
calculate_seperators_pull
(
child
,
graph
)
# add s to incoming vars from child
if
graph
[
factor
][
child
][
'
inVars
'
]
==
None
:
graph
[
factor
][
child
][
'
inVars
'
]
=
copy
.
copy
(
s
)
else
:
tmp
=
graph
[
factor
][
child
][
'
inVars
'
]
graph
[
factor
][
child
][
'
inVars
'
]
=
tmp
|
s
for
c2
in
graph
.
children
(
factor
):
if
child
!=
c2
:
#TODO: add s to outgoing vars from c2
if
graph
[
factor
][
child
][
'
outVars
'
]
==
None
:
graph
[
factor
][
child
][
'
outVars
'
]
=
copy
.
copy
(
s
)
else
:
tmp
=
graph
[
factor
][
child
][
'
outVars
'
]
graph
[
factor
][
child
][
'
outVars
'
]
=
tmp
|
s
#self.calculate_seperators_push(child,graph,s)
pullSet
=
s
|
pullSet
pullSet
=
s
|
set
(
factor
.
get_variables
())
return
pullSet
def
calculate_seperators_push
(
self
,
factor
,
graph
,
setOut
):
#TODO: add local vars to set
#setOut =
localSet
=
copy
.
copy
(
setOut
)
setOut
.
add
(
localVars
)
for
child
in
graph
.
children
(
factor
):
#add setOut to outgoing vars from child
child
.
calculate_seperators_push
(
child
,
graph
,
setOut
)
...
...
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