sigmoid <- function(x) 1/(1 + exp(-x))
x <- seq(-5, 5, 0.1)
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
plot_ly(type = "scatter", mode = "lines") |>
add_trace(x = x, y = sigmoid(x), name = "Sigmoid")
tanh <- function(x) (exp(x) - exp(-x)) / (exp(x) + exp(-x))
x <- seq(-5, 5, length.out = 100)
plot_ly(type = "scatter", mode = "lines") %>%
add_trace(x = x, y = sigmoid(x), name = "Sigmoid") %>%
add_trace(x = x, y = tanh(x), name = "Tanh")
relu <- function(x) pmax(0, x) # ReLU (rectified linear unit)NAを消して数式を入力すること。
x <- seq(-5, 5, length.out = 100)
plot_ly(type = "scatter", mode = "lines") %>%
add_trace(x = x, y = sigmoid(x), name = "Sigmoid") %>%
add_trace(x = x, y = tanh(x), name = "Tanh") %>%
add_trace(x = x, y = relu(x), name = "ReLU")
softmax <- function(y) {
exp_y <- exp(y - max(y))
exp_y / sum(exp_y)
}
y <- c(-1.0, 0.2, -1.5, 2.0)
xnames <- paste0('y', seq_along(y))
p <- softmax(y)
plot_ly(type = "bar", x = xnames, y = y, name = "入力値 y") |>
add_trace(y = p, name = "Softmax 変換後")
sigmoid <- function(t) 1 / (1 + exp(-t))
x <- c(0.2, 0.3, 0.4)
w <- c(0.3, 0.2, 0.1)
b <- 0.1
t <- sum(w * x) + b
y <- sigmoid(t)
y
## [1] 0.5646363