Beispiel #1
0
def demean_stream(in_stream, window_size, step_size,
                  num_windows, initial_state=None):
    out_stream = StreamArray()
    if initial_state is None:
        initial_state=np.zeros([2, num_windows])
    wf(in_stream, out_stream, demean_across_multiple_windows,
       window_size, step_size, initial_state)
    return out_stream
Beispiel #2
0
def stream_bandpass_filter_windowing(
        in_stream, out_stream, filter_type,
        drop_start, drop_end, output_size,
        b, a):
    
    def func(window, drop_start, b, a):
        y = filter_type(b, a, window)[drop_start: drop_start+len(window)]
        return _multivalue(y)

    window_size = drop_start + output_size + drop_end
    step_size = output_size
    wf(in_stream, out_stream, func, window_size, step_size,
       drop_start=drop_start, b=b, a=a)
Beispiel #3
0
def lossy_integrate_stream(
        in_stream, window_size, initial_value, FACTOR):
    out_stream = StreamArray()
    wf(in_stream, out_stream, lossy_integration,
       window_size, window_size, initial_value, FACTOR=FACTOR)
    return out_stream
from Stream import Stream
from Operators import stream_agent, wf
from examples_element_wrapper import print_stream
import numpy as np
from random import randint
"""Simple example of the window function wf with
window size and step size of 3. Output is the mean
of the clipped window with a_min=9, a_max=11. These
values are used in this example so that you can
check the results easily.

"""

u = Stream('u')
v = Stream('v')
y = Stream('y')
print_stream(u)
print_stream(v)
print_stream(y)

def h(list_of_lists):
    return max([np.std(lst) for lst in list_of_lists])

wf([u, v], y, h, 5, 5)

u.extend([randint(0, 20) for _ in range(21)])
v.extend([randint(0, 20) for _ in range(25)])
from Stream import Stream
from Operators import wf
from examples_element_wrapper import print_stream
from random import random
""" Simple example of a windows-wrapper.

"""

x = Stream('x')
y = Stream('y')
print_stream(x)
print_stream(y)

n = 3
wf(x, y, lambda u: u[0], 1, n)

x.extend(range(20))

from Stream import Stream
from Operators import stream_agent, wf
from examples_element_wrapper import print_stream
import numpy as np
from random import randint
"""Simple example of the window function wf with
window size and step size of 3. Output is the mean
of the clipped window with a_min=9, a_max=11. These
values are used in this example so that you can
check the results easily.

"""

x = Stream('x')
y = Stream('y')
z = Stream('z')
print_stream(x)
print_stream(y)
print_stream(z)

def execute_list_of_func(v, list_of_func):
    return ([f(v) for f in list_of_func])


wf(x, [y,z], execute_list_of_func, 3, 1, list_of_func=[max, min])

x.extend([randint(0, 20) for _ in range(20)])
from random import random
""" Simple example of a windows-wrapper.

"""

x = Stream('x')
y = Stream('y')
z = Stream('z')

print_stream(x)
print_stream(y)
print_stream(z)

stream_agent(inputs=x, outputs=y, f_type='window', f=np.mean,
             window_size=5, step_size=5)
# Alternative form
wf(x, z, np.mean, 5, 5)

x.extend([99.5+random() for _ in range(21)])

# Second example
# Illustrates that step_size may be larger than window_size.
# Stream b samples every n-th element of stream a.
a = Stream('a')
b = Stream('b')
print_stream(a)
print_stream(b)
n = 6
wf(a, b, lambda l: l[0], 1, n)
a.extend(range(18))
from examples_element_wrapper import print_stream
import numpy as np
from random import randint

"""Simple example of the window function wf with
window size and step size of 3. Output is the mean
of the clipped window with a_min=9, a_max=11. These
values are used in this example so that you can
check the results easily.

"""

u = Stream("u")
v = Stream("v")
y = Stream("y")
z = Stream("z")
print_stream(u)
print_stream(v)
print_stream(y)
print_stream(z)


def g(list_of_lists):
    return (max([np.std(lst) for lst in list_of_lists]), min([np.std(lst) for lst in list_of_lists]))


wf([u, v], [y, z], g, 5, 5)

u.extend([randint(0, 20) for _ in range(21)])
v.extend([randint(0, 20) for _ in range(25)])
from Stream import Stream
from Operators import stream_agent, wf
from examples_element_wrapper import print_stream
import numpy as np
from random import randint
"""Simple example of the window function wf with
window size and step size of 3. Output is the mean
of the clipped window with a_min=9, a_max=11. These
values are used in this example so that you can
check the results easily.

"""

x = Stream('x')
y = Stream('y')
print_stream(x)
print_stream(y)

def h(lst, a_min, a_max):
    return np.mean(np.clip(lst, a_min, a_max))
wf(x, y, h, 3, 3, a_min=9, a_max=11)

x.extend([randint(0, 20) for _ in range(20)])