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

Switched to scipy's kde, which is smart enough to factorize the mean.

parent 106c3f5c
No related branches found
No related tags found
No related merge requests found
......@@ -2,4 +2,4 @@
Estimate high-resolution photon spectrometer data from low-resolution non-invasive measurements.
"""
VERSION = "0.1.2"
VERSION = "0.1.3"
......@@ -13,7 +13,7 @@ from sklearn.pipeline import Pipeline
from sklearn.kernel_approximation import Nystroem
#from sklearn.linear_model import ARDRegression
from sklearn.linear_model import BayesianRidge
from sklearn.neighbors import KernelDensity
from scipy.stats import gaussian_kde
from sklearn.ensemble import IsolationForest
from functools import reduce
from itertools import product
......@@ -765,14 +765,13 @@ class Model(TransformerMixin, BaseEstimator):
Return: weights.
"""
self.kde_xgm = KernelDensity(bandwidth="scott", kernel="gaussian")
self.kde_xgm.fit(intensity.reshape(-1, 1))
self.kde_xgm = gaussian_kde(intensity.reshape(-1), bw_method="scott")
self.mu_xgm = np.mean(intensity.reshape(-1), axis=0)
self.sigma_xgm = np.std(intensity.reshape(-1), axis=0)
q = np.quantile(intensity, [0.10, 0.90])
l, h = q[0], q[1]
x = intensity*((intensity > l) & (intensity < h)) + l*(intensity <= l) + h*(intensity >= h)
log_prob = self.kde_xgm.score_samples(x.reshape(-1, 1))
log_prob = self.kde_xgm.logpdf(x.reshape(-1))
w = np.exp(-log_prob)
w = w/np.median(w)
return w
......@@ -920,8 +919,7 @@ class Model(TransformerMixin, BaseEstimator):
# get intensity effect
intensity = np.sum(z, axis=1)
self.kde_intensity = KernelDensity(bandwidth="scott", kernel="gaussian")
self.kde_intensity.fit(intensity.reshape(-1, 1))
self.kde_intensity = gaussian_kde(intensity.reshape(-1), bw_method="scott")
self.mu_intensity = np.mean(intensity.reshape(-1), axis=0)
self.sigma_intensity = np.std(intensity.reshape(-1), axis=0)
......@@ -970,11 +968,11 @@ class Model(TransformerMixin, BaseEstimator):
low_pca = pca_model.transform(low_res)
return self.ood['full'].predict(low_pca)
def xgm_profile(self) -> KernelDensity:
def xgm_profile(self) -> gaussian_kde:
"""Get KDE for the XGM intensity."""
return self.kde_xgm
def intensity_profile(self) -> KernelDensity:
def intensity_profile(self) -> gaussian_kde:
"""Get KDE for the predicted intensity."""
return self.kde_intensity
......
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