νƒœκ·Έ 보관물: kernel-smoothing

kernel-smoothing

컀널 밀도 μΆ”μ •κΈ°λ₯Ό 2D에 톡합 의뒰 κ·Έλž˜μ„œ F

아무도이 길을 따라 κ°€κ³  μ‹Άμ–΄ν•˜λŠ” κ²½μš°μ— λŒ€λΉ„ ν•˜μ—¬μ΄ 질문 μ—μ„œ μ™”μŠ΅λ‹ˆλ‹€ .

기본적으둜 λ‚˜λŠ” 각 객체에 주어진 수의 μΈ‘μ • 값이 λΆ™μ–΄μžˆλŠ” N 개의 객체 둜 κ΅¬μ„±λœ 데이터 μ„ΈνŠΈ 을 가지고 μžˆμŠ΅λ‹ˆλ‹€ (이 경우 2 개).

Ξ©

N

Ξ©=o1[x1,y1],o2[x2,y2],...,oN[xN,yN]

IλŠ” ν™•λ₯ μ„ κ²°μ •ν•˜λŠ” 방법이 ν•„μš” μƒˆλ‘œμš΄ 였브젝트 에 μ†ν•˜λŠ” Ξ© IλŠ” ν™•λ₯  밀도 μˆ˜λ“ μ§ˆλ¬Έμ— 의뒰 κ·Έλž˜μ„œ F λ‚΄κ°€ 이미 νŒλ‹¨ 컀널 밀도 μΆ”μ •κΈ° 톡해을 .

p[xp,yp]

Ξ©

f^

제 λͺ©ν‘œλŠ”이 μƒˆλ‘œμš΄ 였브젝트의 ν™•λ₯  (νšλ“ν•˜κΈ° λ•Œλ¬Έμ— 섀정이 2D 데이터에 μ†ν•˜λŠ”) Ω을 , IλŠ” PDF둜 톡합 λ“€μ—ˆλ‹€ Fλ₯Ό β€œμœ„μ— μ§€μ§€μ²΄μ˜ κ°’λ˜λŠ” 밀도 ” κ΄€μ°° ν•œ 것보닀 μ μŠ΅λ‹ˆλ‹€ β€œ. 은 β€œκ΄€μ°°β€λ°€λ„κ°€ fλ₯Ό μƒˆλ‘œμš΄ 객체 평가 (P) , 즉 : F ( X의 P , Y , P ) . λ”°λΌμ„œ 방정식을 ν’€μ–΄μ•Όν•©λ‹ˆλ‹€.

p[xp,yp]

Ξ©

f^

f^

p

f^(xp,yp)

∬x,y:f^(x,y)<f^(xp,yp)f^(x,y)dxdy

λ‚΄ 2D 데이터 μ„ΈνŠΈ (python의 stats.gaussian_kde λͺ¨λ“ˆμ„ 톡해 얻은)의 PDFλŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

여기에 이미지 μ„€λͺ…을 μž…λ ₯ν•˜μ‹­μ‹œμ˜€

μ—¬κΈ°μ„œ λΉ¨κ°„ 점 은 λ‚΄ 데이터 μ„ΈνŠΈμ˜ PDF μœ„μ— 그렀진 μƒˆ 객체 λ‚˜νƒ€λƒ…λ‹ˆλ‹€ .

p[xp,yp]

κ·Έλž˜μ„œ μ§ˆλ¬Έμ€ : pdfκ°€ κ·Έλ ‡κ²Œ 보일 λ•Œ ν•œκ³„ λŒ€ν•΄ μœ„μ˜ 적뢄을 μ–΄λ–»κ²Œ 계산할 수 μžˆμŠ΅λ‹ˆκΉŒ?

x,y:f^(x,y)<f^(xp,yp)

λ”ν•˜λ‹€

의견 쀑 ν•˜λ‚˜μ—μ„œ μ–ΈκΈ‰ ν•œ Monte Carlo 방법이 μ–Όλ§ˆλ‚˜ 잘 μž‘λ™ν•˜λŠ”μ§€ ν™•μΈν•˜κΈ° μœ„ν•΄ λͺ‡ 가지 ν…ŒμŠ€νŠΈλ₯Ό μˆ˜ν–‰ν–ˆμŠ΅λ‹ˆλ‹€. 이것이 λ‚΄κ°€ 얻은 κ²ƒμž…λ‹ˆλ‹€ :

