def pack_distribution(self, p_sparse, p_dense=None):
"""
convenience routine to translate a distribution from a dictionary to
a dense array, using this state enumeration
"""
if p_dense is None:
p_dense = numpy.zeros((self.size, ), dtype=numpy.float)
# guard against case where p_sparse is empty
if len(p_sparse) == 0:
return p_dense
p_states, p_values = domain.from_mapping(p_sparse)
# now sort the states, keeping them synchronised with the
# ordering of the values
order = numpy.lexsort(p_states)
p_states = p_states[:, order]
p_values = p_values[order]
p_indices = self.indices(p_states)
p_dense[p_indices] = p_values
return p_dense
评论列表
文章目录