Don't maintain state for some objects

Open
#329 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start by reading how stream objects store and propagate state, then compare that behavior with the saveStreamState and restoreStreamState examples in the issue. Define the native behavior around temporarily using current data for predictions without accumulating it, and verify that normal feature rows still update rolling state.

Written by the indexing model from the issue text.

Description

Hey, thanks for this library, it's great. I'm building an ML application that is learning in an online way. So, it's constantly acquiring new feature rows, but also having to serve up predictions at the same time. I want to use Streamz to accumulate data, however, for my real feature rows, I want the accumulators to maintain state (say, a rolling mean). But for my predictions, I don't want the state to get accumulated into the roller.

As an example, let's say i'm recording temperature measurements once every 15 seconds. Every 15 seconds I want to generate a new feature vector that contains the rolling mean of the last 25 temperatures. However, inside of that 15 second window, I may get asked to serve up a prediction, for which I want to use the current temperature in the rolling mean, but I don't want the current temperature to be accumulated into the roller's state.

Is there a straightforward way to do this currently?

EDIT: For now i'm doing this:

    state = None
    if hasattr(stream, 'state'):
        state = stream.state
    
    return {
        'state': state,
        'children': [saveStreamState(s) for s in stream.downstreams]
    }


def restoreStreamState(stream, stateTree):
    stream.state = stateTree['state']
    for subStream, subTree in zip(stream.downstreams, stateTree['children']):
        restoreStreamState(subStream, subTree)

Which seems to work. It'd be cool if there was some way to do it natively, though.

Dominant language
Python
Stars
1.3k
Forks
149
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-streamz/streamz

All issues in python-streamz/streamz

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.