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
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
Social Cognitive Systems
PRIMO
Commits
c8be19fc
Commit
c8be19fc
authored
12 years ago
by
Denis John
Browse files
Options
Downloads
Patches
Plain Diff
easy factorelimination
parent
3a87d612
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
primo/reasoning/density/ProbabilityTable.py
+20
-0
20 additions, 0 deletions
primo/reasoning/density/ProbabilityTable.py
primo/reasoning/factorelemination/EasiestFactorElimination.py
+52
-3
52 additions, 3 deletions
...o/reasoning/factorelemination/EasiestFactorElimination.py
with
72 additions
and
3 deletions
primo/reasoning/density/ProbabilityTable.py
+
20
−
0
View file @
c8be19fc
...
...
@@ -173,6 +173,26 @@ class ProbabilityTable(Density):
reduced
.
variables
.
remove
(
node
)
return
reduced
def
set_evidence
(
self
,
evidence
):
'''
Returns a new version of the ProbabilityTable with only the evidence
not equal zero
'''
ev
=
ProbabilityTable
()
ev
.
variables
=
copy
.
copy
(
self
.
variables
)
ev
.
table
=
numpy
.
zeros
(
self
.
table
.
shape
)
tmpCpd
=
self
.
table
pos_variable
=
ev
.
variables
.
index
(
evidence
[
0
])
pos_value
=
ev
.
variables
[
pos_variable
].
value_range
.
index
(
evidence
[
1
])
ev
.
table
=
numpy
.
rollaxis
(
ev
.
table
,
pos_variable
,
0
)
tmpCpd
=
numpy
.
rollaxis
(
tmpCpd
,
pos_variable
,
0
)
ev
.
variables
.
insert
(
0
,
ev
.
variables
.
pop
(
pos_variable
))
ev
.
table
[
pos_value
]
=
tmpCpd
[
pos_value
]
return
ev
...
...
This diff is collapsed.
Click to expand it.
primo/reasoning/factorelemination/EasiestFactorElimination.py
+
52
−
3
View file @
c8be19fc
...
...
@@ -31,10 +31,59 @@ class EasiestFactorElimination(object):
return
finCpd
def
calculate_PosteriorMarginal
(
self
,
variables
,
evidence
):
bn
=
bn
.
copy
()
#TODO
# Verbundwahrscheinlichkeit / PoE
# Erst wie Prior Marginal nur mit setzen der Evidence
# Dann PoE berechnen und damit normalisieren
nodes
=
self
.
bn
.
get_all_nodes
()
unzipped_list
=
zip
(
*
evidence
)
node1
=
nodes
.
pop
()
if
node1
in
unzipped_list
[
0
]:
ind
=
unzipped_list
[
0
].
index
(
node1
)
finCpd
=
node1
.
get_cpd
().
set_evidence
(
evidence
[
ind
])
else
:
finCpd
=
node1
.
get_cpd
()
for
n
in
nodes
:
if
n
in
unzipped_list
[
0
]:
ind
=
unzipped_list
[
0
].
index
(
n
)
nCPD
=
n
.
get_cpd
().
set_evidence
(
evidence
[
ind
])
finCpd
=
finCpd
.
multiplication
(
nCPD
)
else
:
finCpd
=
finCpd
.
multiplication
(
n
.
get_cpd
())
for
v
in
finCpd
.
get_variables
()[:]:
finCpd
=
finCpd
.
marginalization
(
v
)
return
finCpd
def
calculate_PoE
(
self
,
evidence
):
bn
=
bn
.
copy
()
def
calculate_PoE
(
self
,
evidence
):
nodes
=
self
.
bn
.
get_all_nodes
()
unzipped_list
=
zip
(
*
evidence
)
node1
=
nodes
.
pop
()
if
node1
in
unzipped_list
[
0
]:
ind
=
unzipped_list
[
0
].
index
(
node1
)
finCpd
=
node1
.
get_cpd
().
set_evidence
(
evidence
[
ind
])
else
:
finCpd
=
node1
.
get_cpd
()
for
n
in
nodes
:
if
n
in
unzipped_list
[
0
]:
ind
=
unzipped_list
[
0
].
index
(
n
)
nCPD
=
n
.
get_cpd
().
set_evidence
(
evidence
[
ind
])
finCpd
=
finCpd
.
multiplication
(
nCPD
)
else
:
finCpd
=
finCpd
.
multiplication
(
n
.
get_cpd
())
for
v
in
finCpd
.
get_variables
()[:]:
finCpd
=
finCpd
.
marginalization
(
v
)
return
finCpd
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