diff --git a/src/deepc/__init__.py b/src/deepc/__init__.py index c8bf12e..145c728 100644 --- a/src/deepc/__init__.py +++ b/src/deepc/__init__.py @@ -1,6 +1,5 @@ -from .math import linear_chirp from .lti import DiscreteLTI, RandomNoiseDiscreteLTI from .deepc import deePC from .controller import Controller -__all__ = ["linear_chirp", "DiscreteLTI", "RandomNoiseDiscreteLTI", "deePC", "Controller"] +__all__ = ["DiscreteLTI", "RandomNoiseDiscreteLTI", "deePC", "Controller"] diff --git a/src/deepc/math.py b/src/deepc/math.py index c554fc1..039c4cd 100644 --- a/src/deepc/math.py +++ b/src/deepc/math.py @@ -54,21 +54,3 @@ def projected_gradient_method( return x_new x_old = x_new return x_old - - -def linear_chirp(f0: float, f1: float, samples: int, phi: float = 0) -> list[float]: - """ - Generate a linear chirp signal. - Args: - f0: Start frequency in Hz. - f1: End frequency in Hz. - samples: Number of samples. - phi: Phase offset in radians. - """ - return [ - math.sin( - phi - + 2 * math.pi * (f0 * (i / (samples - 1)) + 0.5 * (f1 - f0) * (i / (samples - 1)) ** 2) - ) - for i in range(samples) - ] diff --git a/src/deepcpp/algorithm.cpp b/src/deepcpp/algorithm.cpp index e7d7aee..7051823 100644 --- a/src/deepcpp/algorithm.cpp +++ b/src/deepcpp/algorithm.cpp @@ -122,16 +122,3 @@ VectorXd projected_gradient_method( } return x_old; } - -std::vector linear_chirp(double f0, double f1, int samples, int phi) -{ - double Pi = 3.14159265358979323846; - std::vector res; - res.reserve(samples); - for (int i = 0; i < samples; ++i) - { - double t = i / (samples - 1.0); - res.push_back(std::sin(phi + 2 * Pi * (f0 * t + 0.5 * (f1 - f0) * t * t))); - } - return res; -} diff --git a/src/deepcpp/algorithm.h b/src/deepcpp/algorithm.h index bddbb09..bdae33e 100644 --- a/src/deepcpp/algorithm.h +++ b/src/deepcpp/algorithm.h @@ -32,6 +32,3 @@ VectorXd projected_gradient_method( std::function projection, int max_iterations = 300, double tolerance = 1e-6); - - -std::vector linear_chirp(double f0, double f1, int samples, int phi = 0); diff --git a/tests/deepc/helpers/__init__.py b/tests/deepc/helpers/__init__.py index bba1f23..d042632 100644 --- a/tests/deepc/helpers/__init__.py +++ b/tests/deepc/helpers/__init__.py @@ -1,4 +1,5 @@ -from deepc import DiscreteLTI, linear_chirp +import numpy as np +from deepc import DiscreteLTI def create_1D_in_1D_out_LTI() -> DiscreteLTI: @@ -36,10 +37,6 @@ def create_2D_in_3D_out_LTI() -> DiscreteLTI: def gather_offline_data(system: DiscreteLTI, samples: int) -> tuple: - if system.input_dim == 1: - u_d = linear_chirp(0, samples / 2, samples) - else: - chirps = [linear_chirp(0, samples / 2, samples, 0.1 * i) for i in range(system.input_dim)] - u_d = list(zip(*chirps)) # Transpose the list of chirp signals + u_d = np.random.uniform(-1, 1, (samples, system.input_dim)) y_d = system.apply_multiple(u_d) return u_d, y_d diff --git a/tests/deepc/test_math.py b/tests/deepc/test_math.py index 34c68a7..460ace1 100644 --- a/tests/deepc/test_math.py +++ b/tests/deepc/test_math.py @@ -1,6 +1,6 @@ import unittest import numpy as np -from deepc.math import linear_chirp, left_pseudoinverse, right_pseudoinverse, hankel_matrix +from deepc.math import left_pseudoinverse, right_pseudoinverse, hankel_matrix class TestLeftPseudoinverse(unittest.TestCase): @@ -77,24 +77,5 @@ def test_size_3_and_3_rows(self): np.testing.assert_array_equal(hankel_matrix(3, [(1, 2), (3, 4), (5, 6)]), [[1], [2], [3], [4], [5], [6]]) -class TestLinearChirp(unittest.TestCase): - def test_len(self): - chirp = linear_chirp(0, 100, 1000) - self.assertEqual(len(chirp), 1000) - - def test_start(self): - chirp = linear_chirp(0, 100, 1000) - self.assertAlmostEqual(chirp[0], 0) - - def test_end(self): - chirp = linear_chirp(0, 100, 1000) - self.assertAlmostEqual(chirp[-1], 0) - - def test_symmetry(self): - chirp1 = linear_chirp(0, 100, 1_000) - chirp2 = [-x for x in reversed(linear_chirp(100, 0, 1_000))] - np.testing.assert_allclose(chirp1, chirp2, atol=1e-12) - - if __name__ == "__main__": unittest.main() diff --git a/tests/deepcpp/test_algorithm.cpp b/tests/deepcpp/test_algorithm.cpp index 356b1bc..23f19ec 100644 --- a/tests/deepcpp/test_algorithm.cpp +++ b/tests/deepcpp/test_algorithm.cpp @@ -182,29 +182,3 @@ TEST(Algorithm, ProjectedGradientMethod) EXPECT_EQ(res, Vector(0, 0)); } - -TEST(LinearChirp, Size) -{ - auto chirp = linear_chirp(0, 100, 1'000); - EXPECT_EQ(chirp.size(), 1'000); -} - -TEST(LinearChirp, Start) -{ - auto chirp = linear_chirp(0, 100, 1'000); - EXPECT_NEAR(chirp[0], 0, 1e-12); -} - -TEST(LinearChirp, End) -{ - auto chirp = linear_chirp(0, 100, 1'000); - EXPECT_NEAR(chirp[999], 0, 1e-12); -} - -TEST(LinearChirp, Symmetry) -{ - auto chirp1 = linear_chirp(0, 100, 1'000); - auto chirp2 = linear_chirp(100, 0, 1'000); - for (int i = 0; i < 1'000; ++i) - EXPECT_NEAR(chirp1[i], -chirp2[999 - i], 1e-12); -} diff --git a/tests/deepcpp/test_deepc.cpp b/tests/deepcpp/test_deepc.cpp index de909d7..86a2f67 100644 --- a/tests/deepcpp/test_deepc.cpp +++ b/tests/deepcpp/test_deepc.cpp @@ -48,13 +48,9 @@ DiscreteLTI lti_2D_input_3D_output() std::tuple, std::vector> gather_offline_data(DiscreteLTI &system) { const int samples = 1'000; - std::vector u_d(samples, VectorXd::Zero(system.input_dim())); - for (int i = 0; i < system.input_dim(); ++i) - { - std::vector chirp = linear_chirp(0, samples / 2, samples, 0.1 * i); - for (int j = 0; j < samples; ++j) - u_d[j](i) = chirp[j]; - } + std::vector u_d; + for (int i = 0; i < samples; ++i) + u_d.push_back(VectorXd::Random(system.input_dim())); std::vector y_d = system.apply_multiple(u_d); return {u_d, y_d}; }