μ € λŒ€μ—­ν­ μ˜μ—­μ˜ 경우 두 λŒ€μ—­ν­μ΄ 거의 λ™μΌν•œ 변동을 λ‚˜νƒ€λ‚΄λŠ” 값이 μ•½κ°„ 더 크게 λ‚˜νƒ€λ‚©λ‹ˆλ‹€. ν‘œμ—μ„œμ˜ κ°€μž₯ 큰 λ³€ν™”λŠ” 차이 μ€€λ‹€ μ‹€λ²„μ˜ VS 2,500 1,000 μƒ˜ν”Œ 값을 비ꡐ 점 (x, y) = (2.4,1.5) λ°œμƒ 0.0126λ˜λŠ” ~1.3%. 제 κ²½μš°μ—λŠ” 이것이 λŒ€λΆ€λΆ„ ν—ˆμš©λ©λ‹ˆλ‹€.

νŽΈμ§‘ : 방금 2 μ°¨μ›μ—μ„œ Scott의 κ·œμΉ™μ΄ 여기에 주어진 μ •μ˜μ— 따라 Silverman의 κ·œμΉ™κ³Ό λ™μΌν•˜λ‹€λŠ” 것을 μ•Œμ•˜ μŠ΅λ‹ˆλ‹€ .



λ‹΅λ³€

κ°„λ‹¨ν•œ 방법은 적뢄 μ˜μ—­μ„ λž˜μŠ€ν„° ν™”ν•˜κ³  적뢄에 λŒ€ν•œ 이산 근사λ₯Ό κ³„μ‚°ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€.

μ£Όμ˜ν•΄μ•Ό ν•  사항이 μžˆμŠ΅λ‹ˆλ‹€.

  1. 포인트의 λ²”μœ„λ³΄λ‹€ 더 λ§Žμ€ 것을 ν¬ν•¨ν•΄μ•Όν•©λ‹ˆλ‹€. 컀널 밀도 μΆ”μ •μΉ˜κ°€ 인식 κ°€λŠ₯ν•œ 값을 κ°€μ§ˆ λͺ¨λ“  μœ„μΉ˜λ₯Ό ν¬ν•¨ν•΄μ•Όν•©λ‹ˆλ‹€. 즉, 포인트의 λ²”μœ„λ₯Ό 컀널 λŒ€μ—­ν­μ˜ 3 ~ 4 배둜 ν™•μž₯ν•΄μ•Όν•©λ‹ˆλ‹€ (κ°€μš°μŠ€ μ»€λ„μ˜ 경우).

  2. λž˜μŠ€ν„°μ˜ 해상도에 따라 κ²°κ³Όκ°€ μ•½κ°„ λ‹€λ₯Ό 수 μžˆμŠ΅λ‹ˆλ‹€. ν•΄μƒλ„λŠ” λŒ€μ—­ν­μ˜ μž‘μ€ λΆ€λΆ„μ΄μ–΄μ•Όν•©λ‹ˆλ‹€. 계산 μ‹œκ°„μ€ λž˜μŠ€ν„°μ˜ μ…€ μˆ˜μ— λΉ„λ‘€ν•˜κΈ° λ•Œλ¬Έμ— μ˜λ„ ν•œ 것보닀 거친 해상도λ₯Ό μ‚¬μš©ν•˜μ—¬ 일련의 계산을 μˆ˜ν–‰ν•˜λŠ” 데 거의 μ‹œκ°„μ΄ 걸리지 μ•ŠμŠ΅λ‹ˆλ‹€. 졜고의 해상도. 그렇지 μ•Šμ€ 경우 더 μ •λ°€ν•œ 해상도가 ν•„μš”ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λ‹€μŒμ€ 256 포인트의 데이터 μ„ΈνŠΈμ— λŒ€ν•œ κ·Έλ¦Όμž…λ‹ˆλ‹€.

