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

Allow for no smoothing.

parent c4fa650d
No related branches found
No related tags found
1 merge request!1Add Kernel PCA as an alternative preprocessing step
......@@ -8,7 +8,6 @@ from autograd import grad
from scipy.signal import fftconvolve
from scipy.signal import find_peaks_cwt
from scipy.optimize import fmin_l_bfgs_b
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import KernelPCA, PCA
from sklearn.pipeline import Pipeline, FeatureUnion
from sklearn.base import TransformerMixin, BaseEstimator
......@@ -34,6 +33,7 @@ class PromptNotFoundError(Exception):
def __str__(self) -> str:
return "No prompt peak has been detected."
class HighResolutionSmoother(TransformerMixin, BaseEstimator):
"""
Smoothens out the high resolution data.
......@@ -72,6 +72,8 @@ class HighResolutionSmoother(TransformerMixin, BaseEstimator):
Returns: Smoothened out spectrum.
"""
if self.high_res_sigma <= 0:
return X
# use a default energy axis is none is given
# assume only the energy step
energy = np.broadcast_to(self.energy, X.shape)
......@@ -449,6 +451,8 @@ class Model(TransformerMixin, BaseEstimator):
Set to None to perform no selection.
validation_size: Fraction (number between 0 and 1) of the data to take for
validation and systematic uncertainty estimate.
n_pca_nonlinear: Number of nonlinear PCA components added at the preprocessing stage
to obtain nonlinearities as an input and improve the prediction.
"""
def __init__(self,
......@@ -465,9 +469,13 @@ class Model(TransformerMixin, BaseEstimator):
if n_pca_nonlinear <= 0:
x_pca_model = PCA(n_pca_lr, whiten=True)
else:
x_pca_model = FeatureUnion([('linear', PCA(n_pca_lr, whiten=True)),
x_pca_model = FeatureUnion([
('linear', PCA(n_pca_lr, whiten=True)),
('nonlinear', Pipeline([('prep', PCA(n_pca_lr, whiten=True)),
('kpca', KernelPCA(n_pca_nonlinear, kernel='rbf', n_jobs=-1)),
('kpca', KernelPCA(n_pca_nonlinear,
kernel='rbf',
gamma=0.1,
n_jobs=-1)),
])),
])
self.x_model = Pipeline([
......@@ -475,7 +483,8 @@ class Model(TransformerMixin, BaseEstimator):
('pca', x_pca_model),
('unc', UncertaintyHolder()),
])
self.y_model = Pipeline([('smoothen', HighResolutionSmoother(high_res_sigma)),
self.y_model = Pipeline([
('smoothen', HighResolutionSmoother(high_res_sigma)),
('pca', PCA(n_pca_hr, whiten=False)),
('unc', UncertaintyHolder()),
])
......
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