当前位置: 首页>>代码示例>>Python>>正文


Python Stream.print_recent方法代码示例

本文整理汇总了Python中Stream.Stream.print_recent方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.print_recent方法的具体用法?Python Stream.print_recent怎么用?Python Stream.print_recent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream.Stream的用法示例。


在下文中一共展示了Stream.print_recent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def main():
    # Functions: list -> list
    def square(lst):
        return [v*v for v in lst]

    def double(lst):
        return [2*v for v in lst]

    def even(lst):
        return [v for v in lst if not v%2]

    # Functions: stream -> stream.
    # Each element of the output stream is f() applied to the corresponding
    # element of the input stream.
    stream_square = partial(stream_func, f_type='list', f=square, num_outputs=1)
    stream_double = partial(stream_func, f_type='list', f=double, num_outputs=1)
    stream_even = partial(stream_func, f_type='list', f=even, num_outputs=1)
    # Create stream x, and give it name 'x'.
    x = Stream('input')

    # u is the stream returned by stream_square(x)  and
    # v is the stream returned by stream_double(x)
    # w is the stream returned by stream_square(v) and
    #   so w could have been defined as:
    #   stream_square(stream_double(x))
    # a is the stream containing only even values of x
    u = stream_square(x)
    v = stream_double(x)
    w = stream_square(v)
    a = stream_even(x)

    # Give names to streams u, v, and w. This is helpful in reading output.
    u.set_name('square of input')
    v.set_name('double of input')
    w.set_name('square of double of input')
    a.set_name('even values in input')

    print
    print 'add [3, 5] to the tail of the input stream'
    # Add values to the tail of stream x.
    x.extend([3, 5])

    # Print the N most recent values of streams x, u, v, w.
    x.print_recent()
    u.print_recent()
    v.print_recent()
    w.print_recent()
    a.print_recent()    

    print
    print 'add [2, 6] to the tail of the input stream'
    # Add more values to the tail of stream x.
    x.extend([2, 6])

    # Print the N most recent values of streams x, u, v, w.
    x.print_recent()
    u.print_recent()
    v.print_recent()
    w.print_recent()
    a.print_recent()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:62,代码来源:example_list_single_in_single_out_stateless.py

示例2: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def test():

    x = Stream('x')

    y,z = max_min_of_windows_in_stream(x)

    y.set_name('y')
    z.set_name('z')

    check(y, [5])
    check(z, [3])
    
    x.extend([3,5])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    x.extend([11,15])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:27,代码来源:test_example_window_single_in_multi_out_stateless.py

示例3: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def test():

    x = Stream('x')

    y,z = exp_smooth_max_and_std_of_windows_in_stream(x)

    y.set_name('y')
    z.set_name('z')

    check(y, [1.6000000000000001, 4.3200000000000003])
    check(z, [0.65319726474218087, 0.78383671769061702])
    
    x.extend([1, 2, 3, 4, 5])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    x.extend([6, 12, 13, 14, 15])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:27,代码来源:test_example_window_single_in_multi_out_stateful.py

示例4: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def main():
    def max_of_std(lst, state):
        a = np.array(lst)
        state = max(a.std(), state)
        return (state, state)
    print "example_1"
    print "example function from list to value: mean_and_sigma() "
    window_size = 10
    step_size = 10
    print "window_size = ", window_size
    print "step_size = ", step_size
    print ""

    x = Stream('x')
    # x is the in_stream.
    # sum() is the function on the window

    z = stream_func(x, f_type='window', f=max_of_std, num_outputs=1, state=0.0,
                    window_size=window_size, step_size=step_size)

    z.set_name('z')
 

    x.extend([random.random() for i in range(30)])
    x.print_recent()
    z.print_recent()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:28,代码来源:example_window_single_in_single_out_stateful.py