ν¬μΈνŠΈλŠ” 두 개의 컀널 밀도 μΆ”μ •μΉ˜μ— 겹쳐진 검은 점으둜 ν‘œμ‹œλ©λ‹ˆλ‹€. 6 개의 큰 적색 점은 μ•Œκ³ λ¦¬μ¦˜μ΄ ν‰κ°€λ˜λŠ” "ν”„λ‘œλΈŒ"μž…λ‹ˆλ‹€. 이것은 1000 x 1000 μ…€μ˜ ν•΄μƒλ„μ—μ„œ 4 개의 λŒ€μ—­ν­ (기본적으둜 1.8 (수직)κ³Ό 3 (μˆ˜ν‰), 1/2, 1, 5 λ‹¨μœ„)에 λŒ€ν•΄ μˆ˜ν–‰λ˜μ—ˆμŠ΅λ‹ˆλ‹€. λ‹€μŒ 산점도 λ§€νŠΈλ¦­μŠ€λŠ” κ²°κ³Όκ°€ 6 가지 ν”„λ‘œλΈŒ 포인트의 λŒ€μ—­ν­μ— μ–Όλ§ˆλ‚˜ κ°•ν•œ 영ν–₯을 λ―ΈμΉ˜λŠ”μ§€λ₯Ό λ³΄μ—¬μ€λ‹ˆλ‹€.

λ³€ν˜•μ€ 두 가지 이유둜 λ°œμƒν•©λ‹ˆλ‹€. λΆ„λͺ…νžˆ 밀도 μΆ”μ •μΉ˜κ°€ λ‹€λ₯΄λ―€λ‘œ ν•œ 가지 ν˜•νƒœμ˜ 변동이 λ°œμƒν•©λ‹ˆλ‹€. 더 μ€‘μš”ν•œ 것은 밀도 μΆ”μ •μΉ˜μ˜ 차이가 단일 ( "ν”„λ‘œλΈŒ") μ§€μ μ—μ„œ 큰 차이λ₯Ό λ§Œλ“€ 수 μžˆλ‹€λŠ” 것 μž…λ‹ˆλ‹€. ν›„μžμ˜ λ³€ν˜•μ€ 점 κ΅°μ§‘μ˜ 쀑간 밀도 "정지"μ£Όμœ„μ—μ„œ κ°€μž₯ ν½λ‹ˆλ‹€.이 계산이 κ°€μž₯ 많이 μ‚¬μš©λ˜λŠ” μœ„μΉ˜μž…λ‹ˆλ‹€.

μ΄λŠ” μ΄λŸ¬ν•œ 계산 κ²°κ³Όλ₯Ό μ‚¬μš©ν•˜κ³  해석 ν•  λ•Œ μƒλ‹Ήν•œμ£Όμ˜κ°€ ν•„μš”ν•˜λ‹€λŠ” 것을 λ³΄μ—¬μ€λ‹ˆλ‹€. μ΄λŠ” μƒλŒ€μ μœΌλ‘œ μž„μ˜μ˜ κ²°μ • (μ‚¬μš©ν•  λŒ€μ—­ν­)에 맀우 민감 ν•  수 있기 λ•Œλ¬Έμž…λ‹ˆλ‹€.


R μ½”λ“œ

이 μ•Œκ³ λ¦¬μ¦˜μ€ 첫 번째 ν•¨μˆ˜μ˜ 6 쀄에 ν¬ν•¨λ˜μ–΄ fμžˆμŠ΅λ‹ˆλ‹€. μ‚¬μš©λ²•μ„ μ„€λͺ…ν•˜κΈ° μœ„ν•΄ λ‚˜λ¨Έμ§€ μ½”λ“œλŠ” μ•žμ˜ 그림을 μƒμ„±ν•©λ‹ˆλ‹€.

library(MASS)     # kde2d
library(spatstat) # im class
f <- function(xy, n, x, y, ...) {
  #
  # Estimate the total where the density does not exceed that at (x,y).
  #
  # `xy` is a 2 by ... array of points.
  # `n`  specifies the numbers of rows and columns to use.
  # `x` and `y` are coordinates of "probe" points.
  # `...` is passed on to `kde2d`.
  #
  # Returns a list:
  #   image:    a raster of the kernel density
  #   integral: the estimates at the probe points.
  #   density:  the estimated densities at the probe points.
  #
  xy.kde <- kde2d(xy[1,], xy[2,], n=n, ...)
  xy.im <- im(t(xy.kde$z), xcol=xy.kde$x, yrow=xy.kde$y) # Allows interpolation $
  z <- interp.im(xy.im, x, y)                            # Densities at the probe points
  c.0 <- sum(xy.kde$z)                                   # Normalization factor $
  i <- sapply(z, function(a) sum(xy.kde$z[xy.kde$z < a])) / c.0
  return(list(image=xy.im, integral=i, density=z))
}
#
# Generate data.
#
n <- 256
set.seed(17)
xy <- matrix(c(rnorm(k <- ceiling(2*n * 0.8), mean=c(6,3), sd=c(3/2, 1)),
               rnorm(2*n-k, mean=c(2,6), sd=1/2)), nrow=2)
