estimated_standard_deviation:rscript02
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| estimated_standard_deviation:rscript02 [2026/03/10 05:27] – created hkimscil | estimated_standard_deviation:rscript02 [2026/03/17 22:58] (current) – hkimscil | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| < | < | ||
| - | # the above no gradient | + | rm(list=ls()) |
| + | rnorm2 <- function(n, | ||
| + | mean+sd*scale(rnorm(n)) | ||
| + | } | ||
| + | |||
| + | # set.seed(191) | ||
| + | nx <- 1000 | ||
| + | mx <- 50 | ||
| + | sdx <- mx * 0.1 | ||
| + | sdx # 5 | ||
| + | x <- rnorm2(nx, mx, sdx) | ||
| + | # x <- rnorm2(1000, | ||
| + | |||
| + | mean(x) | ||
| + | sd(x) | ||
| + | length(x) | ||
| + | hist(x) | ||
| + | |||
| + | # the above no gradient | ||
| gradient <- function(x, v){ | gradient <- function(x, v){ | ||
| residuals = x - v | residuals = x - v | ||
| Line 25: | Line 43: | ||
| msrs <- c() | msrs <- c() | ||
| vs <- c() | vs <- c() | ||
| + | grads <- c() | ||
| msr <- function(x, v) { | msr <- function(x, v) { | ||
| Line 33: | Line 52: | ||
| nlen <- 75 | nlen <- 75 | ||
| for (epoch in 1:nlen) { | for (epoch in 1:nlen) { | ||
| - | residual <- residuals(zx, | + | |
| msr.x <- msr(zx, v) | msr.x <- msr(zx, v) | ||
| msrs <- append(msrs, | msrs <- append(msrs, | ||
| | | ||
| grad <- gradient(zx, | grad <- gradient(zx, | ||
| + | grads <- grad | ||
| step.v <- grad * learning.rate # | step.v <- grad * learning.rate # | ||
| v <- v - step.v # 그 다음 v값 | v <- v - step.v # 그 다음 v값 | ||
| Line 45: | Line 65: | ||
| tail(msrs) | tail(msrs) | ||
| tail(vs) | tail(vs) | ||
| + | tail(grads) | ||
| plot(vs, msrs, type=' | plot(vs, msrs, type=' | ||
| + | plot(vs, grads, type=' | ||
| # scaled | # scaled | ||
estimated_standard_deviation/rscript02.1773120468.txt.gz · Last modified: by hkimscil
