linear-interpolation

SQL Server Interpolate Missing rows

独自空忆成欢 提交于 2019-12-01 19:51:47
I have the following table which records a value per day. The problem is that sometimes days are missing. I want to write a SQL query that will: Return the missing days Calculate the missing value using linear interpolation So from the following source table: Date Value -------------------- 2010/01/10 10 2010/01/11 15 2010/01/13 25 2010/01/16 40 I want to return: Date Value -------------------- 2010/01/10 10 2010/01/11 15 2010/01/12 20 2010/01/13 25 2010/01/14 30 2010/01/15 35 2010/01/16 40 Any help would be greatly appreciated. declare @MaxDate date declare @MinDate date select @MaxDate = MAX

linear interpolate missing values in time series

久未见 提交于 2019-11-30 20:53:52
I would like to add all missing dates between min and max date in a data.frame and linear interpolate all missing values, like df <- data.frame(date = as.Date(c("2015-10-05","2015-10-08","2015-10-09", "2015-10-12","2015-10-14")), value = c(8,3,9,NA,5)) date value 2015-10-05 8 2015-10-08 3 2015-10-09 9 2015-10-12 NA 2015-10-14 5 date value approx 2015-10-05 8 8 2015-10-06 NA 6.33 2015-10-07 NA 4.67 2015-10-08 3 3 2015-10-09 9 9 2015-10-10 NA 8.20 2015-10-11 NA 7.40 2015-10-12 NA 6.60 2015-10-13 NA 5.80 2015-10-14 5 5 Is there a clear solution with dplyr and approx ? (I do not like my 10 line

fastest way to use numpy.interp on a 2-D array

穿精又带淫゛_ 提交于 2019-11-30 15:22:36
I have the following problem. I am trying to find the fastest way to use the interpolation method of numpy on a 2-D array of x-coordinates. import numpy as np xp = [0.0, 0.25, 0.5, 0.75, 1.0] np.random.seed(100) x = np.random.rand(10) fp = np.random.rand(10, 5) So basically, xp would be the x-coordinates of the data points, x would be an array containing the x-coordinates of the values I want to interpolate, and fp would be a 2-D array containing y-coordinates of the datapoints. xp [0.0, 0.25, 0.5, 0.75, 1.0] x array([ 0.54340494, 0.27836939, 0.42451759, 0.84477613, 0.00471886, 0.12156912, 0

Speeding up an interpolation exercise

风流意气都作罢 提交于 2019-11-30 10:29:22
I'm running about 45,000 local linear regressions (essentially) on about 1.2 million observations, so I'd appreciate some help trying to speed things up because I'm impatient. I'm basically trying to construct year-by-position wage contracts--the function wage(experience given firm,year,position)--for a bunch of firms. Here's the data (basic structure of) set I'm working with: > wages firm year position exp salary 1: 0007 1996 4 1 20029 2: 0007 1996 4 1 23502 3: 0007 1996 4 1 22105 4: 0007 1996 4 2 23124 5: 0007 1996 4 2 22700 --- 1175141: 994 2012 5 2 47098 1175142: 994 2012 5 2 45488 1175143

fastest way to use numpy.interp on a 2-D array

不想你离开。 提交于 2019-11-29 21:52:45
问题 I have the following problem. I am trying to find the fastest way to use the interpolation method of numpy on a 2-D array of x-coordinates. import numpy as np xp = [0.0, 0.25, 0.5, 0.75, 1.0] np.random.seed(100) x = np.random.rand(10) fp = np.random.rand(10, 5) So basically, xp would be the x-coordinates of the data points, x would be an array containing the x-coordinates of the values I want to interpolate, and fp would be a 2-D array containing y-coordinates of the datapoints. xp [0.0, 0.25

Speeding up an interpolation exercise

纵然是瞬间 提交于 2019-11-29 15:15:16
问题 I'm running about 45,000 local linear regressions (essentially) on about 1.2 million observations, so I'd appreciate some help trying to speed things up because I'm impatient. I'm basically trying to construct year-by-position wage contracts--the function wage(experience given firm,year,position)--for a bunch of firms. Here's the data (basic structure of) set I'm working with: > wages firm year position exp salary 1: 0007 1996 4 1 20029 2: 0007 1996 4 1 23502 3: 0007 1996 4 1 22105 4: 0007

Moving object from vector A to B in 2d environment with in increments of percents

本小妞迷上赌 提交于 2019-11-29 14:53:56
问题 I know coordinates of vectors A and B. How can I count first point between these two vectors? First vector X is 1% of the distance between vectors A and B. So first I will move object in vector A 1% closer to vector B. So I need to calculate vector X that is new vector for object, until it reaches vector B. 回答1: You want lerping. For reference, the basic formula is: x = A + t * (B - A) Where t is between 0 and 1. (Anything outside that range makes it an extra polation.) Check that x = A when

R: Interpolation of NAs by group

孤街醉人 提交于 2019-11-29 08:20:35
I would like to perform a linear interpolation in a variable of a data frame which takes into account the: 1) time difference between the two points, 2) the moment when the data was taken and 3) the individual taken for measure the variable. For example in the next dataframe: df <- data.frame(time=c(1,2,3,4,5,6,7,1,2,3), Individuals=c(1,1,1,1,1,1,1,2,2,2), Value=c(1, 2, 3, NA, 5, NA, 7, 5, NA, 7)) df I would like to obtain: result <- data.frame(time=c(1,2,3,4,5,6,7,1,2,3), Individuals=c(1,1,1,1,1,1,1,2,2,2), Value=c(1, 2, 3, 4, 5, 6, 7, 5, 5.5, 6)) result I cannot use exclusively the function

Bilinear image interpolation / scaling - A calculation example

北慕城南 提交于 2019-11-29 02:56:44
问题 I would like to ask you about some bilinear interpolation / scaling details. Let's assume that we have this matrix: |100 | 50 | |70 | 20 | This is a 2 x 2 grayscale image. Now, I would like scale it by factor of two and my matrix looks like this: | 100 | f1 | 50 | f2 | | f3 | f4 | f5 | f6 | | 70 | f7 | 20 | f8 | so if we would like to calculate f4 , the calculation is defined as f1 = 100 + 0.5(50 - 100) = 75 f7 = 70 + 0.5(20 - 70) = 45 and now finally: f4 = 75 + 0.5(45 - 75) = 60 However, I

Best way to interpolate values in SQL

寵の児 提交于 2019-11-28 23:30:23
I have a table with rate at certain date : Rates Id | Date | Rate ----+---------------+------- 1 | 01/01/2011 | 4.5 2 | 01/04/2011 | 3.2 3 | 04/06/2011 | 2.4 4 | 30/06/2011 | 5 I want to get the output rate base on a simple linear interpolation. So if I enter 17/06/2011: Date Rate ---------- ----- 01/01/2011 4.5 01/04/2011 3.2 04/06/2011 2.4 17/06/2011 30/06/2011 5.0 the linear interpolation is (5 + 2,4) / 2 = 3,7 Is there a way to do a simple query (SQL Server 2005), or this kind of stuff need to be done in a programmatic way (C#...) ? Something like this (corrected): SELECT CASE WHEN next