Exemplo n.º 1
0
 def test_no_scaling(self) -> None:
     gs = GeomScaler()
     gs.fit(square)
     test_square = numpy.copy(square)
     test_square[..., :2] -= 0.5
     normalized_without_scaling_square = gs.transform(test_square,
                                                      with_std=False)
     numpy.testing.assert_array_equal(test_square,
                                      normalized_without_scaling_square)
Exemplo n.º 2
0
 def test_zero_padded_transform(self) -> None:
     gs = GeomScaler()
     gs.fit(square)
     zero_padding = numpy.repeat(square[:1, -1], repeats=4, axis=0)
     padded_square = numpy.concatenate([square[0], zero_padding], axis=0)
     normalized_square = gs.transform(numpy.array([padded_square]),
                                      padding_type='zero')
     numpy.testing.assert_array_equal(normalized_square[0, -4:],
                                      zero_padding)
Exemplo n.º 3
0
 def test_upsized_transform(self) -> None:
     gs = GeomScaler()
     square_0 = square[0] * 2
     square_0[:4, 2] = 1.
     square_0[4, 4] = 1.
     gs.fit(numpy.array([square_0]))
     n_square = gs.transform(numpy.array([square_0]))
     numpy.testing.assert_array_equal(n_square, normalized_square)
     coords = [geom[:, :2].flatten() for geom in n_square]
     coords = [item for sublist in coords for item in sublist]
     std = numpy.std(coords)
     numpy.testing.assert_array_almost_equal(std, 1., 1)
Exemplo n.º 4
0
    def test_transform(self) -> None:
        with self.subTest('It rejects unfitted geometry scalers on transform'):
            with self.assertRaises(AssertionError):
                gs = GeomScaler()
                gs.transform(square)

        with self.subTest('It transforms a sample square'):
            gs = GeomScaler()
            # scaled_square = square[0] * 2
            # scaled_square[4, 12] = 1.
            gs.fit(square)
            n_square = gs.transform(square)
            numpy.testing.assert_array_equal(n_square, normalized_square)

            coords = [geom[:, :2].flatten() for geom in n_square]
            coords = [item for sublist in coords for item in sublist]
            std = numpy.std(coords)
            numpy.testing.assert_array_almost_equal(std, 1., 1)
Exemplo n.º 5
0
 def test_no_centering(self) -> None:
     gs = GeomScaler()
     gs.fit(square)
     test_square = numpy.copy(square)
     test_square[..., :2] += 2
     gs.scale_factor = 1.  # manually override scale for testing
     normalized_without_centering_square = gs.transform(test_square,
                                                        with_mean=False)
     numpy.testing.assert_array_equal(test_square,
                                      normalized_without_centering_square)
Exemplo n.º 6
0
 def test_scaling_square_dup_nodes(self) -> None:
     gs = GeomScaler()
     gs.fit(square_duplicate_nodes)
     self.assertEqual(gs.scale_factor, 0.5)
Exemplo n.º 7
0
 def test_scaling_square(self) -> None:
     gs = GeomScaler()
     gs.fit(square)
     self.assertEqual(gs.scale_factor, 0.5)