示例5: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def main():

    def mean_of_window(stream):

        def mean(lst, state):
            sum_window, next_value_dropped = state
            if sum_window is None:
                sum_window = sum(lst)
            else:
                sum_window = sum_window + lst[-1] - next_value_dropped
            mean = sum_window/len(lst)
            next_value_dropped = lst[0]
            state = (sum_window, next_value_dropped)
            return (mean, state)

        return stream_func(
            inputs=stream,
            f_type='window',
            f=mean,
            num_outputs=1,
            state=(None, None),
            window_size=2,
            step_size=2)


    def max_of_std(lst, state):
        a = np.array(lst).std()
        if a > state:
            state = a
            return (a, state)
        else:
            return (_no_value, state)
        

    x = Stream('x')
    # x is the input stream.


    g = partial(stream_func, f_type='window',
                f=max_of_std,
                num_outputs=1, state=0.0,
                window_size=10, step_size=10)

    y = g(x)
    z = g(y)
    means = mean_of_window(x)

    y.set_name('y')
    z.set_name('z')
    means.set_name('means')

    x.extend([random.random() for i in range(30)])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    means.print_recent()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:58,代码来源:example_window_single_in_single_out_stateful.py

示例6: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def main():
    # Functions: list -> list of lists
    def even_odd(list_of_integers):
        evens_list = [n for n in list_of_integers if not n%2]
        odds_list = [n for n in list_of_integers if n%2]
        return (evens_list, odds_list)

    # Functions: stream -> stream.
    # The n-th element of the output stream is f() applied to the n-th
    # elements of each of the input streams.
    # Function mean is defined above, and functions sum and max are the
    # standard Python functions.
    stream_even_odd = partial(stream_func, f_type='list', f=even_odd, num_outputs=2)

    # Create stream x, and give it name 'x'.
    x = Stream('input_0')

    # u is the stream returned by stream_sum([x,y])  and
    # v is the stream returned by stream_max([x,y])
    # w is the stream returned by stream_mean([x,y]).
    # u[i] = sum(x[i],y[i])
    # v[i] = max(x[i],y[i])
    # w[i] = mean(x[i],y[i])    
    evens, odds = stream_even_odd(x)

    # Give names to streams u, v, and w. This is helpful in reading output.
    evens.set_name('even numbers in x')
    odds.set_name('odd numbers in x')

    print
    print 'Adding [3, 5, 8] to input stream'
    # Add values to the tail of stream x.
    x.extend([3, 5, 8])

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()

    print 'recent values of output streams'
    evens.print_recent()
    odds.print_recent()


    print
    print 'Adding [4, 6, 2, 1] to the input stream'
    # Add more values to the tail of stream x.
    x.extend([4, 6, 2, 1])

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()

    print 'recent values of output streams'
    evens.print_recent()
    odds.print_recent()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:57,代码来源:example_list_single_in_multi_out_stateless.py

示例7: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def test():

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

    
    z = sum_diffs_means_of_windows([x,y])
    
    z.set_name('z')

    check(z, [1.0])
    
    x.extend([3,5])
    y.extend([2])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    x.extend([11,15])
    y.extend([4, -10, -12])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:29,代码来源:test_example_window_multi_in_single_out_stateful.py

示例8: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def main():
    def sum_diff_of_means(list_of_two_lists, cumulative):
        a, b = list_of_two_lists
        cumulative += np.mean(a) - np.mean(b)
        return (cumulative, cumulative)
    x = Stream('x')
    y = Stream('y')
    z = stream_func([x,y], f_type='window', f=sum_diff_of_means,
                    num_outputs=1, state = 0,
                    window_size=2, step_size=2)
    z.set_name('z')
    
    x.extend([3,5])
    y.extend([2])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    x.extend([11,15])
    y.extend([4, -10, -12])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:27,代码来源:example_window_multi_in_single_out_stateful.py

