Ejemplo n.º 1
0
class TestExperimentLogisticRegression(unittest.TestCase):
    def test_run_and_analyze(self):
        self.lr16_4 = ExperimentLogisticRegression('exp1.log', 8, 2, 2**8,
                                                   0xbeef, 0xbeef,
                                                   LTFArray.transform_id,
                                                   LTFArray.combiner_xor)
        self.lr16_4.execute()
Ejemplo n.º 2
0
    def test_fix_convergence(self, logger):
        """
        This methods checks the results of a ExperimentLogisticRegression to match a recorded result which was
        generated with the same parameters.
        """
        n = 8
        k = 2
        N = 255
        seed_instance = 0xBAE55E
        seed_model = 0x5C6AE1E
        seed_challenge = 0xB0661E
        seed_distance = 0xB0C
        experiment = ExperimentLogisticRegression(
            LOG_PATH + 'exp',
            LRParameters(n=n,
                         k=k,
                         N=N,
                         seed_model=seed_model,
                         seed_distance=seed_distance,
                         seed_instance=seed_instance,
                         seed_challenge=seed_challenge,
                         transformation='soelter_lightweight_secure',
                         combiner='xor',
                         mini_batch_size=0,
                         shuffle=False,
                         convergence_decimals=2))
        experiment.execute(logger.queue, logger.logger_name)

        result_str = logger.read_result_log()
        self.assertFalse(result_str == '', 'The result log was empty.')

        error = 'LR learning results deviate from legacy learning results.'
        self.assertEqual(experiment.result.iteration_count, 274, error)
        self.assertEqual(experiment.result.epoch_count, 274, error)
        self.assertEqual(experiment.result.gradient_step_count, 274, error)
        self.assertEqual(experiment.result.accuracy, 0.98828125, error)
        print(experiment.result.model)
        assert_array_equal(
            around(experiment.result.model, decimals=8),
            around([
                0.00351544,
                -0.00504143,
                0.01470355,
                0.00481524,
                0.00649157,
                -0.00301955,
                -0.0025765,
                0.00841928,
                0.,
                0.03248558,
                0.37524702,
                -0.0683109,
                0.40447738,
                0.49995907,
                0.52796785,
                0.00060493,
                -0.40093716,
                0.,
            ],
                   decimals=8), error)
Ejemplo n.º 3
0
 def test_run_and_analyze(self, logger):
     """
     This method only runs the experiment.
     """
     lr16_4 = ExperimentLogisticRegression(
         LOG_PATH + 'exp1',
         8,
         2,
         2**8,
         0xbeef,
         0xbeef,
         LTFArray.transform_id,
         LTFArray.combiner_xor,
     )
     lr16_4.execute(logger.queue, logger.logger_name)
Ejemplo n.º 4
0
    def test_fix_convergence(self, logger):
        """
        This methods checks the results of a ExperimentLogisticRegression to match a recorded result which was
        generated with the same parameters.
        """
        n = 8
        k = 2
        N = 255
        seed_instance = 0xBAE55E
        seed_model = 0x5C6AE1E
        seed_challenge = 0xB0661E
        seed_distance = 0xB0C
        experiment = ExperimentLogisticRegression(
            LOG_PATH + 'exp',
            LRParameters(n=n,
                         k=k,
                         N=N,
                         seed_model=seed_model,
                         seed_distance=seed_distance,
                         seed_instance=seed_instance,
                         seed_challenge=seed_challenge,
                         transformation='soelter_lightweight_secure',
                         combiner='xor',
                         mini_batch_size=0,
                         shuffle=False,
                         convergence_decimals=2))
        experiment.execute(logger.queue, logger.logger_name)

        result_str = logger.read_result_log()
        self.assertFalse(result_str == '', 'The result log was empty.')

        error = 'LR learning results deviate from legacy learning results.'
        self.assertEqual(experiment.result.iteration_count, 256, error)
        self.assertEqual(experiment.result.epoch_count, 256, error)
        self.assertEqual(experiment.result.gradient_step_count, 256, error)
        self.assertEqual(experiment.result.accuracy, 0.98828125, error)
        assert_array_equal(
            around(experiment.result.model, decimals=8),
            around([
                3.99071615e-03, -5.65532862e-03, 1.63862406e-02,
                5.37762262e-03, 7.29781422e-03, -3.35141930e-03,
                -2.95642974e-03, 9.40114614e-03, 1.26572532e-07,
                3.49183531e-02, 3.68758330e-01, -7.85028286e-02,
                4.17595994e-01, 5.09973673e-01, 5.13855116e-01, 2.97216086e-04,
                -3.96978992e-01, -5.41390228e-03
            ],
                   decimals=8), error)
