Esempio n. 1
0
    def test_positivity(self):
        """Test positivity."""
        npt.assert_equal(positivity.positive(-1), 0, err_msg=self.err)

        npt.assert_equal(
            positivity.positive(-1.0),
            -float(0),
            err_msg=self.err,
        )

        npt.assert_equal(
            positivity.positive(self.data1),
            self.data2,
            err_msg=self.err,
        )

        for expected, output in zip(self.data4, self.pos_dtype_obj):
            print(expected, output)
            npt.assert_array_equal(expected, output, err_msg=self.err)

        npt.assert_raises(TypeError, positivity.positive, '-1')
Esempio n. 2
0
 def setUp(self):
     """Set test parameter values."""
     self.data1 = np.arange(9).reshape(3, 3) - 5
     self.data2 = np.array([[0, 0, 0], [0, 0, 0], [1, 2, 3]])
     self.data3 = np.array(
         [np.arange(5) - 3, np.arange(4) - 2],
         dtype=object,
     )
     self.data4 = np.array(
         [np.array([0, 0, 0, 0, 1]),
          np.array([0, 0, 0, 1])],
         dtype=object,
     )
     self.pos_dtype_obj = positivity.positive(self.data3)
     self.err = 'Incorrect positivity'
Esempio n. 3
0
    def op(self, data, **kwargs):
        """Operator

        This method projects each column of the matrix data onto the simplex
        sum_i v_i = mass, v_i>=0

        Parameters
        ----------
        data : np.ndarray
            Input data array

        Returns
        -------
        np.ndarray all positive elements from input data

        """
        if self.pos_en:
            return positive(data)
        else:
            return columns_wise_simplex_proj(data,mass=self.mass)
Esempio n. 4
0
    def __init__(self):

        self.op = lambda x: positive(x)
        self.cost = self._cost_method
Esempio n. 5
0
    def __init__(self):

        self.op = lambda input_data: positive(input_data)
        self.cost = self._cost_method