示例9: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def test():

    # Create stream x, and give it name 'x'.
    x = Stream('input_0')

    # u is the stream returned by stream_sum([x,y])  and
    # v is the stream returned by stream_max([x,y])
    # w is the stream returned by stream_mean([x,y]).
    # u[i] = sum(x[i],y[i])
    # v[i] = max(x[i],y[i])
    # w[i] = mean(x[i],y[i])    
    evens, odds = stream_even_odd(x)

    # Give names to streams u, v, and w. This is helpful in reading output.
    evens.set_name('even numbers in x')
    odds.set_name('odd numbers in x')

    check(evens, [8, 4, 6, 2])
    check(odds, [3,5])

    print
    print 'Adding [3, 5, 8], [1, 7, 2], [2, 3] to 3 input streams'
    # Add values to the tail of stream x.
    x.extend([3, 5, 8])

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()

    print 'recent values of output streams'
    evens.print_recent()
    odds.print_recent()


    print
    print 'Adding [4, 6, 2], [2, 3, 8], [5, 3, 0, -1] to 3 input streams'
    # Add more values to the tail of stream x.
    x.extend([4, 6, 2])

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()

    print 'recent values of output streams'
    evens.print_recent()
    odds.print_recent()

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:50,代码来源:test_example_element_single_in_multi_out_stateless.py

示例10: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def test():

    # Create stream x, and give it name 'x'.
    x = Stream('input_0')

    id_0_average, id_1_average = stream_split_by_sensor_id(x)

    # Give names to streams u, v, and w. This is helpful in reading output.
    id_0_average.set_name('average of id_0 sensors in x')
    id_1_average.set_name('average of id_1 sensors in x')

    check(id_0_average, [2.0, 3.0, 5.0, 4.0, 4.0])
    check(id_1_average, [5.0, 3.0, 3.0, 4.0, 5.0, 6.0])

    print
    print 'Adding ([(0,2), (0,4), (1,5), (1,1), (0,9)]'
    print 'to the input stream.'
    # Add values to the tail of stream x.
    x.extend([(0,2), (0,4), (1,5), (1,1), (0,9)])

    # Print recent values of the streams
    print
    print 'recent values of input streams'
    x.print_recent()

    print
    print 'recent values of output streams'
    id_0_average.print_recent()
    id_1_average.print_recent()

    print
    print
    print 'Adding ([(1,3), (1,7), (0,1), (1,9), (1,11), (0,4)])'
    print 'to the input stream.'
    # Add values to the tail of stream x.
    x.extend([(1,3), (1,7), (0,1), (1,9), (1,11), (0,4)])

    # Print recent values of the streams
    print 'recent values of input streams'
    print
    x.print_recent()

    print 'recent values of output streams'
    print
    id_0_average.print_recent()
    id_1_average.print_recent()

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:50,代码来源:test_example_element_single_in_multi_out_stateful.py

示例11: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def test():
    in_1 = Stream(name='in_1')
    out_1 = Stream(name='out_1')
    out_2 = Stream(name= 'out_2')

    check(out_1, [4, 8])
    check(out_2, [3, 5])

    stream_agent(
        inputs=in_1,
        outputs=[out_1, out_2],
        f_type='element',
        f=number_even_odd)
    in_1.extend([3, 4, 5, 8])
    out_1.print_recent()
    out_2.print_recent()

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:20,代码来源:test_example_agent_split.py

