Menu

A neural network for a > 4, written by hand
📰

A neural network for a > 4, written by hand

DEV Community: rust·Sharang Parnerkar·5 days ago
#qhdGKywx
#devtorust#devto#dev#relu#flag
Reading 0:00
15s threshold

Let's start with a small program, where a is a whole number from 0 through 100:

let result = if a > 4 { 10 } else { 12 };

Enter fullscreen mode

Exit fullscreen mode

We're going to build a neural network that gives the same result for those 101 inputs. Neural networks are usually trained, which means their numbers are learned from examples. We won't train anything. We'll construct the numbers directly from the program.

The construction comes from Cheng Lou's handwired , a JavaScript project that turns ordinary code into neural-network operations, and this same comparison is the first example in its README. I ported handwired to Rust as handwired-rs , which this series uses.

Why would anyone want this? Not for speed: three arithmetic steps in place of one if is not a better way to write an if , and this post only demonstrates the mechanism.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.