GithubHelp home page GithubHelp logo

stanford-futuredata / asap Goto Github PK

View Code? Open in Web Editor NEW
188.0 21.0 31.0 1.29 MB

ASAP: Prioritizing Attention via Time Series Smoothing

Home Page: http://futuredata.stanford.edu/asap

License: Apache License 2.0

JavaScript 4.34% HTML 1.51% Jupyter Notebook 94.15%
visualization time-series smoothing

asap's Introduction

asap's People

Contributors

kexinrong avatar pbailis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asap's Issues

Python 3 does not have a csv.next() method

the csv reader code appears to be broken here at ASAP.py#L222 because '_csv.reader' object has no attribute 'next' in Python 3. Instead the code on L222 should read args._head = next(icsv) for Python 3.

An easy fix is to either call sys.version_info to check for Python version, or at least include a note stating that this code depends on a Python 2 version of the csv package.

Timeseries data consistency

How to cope when shrinking a timeseries dataset?

I noticed that:
x = Array.apply(null, Array(y.length)).map(function (_, i) {return i;}) in index.html only gives us the indexes related to y`s length

I tried doing something like this but I doubt its correctness..

smooth_val = 100
var y = smooth(rsdata["values"], smooth_val)
step - Math.ceil(rsdata["timestamps"].length/smooth_val)
x = rsdata["timestamps"].filter((x,i) => i%step == 0)

does anyone have a solution?

Python Script Giving Different Results from Demo Site

I created some fake data like this:

n = 201
x = np.linspace(0, 1, n)
y = np.sin(4*np.pi*x*x)
chirp = 0.5*np.sin((2.0*np.pi*x)/0.05)
chirp_inx = np.argwhere((x > 0.4) & (x < 0.45))
y[chirp_inx] = chirp[chirp_inx]
noise = np.random.normal(0, 0.1, n)
y_noise = y + noise

So, my data is in y_noise. The smoothed values generated from the Python script:

ASAP.smooth(y_noise)

is different from the values shown from the demo site. You can tell because the smoothed values generated from the Python script produces a min-value of 0.010680608603816815 and a max-value of 0.48671462099352242. Whereas the demo site produces a plot that has a min-value near -1.0 and a max-value of +1.0.

Moving average implementation appears incorrect

I was looking into why the numpy version of SMA didn't match the for loop version, and looking at each step in the for loop version, it appears that it is not doing the final window correctly. Is this intentional or am I misinterpreting what is going on? I haven't tested the JS version, but appears to be identical to the python one.

In [1]: x = [42,75,3,5,99,22,88]


In [2]: SMA(x, 3, 1)
window: [42, 75, 3] 	 sum(  120.0000) / count(    3.0000) =    40.0000  
window: [75, 3, 5] 	 sum(   83.0000) / count(    3.0000) =    27.6667  
window: [3, 5, 99] 	 sum(  107.0000) / count(    3.0000) =    35.6667  
window: [5, 99, 22, 88] 	 sum(  214.0000) / count(    4.0000) =    53.5000  
window: [99, 22, 88, 88] 	 sum(  297.0000) / count(    4.0000) =    53.5000  
Out[2]: [40.0, 27.666666666666668, 35.666666666666664, 53.5]
def SMA(data, _range, slide):
    ret = []
    s = 0.0
    c = 0.0
    window_start = 0
    window = []
    for i in range(len(data)):
        if i-window_start >= _range or i==len(data)-1:
            if i==len(data)-1 or c==0:
                s += data[i]
                window.append(data[i])
                c += 1
            ret.append( s/c )
            print("window: {} \t sum({:10.4f}) / count({:10.4f}) = {:10.4f}  ".format(window, s, c, ret[-1]))
            old_start = window_start
            while window_start < len(data) and window_start-old_start < slide:
                s -= data[window_start]
                window = window[1::]
                c -= 1
                window_start += 1
        s += data[i]
        window.append(data[i])
        c += 1
    print("window: {} \t sum({:10.4f}) / count({:10.4f}) = {:10.4f}  ".format(window, s, c, ret[-1]))
    return ret

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.