sigmoid <- function(x) 1/(1 + exp(-x))

x <- seq(-5, 5, 0.1)
library(plotly)
##  要求されたパッケージ ggplot2 をロード中です
## 
##  次のパッケージを付け加えます: 'plotly'
##  以下のオブジェクトは 'package:ggplot2' からマスクされています:
## 
##     last_plot
##  以下のオブジェクトは 'package:stats' からマスクされています:
## 
##     filter
##  以下のオブジェクトは 'package:graphics' からマスクされています:
## 
##     layout
plot_ly(type = "scatter", mode = "lines") |>
  add_trace(x = x, y = sigmoid(x), name = "Sigmoid")
sigmoid <- function(x) {
  return(1 / (1 + exp(-x)))
}

tanh_custom <- function(x) {
  return((exp(x) - exp(-x)) / (exp(x) + exp(-x)))
}

x <- seq(-5, 5, by = 0.1)

library(plotly)

plot_ly(type = "scatter", mode = "lines") |>
  add_trace(x = x, y = sigmoid(x), name = "Sigmoid") |>
  add_trace(x = x, y = tanh_custom(x), name = "Tanh")
relu <- function(x) pmax(0, x)

tanh <- function(x) (exp(x) - exp(-x)) / (exp(x) + exp(-x))

sigmoid <- function(x) 1/(1 + exp(-x))

x <- seq(-5, 5, by = 0.1)

library(plotly)
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) / sum(exp(y))

y <- c(-1.0, 0.2, -1.5, 2.0)
xnames <- paste0('y', seq_along(y))

p <- softmax(y)

sum_p <- sum(p)

library(plotly)
plot_ly(type = "bar", x = xnames, y = y, name = "入力値 y") |>
  add_trace(y = p, name = "Softmax 変換後")
print(paste("確率 p の合計値:", sum_p))
## [1] "確率 p の合計値: 1"
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(x * w) + b

output <- sigmoid(t)

threshold <- 0.5
is_activated <- output > threshold

cat("合計入力 t:", t, "\n")
## 合計入力 t: 0.26
cat("シグモイド出力:", output, "\n")
## シグモイド出力: 0.5646363
cat("ニューロンは活性化するか:", is_activated, "\n")
## ニューロンは活性化するか: TRUE