|
|
|
@ -7,41 +7,13 @@ from scipy.signal import argrelextrema
|
|
|
|
|
import math |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Jumpdetector: |
|
|
|
|
class JumpDetector: |
|
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
|
self.segments = [] |
|
|
|
|
self.confidence = 1.5 |
|
|
|
|
self.convolve_max = 120 |
|
|
|
|
|
|
|
|
|
def intersection_segment(self, data, median): |
|
|
|
|
cen_ind = [] |
|
|
|
|
for i in range(1, len(data)-1): |
|
|
|
|
if data[i - 1] < median and data[i + 1] > median: |
|
|
|
|
cen_ind.append(i) |
|
|
|
|
del_ind = [] |
|
|
|
|
for i in range(1,len(cen_ind)): |
|
|
|
|
if cen_ind[i] == cen_ind[i - 1] + 1: |
|
|
|
|
del_ind.append(i - 1) |
|
|
|
|
del_ind = del_ind[::-1] |
|
|
|
|
for i in del_ind: |
|
|
|
|
del cen_ind[i] |
|
|
|
|
return cen_ind |
|
|
|
|
|
|
|
|
|
def logistic_sigmoid(self, x , y, alpha, height): |
|
|
|
|
distribution = [] |
|
|
|
|
for i in range(x, y): |
|
|
|
|
F = 1 * height / (1 + math.exp(-i * alpha)) |
|
|
|
|
distribution.append(F) |
|
|
|
|
return distribution |
|
|
|
|
|
|
|
|
|
def alpha_finder(self, data): |
|
|
|
|
""" |
|
|
|
|
поиск альфы для логистической сигмоиды |
|
|
|
|
""" |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def fit(self, dataframe, segments): |
|
|
|
|
#self.alpha_finder() |
|
|
|
|
data = dataframe['value'] |
|
|
|
@ -64,10 +36,10 @@ class Jumpdetector:
|
|
|
|
|
min_line = ax_list[min_peak, 0] |
|
|
|
|
max_line = ax_list[max_peak, 0] |
|
|
|
|
sigm_heidht = max_line - min_line |
|
|
|
|
pat_sigm = logistic_sigmoid(-120, 120, 1, sigm_heidht) |
|
|
|
|
pat_sigm = utils.logistic_sigmoid(-120, 120, 1, sigm_heidht) |
|
|
|
|
for i in range(0, len(pat_sigm)): |
|
|
|
|
pat_sigm[i] = pat_sigm[i] + min_line |
|
|
|
|
cen_ind = self.intersection_segment(flat_segment, mids[0]) |
|
|
|
|
cen_ind = utils.intersection_segment(flat_segment, mids[0]) |
|
|
|
|
c = [] |
|
|
|
|
for i in range(len(cen_ind)): |
|
|
|
|
x = cen_ind[i] |
|
|
|
@ -104,27 +76,21 @@ class Jumpdetector:
|
|
|
|
|
self.convolve_max = max(convolve_list) |
|
|
|
|
else: |
|
|
|
|
self.convolve_max = 120 # макс метрика свертки равна отступу(120), вау! |
|
|
|
|
|
|
|
|
|
def logistic_sigmoid(x1, x2, alpha, height): |
|
|
|
|
distribution = [] |
|
|
|
|
for i in range(x, y): |
|
|
|
|
F = 1 * height / (1 + math.exp(-i * alpha)) |
|
|
|
|
distribution.append(F) |
|
|
|
|
return distribution |
|
|
|
|
|
|
|
|
|
def predict(self, dataframe): |
|
|
|
|
async def predict(self, dataframe): |
|
|
|
|
data = dataframe['value'] |
|
|
|
|
|
|
|
|
|
result = self.__predict(data) |
|
|
|
|
result = await self.__predict(data) |
|
|
|
|
result.sort() |
|
|
|
|
|
|
|
|
|
if len(self.segments) > 0: |
|
|
|
|
result = [segment for segment in result if not utils.is_intersect(segment, self.segments)] |
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
def __predict(self, data): |
|
|
|
|
async def __predict(self, data): |
|
|
|
|
window_size = 24 |
|
|
|
|
all_max_flatten_data = data.rolling(window=window_size).mean() |
|
|
|
|
all_mins = argrelextrema(np.array(all_max_flatten_data), np.less)[0] |
|
|
|
|
extrema_list = [] |
|
|
|
|
# добавить все пересечения экспоненты со сглаженным графиком |
|
|
|
|
|
|
|
|
@ -172,3 +138,9 @@ class Jumpdetector:
|
|
|
|
|
(self.confidence, self.convolve_max) = pickle.load(file) |
|
|
|
|
except: |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
def alpha_finder(self, data): |
|
|
|
|
""" |
|
|
|
|
поиск альфы для логистической сигмоиды |
|
|
|
|
""" |
|
|
|
|
pass |
|
|
|
|