Ejemplo n.º 5
0
 def test_run_and_analyze(self, logger):
     """
     This method only runs the experiment.
     """
     lr16_4 = ExperimentLogisticRegression(
         LOG_PATH + 'exp1',
         LRParameters(n=8,
                      k=2,
                      N=2**8,
                      seed_model=0xbeef,
                      seed_distance=0xbeef,
                      seed_instance=0xdead,
                      seed_challenge=0xdead,
                      transformation='id',
                      combiner='xor',
                      mini_batch_size=2,
                      shuffle=False,
                      convergence_decimals=2))
     lr16_4.execute(logger.queue, logger.logger_name)
Ejemplo n.º 6
0
    def test_fix_convergence(self, logger):
        """
        This methods checks the results of a ExperimentLogisticRegression to match a recorded result which was
        generated with the same parameters.
        """
        n = 8
        k = 2
        N = 255
        seed_instance = 0xBAE55E
        seed_model = 0x5C6AE1E
        seed_challenge = 0xB0661E
        seed_distance = 0xB0C
        experiment = ExperimentLogisticRegression(
            LOG_PATH + 'exp',
            n,
            k,
            N,
            seed_instance,
            seed_model,
            LTFArray.transform_soelter_lightweight_secure,
            LTFArray.combiner_xor,
            seed_challenge=seed_challenge,
            seed_chl_distance=seed_distance,
        )
        experiment.execute(logger.queue, logger.logger_name)

        legacy_result = [
            '0xbae55e', '0x5c6ae1e', '0', '8', '2', '255',
            'transform_soelter_lightweight_secure', 'combiner_xor', '363',
            '1.000000', '0.00443419669755,-0.00616546911566,0.0186346081194,'
            '0.0061619719475,0.00795284461334,-0.00443539877583,'
            '-0.00316047872599,0.00993214368373,0.0507595729459,'
            '0.415207373134,-0.0517173737839,0.285900582842,'
            '0.467512016377,0.550102231366,-0.000739711610042,'
            '-0.467757977178\n'
        ]
        result_str = logger.read_result_log()
        self.assertFalse(result_str == '', 'The result log was empty.')
        experiment_result = result_str.split('\t')
        # remove execution time
        del experiment_result[9]
        self.assertTrue(experiment_result == legacy_result,
                        'You changed the code significant.')
Ejemplo n.º 7
0
class TestExperimentLogisticRegression(TestBase):
    def test_run_and_analyze(self):
        logger_name = 'log'

        # Setup multiprocessing logging
        queue = multiprocessing.Queue(-1)
        listener = multiprocessing.Process(target=log_listener,
                                           args=(
                                               queue,
                                               setup_logger,
                                               logger_name,
                                           ))
        listener.start()

        self.lr16_4 = ExperimentLogisticRegression('exp1', 8, 2, 2**8, 0xbeef,
                                                   0xbeef,
                                                   LTFArray.transform_id,
                                                   LTFArray.combiner_xor)
        self.lr16_4.execute(queue, logger_name)

        queue.put_nowait(None)
        listener.join()