def seq_filters(self): """ :return: """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # The norm of the signal. Builtin filter. norm = NormFilter() # Abstract sliding window. Builtin filter. sw = BaseSWFilter(min_size=2) sw_mean = sw | numeric.mean # or sw_mean = MeanSWFilter() return [ FilterDescription( name='$F_{L_1} = |F_{t}|_{L_1}$', plot_options=PlotOptions( style='-', color='lightgray', width=3.0, ), formula=original | norm(l=1), ), FilterDescription(name='$M_{50} = |\hat{\mu}_{50}(F_{L_1})|$', plot_options=PlotOptions( style='-', color='orange', width=2.0, ), formula=norm(l=1) | sw_mean(s=50)), FilterDescription(name='$M_{100} = |\hat{\mu}_{100}(F_{L_1})|$', plot_options=PlotOptions( style='-', color='red', width=2.0, ), formula=norm(l=1) | sw_mean(s=100)), FilterDescription(name='$M_{200} = |\hat{\mu}_{200}(F_{L_1})|$', plot_options=PlotOptions( style='-', color='blue', width=2.0, ), formula=norm(l=1) | sw_mean(s=200)), ]
def seq_filters(self): """ :return: """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # Shift signal to one frame. Builtin filter. shift = ShiftSWFilter() # The difference between neighboring frames. diff = original - shift # The norm of the signal. Builtin filter. norm = NormFilter() # Abstract sliding window. Builtin filter. sw = BaseSWFilter(min_size=2) sw_mean = sw | numeric.mean # or sw_mean = MeanSWFilter() sw_median = MedianSWFilter(size=10) # sw_max = sw | max sign_change = SignChangeFilter() atan = (diff | original * 256.0 | numeric.math.atan | original * 2.0 | original / numeric.math.pi) # or atan = AtanFilter() def sw_mean_diff(g, l): """ :param g: :param l: :return: """ return (norm(l=1) | sw_median(s=10) | (sw_mean(s=g) - sw_mean(s=l)) | (sign_change * atan)) # Sequence of voters. voters = range(self.VOTER_COUNT) # Sequence of sliding window sizes. sizes = list(self.VOTER_SIZE * (i + 1) for i in voters) # Sequence of votes of different range normalizations. sw_mean_diff_seq = tuple( sw_mean_diff(g=g_size, l=l_size) for g_size in sizes for l_size in sizes if g_size > l_size) # fork = ForkFilter() # # bulk = BulkFilter() # Average vote of different range normalizations. sw_mean_diff_norm = (original | sum(sw_mean_diff_seq) | original / len(sw_mean_diff_seq)) # # print('sw_mean_diff(25,12) = ', sw_mean_diff_norm) return [ FilterDescription( name='$F_{L_1} = |F_{t}|_{L_1}$', plot_options=PlotOptions( style='-', color='lightgray', width=3.0, ), formula=norm(l=1), ), # # # FilterDescription( # name='$M_{50} = |\hat{\mu}_{50}(F_{L_1})|$', # plot_options=PlotOptions( # style='-', # color='orange', # width=2.0, # ), # formula=norm(l=1) | sw_mean(s=50) # ), # # FilterDescription( # name='$M_{100} = |\hat{\mu}_{100}(F_{L_1})|$', # plot_options=PlotOptions( # style='-', # color='red', # width=2.0, # ), # formula=norm(l=1) | sw_mean(s=100) # ), # # FilterDescription( # name='$M_{200} = |\hat{\mu}_{200}(F_{L_1})|$', # plot_options=PlotOptions( # style='-', # color='blue', # width=2.0, # ), # formula=norm(l=1) | sw_mean(s=200) # ), # # # FilterDescription( # name='$|M_{200} - M_{50}| \\to_{\pm} 0$', # plot_options=PlotOptions( # style='--', # color='blue', # width=1.2, # ), # formula=( # norm(l=1) # | (sw_mean(s=200) - sw_mean(s=50)) # # | sign_changes # # | abs # # | original * 0.9 # ) # ), # # # FilterDescription( # name='$M_{50} = |\hat{\mu}_{50}(F_{L_1})|$', # plot_options=PlotOptions( # style='-', # color='orange', # width=2.0, # ), # formula=norm(l=1) | sw_mean(s=50) # ), # # # # FilterDescription( # name='$M_{50} = |\hat{\mu}_{50}(F_{L_1})|$', # plot_options=PlotOptions( # style='-', # color='orange', # width=2.0, # ), # formula=norm(l=1) | sw_mean(s=50) # ), FilterDescription(name='25', plot_options=PlotOptions( style='-', color='orange', width=2.0, ), formula=norm(l=1) | sw_mean(s=25)), FilterDescription(name='50', plot_options=PlotOptions( style='-', color='red', width=2.0, ), formula=norm(l=1) | sw_mean(s=50)), FilterDescription(name='75', plot_options=PlotOptions( style='-', color='green', width=2.0, ), formula=norm(l=1) | sw_mean(s=75)), FilterDescription(name='100', plot_options=PlotOptions( style='-', color='purple', width=2.0, ), formula=norm(l=1) | sw_mean(s=100)), FilterDescription(name='$A|M_{200} - M_{100}| \\to_{\pm} 0$', plot_options=PlotOptions( style='--', color='blue', width=1.0, ), formula=norm(l=1) | sw_mean_diff_norm # sw_mean_diff(25,12) ), ]
def seq_filters(self): """ :return: """ delay = DelayFilter() norm = NormFilter() modulus = ModulusFilter() shift = ShiftSWFilter() diff = delay(0) - shift mean = MeanSWFilter() std = StdSWFilter() dtr = DecisionTreeRegressorSWFilter(regressor_depth=2) def bill(c=3.0, s=1): """ :param c: :param s: :return: """ # noinspection PyTypeChecker return (delay(0) > (mean(s=s) + c * std(s=s))) | int return [ FilterDescription( name='$F_{L_1} = |F_{t}|_{L_1}$', plot_options=PlotOptions( style='-', color='lightgray', width=3.0, ), formula=norm(l=1), ), FilterDescription(name='$DTR_{300,2}$', plot_options=PlotOptions( style='-', color='red', width=2.0, ), formula=norm(l=1) | dtr(s=300, d=2)), FilterDescription(name='$S = ' '1/k\sum_{i=1}^{k+1} DTR_{i \cdot 25, 2} $', plot_options=PlotOptions( style='-', color='green', width=2.0, ), formula=norm(l=1) | sum(dtr(s=25 * i + 1) for i in range(1, 9)) / 8), FilterDescription(name="$B_{50}/n = " "(|S'| > |(\hat{\mu}_{50} " "+ A \hat{\sigma}_{50})(S')|)" "/n$", plot_options=PlotOptions( style='-', color='magenta', width=2.0, ), formula=norm(l=1) | sum(dtr(s=25 * i + 1) for i in range(1, 9)) / 8 | diff | modulus | bill(s=50) / 8), FilterDescription(name='$V(t) = ' '1/n\sum_{j=1}^{n+1} B_{j \cdot 25} $', plot_options=PlotOptions( style=':', color='blue', width=2.0, ), formula=norm(l=1) | sum(dtr(s=25 * i + 1) for i in range(1, 9)) / 8 | diff | modulus | sum(bill(s=25 * j) for j in range(1, 9)) / 8), ]
dht = DHTFilter() log = LogFilter() exp = ExpFilter() colour = ColourFilter() extrema = ExtremaSWFilter( strict_windows=True, overlap_size=0, cs=False, ) delay = DelayFilter() original = delay(0) savgol = SavitzkyGolaySWFilter( window_size=50, strict_windows=True, overlap_size=0, # cs=False ) wiener = WienerSWFilter( window_size=50, strict_windows=True, overlap_size=0, )
def seq_filters(self): """ Returns filter chart options. What we do: 1. Declare «builtin» filters. 2. Build custom filters. 3. Build target filter. 4. Plot them with `FilterDescription` :returns: filter descriptions for rescaling normalization. :rtype: list of FilterDescription """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # Shift signal to one frame. Builtin filter. shift = ShiftSWFilter() # The difference between neighboring frames. diff = original - shift # The norm of the signal. Builtin filter. norm = NormFilter() # Threshold filter. threshold = original > self.THRESHOLD # Abstract sliding window. Builtin filter. sw = BaseSWFilter(size=self.SLIDING_WINDOW_SIZE, min_size=2) # Sliding window that returns maximum. sw_max = sw | max # Sliding window that returns minimum. sw_min = sw | min # Sum of absolute difference filter. sad_filter = diff | abs | norm(l=1) # Range normalization. sw_norm = (original - sw_min) / (sw_max - sw_min) # Frame difference rescaling normalization by span. rescaling_filter = sad_filter | sw_norm return [ FilterDescription( # Original signal. name='$F_{L_1} = ||F_{t}||_{L_1}$', plot_options=PlotOptions( style='-', color='gray', width=3.0, ), formula=norm(l=1), ), FilterDescription( # Rescaling Normalization by Span. name=('$D_{{\,{size},t}} ' '= sw\_norm_{{\,{size} }} D_{{t}}$'.format( size=self.SLIDING_WINDOW_SIZE)), plot_options=PlotOptions( style='-', color='green', width=1.0, ), formula=rescaling_filter), FilterDescription( # Sum of absolute difference filter. name='$D_{t} = ||F_{t} - F_{t-1}||_{L_1}$', plot_options=PlotOptions( style='-', color='blue', width=2.0, ), formula=sad_filter | norm(l=1)), FilterDescription( # rescaling filter > threshold. name=('$D_{{\,{size},t}} > T_{{const}} $'.format( size=self.SLIDING_WINDOW_SIZE)), plot_options=PlotOptions( style=':', color='teal', width=2.0, ), formula=rescaling_filter | threshold), FilterDescription( # The threshold value. name=('$T_{{const}} = {} \in (0; 1)$'.format(self.THRESHOLD)), plot_options=PlotOptions( style='-', color='black', width=2.0, ), formula=norm(l=1) | self.THRESHOLD, ), ]
def seq_filters(self): """ Returns filter chart options. What we do: 1. Declare «builtin» filters. 2. Build custom filters. 3. Build target filter. 4. Plot them with `FilterDescription` :returns: filter descriptions for average normalization. :rtype: list of FilterDescription """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # Shift signal to one frame. Builtin filter. shift = ShiftSWFilter() # The difference between neighboring frames. diff = original - shift # The norm of the signal. Builtin filter. norm = NormFilter() # Threshold filter. # noinspection PyUnusedLocal threshold = original > self.THRESHOLD # Sum of absolute difference filter. sad_filter = diff | abs | norm(l=1) # Abstract sliding window. Builtin filter. sw = BaseSWFilter(size=self.SLIDING_WINDOW_SIZE, min_size=2) # Sliding window that returns maximum. sw_max = sw | max # Sliding window that returns minimum. sw_min = sw | min # Range normalization. sw_norm = (original - sw_min) / (sw_max - sw_min) # Sequence of voters. voters = range(self.VOTER_COUNT) # Sequence of sliding window sizes. sizes = (self.VOTER_SIZE * (i + 1) for i in voters) # Sequence of votes of different range normalizations. sw_norm_votes_seq = (sw_norm(size=size) for size in sizes) # Average vote of different range normalizations. sw_vote_norm = Filter.sum(sw_norm_votes_seq) / self.VOTER_COUNT return ( FilterDescription( # Original signal. name='$F_{L_1} = ||F_{t}||_{L_1}$', plot_options=PlotOptions( style='-', color='gray', width=3.0, ), formula=norm(l=1), ), FilterDescription( # Sum of absolute difference filter. name='$D_{t} = ||F_{t} - F_{t-1}||_{L_1}$', plot_options=PlotOptions( style=':', color='gray', width=1.0, ), formula=sad_filter), FilterDescription( # Rescaling normalization with neighborhood size = 100. name=('$D_{{\,{size},t}}' '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(size=100)), plot_options=PlotOptions( style='--', color='purple', width=1.0, ), formula=sad_filter | sw_norm(size=100)), FilterDescription( # Rescaling normalization with neighborhood size = 200. name=('$D_{{\,{size},t}} ' '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(size=200)), plot_options=PlotOptions( style='-', color='orange', width=1.0, ), formula=sad_filter | sw_norm(s=200)), FilterDescription( # Rescaling normalization with neighborhood size = 300. name=('$D_{{\,{size},t}} ' '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(size=300)), plot_options=PlotOptions( style='-', color='violet', width=1.0, ), formula=sad_filter | sw_norm(s=300)), FilterDescription( # Rescaling normalization with neighborhood size = 400. name=('$D_{{\,{size},t}} ' '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(size=400)), plot_options=PlotOptions( style='-', color='red', width=1.0, ), formula=sad_filter | sw_norm(s=400)), FilterDescription( # Average vote of different range normalizations. name=('$V_{{\,{size},v,t}} = ' '\sum^{{i=v+1}}_{{i=1}} ' '\\frac{{ D_{{\,{size} i,t}} }}{{v}};' ' v = {voter_count}$'.format( size=self.VOTER_SIZE, voter_count=self.VOTER_COUNT)), plot_options=PlotOptions( style='-', color='green', width=2.0, ), formula=sad_filter | sw_vote_norm), FilterDescription( # The threshold value. name=('$T_{{const}} = {} \in (0; 1)$'.format(self.THRESHOLD)), plot_options=PlotOptions( style='-', color='black', width=2.0, ), formula=norm(l=1) | self.THRESHOLD, ), )
def seq_filters(self): """ :return: """ delay = DelayFilter() norm = NormFilter() shift = ShiftSWFilter() original = delay(0) diff = original - shift # noinspection PyPep8Naming T_CONST = 0.8 # noinspection PyPep8Naming,PyUnusedLocal S_CONST = 100 # noinspection PyUnusedLocal threshold = original > T_CONST # noinspection PyUnusedLocal mean = MedianSWFilter( size=200 ) # noinspection PyUnusedLocal median = MedianSWFilter( size=200 ) sad_filter = norm(l=1) | diff | abs def pow_2(x): """ :param x: :return: """ return x * x d_chi = ( (diff | pow_2) / (Filter.to_tuple(original, shift) | max) ) return ( FilterDescription( # Original signal. name='$F_{L_1} = |F_{t}|_{L_1}$', plot_options=PlotOptions( style='-', color='gray', width=3.0, ), formula=norm(l=1), ), # FilterDescription( # name='$D_{{\,{size},t}} ' # '= swnorm_{{\,{size} }} D_{{t}}$'.format( # size=S_CONST # ), # plot_options=dict( # linestyle='-', # color='green', # linewidth=1.0, # ), # filter=sad_filter | norm(l=1) | swnorm # ), FilterDescription( name='$D_{t} = |F_{t} - F_{t-1}|_{L_1}$', plot_options=PlotOptions( style='-', color='blue', width=2.0, ), formula=sad_filter | norm(l=1) ), FilterDescription( # Original signal. name='$F_{L_1} d_{chi} = |F_{t}|_{L_1}$', plot_options=PlotOptions( style='-', color='red', width=3.0, ), formula=norm(l=1) | d_chi, ), # FilterDescription( # # The threshold value. # name='$T_{{const}} = {} \in (0; 1)$'.format(T_CONST), # plot_options=dict( # linestyle='-', # color='black', # linewidth=2.0, # ), # filter=norm(l=1) | T_CONST, # ), )
def seq_filters(self): """ :return: """ sgn_changes = SignAngleDiff1DFilter() delay = DelayFilter() norm = NormFilter() modulus = ModulusFilter() shift = ShiftSWFilter() diff = delay(0) - shift mean = MeanSWFilter() std = StdSWFilter() # noinspection PyUnusedLocal dtr = DecisionTreeRegressorSWFilter(regressor_depth=2) def bill(c=3.0, s=1): """ :param c: :param s: :return: """ # noinspection PyTypeChecker return (delay(0) > (mean(s=s) + c * std(s=s))) | int def mdiff_bill(s=1): """ :param s: :return: """ return (mean(s=s * 2) - mean(s=s)) | sgn_changes return [ FilterDescription( name='$F_{L_1} = |F_{t}|_{L_1}$', plot_options=PlotOptions( style='-', color='lightgray', width=3.0, ), formula=norm(l=1), ), FilterDescription(name='$V(t) = ' '1/n\sum_{j=1}^{n+1} B_{j \cdot 25} $', plot_options=PlotOptions( style=':', color='blue', width=2.0, ), formula=norm(l=1) | sum(mdiff_bill(s=i * 25) for i in range(1, 9)) / 8), FilterDescription(name='$V(t) = ' '1/n\sum_{j=1}^{n+1} B_{j \cdot 25} $', plot_options=PlotOptions( style=':', color='blue', width=2.0, ), formula=norm(l=1) | sum(mdiff_bill(s=i * 25) for i in range(1, 9)) / 8 | diff | modulus | sum(bill(s=25 * j) for j in range(1, 9)) / 8), ]
def seq_filters(self): """ :return: """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # Shift signal to one frame. Builtin filter. shift = ShiftSWFilter() # The difference between neighboring frames. diff = original - shift # The norm of the signal. Builtin filter. norm = NormFilter() # Abstract sliding window. Builtin filter. sw = BaseSWFilter(min_size=2) # Sum of absolute difference filter. sad_filter = original | diff | abs | norm(l=1) sw_mean = sw | numeric.mean # or sw_mean = MeanSWFilter() sw_std = sw | numeric.std # or sw_std = StdSWFilter() def z_score(size=1): """ :param size: :return: """ return (((original - sw_mean(s=size)) / sw_std(s=size)) / numeric.sqrt(size) | abs) def z_test(size=1): """ ... """ estimation = z_score(size) return estimation # Sequence of voters. voters = range(self.VOTER_COUNT) # Sequence of sliding window sizes. sizes = (self.VOTER_SIZE * (i + 1) for i in voters) # Sequence of votes of different sizes. z_vote_seq = (z_test(size=size) for size in sizes) # Average vote of different sizes. z_vote = sum(z_vote_seq) / self.VOTER_COUNT return [ FilterDescription( name='$F_{L_1} = ||F_{t}||_{L_1}$', plot_options=PlotOptions( style='-', color='gray', width=3.0, ), formula=norm(l=1), ), FilterDescription( # Sum of absolute difference filter. name='$D_{t} = ||F_{t} - F_{t-1}||_{L_1}$', plot_options=PlotOptions( style='-', color='blue', width=2.0, ), formula=sad_filter), FilterDescription( name=('$D_{{t}} > E_{{ {size} }}\ (D_{{t}})$'.format( size=100)), plot_options=PlotOptions( style='--', color='green', width=1.0, ), formula=(diff | norm(l=1) | z_test(size=50))), FilterDescription( name=('$D_{{t}} > E_{{ {size} }}\ (D_{{t}})$'.format( size=200)), plot_options=PlotOptions( style='--', color='red', width=1.0, ), formula=(diff | norm(l=1) | z_test(size=200))), FilterDescription(name=('VOTE'), plot_options=PlotOptions( style='-', color='red', width=2.0, ), formula=(diff | norm(l=1) | z_vote)), ]
def seq_filters(self): """ :return: """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # Shift signal to one frame. Builtin filter. shift = ShiftSWFilter() # The difference between neighboring frames. diff = original - shift # The norm of the signal. Builtin filter. norm = NormFilter() # Abstract sliding window. Builtin filter. sw = BaseSWFilter(min_size=2) # Sum of absolute difference filter. sad_filter = diff | abs | norm(l=1) sw_mean = sw | numeric.mean # or sw_mean = MeanSWFilter() sw_std = sw | numeric.std # or sw_std = StdSWFilter() def sigma_estimation(sigma=3.0, size=1): """ :param float sigma: :param int size: :return: """ return sw_mean(s=size) + sigma * sw_std(s=size) def sigma_check(**kwargs): """ ... """ return original > sigma_estimation(**kwargs) return [ FilterDescription( name='$F_{L_1} = ||F_{t}||_{L_1}$', plot_options=PlotOptions( style='-', color='gray', width=3.0, ), formula=norm(l=1), ), FilterDescription( # Sum of absolute difference filter. name='$D_{t} = ||F_{t} - F_{t-1}||_{L_1}$', plot_options=PlotOptions( style='-', color='blue', width=2.0, ), formula=sad_filter), FilterDescription( # Estimation for sum of absolute difference name=('$E_{{ {size} }}\ (D_{{t}}) = ' '\hat{{\mu}}_{{ {size} }}[D_{{t}}] + A \cdot ' '\hat{{\sigma}}_{{ {size} }}[D_{{t}}]$'.format( size=100)), plot_options=PlotOptions( style='-', color='orange', width=2.0, ), formula=(sad_filter | sigma_estimation(size=100))), FilterDescription( # Estimation for sum of absolute difference name=('$E_{{ {size} }}\ (D_{{t}}) = ' '\hat{{\mu}}_{{ {size} }}[D_{{t}}] + A \cdot ' '\hat{{\sigma}}_{{ {size} }}[D_{{t}}]$'.format( size=200)), plot_options=PlotOptions( style='-', color='red', width=2.0, ), formula=(sad_filter | sigma_estimation(size=200))), FilterDescription( name=('$D_{{t}} > E_{{ {size} }}\ (D_{{t}})$'.format( size=100)), plot_options=PlotOptions( style='--', color='green', width=1.0, ), formula=(sad_filter | sigma_check(size=100))), FilterDescription( name=('$D_{{t}} > E_{{ {size} }}\ (D_{{t}})$'.format( size=200)), plot_options=PlotOptions(style='--', color='red', width=1.5, marker='x'), formula=(sad_filter | sigma_check(size=200) * 0.8)), ]
def seq_filters(): """ :return: """ delay = DelayFilter() original = delay(0) norm = NormFilter() shift = ShiftSWFilter( window_size=2, strict_windows=False, cs=False, ) mean = MeanSWFilter( window_size=25, # strict_windows=True, cs=False) std = StdSWFilter( window_size=25, strict_windows=True, ) dtr = DecisionTreeRegressorSWFilter( window_size=100, strict_windows=True, overlap_size=0, cs=False, ) sad = original - shift def sigma3(c=3.0, **kwargs): """ :param c: :param kwargs: :return: """ # noinspection PyTypeChecker return (original > (mean(**kwargs) + c * std(**kwargs))) | int return [ SmartDict( name='$F_{L_1} = |F_{t}|_{L_1}$', plot_options=SmartDict( linestyle='-', color='lightgray', linewidth=3.0, ), filter=norm(l=1), ), SmartDict(name='$DTR_{300,2}$', plot_options=SmartDict( linestyle='-', color='red', linewidth=2.0, ), filter=norm(l=1) | dtr(s=300, d=2)), SmartDict(name='$S_{DTR} = ' '\\frac{1}{k}\sum_{i=1}^{k} DTR_{i \cdot 25, 2} $', plot_options=SmartDict( linestyle='-', color='green', linewidth=2.0, ), filter=norm(l=1) | sum([dtr(s=25 * i + 1) for i in range(1, 9)]) / 8), SmartDict(name='$B_{DTR} = \\frac{1}{k}\sum_{i=1}^{k} ' 'DTR_{i \cdot 25, 2} $', plot_options=SmartDict( linestyle='-', color='magenta', linewidth=2.0, ), filter=norm(l=1) | sum([dtr(s=25 * i + 1) for i in range(1, 9)]) / 8 | (sad | abs) | sum(sigma3(s=25 * j) for j in range(1, 2)) / 8), SmartDict(name="$V(t)$", plot_options=SmartDict( linestyle=':', color='blue', linewidth=2.0, ), filter=norm(l=1) | sum(dtr(s=25 * i + 1) for i in range(1, 9)) / 8 | (sad | abs) | sum(sigma3(s=25 * j) for j in range(1, 9)) / 8), ]
def seq_filters(self): """ Returns chart option sequence for SAD filter illustration. What we do: 1. Declare «builtin» filters. 2. Build custom filters. 3. Build target filter. 4. Plot them with `FilterDescription` :returns: filter descriptions for SAD filter. :rtype: list of FilterDescription """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # Shift signal to one frame. Builtin filter. shift = ShiftSWFilter() # The difference between neighboring frames. diff = original - shift # The norm of the signal. Builtin filter. norm = NormFilter() # Threshold filter. threshold = original > self.THRESHOLD # Sum of absolute difference filter. sad_filter = diff | abs | norm(l=1) return ( FilterDescription( # Original signal. name='$F_{L_1} = ||F_{t}||_{L_1}$', plot_options=PlotOptions( style='-', color='gray', width=3.0, ), formula=norm(l=1), ), FilterDescription( # Sum of absolute difference filter. name='$D_{t} = ||F_{t} - F_{t-1}||_{L_1}$', plot_options=PlotOptions( style='-', color='blue', width=2.0, ), formula=sad_filter), FilterDescription( # Sum of absolute difference filter > threshold. name='$D_{t} > T_{const} $', plot_options=PlotOptions( style=':', color='green', width=2.0, ), formula=sad_filter | threshold), FilterDescription( # The threshold value. name='$T_{{const}} = {threshold} \in (0; 1)$'.format( threshold=self.THRESHOLD), plot_options=PlotOptions( style='-', color='black', width=2.0, ), formula=norm(l=1) | self.THRESHOLD, ), )
def seq_filters(self): """ :return: """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # The norm of the signal. Builtin filter. norm = NormFilter() # Abstract sliding window. Builtin filter. sw = BaseSWFilter(min_size=2) sw_mean = sw | numeric.mean # or sw_mean = MeanSWFilter() sign_change = SignChangeFilter() return [ FilterDescription( name='$F_{L_1} = |F_{t}|_{L_1}$', plot_options=PlotOptions( style='-', color='lightgray', width=3.0, ), formula=norm(l=1), ), FilterDescription(name='$M_{50} = |\hat{\mu}_{50}(F_{L_1})|$', plot_options=PlotOptions( style='-', color='orange', width=2.0, ), formula=norm(l=1) | sw_mean(s=50)), FilterDescription(name='$M_{100} = |\hat{\mu}_{100}(F_{L_1})|$', plot_options=PlotOptions( style='-', color='red', width=2.0, ), formula=norm(l=1) | sw_mean(s=100)), FilterDescription(name='$M_{200} = |\hat{\mu}_{200}(F_{L_1})|$', plot_options=PlotOptions( style='-', color='blue', width=2.0, ), formula=norm(l=1) | sw_mean(s=200)), FilterDescription(name='$|M_{100} - M_{50}| \\to_{\pm} 0$', plot_options=PlotOptions( style=':', color='purple', width=1.1, ), formula=(norm(l=1) | (sw_mean(s=100) - sw_mean(s=50)) | sign_change | abs | original * 1)), FilterDescription(name='$|M_{200} - M_{50}| \\to_{\pm} 0$', plot_options=PlotOptions( style='--', color='blue', width=1.2, ), formula=(norm(l=1) | (sw_mean(s=200) - sw_mean(s=50)) | sign_change | abs | original * 0.9)), FilterDescription(name='$|M_{200} - M_{100}| \\to_{\pm} 0$', plot_options=PlotOptions( style='-', marker='x', color='green', width=1.3, ), formula=(norm(l=1) | (sw_mean(s=200) - sw_mean(s=100)) | sign_change | abs | original * 0.8)) ]
def seq_filters(self): """ :return: """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # Shift signal to one frame. Builtin filter. shift = ShiftSWFilter() # The difference between neighboring frames. diff = original - shift # The norm of the signal. Builtin filter. norm = NormFilter() # Abstract sliding window. Builtin filter. sw = BaseSWFilter(min_size=2) # Sum of absolute difference filter. sad_filter = diff | abs | norm(l=1) sw_mean = sw | numeric.mean # or sw_mean = MeanSWFilter() sw_std = sw | numeric.std # or sw_std = StdSWFilter() def sigma_estimation(sigma=3.0, size=1): """ :param float sigma: :param int size: :return: """ return sw_mean(s=size) + sigma * sw_std(s=size) def sigma_check(**kwargs): """ ... """ return original > sigma_estimation(**kwargs) # Sequence of voters. voters = range(self.VOTER_COUNT) # Sequence of sliding window sizes. sizes = (self.VOTER_SIZE * (i + 1) for i in voters) # Sequence of votes of different sizes. sigma_vote_seq = (sigma_check(size=size) for size in sizes) # Average vote of different sizes. sigma_vote = sum(sigma_vote_seq) / self.VOTER_COUNT return [ FilterDescription( name='$F_{L_1} = ||F_{t}||_{L_1}$', plot_options=PlotOptions( style='-', color='gray', width=3.0, ), formula=norm(l=1), ), FilterDescription( # Sum of absolute difference filter. name='$D_{t} = ||F_{t} - F_{t-1}||_{L_1}$', plot_options=PlotOptions( style='-', color='blue', width=2.0, ), formula=sad_filter), FilterDescription( name=('$D_{{t}} > E_{{ {size} }}\ (D_{{t}})$'.format( size=100)), plot_options=PlotOptions( style='--', color='green', width=1.0, ), formula=(sad_filter | sigma_check(size=100))), FilterDescription( name=('$D_{{t}} > E_{{ {size} }}\ (D_{{t}})$'.format( size=200)), plot_options=PlotOptions(style='--', color='red', width=1.5, marker='x'), formula=(sad_filter | sigma_check(size=200) * 0.8)), FilterDescription(name=('VOTE'), plot_options=PlotOptions( style='-', color='green', width=1.5, ), formula=(sad_filter | sigma_vote)), FilterDescription( # The threshold value. name=('$T_{{const}} = {} \in (0; 1)$'.format(self.THRESHOLD)), plot_options=PlotOptions( style='-', color='black', width=2.0, ), formula=norm(l=1) | self.THRESHOLD, ), ]
def seq_filters(self): """ Returns chart options for FFMpeg-like filter. What we do: 1. Declare «builtin» filters. 2. Build custom filters. 3. Build target filter. 4. Plot them with `FilterDescription` :returns: filter descriptions for FFMpeg-like filter. :rtype: list of FilterDescription """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # Shift signal to one frame. Builtin filter. shift = ShiftSWFilter() # The difference between neighboring frames. diff = original - shift # The norm of the signal. Builtin filter. norm = NormFilter() # Threshold filter. threshold = (original > self.THRESHOLD) * 1.1 # Sum of absolute difference filter. sad_filter = diff | abs | norm(l=1) # The absolute difference of two consecutive differences. sad_diff_filter = sad_filter | diff | abs # The minimum between the difference # and the difference in the difference. ffmpeg_like = Filter.to_tuple(sad_filter, sad_diff_filter) | min # Faster implementation of FFMpeg-like filter. # ffmpeg_like_fast = FFMpegLikeThresholdSWFilter() return ( FilterDescription( # Original signal. name='$F_{L_1} = ||F_{t}||_{L_1}$', plot_options=PlotOptions( style='-', color='gray', width=3.0, ), formula=norm(l=1), ), FilterDescription( # FFMpeg-like filter. name='$D^{ffmpeg}_{t} = \min(D_t, |D_t-D_{t-1}|)$', plot_options=PlotOptions( style='-', color='red', width=2.0, ), formula=ffmpeg_like), FilterDescription( # FFMpeg-like filter > threshold. name='$D^{ffmpeg}_{t} > T_{const} $', plot_options=PlotOptions( style=':', color='orange', width=2.0, ), formula=ffmpeg_like | threshold), FilterDescription( # The threshold value. name='$T_{{const}} = {threshold} \in (0; 1)$'.format( threshold=self.THRESHOLD), plot_options=PlotOptions( style='-', color='black', width=2.0, ), formula=norm(l=1) | self.THRESHOLD, ), )
def seq_filters(self): """ :return: """ # Linear delay filter. Builtin filter. delay = DelayFilter() # The incoming signal is unchanged. original = delay(0) # Shift signal to one frame. Builtin filter. shift = ShiftSWFilter() # The difference between neighboring frames. diff = original - shift # The norm of the signal. Builtin filter. norm = NormFilter() # Abstract sliding window. Builtin filter. sw = BaseSWFilter(min_size=2) sw_mean = sw | numeric.mean # or sw_mean = MeanSWFilter() sign_change = SignChangeFilter() atan = (diff | original * 256.0 | numeric.math.atan | 2 * original | original / numeric.math.pi) # or atan = AtanFilter() def sw_mean_diff(g, l): """ :param g: :param l: :return: """ return (norm(l=1) | (sw_mean(s=g) - sw_mean(s=l)) | (sign_change * atan)) return [ FilterDescription( name='$F_{L_1} = |F_{t}|_{L_1}$', plot_options=PlotOptions( style='-', color='lightgray', width=3.0, ), formula=norm(l=1), ), FilterDescription(name='$M_{50} = |\hat{\mu}_{50}(F_{L_1})|$', plot_options=PlotOptions( style='-', color='orange', width=2.0, ), formula=norm(l=1) | sw_mean(s=50)), FilterDescription(name='$M_{100} = |\hat{\mu}_{100}(F_{L_1})|$', plot_options=PlotOptions( style='-', color='red', width=2.0, ), formula=norm(l=1) | sw_mean(s=100)), FilterDescription(name='$M_{200} = |\hat{\mu}_{200}(F_{L_1})|$', plot_options=PlotOptions( style='-', color='blue', width=2.0, ), formula=norm(l=1) | sw_mean(s=200)), FilterDescription( name='$|M_{200} - M_{50}| \\to_{\pm} 0$', plot_options=PlotOptions( style='--', color='blue', width=1.2, ), formula=( norm(l=1) | (sw_mean(s=200) - sw_mean(s=50)) # | sign_changes # | abs # | original * 0.9 )), FilterDescription(name='$A|M_{200} - M_{50}| \\to_{\pm} 0$', plot_options=PlotOptions( style='-', marker='x', color='green', width=1.3, ), formula=sw_mean_diff(200, 50)), FilterDescription( # The threshold value. name='0', plot_options=PlotOptions( style='-', color='black', width=2.0, ), formula=norm(l=1) | 0), ]