Skip to main content
added 963 characters in body
Source Link
Sextus Empiricus
  • 86.4k
  • 6
  • 115
  • 301

Example 1

You can not use a general rule of thumb that converts the bandwith for estimating $g(x)$ to a bandwidth for estimating $g'(x)$. The reason is that it depends on the situation and sometimes the bandwidth is ideally larger, other times it is ideally shorter.

The code below demonstrates this with the fit of a sine function. If this is done with quadratic polynomials then it is advantageous to have a shorter bandwidth for the $g'(x)$ estimate. On the other hand, if this is done with cubic polynomials then it is advantageous to have a longer bandwidth for the $g'(x)$ estimate.

example demo

set.seed(1)
library(signal)
k = 10

sim = function(n,p) {
    x = 0:1000
    y = sin(x/1000*k*2*pi)
    dy = cos(x/1000*k*2*pi)/1000*k*2*pi
    z = y+rnorm(length(x),0,0.4)
    yhat = sgolayfilt(z,p,n,0)
    dyhat = sgolayfilt(z,p,n,1)
    c(mean((yhat-y)^2),mean((dyhat-dy)^2))
}
sim = Vectorize(sim)

for (p in c(2,3)){

  type = c("","quadratic polynomial fits", "cubic polynomial fits")[p]

  w = seq(5,201,2)
  x = sim(w,p)

  plot(w,x[1,], log = "y", 
     xlab = "filter length", ylab = "mean squared error", main = paste0(type, "\n function value estimate"))
  plot(w,x[2,], log = "y",
     xlab = "filter length", ylab = "mean squared error", main = paste0(type, "\n derivative estimate"))

}

Example 2

Here's another example that illustrates the complications. Here $g(x)$ is a sum of a quadratic function and a sine wave function. You can see that the behaviour of $g'(x)$ is a lot different from $g(x)$.

  • The derivative $g'(x)$ makes a lot of oscillations and using a large bandwidth would result in a large bias for the estimate of the slope.

  • On the other hand for the function value $g(x)$ the effect of the oscillations in the derivative are less important as they even out, and using a large bandwidth would not result in a large bias for the estimate of the function value.

exampke of problematic function


Conclusion

These examples show that the ideal bandwidth for estimating $g(x)$ might not tell you much about the ideal bandwidth for estimating $g'(x)$. You need some more direct way to estimate the bias variance tradeoff as function of the bandwidth.

You can not use a general rule of thumb that converts the bandwith for estimating $g(x)$ to a bandwidth for estimating $g'(x)$. The reason is that it depends on the situation and sometimes the bandwidth is ideally larger, other times it is ideally shorter.

The code below demonstrates this with the fit of a sine function. If this is done with quadratic polynomials then it is advantageous to have a shorter bandwidth for the $g'(x)$ estimate. On the other hand, if this is done with cubic polynomials then it is advantageous to have a longer bandwidth for the $g'(x)$ estimate.

example demo

set.seed(1)
library(signal)
k = 10

sim = function(n,p) {
    x = 0:1000
    y = sin(x/1000*k*2*pi)
    dy = cos(x/1000*k*2*pi)/1000*k*2*pi
    z = y+rnorm(length(x),0,0.4)
    yhat = sgolayfilt(z,p,n,0)
    dyhat = sgolayfilt(z,p,n,1)
    c(mean((yhat-y)^2),mean((dyhat-dy)^2))
}
sim = Vectorize(sim)

for (p in c(2,3)){

  type = c("","quadratic polynomial fits", "cubic polynomial fits")[p]

  w = seq(5,201,2)
  x = sim(w,p)

  plot(w,x[1,], log = "y", 
     xlab = "filter length", ylab = "mean squared error", main = paste0(type, "\n function value estimate"))
  plot(w,x[2,], log = "y",
     xlab = "filter length", ylab = "mean squared error", main = paste0(type, "\n derivative estimate"))

}

