Esempio n. 1
0
    def __init__(self, xk, pk):
        """ Create a bit vector RV with the specified distribution.

        Parameters:
        -----------
        xk : sequence of bit vectors
        pk : sequence of floats
            A sequence of bit vectors with corresponding probabilities. The bit
            vectors must be of the same length l. Any bit vector of length l not
            specified has zero probability.
        """
        xk = np.array(xk, copy=0)
        pk = np.array(pk, copy=0)
        is_nonzero_p = (pk != 0)
        xk, pk = xk[is_nonzero_p], pk[is_nonzero_p]

        self.length = xk.shape[1]
        self._table = dict(izip(bit_vector_to_str(xk), pk))
        self._xk = xk
        self._rv = rv_discrete(values=(np.arange(len(xk)), pk))
Esempio n. 2
0
 def pmf(self, xk):
     """ The probability mass function evaluated for the given bit vector(s).
     """
     return self._pmf(bit_vector_to_str(xk))