def test_effective_length_se(self): """ Tests for the effective length in the SE kernel. """ # pylint: disable=too-many-locals self.report('Tests for the effective length in the SE kernel.') data_1 = np.array([1, 2]) data_2 = np.array([[0, 1, 2], [1, 1, 0.5]]) bws_1 = [0.1, 1] bws_2 = [0.5, 1, 2] res_l2_1 = np.sqrt(104) res_l2_2 = np.array([np.sqrt(2), np.sqrt(5.0625)]) res_l1_1 = 12 res_l1_2 = np.array([2, 3.25]) dim_1 = 2 dim_2 = 3 all_data = [(data_1, bws_1, dim_1, res_l2_1, res_l1_1), (data_2, bws_2, dim_2, res_l2_2, res_l1_2)] for data in all_data: kern = SEKernel(data[2], 1, data[1]) eff_l1_norms = kern.get_effective_norm(data[0], order=1, is_single=len(data[0].shape) == 1) eff_l2_norms = kern.get_effective_norm(data[0], order=2, is_single=len(data[0].shape) == 1) assert np.linalg.norm(eff_l2_norms - data[3]) < 1e-5 assert np.linalg.norm(eff_l1_norms - data[4]) < 1e-5
def test_compute_std_slack_se(self): """ Tests for the effective length in the SE kernel. """ self.report('Tests for std slack in the SE kernel.') # The data here are in the order [dim, scale, num_data] prob_params = [[2, 1, 10], [3, 2, 0], [10, 6, 13]] n = 5 for prob in prob_params: dim_bws = list(np.random.random(prob[0]) * 0.3 + 0.5) kern = SEKernel(prob[0], prob[1], dim_bws) X_1 = np.random.random((n, prob[0])) X_2 = np.random.random((n, prob[0])) X_tr = np.random.random((prob[2], prob[0])) _, std_1 = self._compute_post_covar(kern, X_tr, X_1) _, std_2 = self._compute_post_covar(kern, X_tr, X_2) std_diff = np.abs(std_1 - std_2) std_slack = kern.compute_std_slack(X_1, X_2) diff_12_scaled = kern.get_effective_norm(X_1 - X_2, order=2, is_single=False) kern_diff_12_scaled = kern.hyperparams['scale'] * diff_12_scaled assert np.all(std_diff <= std_slack) assert np.all(std_slack <= kern_diff_12_scaled)