def toy_data_quantile(n_samples=50, probs=0.5, pattern=SinePattern(),
noise=(1., .2, 0., 1.5), random_state=None):
"""Sine wave toy dataset.
The target y is computed as a sine curve at of modulated by a sine envelope
with some period (default 1/3Hz) and mean (default 1). Moreover, this
pattern is distorted with a random Gaussian noise with mean 0 and a
linearly decreasing standard deviation (default from 1.2 at X = 0 to 0.2 at
X = 1 . 5).
Parameters
----------
n_samples : int
Number of samples to generate.
probs : list or float, shape = [n_quantiles], default=0.5
Probabilities (quantiles levels).
pattern : callable, default = SinePattern()
Callable which generates n_sample 1D data (inputs and targets).
noise : :rtype: (float, float, float, float)
Noise parameters (variance, shift, support_min, support_max).
Returns
-------
X : array, shape = [n_samples, 1]
Input data.
y : array, shape = [n_sample, 1]
Targets.
quantiles : array, shape = [n_samples x n_quantiles]
True conditional quantiles.
"""
probs = array(probs, ndmin=1)
noise_var, noise_shift, noise_min, noise_max = noise
random_state = check_random_state(random_state)
pattern.random_state = random_state
inputs, targets = pattern(n_samples)
# Noise decreasing std (from noise+0.2 to 0.2)
noise_std = noise_shift + (noise_var * (noise_max - inputs) /
(noise_max - noise_min))
# Gaussian noise with decreasing std
add_noise = noise_std * random_state.randn(n_samples, 1)
observations = targets + add_noise
quantiles = [targets + array([norm.ppf(p, loc=0., scale=abs(noise_c))
for noise_c in noise_std]) for p in probs]
return inputs, observations.ravel(), quantiles
评论列表
文章目录