def mk_data(n_samples=200, random_state=0, separability=1,
noise_corr=2, dim=100):
rng = np.random.RandomState(random_state)
y = rng.random_integers(0, 1, size=n_samples)
noise = rng.normal(size=(n_samples, dim))
if not noise_corr is None and noise_corr > 0:
noise = ndimage.gaussian_filter1d(noise, noise_corr, axis=0)
noise = noise / noise.std(axis=0)
# We need to decrease univariate separability as dimension increases
centers = 4. / dim * np.ones((2, dim))
centers[0] *= -1
X = separability * centers[y] + noise
return X, y
###############################################################################
# Code to run the cross-validations
python类gaussian_filter1d()的实例源码
cross_validation_simulations.py 文件源码
项目:cross_validation_failure
作者: GaelVaroquaux
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
perfect_predictor_simulation.py 文件源码
项目:cross_validation_failure
作者: GaelVaroquaux
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def mk_data(n_samples=200, random_state=0, separability=1,
noise_corr=2, dim=100):
rng = np.random.RandomState(random_state)
y = rng.random_integers(0, 1, size=n_samples)
noise = rng.normal(size=(n_samples, dim))
if not noise_corr is None and noise_corr > 0:
noise = ndimage.gaussian_filter1d(noise, noise_corr, axis=0)
noise = noise / noise.std(axis=0)
# We need to decrease univariate separability as dimension increases
centers = 4. / dim * np.ones((2, dim))
centers[0] *= -1
X = separability * centers[y] + noise
return X, y
###############################################################################
# The perfect predictor
dimensionality_simulations.py 文件源码
项目:cross_validation_failure
作者: GaelVaroquaux
项目源码
文件源码
阅读 69
收藏 0
点赞 0
评论 0
def mk_data(n_samples=200, random_state=0, separability=1,
noise_corr=2, dim=100):
rng = np.random.RandomState(random_state)
y = rng.random_integers(0, 1, size=n_samples)
noise = rng.normal(size=(n_samples, dim))
if not noise_corr is None and noise_corr > 0:
noise = ndimage.gaussian_filter1d(noise, noise_corr, axis=0)
noise = noise / noise.std(axis=0)
# We need to decrease univariate separability as dimension increases
centers = 4. / dim * np.ones((2, dim))
centers[0] *= -1
X = separability * centers[y] + noise
return X, y
###############################################################################
# Code to run the cross-validations
def gaussian_smooth(self, fwhm, **kwargs):
profile_sigma = fwhm / (2 * (2*np.log(2))**0.5)
# The requested FWHM is in Angstroms, but the dispersion between each
# pixel is likely less than an Angstrom, so we must calculate the true
# smoothing value
true_profile_sigma = profile_sigma / np.median(np.diff(self.dispersion))
smoothed_flux = ndimage.gaussian_filter1d(self.flux, true_profile_sigma, **kwargs)
# TODO modify ivar based on smoothing?
return self.__class__(self.dispersion, smoothed_flux, self.ivar.copy(), metadata=self.metadata.copy())
def _erfimage_imshow(ax, ch_idx, tmin, tmax, vmin, vmax, ylim=None, data=None,
epochs=None, sigma=None, order=None, scalings=None,
vline=None, x_label=None, y_label=None, colorbar=False,
cmap='RdBu_r'):
"""Aux function to plot erfimage on sensor topography"""
from scipy import ndimage
import matplotlib.pyplot as plt
this_data = data[:, ch_idx, :].copy()
if callable(order):
order = order(epochs.times, this_data)
if order is not None:
this_data = this_data[order]
if sigma > 0.:
this_data = ndimage.gaussian_filter1d(this_data, sigma=sigma, axis=0)
ax.imshow(this_data, extent=[tmin, tmax, 0, len(data)], aspect='auto',
origin='lower', vmin=vmin, vmax=vmax, picker=True, cmap=cmap,
interpolation='nearest')
ax = plt.gca()
if x_label is not None:
ax.set_xlabel(x_label)
if y_label is not None:
ax.set_ylabel(y_label)
if colorbar:
plt.colorbar()
def _erfimage_imshow_unified(bn, ch_idx, tmin, tmax, vmin, vmax, ylim=None,
data=None, epochs=None, sigma=None, order=None,
scalings=None, vline=None, x_label=None,
y_label=None, colorbar=False, cmap='RdBu_r'):
"""Aux function to plot erfimage topography using a single axis"""
from scipy import ndimage
_compute_scalings(bn, (tmin, tmax), (0, len(epochs.events)))
ax = bn.ax
data_lines = bn.data_lines
extent = (bn.x_t + bn.x_s * tmin, bn.x_t + bn.x_s * tmax, bn.y_t,
bn.y_t + bn.y_s * len(epochs.events))
this_data = data[:, ch_idx, :].copy()
if callable(order):
order = order(epochs.times, this_data)
if order is not None:
this_data = this_data[order]
if sigma > 0.:
this_data = ndimage.gaussian_filter1d(this_data, sigma=sigma, axis=0)
data_lines.append(ax.imshow(this_data, extent=extent, aspect='auto',
origin='lower', vmin=vmin, vmax=vmax,
picker=True, cmap=cmap,
interpolation='nearest'))
def __call__(self, data):
if data.domain != self.domain:
data = data.from_table(self.domain, data)
xs, xsind, mon, X = _transform_to_sorted_features(data)
X, nans = _nan_extend_edges_and_interpolate(xs[xsind], X)
X = gaussian_filter1d(X, sigma=self.sd, mode="nearest")
if nans is not None:
X[nans] = np.nan
return _transform_back_to_features(xsind, mon, X)