def main(): x = Stream('x') y = Stream('y') z = Stream('z') print_stream(x) print_stream(y) print_stream(z) timed_merge_agent([x,y], z) x.extend([(1, 'a'), (3, 'b'), (3, 'c'), (10, 'd'), (15, 'e'), (17, 'f')]) y.extend([(2, 'A'), (3, 'B'), (3, 'C'), (9, 'D'), (20, 'E')]) t = Stream('t') u = Stream('u') v = Stream('v') w = Stream('w') print_stream(t) print_stream(u) print_stream(v) print_stream(w) timed_merge_agent([u,v], w, call_streams=[t]) u.extend([(1, 'a'), (3, 'b'), (3, 'c'), (10, 'd'), (15, 'e'), (17, 'f')]) v.extend([(2, 'A'), (3, 'B'), (3, 'C'), (9, 'D'), (20, 'E')]) t.append(0) u.extend([(21, 'g'), (23, 'h'), (33, 'i'), (40, 'j'), (50, 'K')]) v.extend([(22, 'F'), (23, 'G'), (43, 'H'), (51, 'I'), (59, 'J')]) t.append(0)
ef(x, y, np.sin, call_streams=[trigger_1]) # Create an agent that puts the clipped elements of x # into z where values below a_min are set to a_min and # values above a_max are set to a_max. This agent # executes when elements appear in stream trigger_2. # This agent remains asleep until woken up by new elements # in trigger_2. ef(x, z, np.clip, call_streams=[trigger_2], a_min=2, a_max=8) # Put elements 0, 1, 2, 3, 4 into stream, x. # The agents only process elements in x when their trigger # streams have new values. x.extend(range(5)) # Wake up the agent that puts values into y. # Now y has 5 values: sine(0),... , sine(4) trigger_1.append(1) # Wake up the agent that puts values into z. # Now z has 5 values: clip(0, 2, 8).... clip(4, 2, 8) trigger_2.append(1) # Put elements 5, 6, 7, 8, 9 into stream x. x.extend(range(5, 10)) # Now x has 10 values 0, ..., 9 whereas y and z each # have 5 values. # Do NOT wake up the agent that puts values into y, but do # wake up the agent that puts values into z. trigger_2.append(2) # Now z has 10 values: clip(0, 2, 8).... clip(9, 2, 8) # because the clip agents was woken up by trigger 2, and # the agent processed the messages 5, ..., 9 waiting for it # and it put 5 values into z.
print 'std/avg = ', std/avg, 'window_size = ', window_size return ([avg, std], window_size, step_size) initial_window_size = 6 initial_step_size = 6 awf([u,v], [y,z], h, initial_window_size, initial_step_size, call_streams=[a], ratio=0.6, min_window_size=4) u.extend([randint(0, 20) for _ in range(15)]) v.extend([randint(0, 20) for _ in range(15)]) print 'UNPROCESSED INPUT \n' # Agent does not execute though it has unprocessed input. u.extend([randint(0, 20) for _ in range(15)]) v.extend([randint(0, 20) for _ in range(15)]) print 'MORE UNPROCESSED INPUT \n' print 'INPUT IS PROCESSED WHEN VALUE APPEARS IN CALL STREAM.' a.append(1) # Agent processes unprocessed input. u.extend([randint(0, 20) for _ in range(15)]) v.extend([randint(0, 20) for _ in range(15)]) print '\n MORE UNPROCESSED INPUT \n' # Agent does not execute though it has unprocessed input. print 'INPUT IS PROCESSED WHEN NEXT VALUE APPEARS IN CALL STREAM.' a.append(2) # Agent processes unprocessed input.
window_size=window_size, step_size=step_size) # Create and name the input streams of the function. l_stream = Stream('l stream') m_stream = Stream('m stream') # The function returns a list of two streams. inrange_exp_smooth_stream, outlier_exp_smooth_stream = \ inrange_and_outlier_streams( list_of_two_streams=[l_stream, m_stream], window_size=20, step_size=20, alpha=0.9, threshold=1) # Give names to the output streams and print them. inrange_exp_smooth_stream.set_name('inrange exp smooth') outlier_exp_smooth_stream.set_name('outlier exp smooth') print_stream(inrange_exp_smooth_stream) print_stream(outlier_exp_smooth_stream) # Drive the example. # Add values to input streams l_stream and m_stream. # Most of the output values should be in range because they # are uniform random numbers in the interval (0.0, 1.0). for _ in range(100): x = random.random() l_stream.append(x) m_stream.append(x+0.01*random.random())
window_size=window_size, step_size=step_size) # Create and name the input streams of the function. l_stream = Stream('l stream') m_stream = Stream('m stream') # The function returns a list of two streams. inrange_exp_smooth_stream, outlier_exp_smooth_stream = \ inrange_and_outlier_streams( list_of_two_streams=[l_stream, m_stream], window_size=20, step_size=20, alpha=0.9, threshold=1) # Give names to the output streams and print them. inrange_exp_smooth_stream.set_name('inrange exp smooth') outlier_exp_smooth_stream.set_name('outlier exp smooth') print_stream(inrange_exp_smooth_stream) print_stream(outlier_exp_smooth_stream) # Drive the example. # Add values to input streams l_stream and m_stream. # Most of the output values should be in range because they # are uniform random numbers in the interval (0.0, 1.0). for _ in range(100): x = random.random() l_stream.append(x) m_stream.append(x+0.01*random.random())
inputs=a, # The input is a single stream f_type='timed', # Identifes 'timed' wrapper f=sum_values_in_timed_list, # Function that is wrapped. num_outputs=1, # Single output stream window_size=4.0, step_size=2.0) z.set_name('sum of a') print_stream(z) # Drive the input streams. t = 0.0 for _ in range(20): t += random.random() v = random.randint(0, 9) a.append(TimeAndValue(t, v)) ############################################################ ############################################################ # SECTION 2. SINGLE INPUT, SINGLE OUTPUT, STATEFUL ############################################################ ############################################################ print print '**************************************************' print 'SECTION 2' print 'EXAMPLES OF SINGLE INPUT, SINGLE OUTPUT, STATEFUL' print '**************************************************' #_____________________________________________________________ # EXAMPLE 1