コード例 #1
0
ファイル: engine.py プロジェクト: BaxterEaves/baxcat_cxx
    def probability(self, x, cols, given=None):
        """ Predictive probability of x_1, ..., x_n given y_1, ..., y_n

        Parameters
        ----------
        x : numpy.ndarray(2,)
            2-D numpy array where each row is a set of observations and each
            column corresponds to a feature.
        cols : list
            The names of each column/feature of `x`.
        given : list(tuple)
            List of (name, value,) conditional contraints for the probability

        Returns
        -------
        logps : numpy.ndarray

        Examples
        --------
        The probability that an animal is fast and agile given that it is
        bulbous.

        >>> engine = Engine.load('examples/zoo.bcmodels')
        >>> engine.probability(np.array([[1, 1]]), ['fast', 'agile'],
        ...                    given=[('bulbous': 1]))
        """
        # TODO: make sure that given goes not caontain columns rom cols
        x = du.format_query_data(x)
        col_idxs = [self._converters['col2idx'][col] for col in cols]
        x_cnv = du.convert_data(x, cols, self._dtypes, self._converters)

        if given is not None:
            given = du.convert_given(given, self._dtypes, self._converters)

        return mu.probability(x_cnv, self._models, col_idxs, given=given)
コード例 #2
0
ファイル: engine.py プロジェクト: BaxterEaves/baxcat_cxx
    def probability(self, x, cols, given=None):
        """ Predictive probability of x_1, ..., x_n given y_1, ..., y_n

        Parameters
        ----------
        x : numpy.ndarray(2,)
            2-D numpy array where each row is a set of observations and each
            column corresponds to a feature.
        cols : list
            The names of each column/feature of `x`.
        given : list(tuple)
            List of (name, value,) conditional contraints for the probability

        Returns
        -------
        logps : numpy.ndarray

        Examples
        --------
        The probability that an animal is fast and agile given that it is
        bulbous.

        >>> engine = Engine.load('examples/zoo.bcmodels')
        >>> engine.probability(np.array([[1, 1]]), ['fast', 'agile'],
        ...                    given=[('bulbous': 1]))
        """
        # TODO: make sure that given goes not caontain columns rom cols
        x = du.format_query_data(x)
        col_idxs = [self._converters['col2idx'][col] for col in cols]
        x_cnv = du.convert_data(x, cols, self._dtypes, self._converters)

        if given is not None:
            given = du.convert_given(given, self._dtypes, self._converters)

        return mu.probability(x_cnv, self._models, col_idxs, given=given)
コード例 #3
0
def test_format_query_data_should_return_2d_numpy_array_2d_array():
    # 2d array
    x = du.format_query_data(np.eye(2))
    assert isinstance(x, np.ndarray)
    assert x.shape == (
        2,
        2,
    )
コード例 #4
0
def test_format_query_data_should_return_2d_numpy_array_list_of_array():
    # list of arrays
    x = du.format_query_data([np.array([.2, 'string']), np.array([.1, 'x'])])
    assert isinstance(x, np.ndarray)
    assert x.shape == (
        2,
        2,
    )
コード例 #5
0
def test_format_query_data_should_return_2d_numpy_array_obj_array():
    # single object array
    x = du.format_query_data(np.array([.2, 'string']))
    assert isinstance(x, np.ndarray)
    assert x.shape == (
        1,
        2,
    )
コード例 #6
0
def test_format_query_data_should_return_2d_numpy_array_float_array():
    # single float64 array
    x = du.format_query_data(np.array([1.2, 2.1]))
    assert isinstance(x, np.ndarray)
    assert x.shape == (
        1,
        2,
    )
コード例 #7
0
def test_format_query_data_should_return_2d_numpy_array_list():
    # single list
    x = du.format_query_data([1.2, 'string'])
    assert isinstance(x, np.ndarray)
    assert x.shape == (
        1,
        2,
    )
コード例 #8
0
def test_format_query_data_should_return_2d_numpy_array_str():
    # single string data
    x = du.format_query_data('string')
    assert isinstance(x, np.ndarray)
    assert x.shape == (
        1,
        1,
    )
コード例 #9
0
def test_format_query_data_should_return_2d_numpy_array_float():
    # single float data
    x = du.format_query_data(1.2)
    assert isinstance(x, np.ndarray)
    assert x.shape == (
        1,
        1,
    )
コード例 #10
0
def test_format_query_data_should_return_2d_numpy_array_list_of_array():
    # list of arrays
    x = du.format_query_data([np.array([.2, 'string']), np.array([.1, 'x'])])
    assert isinstance(x, np.ndarray)
    assert x.shape == (2, 2,)
コード例 #11
0
def test_format_query_data_should_return_2d_numpy_array_2d_array():
    # 2d array
    x = du.format_query_data(np.eye(2))
    assert isinstance(x, np.ndarray)
    assert x.shape == (2, 2,)
コード例 #12
0
def test_format_query_data_should_return_2d_numpy_array_obj_array():
    # single object array
    x = du.format_query_data(np.array([.2, 'string']))
    assert isinstance(x, np.ndarray)
    assert x.shape == (1, 2,)
コード例 #13
0
def test_format_query_data_should_return_2d_numpy_array_float_array():
    # single float64 array
    x = du.format_query_data(np.array([1.2, 2.1]))
    assert isinstance(x, np.ndarray)
    assert x.shape == (1, 2,)
コード例 #14
0
def test_format_query_data_should_return_2d_numpy_array_list():
    # single list
    x = du.format_query_data([1.2, 'string'])
    assert isinstance(x, np.ndarray)
    assert x.shape == (1, 2,)
コード例 #15
0
def test_format_query_data_should_return_2d_numpy_array_str():
    # single string data
    x = du.format_query_data('string')
    assert isinstance(x, np.ndarray)
    assert x.shape == (1, 1,)
コード例 #16
0
def test_format_query_data_should_return_2d_numpy_array_float():
    # single float data
    x = du.format_query_data(1.2)
    assert isinstance(x, np.ndarray)
    assert x.shape == (1, 1,)