examples_element_wrapper module

This module contains examples of the ‘element’ wrapper. A function that takes a single element of an input stream and generates a single element of an output stream is an example of a function that is wrapped by the ‘element’ wrapper to create a function on streams.

The module has the following parts: (1) op or simple operator:

single input, single output
  1. sink:
    single input, no outputs
  2. source:
    no input, multiple outputs
  3. split:
    single input, multiple output
  4. merge:
    multiple input, single output
  5. general case:
    multiple input, multiple output

All of the first 5 cases are specializations of the general case; however, the syntactic sugar they provide can be helpful.

For each of the above cases we first consider agents that are stateless and then consider agents with state.

examples_element_wrapper.average(v, state)[source]
Parameters:

v : number

The next element of the input stream of the agent.

state: (n, cumulative)

The state of the agent where n : number

The value of the next element in the agent’s input stream.

cumulative : number

The sum of the values that the agent has received on its input stream.

Returns:

(mean, state)

mean : floating point number

The average of the values received so far by the agent

state : (n, cumulative)

The new state of the agent.

examples_element_wrapper.average_stream(stream)[source]
examples_element_wrapper.boolean_of_values_greater_than_threshold(stream, threshold)[source]
examples_element_wrapper.cumulative_stream(stream)[source]
examples_element_wrapper.cumulative_sum(v, cumulative)[source]
Parameters:

v : number

The next element of the input stream of the agent.

cumulative: number

The state of the agent. The state is the sum of all the values received on the agent’s input stream.

Returns:

(cumulative, cumulative)

cumulative : number

The state after the transition, i.e., the sum of values received on the agent’s input stream including the value received in this transition.

examples_element_wrapper.discard_odds(stream)[source]
examples_element_wrapper.discard_odds_1(stream)[source]
examples_element_wrapper.double(v)[source]
examples_element_wrapper.double_stream(stream)[source]
examples_element_wrapper.even(v)[source]
examples_element_wrapper.even2(v)[source]
examples_element_wrapper.even3(v)[source]
examples_element_wrapper.even_1(v)[source]
examples_element_wrapper.even_odd(m)[source]
examples_element_wrapper.even_odd_stream(stream)[source]
examples_element_wrapper.evens_and_halves(stream)[source]
examples_element_wrapper.evens_and_halves_3(stream)[source]
examples_element_wrapper.exp_mult_div_stream(stream, exponent, multiplier, divisor)[source]
examples_element_wrapper.file_to_stream(filename, output_stream, time_period=0)[source]
Parameters:

filename: str

output_stream: Stream

time_period: int or float, nonnegative

examples_element_wrapper.inrange_and_outlier_streams(x_and_y_streams, A, B, DELTA)[source]
examples_element_wrapper.join_streams(list_of_streams)[source]
examples_element_wrapper.main()[source]
examples_element_wrapper.max_and_min_seen_across_all_streams(list_of_streams)[source]
examples_element_wrapper.max_and_min_stream(list_of_streams)[source]
examples_element_wrapper.max_and_min_with_names(list_of_numbers, state)[source]
examples_element_wrapper.max_of_all_inputs(list_of_elements, previous_max)[source]
examples_element_wrapper.max_seen_across_all_streams(list_of_streams)[source]
examples_element_wrapper.max_stream(list_of_streams)[source]
examples_element_wrapper.max_with_index(list_of_numbers, state)[source]
examples_element_wrapper.mean_stream(list_of_streams)[source]
examples_element_wrapper.multiply_elements_in_stream(stream, multiplier)[source]
examples_element_wrapper.print0(stream)[source]
examples_element_wrapper.print_stream(stream)[source]
examples_element_wrapper.print_streams(list_of_streams)[source]
examples_element_wrapper.print_sums(list_of_streams)[source]
examples_element_wrapper.rand(output_stream, num_outputs, time_period=0)[source]
Parameters:

output_stream: Stream

num_outputs: int, positive

time_period: int or float, positive

examples_element_wrapper.single_stream_of_random_numbers(timer_stream)[source]
examples_element_wrapper.square(v)[source]
examples_element_wrapper.square_and_double(m)[source]
examples_element_wrapper.square_and_double_stream(stream)[source]
examples_element_wrapper.square_stream(stream)[source]
examples_element_wrapper.stream_to_file(stream, filename)[source]
examples_element_wrapper.temperature_and_humidity_streams(stream, DELTA)[source]
examples_element_wrapper.timer(output_stream, num_outputs, time_period)[source]
Parameters:

stream: Stream

num_outputs: int, positive

time_period: int or float, positive