def setUp(self):
     argvals = {'input_dim_0': np.array([1, 2, 3, 4])}
     values = np.array([[1, 2, 3, 4],
                        [5, 6, 7, 9],
                        [3, 4, 5, 7],
                        [3, 4, 6, 1],
                        [3, 4, 7, 6]])
     self.dense_fd = DenseFunctionalData(argvals, values)
    def setUp(self):
        argvals = {'input_dim_0': np.array([1, 2, 3, 4]),
                   'input_dim_1': np.array([5, 6, 7])}

        values = np.array([[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]],
                           [[5, 6, 7], [5, 6, 7], [5, 6, 7], [5, 6, 7]],
                           [[3, 4, 5], [3, 4, 5], [3, 4, 5], [3, 4, 5]],
                           [[3, 4, 6], [3, 4, 5], [3, 4, 5], [3, 4, 5]],
                           [[3, 4, 7], [3, 4, 5], [3, 4, 5], [3, 4, 5]]])
        self.dense_fd = DenseFunctionalData(argvals, values)
class TestDenseFunctionalData1D(unittest.TestCase):
    """Test class for the class DenseFunctionalData in one dimension."""

    def setUp(self):
        argvals = {'input_dim_0': np.array([1, 2, 3, 4])}
        values = np.array([[1, 2, 3, 4],
                           [5, 6, 7, 9],
                           [3, 4, 5, 7],
                           [3, 4, 6, 1],
                           [3, 4, 7, 6]])
        self.dense_fd = DenseFunctionalData(argvals, values)

    def test_argvals_stand(self):
        is_equal = np.allclose(self.dense_fd.argvals_stand['input_dim_0'],
                               np.array([0., 0.33333333, 0.66666667, 1.]))
        self.assertTrue(is_equal)

    def test_n_obs(self):
        self.assertEqual(self.dense_fd.n_obs, 5)

    def test_n_dim(self):
        self.assertEqual(self.dense_fd.n_dim, 1)

    def test_range_obs(self):
        self.assertEqual(self.dense_fd.range_obs, (1, 9))

    def test_range_dim(self):
        self.assertEqual(self.dense_fd.range_dim, {'input_dim_0': (1, 4)})

    def test_shape(self):
        self.assertEqual(self.dense_fd.shape, {'input_dim_0': 4})

    def test_subset(self):
        new_dense_fd = self.dense_fd[2]
        self.assertIsInstance(new_dense_fd, DenseFunctionalData)
        self.assertEqual(new_dense_fd.n_obs, 1)
        new_dense_fd = self.dense_fd[1:4]
        self.assertIsInstance(new_dense_fd, DenseFunctionalData)
        self.assertEqual(new_dense_fd.n_obs, 3)

    def test_as_irregular(self):
        irregu_fd = self.dense_fd.as_irregular()
        self.assertIsInstance(irregu_fd, IrregularFunctionalData)
        self.assertEqual(irregu_fd.n_obs, 5)

    def test_is_compatible(self):
        self.assertTrue(self.dense_fd.is_compatible(self.dense_fd))

    def test_mean(self):
        mean_fd = self.dense_fd.mean()
        is_equal = np.allclose(mean_fd.values,
                               np.array([[3., 4., 5.6, 5.4]]))
        self.assertTrue(is_equal)
    def test_check_compatible_dense(self):
        argvals = {
            'input_dim_0': np.array([1, 2, 3, 4]),
            'input_dim_1': np.array([5, 6, 7])
        }
        values = np.array([[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]],
                           [[5, 6, 7], [5, 6, 7], [5, 6, 7], [5, 6, 7]]])
        dense_fd = DenseFunctionalData(argvals, values)

        argvals = {'input_dim_0': np.array([1, 2, 3, 4])}
        values = np.array([[1, 2, 3, 4], [5, 6, 7, 9], [3, 4, 5, 7]])
        dense_fd2 = DenseFunctionalData(argvals, values)
        self.assertRaises(ValueError, _check_same_nobs, dense_fd, dense_fd2)
        self.assertRaises(ValueError, _check_same_ndim, dense_fd, dense_fd2)
Beispiel #5
0
def read_csv_dense(data, argvals):
    """Load a csv file into a DenseFunctionalData object.

    Parameters
    ----------
    data: pd.DataFrame
        Input dataframe.
    argvals: np.ndarray
        An array of argvals.

    Returns
    -------
    obj: DenseFunctionalData
        The loaded csv file

    """
    argvals = {'input_dim_0': argvals}
    values = np.array(data)
    return DenseFunctionalData(argvals, values)
Beispiel #6
0
def read_ts_dense(data):
    """Load a ts file into a DenseFunctionalData object.

    Parameters
    ----------
    data: pd.DataFrame
        Input dataframe.

    Returns
    -------
    obj: DenseFunctionalData
        The loaded ts file.

    """
    argvals = data.loc[0, 'dim_0'].index.values
    values = np.zeros((len(data), len(argvals)))
    for idx, row in data.iterrows():
        values[idx, :] = row['dim_0'].values
    return DenseFunctionalData({'input_dim_0': argvals}, values)
    def test_check_same_type(self):
        argvals = {'input_dim_0': np.array([1, 2, 3, 4])}
        values = np.array([[1, 2, 3, 4], [5, 6, 7, 9], [3, 4, 5, 7]])
        dense_fd = DenseFunctionalData(argvals, values)

        argvals = {
            'input_dim_0': {
                0: np.array([1, 2, 3, 4]),
                1: np.array([2, 4]),
                2: np.array([0, 2, 3])
            }
        }
        values = {
            0: np.array([1, 2, 3, 4]),
            1: np.array([5, 6]),
            2: np.array([8, 9, 7])
        }
        irregu_fd = IrregularFunctionalData(argvals, values)
        self.assertRaises(TypeError, _check_same_type, dense_fd, irregu_fd)