Tests and improvements on data.artificial.SignalEmulator

This commit is contained in:
Petrônio Cândido 2019-02-21 10:01:35 -03:00
parent 6e4dcf3d90
commit be84e6d430
2 changed files with 18 additions and 6 deletions

View File

@ -49,7 +49,7 @@ def generate_linear_periodic_gaussian(period, mu_min, sigma_min, mu_max, sigma_m
:return: :return:
""" """
if period > num: if period > it:
raise("The 'period' parameter must be lesser than 'it' parameter") raise("The 'period' parameter must be lesser than 'it' parameter")
mu_inc = (mu_max - mu_min)/period mu_inc = (mu_max - mu_min)/period
@ -73,6 +73,8 @@ def generate_linear_periodic_gaussian(period, mu_min, sigma_min, mu_max, sigma_m
mu += (mu_inc if signal else -mu_inc) mu += (mu_inc if signal else -mu_inc)
sigma += (sigma_inc if signal else -sigma_inc) sigma += (sigma_inc if signal else -sigma_inc)
sigma = max(sigma, 0.005)
return ret return ret
@ -106,7 +108,9 @@ def generate_senoidal_periodic_gaussian(period, mu_min, sigma_min, mu_max, sigma
ret.extend(tmp) ret.extend(tmp)
mu += mu_range * np.sin(period * k) mu += mu_range * np.sin(period * k)
sigma += mu_range * np.sin (period * k) sigma += sigma_range * np.sin(period * k)
sigma = max(sigma, 0.005)
return ret return ret
@ -169,6 +173,8 @@ def _append(additive, start, before, new):
if l2 < l1: if l2 < l1:
new.extend(np.zeros(l1 - l2).tolist()) new.extend(np.zeros(l1 - l2).tolist())
elif 0 < l1 < l2:
new = new[:l1]
if len(before) == 0: if len(before) == 0:
tmp = np.array(new) tmp = np.array(new)
@ -275,11 +281,11 @@ class SignalEmulator(object):
tmp = generate_gaussian_linear(0, 0, parameters['mu'], parameters['sigma'], tmp = generate_gaussian_linear(0, 0, parameters['mu'], parameters['sigma'],
it=num, num=1, vmin=vmin, vmax=vmax) it=num, num=1, vmin=vmin, vmax=vmax)
elif component['type'] == 'periodic': elif component['type'] == 'periodic':
period = component['period'] period = parameters['period']
mu_min, sigma_min = parameters['mu_min'],parameters['sigma_min'] mu_min, sigma_min = parameters['mu_min'],parameters['sigma_min']
mu_max, sigma_max = parameters['mu_max'],parameters['sigma_max'] mu_max, sigma_max = parameters['mu_max'],parameters['sigma_max']
if parameters['type'] == 'senoidal': if parameters['type'] == 'sinoidal':
tmp = generate_senoidal_periodic_gaussian(period, mu_min, sigma_min, mu_max, sigma_max, tmp = generate_senoidal_periodic_gaussian(period, mu_min, sigma_min, mu_max, sigma_max,
it=num, num=1, vmin=vmin, vmax=vmax) it=num, num=1, vmin=vmin, vmax=vmax)
else: else:
@ -300,7 +306,6 @@ class SignalEmulator(object):
start = np.random.randint(0, len(signal)) start = np.random.randint(0, len(signal))
tmp = [_mx] if np.random.rand() >= .5 else [-_mn] tmp = [_mx] if np.random.rand() >= .5 else [-_mn]
last_num = num last_num = num
last_it = it last_it = it

View File

@ -16,10 +16,17 @@ from pyFTS.common import Transformations, Membership
from pyFTS.data import artificial from pyFTS.data import artificial
"""
cd = artificial.SignalEmulator()\ cd = artificial.SignalEmulator()\
.stationary_gaussian(0,.2,length=10, it=1)\ .stationary_gaussian(0,.2,length=10, it=1)\
.incremental_gaussian(0.5, 0,start=5,length=5)\ .incremental_gaussian(0.5, 0,start=5,length=5)\
.blip()\ .blip()\
.stationary_gaussian(3,.2,length=10, it=1, additive=False) .stationary_gaussian(3,.2,length=10, it=1, additive=False)
print([round(k,3) for k in cd.run()]) print([round(k,3) for k in cd.run()])
"""
signal = artificial.SignalEmulator()\
.stationary_gaussian(1,0.2,length=130,it=10)\
.periodic_gaussian('sinoidal',100, 0.5,0.5,10,1,start=100,length=2000)\
.blip()\
.run()