示例12: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def test():

    # Create stream x and give it names 'x'.
    x = Stream('input')

    # v is the stream returned by stream_cumulative(x)  and
    # w is the stream returned by stream_cumulative(v).
    v = stream_cumulative(x)
    w = stream_cumulative(v)
    # avg is the stream returned by stream_average(x)
    avg = stream_average(x)

    # Give names to streams. This is helpful in reading output.
    v.set_name('cumulative sum of input')
    w.set_name('cumulative sum of cumulative sum of input')
    avg.set_name('average of input')

    check(v, [3, 8, 18, 20, 25, 36])
    check(w, [3, 11, 29, 49, 74, 110])
    check(avg, [3.0, 4.0, 6.0, 5.0, 5.0, 6.0])

    print
    print 'add values [3, 5, 10] to the tail of the input stream.'
    # Add values to the tail of stream x.
    x.extend([3, 5, 10])

    # Print the N most recent values of streams x, v, w.
    x.print_recent()
    v.print_recent()
    w.print_recent()
    avg.print_recent()

    print
    print 'add values [2, 5, 11] to the tail of the input stream.'
    # Add more values to the tail of stream x.
    x.extend([2, 5, 11])

    # Print the N most recent values of streams x, v, w.
    x.print_recent()
    v.print_recent()
    w.print_recent()
    avg.print_recent()

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:46,代码来源:test_example_element_single_in_single_out_stateful.py

示例13: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def test():

    # Create stream x, and give it name 'x'.
    x = Stream('input_0')
    y = Stream('input_1')


    inrange_stream, outlier_stream = inrange_and_outlier_streams([x,y])

    # Give names to streams u, v, and w. This is helpful in reading output.
    inrange_stream.set_name('inrange')
    outlier_stream.set_name('outlier')

    check(inrange_stream, [(10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (18, 180), (19, 190)])
    check(outlier_stream, [(15, 150), (16, 160), (17, 170)])
    print
    # Add values to the tail of stream x.
    x.extend(range(10, 15, 1))
    y.extend(range(10, 15, 1))

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()
    y.print_recent()

    print 'recent values of output streams'
    inrange_stream.print_recent()
    outlier_stream.print_recent()

    print
    print 'Adding [15, 16, ...19], [150, 160,..190] to 2 streams.'
    # Add more values to the tail of stream x.
    x_list = range(15, 20, 1)
    y_list = [10*v for v in x_list]

    x.extend(x_list)
    y.extend(y_list)

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()
    y.print_recent()

    print 'recent values of output streams'
    inrange_stream.print_recent()
    outlier_stream.print_recent()

    print
    print 'The regression parameters take some time to adjust'
    print 'to the new slope. Initially x = y, then x = 10*y'

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:54,代码来源:test_example_element_multi_in_multi_out_stateful.py

示例14: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def main():

    def single_stream_of_random_numbers(trigger_stream):
        def ran():
            return random.random()

        return stream_func(
            inputs=None,
            f_type='element',
            f=ran,
            num_outputs=1,
            call_streams=[trigger_stream])

    def stream_of_normal_and_pareto(clock_stream, b):
        from scipy.stats import norm, pareto

        def normal_and_pareto():
            return [norm.rvs(size=1)[0], pareto.rvs(b, size=1)[0]]

        return stream_func(
            inputs=None,
            f_type='element',
            f=normal_and_pareto,
            num_outputs=2,
            call_streams=[clock_stream]
            )


    trigger = Stream('trigger')
    r = single_stream_of_random_numbers(
        trigger_stream=trigger)
    u, v = stream_of_normal_and_pareto(
        clock_stream=trigger, b=2.62171653214)
    r.set_name('random')
    u.set_name('normal')
    v.set_name('pareto')

    trigger.extend(['tick', 'tick'])
    trigger.print_recent()
    r.print_recent()
    u.print_recent()
    v.print_recent()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:44,代码来源:example_source.py

示例15: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import print_recent [as 别名]
def main():
    print "example_1"
    print

    x = Stream('x')
    y = stream_func(x, f_type='window', f=ksigma,
                    num_outputs=1,  window_size=WINDOW_SIZE,
                    step_size=STEP_SIZE)

    y.set_name('y')
 
    x.extend(range(20))
    x.print_recent()
    y.print_recent()
    print

    x.extend(range(20, 0, -1))
    x.print_recent()
    y.print_recent()
    print
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:22,代码来源:example_window_ksigma.py


注:本文中的Stream.Stream.print_recent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。