Building a Neuron

20190529

I once was forced to take an organic chemistry class. I've tried to block it out. So instead of building a neuron in a test tube, I will use C++. It's a lot less messy and smelly.

We see that neurons are analog computers. We want to build them using digital computers. That means we need to write some code to simulate the analog behavior. We may decide to modify it in the future, but let's get started with something. The functions are fairly simple and straightforward, but we need to keep an eye on efficiency; we're going to need a lot of these things.

Let's start with a Neuron class. Each neuron will need some input synapses, but the number will vary. So let's use a std::vector for those. We also need a threshold value. To show off my cleverness, I will call that variable "threshold." The output is a little bit tricky. Since a biological brain works in parallel it can fire the neurons whenever needed and know that the receiving neurons will get the pulse. But we have to step through all our neurons in some order and decide if they fire or not. Deciding if a neuron fires depends on the outputs of numerous other neurons outputs that may or may not have been calculated yet. So what we will do is store the calculated output. We can step through all the neurons, calculating their outputs from a current set of stored inputs. Once all the new values are calculated from the old, stored values, we make a second pass and update the outputs for the next round. Since I'm really creative, I will call these two variables "newOutput" and "oldOutput."

This is what our class definition looks like so far:

  #include 
  #include "Synapse.h"

  class Neuron
  {
  private:
    std::vector synapses;
    float threshold;
    bool newOutput;
    bool oldOutput;

  };
  
So now we have our Neuron class defined, with the data it needs. But we can't do anything with it since all the data is private and there are no methods. We will take care of that shortly.

Now let's create a class for synapses. Each synapse will need a weight and a place to store its current value. Really straining my creative abilities I named those "weight" and "value."

    class Synapse
    {
    private:
      float weight;
      float value;
    };
  


Previous Contents Next

Small Time Electronics

Your Source for Custom Electronics, Projects, and Information




© 2019 William R Cooke