コード例 #1
0
    def get_sim(self, v1, v2):

        assert_is_array_or_matrix(v1)
        assert_is_array_or_matrix(v2)

        # TODO: figure out where these asserts belong!!
        v1, v2 = to_compatible_matrix_types(v1, v2)
        v1.assert_same_shape(v2)

        return self._sim(v1, v2)
コード例 #2
0
    def get_sims_to_matrix(self, vector, matrix_):

        assert_is_array_or_matrix(vector)
        assert_is_array_or_matrix(matrix_)

        vector, matrix_ = to_compatible_matrix_types(vector, matrix_)

        if vector.shape[1] != matrix_.shape[1] or vector.shape[0] != 1:
            raise ValueError(
                'Inconsistent shapes {0} and {1}'.format(vector.shape, matrix_.shape)
            )

        return self._sims_to_matrix(vector, matrix_)
コード例 #3
0
ファイル: full_additive.py プロジェクト: dimazest/dissect
    def __init__(self, **kwargs):
        #TODO here; very important, should be able to set the intercept
        #when mat a and mat b are given , to true or false. now by default is
        #is false
        """
        Constructor.

        Args:
            A= : matrix A, of matrix-like type (Matrix, ndarray,
            numpy matrix, scipy matrix). Optional (parameters can be set
            through training.)

            B= : matrix B, matrix-like type. Optional.

            learner= : regression learner object, of type RegressionLearner.
            Optional, default LstsqRegressionLearner.
        """
        assert_valid_kwargs(kwargs, ["A", "B", "learner"])

        if "A" in kwargs and "B" in kwargs:
            mat_a = kwargs["A"]
            mat_b = kwargs["B"]
            if not is_array_or_matrix(mat_a):
                raise TypeError("expected matrix type, received: %s"
                                % type(mat_a))

            if not is_array_or_matrix(mat_b):
                raise TypeError("expected matrix type, received: %s"
                                % type(mat_b))

            mat_a, mat_b = to_compatible_matrix_types(mat_a, mat_b)
            self._mat_a_t = mat_a.transpose()
            self._mat_b_t = mat_b.transpose()
            self._has_intercept = False

        else:
            self._regression_learner = LstsqRegressionLearner()
            if "learner" in kwargs:
                self._regression_learner = kwargs["learner"]
            self._has_intercept = self._regression_learner.has_intercept()
コード例 #4
0
ファイル: full_additive.py プロジェクト: kicasta/LSCDetection
    def __init__(self, A=None, B=None, learner=LstsqRegressionLearner()):
        #TODO here; very important, should be able to set the intercept
        #when mat a and mat b are given , to true or false. now by default is
        #is false
        """
        Constructor.

        Args:
            A= : matrix A, of matrix-like type (Matrix, ndarray,
            numpy matrix, scipy matrix). Optional (parameters can be set
            through training.)

            B= : matrix B, matrix-like type. Optional.

            learner= : regression learner object, of type RegressionLearner.
            Optional, default LstsqRegressionLearner.
        """
        if A is not None and B is not None:
            mat_a = A
            mat_b = B
            if not is_array_or_matrix(mat_a):
                raise TypeError("expected matrix type, received: %s"
                                % type(mat_a))

            if not is_array_or_matrix(mat_b):
                raise TypeError("expected matrix type, received: %s"
                                % type(mat_b))

            mat_a, mat_b = to_compatible_matrix_types(mat_a, mat_b)
            self._mat_a_t = mat_a.transpose()
            self._mat_b_t = mat_b.transpose()
            self._has_intercept = False

        else:
            self._regression_learner = learner
            self._has_intercept = self._regression_learner.has_intercept()
コード例 #5
0
ファイル: similarity_test.py プロジェクト: totonac/dissect
def test_to_compatible_matrix_type(vector, other_vector, expected_matrix_type):
    """Test that two vectors are converted to a compatible type."""
    r1, r2 = to_compatible_matrix_types(vector, other_vector)

    assert isinstance(r1, expected_matrix_type)
    assert isinstance(r2, expected_matrix_type)
コード例 #6
0
ファイル: similarity_test.py プロジェクト: Aliases/dissect
def test_to_compatible_matrix_type(vector, other_vector, expected_matrix_type):
    """Test that two vectors are converted to a compatible type."""
    r1, r2 = to_compatible_matrix_types(vector, other_vector)

    assert isinstance(r1, expected_matrix_type)
    assert isinstance(r2, expected_matrix_type)