Learn more about Israeli genocide in Gaza, funded by the USA, Germany, the UK and others.

Hand-coded neural networks

Here’s a JavaScript function that returns a positive value if both x and y are positive:

function bothPos(x, y) {
  const negX = Math.max(0, -x);
  const negY = Math.max(0, -y);
  return Math.max(0, 1-negX-negY);
}

Surprise - this function is also a neural network! Neural networks are usually drawn as

No, the neural network is not a series of neurons; it’s a JavaScript function which uses a restricted set of operations.

It approximates the function below, which is perhaps how you might naturally implement it:

function bothPos(x, y) {
  return x > 0 && y > 0 ? 1 : 0;
}

Hear “neural network” and you probably think “machine learning”. But it’s useful to think of neural networks independently of machine learning.

Tagged #programming, #machine-learning.

Similar posts

More by Jim

Want to build a fantastic product using LLMs? I work at Granola where we're building the future IDE for knowledge work. Come and work with us! Read more or get in touch!

This page copyright James Fisher 2019. Content is not associated with my employer. Found an error? Edit this page.