|
|
@ -1,4 +1,4 @@ |
|
|
|
from models import Model |
|
|
|
from models import Model, ModelState |
|
|
|
from typing import Union, List, Generator |
|
|
|
from typing import Union, List, Generator |
|
|
|
import utils |
|
|
|
import utils |
|
|
|
import numpy as np |
|
|
|
import numpy as np |
|
|
@ -7,6 +7,7 @@ import scipy.signal |
|
|
|
from scipy.fftpack import fft |
|
|
|
from scipy.fftpack import fft |
|
|
|
from scipy.signal import argrelextrema |
|
|
|
from scipy.signal import argrelextrema |
|
|
|
from scipy.stats.stats import pearsonr |
|
|
|
from scipy.stats.stats import pearsonr |
|
|
|
|
|
|
|
from typing import Optional |
|
|
|
import math |
|
|
|
import math |
|
|
|
from scipy.stats import gaussian_kde |
|
|
|
from scipy.stats import gaussian_kde |
|
|
|
from scipy.stats import norm |
|
|
|
from scipy.stats import norm |
|
|
@ -16,6 +17,20 @@ from analytic_types import AnalyticUnitId |
|
|
|
|
|
|
|
|
|
|
|
PEARSON_FACTOR = 0.7 |
|
|
|
PEARSON_FACTOR = 0.7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GeneralModelState(ModelState): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, **kwargs): |
|
|
|
|
|
|
|
super().__init__(**kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def to_json(self) -> dict: |
|
|
|
|
|
|
|
return super().to_json() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
|
|
def from_json(json: Optional[dict] = None): |
|
|
|
|
|
|
|
if json is None: |
|
|
|
|
|
|
|
json = {} |
|
|
|
|
|
|
|
return GeneralModelState(**json) |
|
|
|
|
|
|
|
|
|
|
|
class GeneralModel(Model): |
|
|
|
class GeneralModel(Model): |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
def __init__(self): |
|
|
@ -41,6 +56,9 @@ class GeneralModel(Model): |
|
|
|
center_ind = start + math.ceil((end - start) / 2) |
|
|
|
center_ind = start + math.ceil((end - start) / 2) |
|
|
|
return center_ind |
|
|
|
return center_ind |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_cache(self, cache: Optional[dict] = None) -> GeneralModelState: |
|
|
|
|
|
|
|
return GeneralModelState.from_json(cache) |
|
|
|
|
|
|
|
|
|
|
|
def do_fit(self, dataframe: pd.DataFrame, labeled_segments: list, deleted_segments: list, learning_info: dict, id: AnalyticUnitId) -> None: |
|
|
|
def do_fit(self, dataframe: pd.DataFrame, labeled_segments: list, deleted_segments: list, learning_info: dict, id: AnalyticUnitId) -> None: |
|
|
|
logging.debug('Start method do_fit for analytic unit: {}'.format(id)) |
|
|
|
logging.debug('Start method do_fit for analytic unit: {}'.format(id)) |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
|