Exemplo n.º 1
0
    def test_train_batch_IP_diagonal(self):
        training_data = self._training_data()

        embed = GaussianEmbedding(10, 5,
            covariance_type='diagonal',
            energy_type='IP',
            mu_max=2.0, sigma_min=0.8, sigma_max=1.2, eta=0.1, Closs=1.0
        )

        for k in xrange(0, len(training_data), 100):
            embed.train_batch(training_data[k:(k+100)])

        self._check_results(embed)
Exemplo n.º 2
0
    def test_train_batch_KL_diagonal(self):
        training_data = self._training_data()
        embed = GaussianEmbedding(10, 5,
            covariance_type='diagonal',
            energy_type='KL',
            mu_max=2.0, sigma_min=0.8, sigma_max=1.2, eta=0.1, Closs=1.0
        )

        # diagonal training has more parameters so needs more then one
        # epoch to fully learn data
        for k in xrange(0, len(training_data), 100):
            embed.train_batch(training_data[k:(k+100)])

        self._check_results(embed)
Exemplo n.º 3
0
    def test_train_threads(self):
        training_data = self._training_data()

        embed = GaussianEmbedding(10, 5,
            covariance_type='spherical',
            energy_type='KL',
            mu_max=2.0, sigma_min=0.8, sigma_max=1.2, eta=0.1, Closs=1.0
        )

        def iter_pairs():
            for k in xrange(0, len(training_data), 100):
                yield training_data[k:(k+100)]

        embed.train(iter_pairs(), n_workers=4)

        self._check_results(embed)
Exemplo n.º 4
0
def sample_embed(energy_type='KL', covariance_type='spherical', eta=0.1):
    mu = np.array([
        [0.0, 0.0],
        [1.0, -1.25],
        [-0.1, -0.4],
        [1.2, -0.3],
        [0.5, 0.5],
        [-0.55, -0.75]
    ], dtype=DTYPE)
    if covariance_type == 'spherical':
        sigma = np.array([
            [1.0],
            [5.0],
            [0.8],
            [0.4],
            [1.5],
            [1.4]
        ], dtype=DTYPE)
    elif covariance_type == 'diagonal':
        sigma = np.array([
            [1.0, 0.1],
            [5.0, 5.5],
            [0.8, 1.1],
            [0.9, 1.9],
            [0.65, 0.9],
            [1.5, 1.55]
        ], dtype=DTYPE)

    return GaussianEmbedding(3, size=2,
        covariance_type=covariance_type,
        energy_type=energy_type,
        mu=mu, sigma=sigma, eta=eta
    )
Exemplo n.º 5
0
 def test_eta_multiple(self):
     expected = {
         'mu': 0.1,
         'mu_min': 0.001,
         'sigma': 0.05,
         'sigma_min': 0.000005
     }
     embed = GaussianEmbedding(10, 5, eta=expected)
     actual = embed.eta
     for k, v in list(expected.items()):
         self.assertAlmostEqual(actual[k], v)
Exemplo n.º 6
0
 def test_eta_single(self):
     embed = GaussianEmbedding(10, 5, eta=0.55)
     expected = {
         'mu': 0.55,
         'mu_min': 0.0,
         'sigma': 0.55,
         'sigma_min': 0.0
     }
     actual = embed.eta
     for k, v in expected.items():
         self.assertAlmostEqual(actual[k], v)