Skip to content

Instantly share code, notes, and snippets.

@bquast
Last active April 23, 2026 14:53
Show Gist options
  • Select an option

  • Save bquast/1ff28491c40ea533093b10d3a49a8daf to your computer and use it in GitHub Desktop.

Select an option

Save bquast/1ff28491c40ea533093b10d3a49a8daf to your computer and use it in GitHub Desktop.
# NN-1-layer.R
# Bastiaan Quast
# [email protected]
# create data
inputs = matrix(c(0,1,1,
1,0,1,
1,0,1,
1,1,0 ), nrow=4, byrow=TRUE)
true_values = matrix(c(0,
1,
1,
1 ),nrow=4)
# initialize weights
weights = matrix(runif(n = 3, min=-1, max=1), nrow=3)
# run through the training data 60,000 times
for (j in 1:60000) {
predictions = plogis(inputs %*%weights)
weights_update = (true_values - predictions) * (predictions*(1-predictions))
weights = weights + t(inputs) %*% weights_update
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment