Skip to content

Commit

Permalink
Use float as the data type of samples, pass empty array when there is…
Browse files Browse the repository at this point in the history
… no parent
  • Loading branch information
linzhp committed Nov 8, 2017
1 parent 7c75e16 commit 1a910dd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pgmpy/sampling/Sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def likelihood_weighted_sample(self, evidence=None, size=1, return_type="datafra
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, 'float') 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)
Expand Down Expand Up @@ -238,7 +238,7 @@ def likelihood_weighted_sample(self, evidence=None, size=1, return_type="datafra
sampled[node] = evidence_dict[node]
# do not need to update weight, because all sample will have the same weight
else:
sampled[node] = cpd.sample(size)
sampled[node] = cpd.sample(size, np.empty(0))

return _return_samples(return_type, sampled)

Expand Down

0 comments on commit 1a910dd

Please sign in to comment.