Skip to content
Snippets Groups Projects
Commit 2e3f6d06 authored by Danilo Ferreira de Lima's avatar Danilo Ferreira de Lima
Browse files

Added Nystroem with an insane kernel dimensionality to check if it improves something.

parent 44353618
No related branches found
No related tags found
1 merge request!3Added kernel approximation with the Nystroem sub-space projection method as an alternative
...@@ -14,6 +14,7 @@ from sklearn.base import TransformerMixin, BaseEstimator ...@@ -14,6 +14,7 @@ from sklearn.base import TransformerMixin, BaseEstimator
from sklearn.base import RegressorMixin from sklearn.base import RegressorMixin
from sklearn.kernel_approximation import Nystroem from sklearn.kernel_approximation import Nystroem
from sklearn.linear_model import ARDRegression from sklearn.linear_model import ARDRegression
#from sklearn.svm import LinearSVR
#from sklearn.gaussian_process import GaussianProcessRegressor #from sklearn.gaussian_process import GaussianProcessRegressor
#from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel #from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel
from itertools import product from itertools import product
...@@ -470,6 +471,7 @@ class MultiOutputWithStd(MetaEstimatorMixin, BaseEstimator): ...@@ -470,6 +471,7 @@ class MultiOutputWithStd(MetaEstimatorMixin, BaseEstimator):
""" """
y = Parallel(n_jobs=self.n_jobs)( y = Parallel(n_jobs=self.n_jobs)(
delayed(e.predict)(X, return_std) for e in self.estimators_ delayed(e.predict)(X, return_std) for e in self.estimators_
#delayed(e.predict)(X) for e in self.estimators_
) )
if return_std: if return_std:
y, unc = zip(*y) y, unc = zip(*y)
...@@ -500,13 +502,13 @@ class Model(TransformerMixin, BaseEstimator): ...@@ -500,13 +502,13 @@ class Model(TransformerMixin, BaseEstimator):
def __init__(self, def __init__(self,
channels:List[str]=[f"channel_{j}_{k}" channels:List[str]=[f"channel_{j}_{k}"
for j, k in product(range(1, 5), ["A", "B", "C", "D"])], for j, k in product(range(1, 5), ["A", "B", "C", "D"])],
n_pca_lr: int=600, n_pca_lr: int=1000,
n_pca_hr: int=30, n_pca_hr: int=40,
high_res_sigma: float=0.2, high_res_sigma: float=0.2,
tof_start: Optional[int]=None, tof_start: Optional[int]=None,
delta_tof: Optional[int]=300, delta_tof: Optional[int]=300,
validation_size: float=0.05, validation_size: float=0.05,
n_nonlinear_kernel: int=1000): n_nonlinear_kernel: int=10000):
# models # models
self.x_model = Pipeline([ self.x_model = Pipeline([
('select', SelectRelevantLowResolution(channels, tof_start, delta_tof)), ('select', SelectRelevantLowResolution(channels, tof_start, delta_tof)),
...@@ -522,7 +524,8 @@ class Model(TransformerMixin, BaseEstimator): ...@@ -522,7 +524,8 @@ class Model(TransformerMixin, BaseEstimator):
if n_nonlinear_kernel > 0: if n_nonlinear_kernel > 0:
fit_steps += [('fex', Nystroem(n_components=n_nonlinear_kernel, kernel='rbf', gamma=None, n_jobs=-1))] fit_steps += [('fex', Nystroem(n_components=n_nonlinear_kernel, kernel='rbf', gamma=None, n_jobs=-1))]
#fit_steps += [('regression', FitModel())] #fit_steps += [('regression', FitModel())]
fit_steps += [('regression', MultiOutputWithStd(ARDRegression(n_iter=10)))] fit_steps += [('regression', MultiOutputWithStd(ARDRegression(n_iter=30, verbose=True)))]
#fit_steps += [('regression', MultiOutputWithStd(LinearSVR(verbose=10, max_iter=2000, tol=1e-5)))]
self.fit_model = Pipeline(fit_steps) self.fit_model = Pipeline(fit_steps)
# size of the test subset # size of the test subset
...@@ -567,6 +570,7 @@ class Model(TransformerMixin, BaseEstimator): ...@@ -567,6 +570,7 @@ class Model(TransformerMixin, BaseEstimator):
""" """
x_t = self.x_model.fit_transform(low_res_data) x_t = self.x_model.fit_transform(low_res_data)
y_t = self.y_model.fit_transform(high_res_data, smoothen__energy=high_res_photon_energy) y_t = self.y_model.fit_transform(high_res_data, smoothen__energy=high_res_photon_energy)
#self.fit_model.set_params(fex__gamma=1.0/float(x_t.shape[0]))
self.fit_model.fit(x_t, y_t) self.fit_model.fit(x_t, y_t)
# calculate the effect of the PCA # calculate the effect of the PCA
...@@ -640,6 +644,8 @@ class Model(TransformerMixin, BaseEstimator): ...@@ -640,6 +644,8 @@ class Model(TransformerMixin, BaseEstimator):
""" """
low_pca = self.x_model.transform(low_res_data) low_pca = self.x_model.transform(low_res_data)
high_pca, high_pca_unc = self.fit_model.predict(low_pca, return_std=True) high_pca, high_pca_unc = self.fit_model.predict(low_pca, return_std=True)
#high_pca = self.fit_model.predict(low_pca)
#high_pca_unc = 0
n_trains = high_pca.shape[0] n_trains = high_pca.shape[0]
pca_y = np.concatenate((high_pca, pca_y = np.concatenate((high_pca,
high_pca + high_pca_unc), high_pca + high_pca_unc),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment