Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Roman Sarrazin-Gendron
RNABayesPairing
Commits
8a85d6e3
Commit
8a85d6e3
authored
Mar 27, 2019
by
Roman Sarrazin-Gendron
Browse files
nothing changed
parent
623a49a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
bayespairing/src/pgmpy/sampling/Sampling.py
View file @
8a85d6e3
...
...
@@ -32,10 +32,9 @@ class BayesianModelSampling(Inference):
def
__init__
(
self
,
model
):
if
not
isinstance
(
model
,
BayesianModel
):
raise
TypeError
(
"Model expected type: BayesianModel, got type: "
,
type
(
model
))
self
.
topological_order
=
list
(
nx
.
topological_sort
(
model
))
super
(
BayesianModelSampling
,
self
).
__init__
(
model
)
def
forward_sample
(
self
,
size
=
1
,
return_type
=
'dataframe'
):
"""
Generates sample(s) from joint distribution of the bayesian network.
...
...
@@ -201,12 +200,11 @@ class BayesianModelSampling(Inference):
rec.array([(0, 0, 1, 0.6), (0, 0, 2, 0.6)],
dtype=[('diff', '<i8'), ('intel', '<i8'), ('grade', '<i8'), ('_weight', '<f8')])
"""
types
=
[(
var_name
,
'
int
'
)
for
var_name
in
self
.
topological_order
]
types
=
[(
var_name
,
np
.
int
8
)
for
var_name
in
self
.
topological_order
]
types
.
append
((
'_weight'
,
'float'
))
sampled
=
np
.
zeros
(
size
,
dtype
=
types
).
view
(
np
.
recarray
)
sampled
[
'_weight'
]
=
np
.
ones
(
size
)
evidence_dict
=
{
var
:
st
for
var
,
st
in
evidence
}
for
node
in
self
.
topological_order
:
cpd
=
self
.
model
.
get_cpds
(
node
)
states
=
range
(
self
.
cardinality
[
node
])
...
...
@@ -228,6 +226,7 @@ class BayesianModelSampling(Inference):
for
i
in
range
(
size
):
sampled
[
'_weight'
][
i
]
*=
cpd
.
values
[
evidence_dict
[
node
]]
else
:
print
(
'CALLING SAMPLE_DISCRETE'
,
states
,
cpd
.
values
,
size
)
sampled
[
node
]
=
sample_discrete
(
states
,
cpd
.
values
,
size
)
return
_return_samples
(
return_type
,
sampled
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment