stanford-futuredata / asap Goto Github PK
View Code? Open in Web Editor NEWASAP: Prioritizing Attention via Time Series Smoothing
Home Page: http://futuredata.stanford.edu/asap
License: Apache License 2.0
ASAP: Prioritizing Attention via Time Series Smoothing
Home Page: http://futuredata.stanford.edu/asap
License: Apache License 2.0
I've encountered an issue with the ASAP (As-Sampled-As-Possible) smoothing algorithm implemented in JavaScript. The algorithm produces different results each time the application is restarted, despite being given the same input data. This inconsistency is not observed with other smoothing methods like Savitzky-Golay. :/ I also read your paper but what I understand is it should behave deterministic and source code https://github.com/stanford-futuredata/ASAP/blob/master/ASAP-optimized.js doesn't use some randomness.
any ideas?
The ASAP smoothing algorithm should produce consistent results given the same input data, regardless of application restarts.
Any ideas? I m just using it like that:
const applySmoothing = useCallback((inputData: ReadonlyArray<number>, targetRes: number): number[] => {
try {
return smoothFunction(Array.from(inputData), targetRes);
} catch (error) {
console.error('Error in smoothing:', error);
return Array.from(inputData);
}
}, []);
const [dataSet1, dataSet2, label1, label2, metric, axisRange, pageCount] = useMemo(() => {
const sourceData = useUnprocessedData && fullData ? fullData : processedData;
let d1: number[], d2: number[] | null, l1: string, l2: string, m: number | null, range, total: number;
// ... (switch case for different modes)
if (useUnprocessedData && fullData) {
// ...
} else {
const targetRes = 100;
d1 = applySmoothing(d1, targetRes);
if (d2) d2 = applySmoothing(d2, targetRes);
total = 1;
setStartIndex(0);
if (currentMode === "comparisonMode") {
m = calculateCorrelation(sourceData.subject1.metric, sourceData.subject2.metric);
} else {
m = null;
}
}
range = calculateAxisRange(d1, d2);
return [d1, d2, l1, l2, m, range, total];
}, [processedData, fullData, useUnprocessedData, currentMode, currentPage, itemsPerPage, calculateAxisRange, applySmoothing]);
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.
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?
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.