#
# Example of using `f`.
#
y.probe <- 1:6
x.probe <- rep(6, length(y.probe))
lims <- c(min(xy[1,])-15, max(xy[1,])+15, min(xy[2,])-15, max(xy[2,]+15))
ex <- f(xy, 200, x.probe, y.probe, lim=lims)
ex$density; ex$integral
#
# Compare the effects of raster resolution and bandwidth.
#
res <- c(8, 40, 200, 1000)
system.time(
  est.0 <- sapply(res,
           function(i) f(xy, i, x.probe, y.probe, lims=lims)$integral))
est.0
system.time(
  est.1 <- sapply(res,
           function(i) f(xy, i, x.probe, y.probe, h=1, lims=lims)$integral))
est.1
system.time(
  est.2 <- sapply(res,
           function(i) f(xy, i, x.probe, y.probe, h=1/2, lims=lims)$integral))
est.2
system.time(
  est.3 <- sapply(res,
           function(i) f(xy, i, x.probe, y.probe, h=5, lims=lims)$integral))
est.3
results <- data.frame(Default=est.0[,4], Hp5=est.2[,4],
                      H1=est.1[,4], H5=est.3[,4])
#
# Compare the integrals at the highest resolution.
#
par(mfrow=c(1,1))
panel <- function(x, y, ...) {
  points(x, y)
  abline(c(0,1), col="Red")
}
pairs(results, lower.panel=panel)
#
# Display two of the density estimates, the data, and the probe points.
#
par(mfrow=c(1,2))
xy.im <- f(xy, 200, x.probe, y.probe, h=0.5)$image
plot(xy.im, main="Bandwidth=1/2", col=terrain.colors(256))
points(t(xy), pch=".", col="Black")
points(x.probe, y.probe, pch=19, col="Red", cex=.5)

xy.im <- f(xy, 200, x.probe, y.probe, h=5)$image
plot(xy.im, main="Bandwidth=5", col=terrain.colors(256))
points(t(xy), pch=".", col="Black")
points(x.probe, y.probe, pch=19, col="Red", cex=.5)

λ‹΅λ³€

μ μ ˆν•œ 수의 κ΄€μΈ‘μΉ˜κ°€μžˆλŠ” 경우 톡합을 μ „ν˜€ μˆ˜ν–‰ν•˜μ§€ μ•Šμ•„λ„λ©λ‹ˆλ‹€. μƒˆλ‘œμš΄ ν¬μΈνŠΈκ°€ . 당신이 밀도 좔정이 κ°€μ • ; λŒ€ν•œ κ΄€μΈ‘μΉ˜ 수 λ₯Ό μš”μ•½ ν•˜κ³  ν‘œλ³Έ 크기둜 λ‚˜λˆ•λ‹ˆλ‹€. 이것은 ν•„μš”ν•œ ν™•λ₯ μ— λŒ€ν•œ κ·Όμ‚¬μΉ˜λ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€.

x0

f^

x

f^(x)<f^(x0)

이것은 κ°€ "λ„ˆλ¬΄ μž‘μ§€ μ•Šλ‹€"κ³  μƒ˜ν”Œ 크기가 저밀도 μ§€μ—­μ—μ„œ μ μ ˆν•œ μΆ”μ •μΉ˜λ₯Ό μ œκ³΅ν•˜κΈ°μ— μΆ©λΆ„νžˆ 크고 (ν™•μ‚° 될 μ •λ„λ‘œ) κ°€μ •ν•©λ‹ˆλ‹€. 이변 λŸ‰ 경우 20000 건이 μΆ©λΆ„νžˆ 컀 λ³΄μž…λ‹ˆλ‹€ .

f^(x0)

x

λ‹΅λ³€