Example 1

You can not use a general rule of thumb that converts the bandwith for estimating $g(x)$ to a bandwidth for estimating $g'(x)$. The reason is that it depends on the situation and sometimes the bandwidth is ideally larger, other times it is ideally shorter.

The code below demonstrates this with the fit of a sine function. If this is done with quadratic polynomials then it is advantageous to have a shorter bandwidth for the $g'(x)$ estimate. On the other hand, if this is done with cubic polynomials then it is advantageous to have a longer bandwidth for the $g'(x)$ estimate.

example demo

set.seed(1)
library(signal)
k = 10

sim = function(n,p) {
    x = 0:1000
    y = sin(x/1000*k*2*pi)
    dy = cos(x/1000*k*2*pi)/1000*k*2*pi
    z = y+rnorm(length(x),0,0.4)
    yhat = sgolayfilt(z,p,n,0)
    dyhat = sgolayfilt(z,p,n,1)
    c(mean((yhat-y)^2),mean((dyhat-dy)^2))
}
sim = Vectorize(sim)

for (p in c(2,3)){

  type = c("","quadratic polynomial fits", "cubic polynomial fits")[p]

  w = seq(5,201,2)
  x = sim(w,p)

  plot(w,x[1,], log = "y", 
     xlab = "filter length", ylab = "mean squared error", main = paste0(type, "\n function value estimate"))
  plot(w,x[2,], log = "y",
     xlab = "filter length", ylab = "mean squared error", main = paste0(type, "\n derivative estimate"))

}

Example 2

Here's another example that illustrates the complications. Here $g(x)$ is a sum of a quadratic function and a sine wave function. You can see that the behaviour of $g'(x)$ is a lot different from $g(x)$.

  • The derivative $g'(x)$ makes a lot of oscillations and using a large bandwidth would result in a large bias for the estimate of the slope.

  • On the other hand for the function value $g(x)$ the effect of the oscillations in the derivative are less important as they even out, and using a large bandwidth would not result in a large bias for the estimate of the function value.

exampke of problematic function


Conclusion

These examples show that the ideal bandwidth for estimating $g(x)$ might not tell you much about the ideal bandwidth for estimating $g'(x)$. You need some more direct way to estimate the bias variance tradeoff as function of the bandwidth.

Source Link
Sextus Empiricus
  • 86.4k
  • 6
  • 115
  • 301

You can not use a general rule of thumb that converts the bandwith for estimating $g(x)$ to a bandwidth for estimating $g'(x)$. The reason is that it depends on the situation and sometimes the bandwidth is ideally larger, other times it is ideally shorter.

The code below demonstrates this with the fit of a sine function. If this is done with quadratic polynomials then it is advantageous to have a shorter bandwidth for the $g'(x)$ estimate. On the other hand, if this is done with cubic polynomials then it is advantageous to have a longer bandwidth for the $g'(x)$ estimate.

example demo

set.seed(1)
library(signal)
k = 10

sim = function(n,p) {
    x = 0:1000
    y = sin(x/1000*k*2*pi)
    dy = cos(x/1000*k*2*pi)/1000*k*2*pi
    z = y+rnorm(length(x),0,0.4)
    yhat = sgolayfilt(z,p,n,0)
    dyhat = sgolayfilt(z,p,n,1)
    c(mean((yhat-y)^2),mean((dyhat-dy)^2))
}
sim = Vectorize(sim)

for (p in c(2,3)){

  type = c("","quadratic polynomial fits", "cubic polynomial fits")[p]

  w = seq(5,201,2)
  x = sim(w,p)

  plot(w,x[1,], log = "y", 
     xlab = "filter length", ylab = "mean squared error", main = paste0(type, "\n function value estimate"))
  plot(w,x[2,], log = "y",
     xlab = "filter length", ylab = "mean squared error", main = paste0(type, "\n derivative estimate"))

}