Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chelseaparlett/06226442efcb42dfebedf8d30cf05118 to your computer and use it in GitHub Desktop.
Save chelseaparlett/06226442efcb42dfebedf8d30cf05118 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(ggtext)
library(grid)
library(crayon)
title <- "The <b><span style='color:#FF0000'>Sigmoid Function</span></b> and its <b><span style='color:#0000FF'>Derivative</span></b>"
df <- data.frame(x = -5:5)
ggplot(df, aes(x)) +
stat_function(fun = function(x) 1/(1 + exp(-x)),
color = "red", size = 2, alpha = 0.7) +
stat_function(fun = function(x) (1/(1 + exp(-x))) * (1 - (1/(1 + exp(-x)))),
color = "blue", size = 2, alpha = 0.7) +
theme_minimal() +
labs(x = "X", y = "", title = title) +
theme(plot.title = element_markdown())
title <- "The <b><span style='color:#FF0000'>TanH Function</span></b> and its <b><span style='color:#0000FF'>Derivative</span></b>"
f <- function(x) (2/(1 + exp(-2*x)))-1
ggplot(df, aes(x)) +
stat_function(fun = function(x) f(x),
color = "red", size = 2, alpha = 0.7) +
stat_function(fun = function(x) 1- f(x)**2,
color = "blue", size = 2, alpha = 0.7) +
theme_minimal() +
labs(x = "X", y = "", title = title) +
theme(plot.title = element_markdown())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment