From ed87e6bbd292e581eac66efc069b01af16527ef6 Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Mon, 10 Feb 2014 17:00:50 +0000 Subject: [PATCH] final touches to gradchecker --- GPy/core/model.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GPy/core/model.py b/GPy/core/model.py index 90edcedf..f4e58c9d 100644 --- a/GPy/core/model.py +++ b/GPy/core/model.py @@ -447,14 +447,14 @@ class Model(Parameterized): for i, ind in enumerate(param_list): xx = x.copy() - xx[i] += step + xx[ind] += step f1, g1 = self.objective_and_gradients(xx) - xx[i] -= 2.*step + xx[ind] -= 2.*step f2, g2 = self.objective_and_gradients(xx) numerical_gradient = (f1 - f2) / (2 * step) - ratio = (f1 - f2) / (2 * step * gradient[i]) - difference = np.abs((f1 - f2) / 2 / step - gradient[i]) + ratio = (f1 - f2) / (2 * step * gradient[ind]) + difference = np.abs((f1 - f2) / 2 / step - gradient[ind]) if (np.abs(1. - ratio) < tolerance) or np.abs(difference) < tolerance: formatted_name = "\033[92m {0} \033[0m".format(names[ind]) @@ -462,7 +462,7 @@ class Model(Parameterized): formatted_name = "\033[91m {0} \033[0m".format(names[ind]) r = '%.6f' % float(ratio) d = '%.6f' % float(difference) - g = '%.6f' % gradient[i] + g = '%.6f' % gradient[ind] ng = '%.6f' % float(numerical_gradient) grad_string = "{0:<{c0}}|{1:^{c1}}|{2:^{c2}}|{3:^{c3}}|{4:^{c4}}".format(formatted_name, r, d, g, ng, c0=cols[0] + 9, c1=cols[1], c2=cols[2], c3=cols[3], c4=cols[4]) print grad_string