Git Product home page Git Product logo

braincell's Introduction

braincell

An annotated demonstration of a "single-neuron neural network" model, as a teaching/learning tool for the fundamental underpinnings of machine learning.

Articulating the NN in 'atomic' unit form highlights the hierarchy of operations that are performed at the heart of machine learning:

  • "training" and "reasoning"/guessing in a given model,
  • through the adjustment of synaptic weights relative to known-outcome input data,
  • by iteratively calibrating those weights against a sigmoid function (and its derivative, as self-measured error)

Understanding this schematic, but especially the foundational 'lower-level' mathematical process, allows a better understanding of higher-level machine learning concepts of different flavours (be they collocative, adversarial, etc.).


The "puzzle" posed to the 'atomic' NN is simple: a 3x1 matrix (-> 3 in : 1 out 'neuron'), containing elements of either 0 or 1, in which the 'answer' / expected output is simply the first element.

[ 0, 1, 1, 1 ]  # 0

This keeps the problem space simple enough to focus on its mathematical operations (and avoid the 'code noise' of more involved value processing), while letting it be just complex enough to meaningfully display initialisation and training behaviours.

Usage

Depends on numpy.

Running braincell executes an end-to-end demonstration (initialisation, training, and two test cases).

$ python braincell.py

By default, braincell will output verbosely and perform 10,000 iterations (an accuracy:instantaneity sweet spot).

You can optionally supply (in any order) a specific integer-number of iterations, and/or quiet to turn off iteration verbosity:

$ python braincell.py 10 quiet

Random initial synaptic weights:
 [[0.80190343]
 [0.79406162]
 [0.89057025]]

Training for 10 iterations...

Post-training synaptic weights:
 [[ 1.70780518]
 [-0.71665902]
 [-0.23628915]]

Considering new situation: [1, 0, 0] -> ?
[0.84655139] for an expected output of 1.
Result inaccuracy was 15.3449%

Considering new situation: [0, 1, 0] -> ?
[0.32812911] for an expected output of 0.
Result inaccuracy was 32.8129%

You can also call and use the SingleNeuronNetwork class as you please. It can be used as-is for data with the same matrix configuration and value range as the example it is built around.

However, for a use case with different data shape and value range, you will have to manually customise the matrix initialisation (as synaptic weights), matrix processing, and potentially how the sigmoid function normalises values. But, that amounts to taking the theory learned here, and applying it to a new problem space!

braincell's People

Contributors

oaao avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.