moving-average

Calculating moving average in C++

空扰寡人 提交于 2019-12-03 11:50:35
问题 I am trying to calculate the moving average of a signal. The signal value ( a double ) is updated at random times. I am looking for an efficient way to calculate it's time weighted average over a time window, in real time. I could do it my self, but it is more challenging than I thought. Most of the resources I've found over the internet are calculating moving average of periodical signal, but mine updates at random time. Does anyone know good resources for that ? Thanks 回答1: The trick is the

Calculating weighted moving average using pandas Rolling method

若如初见. 提交于 2019-12-03 08:44:55
I calculate simple moving average: def sma(data_frame, length=15): # TODO: Be sure about default values of length. smas = data_frame.Close.rolling(window=length, center=False).mean() return smas Using the rolling function is it possible to calculate weighted moving average? As I read in the documentation , I think that I have to pass win_type parameter. But I'm not sure which one I have to choose. Here is a definition for weighted moving average. Thanks in advance, Yeah, that part of pandas really isn't very well documented. I think you might have to use rolling.apply() if you aren't using one

Smoothing values over time: moving average or something better?

安稳与你 提交于 2019-12-03 00:20:18
问题 I'm coding something at the moment where I'm taking a bunch of values over time from a hardware compass. This compass is very accurate and updates very often, with the result that if it jiggles slightly, I end up with the odd value that's wildly inconsistent with its neighbours. I want to smooth those values out. Having done some reading around, it would appear that what I want is a high-pass filter, a low-pass filter or a moving average. Moving average I can get down with, just keep a

LINQ to calculate a moving average of a SortedList<dateTime,double>

本小妞迷上赌 提交于 2019-12-02 19:28:05
I have a time series in the form of a SortedList<dateTime,double> . I would like to calculate a moving average of this series. I can do this using simple for loops. I was wondering if there is a better way to do this using linq. my version: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var mySeries = new SortedList<DateTime, double>(); mySeries.Add(new DateTime(2011, 01, 1), 10); mySeries.Add(new DateTime(2011, 01, 2), 25); mySeries.Add(new DateTime(2011, 01, 3), 30);

How do I calculate a rolling mean with custom weights in pandas?

左心房为你撑大大i 提交于 2019-12-02 04:29:22
The Pandas documentation http://pandas.pydata.org/pandas-docs/stable/computation.html has an example of how to calculate moving averages: ser = pd.Series(np.random.randn(10), index=pd.date_range('1/1/2000', periods=10)) pd.rolling_window(ser, 5, 'boxcar') The second line calculates a rolling average with a window of 5 and equal weights on each of the five observations. The docs refer tantalizingly to the possibility of using custom weights ("When passing a win_type instead of explicitly specifying the weights..."), but how do you do it? Thanks! I'm not Math expert, but stahlous explain what

Python: How can we smooth a noisy signal using moving average?

落花浮王杯 提交于 2019-12-02 02:37:13
For an evaluation of a random forest regression, I am trying to improve a result using a moving average filter after fitting a model using a RandomForestRegressor for a dataset found in this link import pandas as pd import math import matplotlib import matplotlib.pyplot as plt import numpy as np from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor from sklearn.model_selection import GridSearchCV from sklearn.metrics import r2_score, mean_squared_error, make_scorer from sklearn.model_selection import train_test_split from math import sqrt from sklearn.cross_validation

Making a custom window type for pandas rolling mean

放肆的年华 提交于 2019-12-01 23:02:10
问题 I understand rolling allows you to specify the window type used for calculating the rolling mean. The docs list a variety of windows type options available here. However, I am trying to use a symmetrically weighted window type of length 4 whose definition is like (and is not available as built-in): (a + 2*b + 2*c + d)/6 where a,b,c and d are the four elements of the rolling window at any given time and [1/6, 2/6, 2/6, 1/6] would be the associated weights. If I go by the default window type

Calculating moving-averages of variable parameters

那年仲夏 提交于 2019-12-01 22:57:50
I have an integer property which is updated every second with a signal-strength value ranging from 0 - 100. I'd like to be able to keep an ongoing measure of the moving average over the last 10, 25, 50 measurements. What's the most efficient way of doing this? I'm currently thinking of implementing a set of FIFO queues using NSMutableArray and popping the leading value every time I add a new one at the end once the array has the requisite number of entries. However, I'm not sure if there's a more efficient way of doing this or not. A queue is the right way. The real efficiency comes with how

SAS: standard deviation on unfixed rolling window

本秂侑毒 提交于 2019-12-01 12:36:52
I think I posted similar question before. But this time I am struggling with data ID. My data looks like date Stock value standard_deviation 01/01/2015 VOD 18 ... 01/01/2015 VOD 15 ... 01/01/2015 VOD 5 ... 03/01/2015 VOD 66 ... 03/01/2015 VOD 7 ... 04/01/2015 VOD 19 ... 04/01/2015 VOD 7 ... 05/01/2015 VOD 3 ... 06/01/2015 VOD 7 ... ..... ... ... ... 01/01/2015 RBS 58 ... 01/01/2015 RBS 445 ... 01/01/2015 RBS 44 ... 03/01/2015 RBS 57 ... I need to work out the moving average/std deviation for each stock based on (-3,+3) trading days. Since those are trading days (not calendar days), and there

Rolling / moving avg by group

我怕爱的太早我们不能终老 提交于 2019-12-01 04:09:12
How to generate rolling mean with grouped data. Here's the data set.seed(31) dd<-matrix(sample(seq(1:20),30,replace=TRUE),ncol=3) Add a group identifier, and sort by group identifier du<-sample(seq(1:4),10,replace=TRUE) d<-cbind(du,dd) d<-d[order(d[,1]),] This gives the rolling mean but ignores group bounderis d_roll_mean <- apply(d[,2:4], 2, function(x) { rollapply(zoo(x), 3, mean, partial=TRUE, align='right') } ) This gives the results below # cbind(d,d_roll_mean) # [1,] 1 3 3 12 3.000000 3.000000 12.000000 # [2,] 2 10 13 8 6.500000 8.000000 10.000000 # [3,] 2 17 2 17 10.000000 6.000000 12