Example #1
0
 def test_mean_data_threshold(self, k):
     """Tests the mean photon number per mode from hard-coded values stored in the array
     ``n_means_data``. The test iterates over different numbers of modes in the data."""
     m = k + 2
     embedding = embed.Exp(m)
     vgbs = param.VGBS(A_eye[:m, :m], mean_photon_number_th, embedding, threshold=True)
     kl = cost.KL(test_data_th[k], vgbs)
     assert np.allclose(kl.mean_n_data, n_means_data_th[:m])
     assert len(kl.mean_n_data) == m
Example #2
0
 def test_grad_threshold(self, k):
     """Tests the calculation of the gradient against an explicit computation from hard-coded
     values of trainable parameters and mean photon numbers from data and model."""
     m = k + 2
     embedding = embed.Exp(m)
     vgbs = param.VGBS(A_eye[:m, :m], mean_photon_number_th, embedding, threshold=True)
     kl = cost.KL(test_data_th[k], vgbs)
     gamma = [-(n_means_data_th[i] - n_means_gbs_th[k][i]) / weights[i] for i in range(m)]
     assert np.allclose(kl.grad(params_fixed[:m]), gamma @ test_jacobian[:m, :m])
Example #3
0
 def test_cost(self, k):
     """Tests the calculation of the Kullback-Liebler cost function against an explicit
     computation from hard-coded values of trainable parameters and mean photon numbers
     from data and model."""
     m = k + 2
     embedding = embed.Exp(m)
     vgbs = param.VGBS(A_eye[:m, :m], mean_photon_number, embedding, threshold=False)
     kl = cost.KL(test_data[k], vgbs)
     assert np.allclose(kl(params_fixed[:m]), test_sum_log_probs[k] / 6)