From 4bf5717bf0efb9f39440351e18a45ad298c33e30 Mon Sep 17 00:00:00 2001 From: Angel Farguell Caus Date: Wed, 27 May 2020 22:06:37 -0600 Subject: [PATCH] new options to set hyperparameters on conf.json --- conf_example.json | 6 +++++- process.py | 16 ++++++++++++---- svm.py | 5 +++-- utils.py | 20 ++++++++++++++++---- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/conf_example.json b/conf_example.json index 041086b..87d549a 100644 --- a/conf_example.json +++ b/conf_example.json @@ -17,7 +17,11 @@ "confal": 100, "toparti": false, "dmaxz": 0.1, - "confau": 100 + "confau": 100, + "sC": 100, + "skgam": 12, + "C": null, + "kgam": null } }, "plot_settings": { diff --git a/process.py b/process.py index 3728365..e36c31e 100644 --- a/process.py +++ b/process.py @@ -316,13 +316,21 @@ if not cloud: print '' print '>> Running Support Vector Machine <<' sys.stdout.flush() +C = svm_settings['C'] +svm_settings.pop('C',None) +kgam = svm_settings['kgam'] +svm_settings.pop('kgam',None) +sC = svm_settings['sC'] +skgam = svm_settings['skgam'] if dyn_pen: - C = np.power(c,3)/100. - kgam = np.sqrt(len(y))/12. + C = np.power(c,3)/sC + kgam = np.sqrt(len(y))/skgam search = False else: - kgam = np.sqrt(len(y))/2. - C = kgam*1000. + if not kgam: + kgam = np.sqrt(len(y))/skgam + if not C: + C = kgam*sC tscale = 24*3600 # scale from seconds to days it = (np.array(time_num_interval)-scale[0])/tscale # time interval in days diff --git a/svm.py b/svm.py index 4eab3f8..31cf40f 100644 --- a/svm.py +++ b/svm.py @@ -308,7 +308,7 @@ def make_meshgrid(x, y, z, s=(50,50,50), exp=.1): np.linspace(z_min, z_max, sz)) return xx, yy, zz -def frontier(clf, xx, yy, zz, bal=.5, plot_decision = False, plot_poly=False, using_weights=False): +def frontier(clf, xx, yy, zz, bal=.5, plot_decision=False, plot_poly=False, using_weights=False, save_decision=False): """ Compute the surface decision frontier for a classifier. @@ -350,7 +350,8 @@ def frontier(clf, xx, yy, zz, bal=.5, plot_decision = False, plot_poly=False, us # Reshaping decision function volume Z = ZZ.reshape(xx.shape) print 'decision function shape: ', Z.shape - sl.save((xx,yy,zz,Z),'decision') + if save_decision: + sl.save((xx,yy,zz,Z),'decision') if plot_decision: try: diff --git a/utils.py b/utils.py index 9ea0d25..9ed73f1 100644 --- a/utils.py +++ b/utils.py @@ -144,6 +144,17 @@ def load_cfg(): else: cfg.svm_settings.dmaxz = 0 cfg.svm_settings.confau = 0 + # overwrite C and kgam hyperparameter values + cfg.svm_settings.C = f_cfg['method_settings']['svm_settings'].get('C',None) + cfg.svm_settings.kgam = f_cfg['method_settings']['svm_settings'].get('kgam',None) + if cfg.dyn_pen: + cfg.svm_settings.sC = f_cfg['method_settings']['svm_settings'].get('sC',100) + else: + cfg.svm_settings.sC = f_cfg['method_settings']['svm_settings'].get('sC',1000) + if cfg.dyn_pen: + cfg.svm_settings.skgam = f_cfg['method_settings']['svm_settings'].get('skgam',12) + else: + cfg.svm_settings.skgam = f_cfg['method_settings']['svm_settings'].get('skgam',12) except: cfg.svm_settings.notnan = True cfg.svm_settings.artil = False @@ -156,12 +167,13 @@ def load_cfg(): cfg.svm_settings.toparti = False cfg.svm_settings.dmaxz = 0 cfg.svm_settings.confau = 0 + cfg.svm_settings.C = None + cfg.svm_settings.kgam = None + cfg.svm_settings.sC = None + cfg.svm_settings.skgam = None cfg.svm_settings.search = cfg.search # Set AppKey for NRT downloads from https://nrt3.modaps.eosdis.nasa.gov/profile/app-keys - try: - cfg.appkey = f_cfg.get('appkey',None) - except: - cfg.appkey = None + cfg.appkey = f_cfg.get('appkey',None) return cfg -- 2.11.4.GIT