ADM Blog

Neural networks in ActionScript 3

Neural Network"An artificial neural network (ANN), usually called "neural network" (NN), is a mathematical model or computational model that tries to simulate the structure and/or functional aspects of biological neural networks. It consists of an interconnected group of artificial neurons and processes information using a connectionist approach to computation. In most cases an ANN is an adaptive system that changes its structure based on external or internal information that flows through the network during the learning phase. Neural networks are non-linear statistical data modeling tools. They can be used to model complex relationships between inputs and outputs or to find patterns in data." (Wikipedia)

Multi Layer PerceptronSo, repetition is the mother of all learning they say. You damn right it is. And you can do it in AS3 of course. Not the fastest choice out there but that's not the point. NN's are usually not that fast but they're useful in so many ways.

So, here is my implementation of a neural network multi-layer-perceptron made in AS3, set to learn a simple XOR problem. It uses 2 inputs neurons , 2 hidden layers, each having 2 neurons and one output neuron. It takes about 2 seconds to train it using 10.000 epochs, but then you can save a snapshot of the NN memory as a byteArray, save it to the server and load it back again in an instant without requiring a new training.  I didn't take the time to thoroughly document the classes just yet but I'm sure you'll find them pretty easy to use.

Some reading material: (this is great)

Sources and Download

Comments (0) Trackbacks (0)
  1. Great post! and I have do the same research on AS3 AI programming, did you have any interesting we discuss it?
    Knight.zhou recently posted..BitboardsMy Profile

  2. excellent code-example. We are working an a NN-approach in flex too to recognise patterns of rectangles.
    I will keep you and knight.zhou updated.

    with best regards from germany

    oliver merx

  3. Very nice work!
    I have a problem though. Using this configuration

    var inputNeurons : int = 4;
    var outputNeurons : int = 3;
    var hiddenNeuronsPerLayer : int = 3;
    var hiddenLayers : int = 2;
    var neuronalBias : Number = 1;
    var initialWeightRange : Number = 1;

    patterns.push(new TrainingPattern(“0.40591048,0.387517028,-0.244808193,0.346336001″,”001”));

    the program doesn’t seem to work.
    I just changed this line in
    this.input = inputPattern.split(“,”);

    in order to split the input, which in my case contains commas.


    • a training pattern must contain binary input and binary output.
      if you have a large 64 bit number as input, then you must add 64 inputNeurons and covert your Number to binary and give it like that. a neuron can input either a 0 or a 1 not a decimal number.

  4. Hi!

    I´m really interested in neural networks in actionscript and I was wondering if you could help understand the basis of this example.

    King regards


    • Hi, the second link as reference material at the bottom of the article is extremely nice. My code is based in what I’ve learned from there. After few pages you’ll learn to calculate it all by hand on a piece of paper. If you try and fail give me a shout and I’ll try to explain it myself. Cheers

  5. Hey,

    I think there is an error in the in the function create.
    It creates one Layer less than expected.

    otherwise great example, thanks. I was able to extend it quite easy
    to some simple Number recognition and currently trying to include
    a context Layer to get an Elman net.


Leave a comment

CommentLuv badge


No trackbacks yet.