From cd9923741ea2e36301deb7956f4ef6dc6db5f174 Mon Sep 17 00:00:00 2001 From: Yannick Calvino Alonso Date: Tue, 22 Nov 2022 14:34:41 +0100 Subject: [PATCH] fixed issue with goptions --> wraper --- qstack/regression/hyperparameters.py | 11 +++++++---- qstack/regression/kernel_utils.py | 3 ++- qstack/regression/regression.py | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/qstack/regression/hyperparameters.py b/qstack/regression/hyperparameters.py index 2b71886..44d9e53 100755 --- a/qstack/regression/hyperparameters.py +++ b/qstack/regression/hyperparameters.py @@ -46,8 +46,11 @@ def hyper_loop(sigma, eta): print(s, e, mean, std, flush=True) errors.append((mean, std, e, s)) return errors - - kernel = get_kernel(akernel, [gkernel, gdict]) + if gkernel == None: + gwrap = None + else: + gwrap = [gkernel, gdict] + kernel = get_kernel(akernel, gwrap) if read_kernel is False: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=test_size, random_state=0) else: @@ -94,7 +97,7 @@ def main(): parser.add_argument('--y', type=str, dest='prop', required=True, help='path to the properties file') parser.add_argument('--test', type=float, dest='test_size', default=defaults.test_size, help='test set fraction (default='+str(defaults.test_size)+')') parser.add_argument('--akernel', type=str, dest='akernel', default=defaults.kernel, help='local kernel type (G for Gaussian, L for Laplacian, myL for Laplacian for open-shell systems) (default '+defaults.kernel+')') - parser.add_argument('--gkernel', type=str, dest='gkernel', default=defaults.gkernel, help='global kernel type (avg for average kernel, rem for REMatch kernel) (default '+defaults.gkernel+')') + parser.add_argument('--gkernel', type=str, dest='gkernel', default=defaults.gkernel, help='global kernel type (avg for average kernel, rem for REMatch kernel) (default )') parser.add_argument('--gdict', nargs='*', action=ParseKwargs, dest='gdict', default=defaults.gdict, help='dictionary like input string to initialize global kernel parameters') parser.add_argument('--splits', type=int, dest='splits', default=defaults.splits, help='k in k-fold cross validation (default='+str(defaults.n_rep)+')') parser.add_argument('--print', type=int, dest='printlevel', default=0, help='printlevel') @@ -110,7 +113,7 @@ def main(): X = np.load(args.repr) y = np.loadtxt(args.prop) - errors = hyperparameters(X, y, read_kernel=args.readk, sigma=args.sigma, eta=args.eta, akernel=args.kernel, test_size=args.test_size, splits=args.splits, printlevel=args.printlevel, adaptive=args.adaptive) + errors = hyperparameters(X, y, read_kernel=args.readk, sigma=args.sigma, eta=args.eta, akernel=args.akernel, test_size=args.test_size, splits=args.splits, printlevel=args.printlevel, adaptive=args.adaptive) print() print('error stdev eta sigma') diff --git a/qstack/regression/kernel_utils.py b/qstack/regression/kernel_utils.py index 0456e79..7462389 100644 --- a/qstack/regression/kernel_utils.py +++ b/qstack/regression/kernel_utils.py @@ -24,7 +24,7 @@ def __call__(self, parser, namespace, values, option_string=None): sigma=32.0, eta=1e-5, kernel='L', - gkernel='avg', + gkernel=None, gdict={'alpha':1.0, 'normalize':1}, test_size=0.2, n_rep=5, @@ -162,6 +162,7 @@ def get_global_K(X, Y, sigma, local_kernel, global_kernel, options): print(f"Final global kernel has size : {K_global.shape}", flush=True) return K_global + def my_laplacian_kernel(X, Y, gamma): """ Compute Laplacian kernel between X and Y """ def cdist(X, Y): diff --git a/qstack/regression/regression.py b/qstack/regression/regression.py index 199a905..a2c6a98 100755 --- a/qstack/regression/regression.py +++ b/qstack/regression/regression.py @@ -25,7 +25,7 @@ def regression(X, y, read_kernel=False, sigma=defaults.sigma, eta=defaults.eta, maes_all = [] for size in train_size: - size_train = int(np.floor(len(y_train)*size)) + size_train = int(np.floor(len(y_train)*size)) if size < 1.0 else size maes = [] for rep in range(n_rep): train_idx = np.random.choice(all_indices_train, size = size_train, replace=False)