ahnr
is a package that implements the artificial hydrocarbon networks developed by Hiram Ponce. Most of the work is based on the book Artificial Organic Networks.
Here are some quick examples to get you started.
The following code let's you create the data to train an artificial hydrocarbon network.
library(ahnr) # Create data set.seed(123) x <- 2 * runif(1000) - 1; x <- sort(x) y <- (x < 0.1) * (0.05 * runif(1000) + atan(pi*x)) + (x >= 0.1 & x < 0.6) * (0.05 * runif(1000) + sin(pi*x)) + (x >= 0.6) * (0.05 * runif(1000) + cos(pi*x)) plot(x, y, type = 'l') # Create the Sigma dataset Sigma <- list(X = data.frame(x = x), Y = data.frame(y = y)) # Create network ahn <- fit(Sigma, 4, 0.01, 2000)
The trained network can be used to visualize its performance.
# Create test data X <- data.frame(x = x) # Simulate ysim <- predict(ahn, X) plot(x, y, type = 'l') lines(x, ysim, type = 'l', lty = 2, col = 'red') legend(-1, 1, c('Original', 'Simulation'), col = c(1,2), lty = c(1,2), cex = 0.8)
A summary of the network can be obtained with the summary
command.
summary(ahn)
Finally, the network itself can be visualized with the visualize
command. The text of the carbon of the first molecule is in red.
visualize(ahn)
# Create data set.seed(12321) t <- seq(0, 15, 0.01) X <- data.frame(x1 = cos(t), x2 = t) Y <- data.frame(y = sin(t)) # Create the Sigma dataset Sigma <- list(X = X, Y = Y) # Create network ahn <- fit(Sigma, 5, 0.01, 2000) # Simulate ysim <- predict(ahn, X) plot(t, Y$y, type = 'l', col = 'black', xlab = 't', ylab = 'y') lines(t, ysim, type = 'l', lty = 2, col = 'red') legend(0, -0.5, c('Original', 'Simulation'), col = c(1,2), lty = c(1,2), cex = 0.6)
summary(ahn)
visualize(ahn)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.