def test_CorrectBuilding(self):
        """Verify that a Dataset is properly created when given valid args.
        """
        db = DatasetBuilder()

        iq = np.zeros((2, 1024))

        db.add(iq, label=1)

        db.add(iq, label=2)
        db.add(iq, label=2)

        db.add(iq, label=3)
        db.add(iq, label=3)
        db.add(iq, label=3)

        db.add(iq, label=4)
        db.add(iq, label=4)
        db.add(iq, label=4)
        db.add(iq, label=4)

        dataset = db.build()

        self.assertEqual(len(dataset), 10)
        self.assertEqual(
            dataset.get_examples_per_class(label="label"), {1: 1, 2: 2, 3: 3, 4: 4}
        )
Beispiel #2
0
 def _load_local(self, path: str) -> Dataset:
     builder = DatasetBuilder()
     data, description = self._read(path)
     for mod, snrs in description.items():
         for snr in snrs:
             for iq in data[(mod, snr)]:
                 builder.add(iq=iq, Modulation=mod, SNR=snr)
     return builder.build()
Beispiel #3
0
 def _create_dataset(cls, extras: dict = {}):
     keys = ["SNR", "Modulation"] + list(extras.keys())
     db = DatasetBuilder(n=cls.NSAMPLES, keys=keys)
     iq = np.zeros((2, cls.NSAMPLES))
     for mod in cls.MODS:
         for snr in cls.SNRS:
             for _ in range(cls.NEXAMPLES):
                 db.add(iq, SNR=snr, Modulation=mod, **extras)
     return db.build()
Beispiel #4
0
    def test_isbalanced(self):
        """Verify that the Dataset can correctly detect imbalance.
        """
        db = DatasetBuilder(n=TestDataset.NSAMPLES, keys=["SNR", "Modulation"])
        iq = np.zeros((2, TestDataset.NSAMPLES))
        for i, mod in enumerate(TestDataset.MODS):
            for snr in TestDataset.SNRS:
                for _ in range(i * TestDataset.NEXAMPLES):
                    db.add(iq, SNR=snr, Modulation=mod)
        baddata = db.build()

        self.assertTrue(TestDataset._data.is_balanced(label="Modulation"))
        self.assertTrue(TestDataset._data.is_balanced(label="SNR"))

        self.assertFalse(baddata.is_balanced(label="Modulation"))
        self.assertTrue(baddata.is_balanced(label="SNR"))
Beispiel #5
0
    def test_equality(self):
        """Verify that the dataset.__eq__ method works
        """
        db = DatasetBuilder(n=TestDataset.NSAMPLES, keys=["SNR", "Modulation"])
        iq = np.zeros((2, TestDataset.NSAMPLES))
        for i, mod in enumerate(TestDataset.MODS):
            for snr in TestDataset.SNRS:
                for _ in range(i * TestDataset.NEXAMPLES):
                    db.add(iq, SNR=snr, Modulation=mod)
        baddata = db.build()

        copieddata = deepcopy(TestDataset._data)

        # By definition, a dataset must be equivalent to itself
        self.assertEqual(TestDataset._data, TestDataset._data)

        # Verify that equality works in both directions
        self.assertEqual(TestDataset._data, copieddata)
        self.assertEqual(copieddata, TestDataset._data)

        # Verify that inequality works in both directions
        self.assertNotEqual(TestDataset._data, baddata)
        self.assertNotEqual(baddata, TestDataset._data)
 def test_BuildingEmptyDataset(self):
     """Verify that an empty dataset can be created by not calling add
     """
     db = DatasetBuilder()
     dataset = db.build()
     self.assertEqual(len(dataset), 0)