Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Last active January 2, 2016 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save primaryobjects/14fdc4efda1a0e24420c to your computer and use it in GitHub Desktop.
Save primaryobjects/14fdc4efda1a0e24420c to your computer and use it in GitHub Desktop.
Neural Network Sort helper method
# See also https://gist.github.com/primaryobjects/5a28e0c27fd433123f1a
# fit: Trained neural network. scaleVal: Original scaled data used in training the network. a, b, c: Numbers to sort.
nnsort <- function(fit, scaleVal, a, b, c) {
numbers <- data.frame(a=a, b=b, c=c, x=0, y=0, z=0)
numbersScaled <- as.data.frame(scale(numbers, attr(scaleVal, 'scaled:center'), attr(scaleVal, 'scaled:scale')))
round(unscale(compute(fit, numbersScaled[,1:3])$net.result, scaleVal))[,4:6]
}
# Example usage:
> nnsort(fit, data, 100, 20, 32)
x y z
20 32 100
> nnsort(fit, data, 37, 6, 4)
x y z
4 6 37
> nnsort(fit, data, 78, 1, 12)
x y z
1 12 78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment