Shop OBEX P1 Docs P2 Docs Learn Events
Artificial neural net on a prop? — Parallax Forums

Artificial neural net on a prop?

Hey all,

Ive been gone a while, putting software on hold while I'm working on a robot base for my next propeller project. I'm working on a simple walking bugbot with a "peripheral nervous system" that would handle basic functions, like moving the legs correctly, to leave higher-level functions to be handled by a prop/other mcu, like deciding where to go, in a horse-and-rider configuration. If you're interested I'm using BEAM nervous nets for those low-level functions.

Anyway, I'm still not done with the base (I thoroughly melted a micro servo the other day trying to solder a five-wire cable onto the motor and potentiometer leads lol) but once I've gotten it working the ultimate goal was to have a prop brain controlling it, which might be able to learn or at least give it some kind of bug-like intelligence. Which brings me to my question here... has anyone tried making a neural net on the propeller? I don't mean a feedforward perceptron chain, I mean an actual, biologically-inspired spiking neural net with feedback and connections between neurons that can be individually strengthened or weakened...

Has anyone attempted something like this? I saw humanoido's horribly expensive big brain thing, but did anyone actually program the beast? Has anyone made a neural net, regardless of type, actually run on the prop?

Thanks everyone!!!ļ

:D

Comments

  • MJBMJB Posts: 1,235
    m00tykins wrote: »
    If you're interested I'm using BEAM nervous nets for those low-level functions.

    Has anyone attempted something like this? I saw humanoido's horribly expensive big brain thing, but did anyone actually program the beast? Has anyone made a neural net, regardless of type, actually run on the prop?
    Braitenberg was head of the institute of biological cybernetic in the town I lived. And I studied technical Cybernetics ...

    so yes - tell a bit more on how you use BEAM

    what size of NW and what update rate do you envision?
    Implementing straight forward NW as an integer simulation should not be complicated.
    You want something to be able to train or learn from experience?
    By dynamically adjusting the connection factors?
    Fastest would be to write the core in PASM.
    But we could easily start with a simulation e.g.in TACHYON since it is interactive,
    nice to play.

  • BEAM is very basic neural networking tech, and actually even calling it a neural network is stretching it greatly. Each "neuron" is just a schmidt-triggered not gate, a resistor, and a capacitor. Here is a link explaining what I'm talking about.

    Anyway, back to the prop: I'd like to get it to learn, yes, possibly using things like charge status and acceleration for "pain"/"pleasure".

    As for the technical implementation, I'm thinking something similar to a cellular automaton, where neurons can only connect to their nearest neighbours. And as you might already be able to tell, I don't mind greatly over-simplifying biology, so a simple addition of inputs, with inhibitory inputs being negative numbers and excitatory being positive, would work fine. And a network in the 10-100 neuron range is my current complexity estimate.

    However, none of this is set in stone, and the main point here was just to see what anyone else has *already* done, and what suggestions other more experienced experimenters (such as yourself) might give. :D


    PS: Sorry about the belated response, I'm moving at the moment... you know how it is :P
  • Maybe this is worth a look?

    http://www.movidius.com/solutions/machine-vision-algorithms/machine-learning

    "The world's first discrete deep learning accelerator. A standalone, ultra-low power neural network compute accelerator inside a standard USB stick. See it first at the Embedded Vision Summit in Santa Clara, CA, May 2-4."
  • Heater.Heater. Posts: 21,230
    m00tykins,
    BEAM is very basic neural networking tech, and actually even calling it a neural network is stretching it greatly. Each "neuron" is just a schmidt-triggered not gate, a resistor, and a capacitor
    Oh yeah. Back in 1971 or there abouts Wireless World magazine, I think it was, ran a construction article about a learning robot called "Cybernetic Cynthia".

    Cynthia was a robotic snail that would retract her head into her shell if you touched her shell.

    But, if you touched her shell frequently she would "learn" that you are friendly and not retract her head so much.

    But then after a time of no such affection she would forget, and retract her head again if you touched her shell.

    Of course Cynthia's "learning" was just the charging of a capacitor when she was touched, which eventually inhibited the head retraction response. The capacitor then discharged if there was no touch input and she was back in "panic mode".

    It's amazing what complicated behaviours you can get out of really simple circuitry.
  • ErNaErNa Posts: 1,752
    and snails have no gender ! Like capacitors.
  • Heater.Heater. Posts: 21,230
    edited 2016-04-30 04:36
    Not all snails are hermaphrodite.

    Cybernetic Cynthia was a robot. Therefore a machine. Machines are traditionally female. Like ships and trains and such.

    My father was Czechoslovakian. I never learned the Czech language. When he spoke English, even after thirty years in England, everything was a "he" or a "she". I never managed to figure out by which rules inanimate objects were one or the other.

    In Finland all people are "han". No way to tell female from male.

    It's all very confusing. Especially as it seems that now a days half the humans don't know what gender they are.

  • evanhevanh Posts: 15,916
    Lol, "now a days"! Heh, I know what mean even if it reads badly.
  • m00tykinsm00tykins Posts: 73
    edited 2016-04-30 14:41
    KeithE wrote: »
    Maybe this is worth a look?

    http://www.movidius.com/solutions/machine-vision-algorithms/machine-learning

    "The world's first discrete deep learning accelerator. A standalone, ultra-low power neural network compute accelerator inside a standard USB stick. See it first at the Embedded Vision Summit in Santa Clara, CA, May 2-4."

    Whoa whoa whoa... Deep learning? Machine vision? Heck no... I'm not making an AI. Its more like Alife. A robot with self-sustaining and adaptive behavior. I don't need it solvin no rubiks cubes. Though multi-core CPUs are great at simple parallel AI/Alife tasks, like genetic algorithms, neural nets, cellular automata and the like.

    Has *nobody* ever tried to make a neural net or any sort of Alife or AI algorithm on the prop? I'm sure someone must at least have made a chatterbot on the prop somewhere...
  • Well, just for the fun of it, I tried attached NN on the Propeller a few years ago (not written or modified by me). It runs completely ok, the speed is...well, probably similar as when I first tried NN's on a 80286 PC.
    In addition I've played with NN's trained on my PC with FAST 2.2 which can generate C-code for the forward pass, example below.
    Have had some thoughts about using this on a ActivityBot with Ping-sensor and/or PropCam to use for navigation, but never really got to it yet.
    BTW It's a pity there's no C-code around for the PropCam (at least that I'm aware of), and mixing Spin and C is not completely straightforward. I have tried both spin2cpp and the spinwrap(?) software but not been been able to get working C-code out of the Spin-code available for PropCam. Less complex Spin-code has typically been ok though.
    
    /*
     *	Blitz code automatically generated by FAST 2.2  non commercial version
     *	Copyright (C) 1992-1996 FORWISS
     */
    #include "simpletools.h"                      // Include simple tools
    
    //#include <math.h>
    
    /*
     *	The weight structure.
     */
    static
    double	w15[] = {-1.76439217569209217, 4.36655452850454662, -11.3117272562388838, -9.37427108798744513, -29.4078007009266571, -18.5223376582524786, 6.45096018259041948, 26.2388557711265804, 6.46568629936442285, -6.75966207311477696, 4.08479886555948735, 2.36226483038759705, 8.50299049245871608, 7.27735365947193014, 2.2739673298444214},
    	w16[] = {-1.31992264001845827, -1.58720059401754954, 0.848603000349898995, 3.90310246078035172, -2.09592608613605869, -25.4699384652474663, 56.6889408755262565, -4.29941618036481454, -7.03395248024147524, 2.18067001280658701, -3.14260925809004288, -3.85712840069556329, -4.9113637822143783, -5.73307815017128153, 1.29634208970550846, -44.4942781332239363},
    	w17[] = {-1.41296110051775847, 1.31977793407398702, 4.09866343529573562, -17.9658116840301432, -16.4185189661750499, -1.46948699107381531, -39.192575913971389, -0.618829815774730396, -13.5675297563166968, -3.24656954273167209, 2.15653717532002087, 5.92618095491581798, 8.17915777985496639, 18.8458509387887432, 6.18235754905518231, -3.33818074282762822, -321.892254482791373},
    	w18[] = {-0.77789036118103172, -37.1628926734991509, -23.1450118552167226, 36.8813261839518631, -1.06689420791099443, -4.47770728741859525, 7.56615357679745237, -69.1867969558394691, -4.26823064078741421, 3.24645698260155013, -1.08697121988778256, -0.60045335703138214, 3.43956927446230232, 2.17119925103739808, 17.1128642586300224, 2.99718756939850595, 12.1010993595605463, -41.8223047907395298},
    	w19[] = {-1.04391164564813477, 0.897955112539973621, -0.41308174864083741, -3.12249718656932185, -1.80675634732110546, -1.69317849296573208, -7.17427465015291776, 23.823048865136002, -0.587995100989109232, 9.81662631390788931, -0.364431013148058924, -5.92715280929956112, -6.3026737580805845, -7.18605510169200645, 7.68198049239150915, -24.3277432409729286, -309.476557343361833, -79.0195823053530546, 13.6408446962576164},
    	w20[] = {-1.97257352454982859, -14.6913682057888106, -28.7658692939317859, -0.105035334301648187, -2.24607361264450844, -1.40381354149974569, 5.65250841710503504, 2.00486631332504306, 2.33256893303225432, 18.6829560921897055, -2.39620661046483985, -17.1773946294951969, 2.5501745764071817, 1.20224087733394303, -4.92172347566849488, -1.82198917090247225, 12.7958639307729456, -124.747241667667666, -3.5335440355885277, -195.471738042602794},
    	w21[] = {-0.571483202292439096, -7.21206607335472327, -7.38822570357443187, 23.3722316411261239, -10.0834892154476883, -10.4292622140911622, -1.66932952983514604, -1.81897975881370955, 23.1416847821382845, 2.25172470646672007, -1.8864430846787017, -9.92037337613828818, 4.43831650863079652, 6.79122657134336816, -8.84426905738105695, -25.3499633153223591, -187.501484594728112, -3.40998290112695113, 31.074756730636917, -76.2226722703540389, 10.5975022180880103},
    	w22[] = {-1.22654642907929756, -20.4591376798609978, -71.7717867914711718, -10.6196023838621425, -2.16094475402937425, -1.63918076629151255, -4.69129230612938741, 3.27101468580981036, 19.6350791606198172, 12.8199593012195301, -3.75978738692761238, -4.45020130257761437, 0.19414133283818108, -0.920299705790132649, -1.59483739719514284, -9.34482726540556818, 4.80333183524316176, 3.82553667144481446, 88.2198056247006406, -418.32382372956755, -20.7453778072688344, -344.632020908201298},
    	w23[] = {-1.94493317254909748, -5.92948979912377983, -14.9513194510343563, 34.4144283554285693, -3.2065515561458886, -2.93545540712164543, 6.76294288308377478, -2.56186419548808519, -58.9588478856443245, -0.621602731171416845, -2.02011848033354768, 18.9001351896851979, 1.02879983702377831, 2.01034914332217429, -6.96560402162603509, 2.31415271628681651, -14.643555936344109, -40.5859942335007489, 9.45340618769235874, -157.175182938642081, 3.64173182664346573, -102.348832576660385, 16.2836993342208807},
    	w24[] = {-1.82639201736359214, -2.71565411649468258, -2.2809150416224635, 21.9461119913414819, -3.38409434125579445, -3.34973896998064369, -3.88833311798351389, -4.04033072610577459, -2.56754410385841858, -21.072761440642708, -4.23382349177014916, -4.50347766771707292, -2.26329628366720481, -3.39902195096491688, -1.13472610005023378, -2.63934699176746168, -35.3851648365492721, -3.03392779536778878, 33.67815795854154, 4.71409993129072014, 47.0915419914092865, 46.5624657691955335, -94.3453562620691031, 6.57895247560344298},
    	w25[] = {-1.95893791661169714, -9.95355331337967364, -5.60414242792089556, 20.0702646215405842, -6.994930506496984, -6.8000595799664767, -0.882437168532628546, -0.61612090754506077, 0.165907998873694451, 8.00326916302357816, -0.154290971395221993, 29.7256386296654718, 0.683826210752388142, 1.93407551104286668, -30.5972445974423657, 1.83240590175459528, -434.918515277524705, -15.8880697544712142, 38.1734487295137939, -28.5032260842813869, -249.874714698287988, -389.053484338546298, -128.154692363437334, -350.126454224481108, -435.350699300619624},
    	w26[] = {-3.19666761919332876, -15.0495452420931084, -5.25558094840276624, -2.56576334147915075, -2.36086346135244263, -3.11638643323744624, -4.61184001926648168, -4.35922194247911676, 54.8717106039221605, -13.2369141351520199, 5.18657213943978679, -23.4792271311481038, -3.68184832122814409, -2.93708889505667692, -2.52495664630229522, 5.4128272656912122, -0.373045201647264291, -14.2531181568207064, -23.0026043569851346, -57.3208378857423071, 26.2104609898941163, 492.847731298316546, -14.3174334604941507, -723.542687901729096, -701.252413004186678, 18.035183498016945},
    	w27[] = {-2.49871573852247586, -0.347081866458399169, -1.61644482942880363, 13.7335843411561243, -2.12214533927868443, -2.67479351806347676, -3.92698536283594102, -3.37654507423813044, -3.71799959185617013, -0.079235968443710558, -2.18124305324618994, 34.9583553793775295, -2.19594028855178358, -2.91562741809295423, -4.69707180603225982, 1.13950572026730113, -205.818914519590948, -411.551596343400092, -63.1159131827128661, -321.926342423452866, -448.836136917679539, -85.8051408467330674, -464.75699993619412, -34.1085955694112641, -153.545996113568719, -116.198628282105247, -418.254458275323373},
    	w28[] = {-1.16078261032378593, 1.76084005572965019, 2.30701118751179557, 2.35031435298307967, -4.6790565015348573, -3.46047778866261213, -0.350709466180242235, -0.28942985936787341, 0.414067345956427357, 0.26110156123013345, 0.121000495385348808, -0.021313977110797015, 1.14245458749702866, 0.935562597890360004, 0.467875587996214259, 0.287576976722421163, -0.310133372001687391, 0.942966334538302475, -0.594368275981936534, -0.133173440023598405, 0.22414599018279785, 1.42703515202280884, 0.050445503706386313, 0.102950207235936855, -1.81589438335429532, -0.026835893479888691, -0.718873012649628884, -0.024914735574642952},
    /*
     *	Hidden unit outputs.
     */
    	Outputs[27];
    
    void	forward_pass(double *input, double *output);
    static	double	sum(double *weight, int cnt);
    
    /*
     *	Call this function with the allocated input and output vectors.
     */
    void
    forward_pass(double *input, double *output)
    {
    	int	i;
    
    	for (i=0; i<14; i++)
    		Outputs[i] = input[i];
    	Outputs[14] = sum(w15, 14);
    	Outputs[15] = sum(w16, 15);
    	Outputs[16] = sum(w17, 16);
    	Outputs[17] = sum(w18, 17);
    	Outputs[18] = sum(w19, 18);
    	Outputs[19] = sum(w20, 19);
    	Outputs[20] = sum(w21, 20);
    	Outputs[21] = sum(w22, 21);
    	Outputs[22] = sum(w23, 22);
    	Outputs[23] = sum(w24, 23);
    	Outputs[24] = sum(w25, 24);
    	Outputs[25] = sum(w26, 25);
    	Outputs[26] = sum(w27, 26);
    	output[0] = sum(w28, 27);
    }
    
    /*
     *	Sums the incoming activations for one neuron and runs the sum
     *	through an activation function.
     */
    static
    double
    sum(double *weight, int cnt)
    {
    	double	sum;
    
    	sum = weight[0];	/* Bias Unit */
    	do {
    		sum += Outputs[cnt-1] * weight[cnt];
    		cnt--;
    	} while (cnt > 0);
    	return 1.0 / (1.0 + exp(-sum));
    }
    
    
    int main()                                    // Main function
    {
      // Add startup code here.
      int i;
    //  double test;
    
    //  test = 2.2;
    //  print ("%f", tanh(test));
        double to[1];
    
      for (i = 0; i < 10; i++)
      {
        double ti[] = {0.217, 0.217, 0.216, 0.116, 0.113, 0.112, 0.116, 0.116, 0.117, 0.117, 0.222, 0.181, 0.156, 0.156};
        forward_pass(ti, to);
        printf ("%f \n", to[0]);
    
      }
    }
    
    
    c
  • banjo wrote: »
    BTW It's a pity there's no C-code around for the PropCam (at least that I'm aware of), and mixing Spin and C is not completely straightforward. I have tried both spin2cpp and the spinwrap(?) software but not been been able to get working C-code out of the Spin-code available for PropCam. Less complex Spin-code has typically been ok though.

    A new version of spin2cpp has been released, and there is a an interactive program now, too. I've used that in the past few days, converting OBEX Spin programs to C without any difficulty.

    forums.parallax.com/discussion/164102/compiling-a-spin-program-on-the-pc
  • banjo wrote: »
    Well, just for the fun of it, I tried attached NN on the Propeller a few years ago (not written or modified by me). It runs completely ok, the speed is...well, probably similar as when I first tried NN's on a 80286 PC.

    That looks like a feedforward neural net. So not really what I'm looking for, but a good start. I'll be using that code as a reference.
  • 78rpm wrote: »
    banjo wrote: »
    BTW It's a pity there's no C-code around for the PropCam (at least that I'm aware of), and mixing Spin and C is not completely straightforward. I have tried both spin2cpp and the spinwrap(?) software but not been been able to get working C-code out of the Spin-code available for PropCam. Less complex Spin-code has typically been ok though.

    A new version of spin2cpp has been released, and there is a an interactive program now, too. I've used that in the past few days, converting OBEX Spin programs to C without any difficulty.

    forums.parallax.com/discussion/164102/compiling-a-spin-program-on-the-pc

    Great, I'll take a look at it, thx for notifying me.

  • m00tykins wrote: »
    banjo wrote: »
    Well, just for the fun of it, I tried attached NN on the Propeller a few years ago (not written or modified by me). It runs completely ok, the speed is...well, probably similar as when I first tried NN's on a 80286 PC.

    That looks like a feedforward neural net. So not really what I'm looking for, but a good start. I'll be using that code as a reference.

    The embedded code is indeed only the forward pass, i.e. 'run time code'. The back-propagation training happened on a PC with the FAST tool and then C-code was generated once the training met the preset goal. The run time code is then run on a Propeller.

    The attached code again is a back-propagation NN where also the training can be done - albeit slowly - on a Propeller
  • @banjo

    The problem is, that neural net is nothing like biology. Even worms don't use a feedforward neural net with backpropagation :P

    The most biologically-realistic, simple "neural net" I've found is Brian's Brain/other miscellaneous cellular automata. By restricting cells to a moore/von neumann neighborhood you can implement neural nets with feedback *without* enormous overhead.

    But, I'm starting to think the propeller might not be the best fit for this. Sure, it comes with 8 cpus, but I need lots of low-performance CPUs more than I need 8 big ones.

    Maybe using 16/32 picaxe 08m2 cpus would work better for my purposes. They're tiny, easily programmed, and can all fit reasonably well on a single piece of perfboard. And inter-processor communication isn't a big concern since using cellular automata means each cpu would only need to communicate with 4/6/8 other cpus at most.

    Also, @MJB I'm still looking forward to your input :)
  • MJBMJB Posts: 1,235
    m00tykins wrote: »
    @banjo

    But, I'm starting to think the propeller might not be the best fit for this. Sure, it comes with 8 cpus, but I need lots of low-performance CPUs more than I need 8 big ones.

    Maybe using 16/32 picaxe 08m2 cpus would work better for my purposes. They're tiny, easily programmed, and can all fit reasonably well on a single piece of perfboard. And inter-processor communication isn't a big concern since using cellular automata means each cpu would only need to communicate with 4/6/8 other cpus at most.

    Also, @MJB I'm still looking forward to your input :)
    I don't understand why you would want a lot of simple physical processors, if you can 'virtualize' the functionality in a single faster processor - especilly iff it comes with 8 cores.

  • Since each neuron needs to run in parallel with the other neurons and since the prop doesn't offer multitasking more than 8 "threads" at once, I think it would make more sense to use 8 different smaller processors instead of having to deal with hub/other bottlenecks
  • kwinnkwinn Posts: 8,697
    m00tykins wrote: »
    Since each neuron needs to run in parallel with the other neurons and since the prop doesn't offer multitasking more than 8 "threads" at once, I think it would make more sense to use 8 different smaller processors instead of having to deal with hub/other bottlenecks

    I don't get your thinking here. Wouldn't you have exactly the same problems with 8 smaller processors on top of having to add software (and possibly hardware) for them to communicate with each other?
  • MJBMJB Posts: 1,235
    m00tykins wrote: »
    Since each neuron needs to run in parallel with the other neurons and since the prop doesn't offer multitasking more than 8 "threads" at once, I think it would make more sense to use 8 different smaller processors instead of having to deal with hub/other bottlenecks
    you just need to define the update rate you want to run and the calculations needed and then this can be run
    on whatever hardware setup is fast enough.
    If you have a ms update rate you can run lots of processing in between on 8 x 80MHz 32-bit COGs. Slow 8-bitters will probably not give you a lot of benefit.


Sign In or Register to comment.