Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Artificial neural network trainer project

Discussion in 'Works In Progress - Archive' started by eaclou, May 31, 2015.

  1. eaclou

    eaclou

    Joined:
    Mar 17, 2015
    Posts:
    53
    Ok, turns out there was a problem with saving/loading of add-ons, so I had to rewrite the way I handled that, but it's working now and I've started hooking the new creatures up to the Trainer module:


    It's still quite rough, but it now supports the new version of Creatures. One of the bigger changes from the old creature set-up is the Add-ons system. Each segment holds a list of modular 'Add-ons' which give it different functionality. The basic types are:
    - External Inputs (like a fixed constant value, timer inputs, or a random noisy signal)
    - Sensors ( tells the 'brain' the current angle position of a joint, whether a segment is touching something, or its orientation/position relative to a target location)
    - Effectors ( active abilities, like Joint Motors, thrusters, grabbers, emit noise, change colors etc.)
    - Physical attributes ( friction, bounciness, color, health, etc.)

    This way, each individual segment can be customized, so you have full control over what kinds of inputs/outputs the creature's brain will have, and which segments have motorized joints or other abilities.

    I'd like to eventually merge the Creature-Builder and Trainer modules together so you can make edits to a creature on-the-fly, but first I think I need to spend some time on the brains themselves. I haven't touched them since the very first prototype, and there's so much room for improvement I think it's time for an upgrade. Right now they're just a static all-to-all direct input-to-output network, with only one kind of activation function (sigmoid). I'd like to implement a more robust brain system that also pays attention to the structure of the creature -- for example, branches (limbs) could be grouped together so neurons within those limbs would be more likely connected to each other than some segment on the other end of the creature that has nothing to do with it, as well as identifying symmetrical features and keeping their neurons similar to each other.
     
    Whiteleaf likes this.
  2. eaclou

    eaclou

    Joined:
    Mar 17, 2015
    Posts:
    53
    Just a small update, I finished hooking up functionality for a bunch of Add-Ons, that I hope will make it possible to create a wide range of creatures/contraptions. I also changed the way I scored performance of the creatures -- previously, I made sure that the scores coming out of the Minigame were normalized to a 0-1 range, by assuming a maximum value. however, this got clunky for things like speed or any other stats that don't have an obvious maximum value. So instead, I store the raw values for each agent and compare them at the end of the generation, normalizing the scores between the top and bottom performers. This way I don't have to worry about what score values come out of the Minigame, it should just work.
    Here are a couple creature experiments so I have something to show:


    Now I think i'm ready to implement a new brain system, which has been long overdue. I'm going to base it on the N.E.A.T. approach ( http://nn.cs.utexas.edu/downloads/papers/stanley.ec02.pdf ) because it looks very well suited to a situation where the topology of the network changes over time, whereas my current approach is completely static. However, I'm going to make a number of modifications to it in order to tailor it to this project. I'm hoping that this will give me a big boost in training performance.
     
  3. sugarbank

    sugarbank

    Joined:
    Aug 27, 2015
    Posts:
    6
    Dude!This looks amazing.Will you ever release this to play around with?Really impressive!evolution neural creatures!
     
  4. eaclou

    eaclou

    Joined:
    Mar 17, 2015
    Posts:
    53
    Thanks! I'm definitely planning on releasing it but i'm still pretty far away from that at the minute -- I'm still just working on the foundational tech. I've been thinking about trying to package up a functional prototype in a couple months after I finish a couple more areas, but it will probably depend a lot on my progress.

    Update:
    Got a version of the new brain-type working -- there are still a number of bugs, but it's mostly functional. I've only implemented random mutation so far (still have to do breeding and species) but whipped up a basic debug visualization of the brains so I can have some clue what's going on inside them in case something's broken:
     
    chelnok likes this.
  5. eaclou

    eaclou

    Joined:
    Mar 17, 2015
    Posts:
    53
    Procrastinated for a little bit and worked on the Brain visualization:


    This weekend i'll go back to integrating the new brain-type by implementing crossover and species, but this was a fun distraction, although I don't want to waste much time at this stage worrying about presentation, since everything is in a lot of flux right now.
     
  6. eaclou

    eaclou

    Joined:
    Mar 17, 2015
    Posts:
    53
    Been a long time since updates, so here's a quick recap of what's new:

    -I finished implementing the new Brain type (based on N.E.A.T), adding support for mutation, crossover, and speciation
    -I implemented Body mutation, so creatures can evolve their segment proportions, add/remove segments, etc. while training, to optimize their body design at the same time as optimizing their brain behavior
    -Re-implemented saving/loading of training sessions
    -Created some macros to modify training settings over time, i.e. slowly ramp-down mutation rate over the course of generations
    -And started diving into GPU programming and rendering tests:



    It's very rough at the minute, but i'm having fun playing around with shaders and the magic of GPU programming. These are just some experiments using procedurally-generated 'particles' as brushstrokes.

    -I implemented a version of 3d marching cubes to build a mesh around the creatures, using a ComputeShader. I create a scalar distance field based on the position and dimensions of each of the creature's segments, and then create a mesh based on that field with the option of further modifying it based on perlin noise or gradients based on segment position (i.e. can taper the front end of each segment). I can then pass that data back to the CPU to create a mesh.
    -Also using a ComputeShader, I determine skin weights for each vertex based on its distance to the creature's segments (the two closest ones in this case) and store those so I can calculate skinning on the GPU in the vertex program of the display shader. This way I can have the mesh follow the movements of the creature - I just have to send the data of each of the creature segment's transforms to the shader.
    -Then I started working with CommandBuffers in order to modify the rendering pipeline. I save the result of the standard rendering of the scene in a renderTexture, then I add a number of passes (using .DrawProcedural()) of 'particles' which can sample the render texture to get the color of the scene at its location.
    -Each particle has size, color, normal, and tangent information so I can orient it with respect to the camera.
    -I also used a simple perlin-noise field to create orientations for the particles, or, in the case of the creatures, I can store normal and tangent information based on the creature segment's size/orientation, so they can 'flow' along the direction of the creature's body.
     
    manpower13, antislash and Arkade like this.
  7. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    i really love what you are doing
     
  8. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Been following this for quite a while now, really cool stuff! You have any video to show of the body mutation? That sounds pretty interesting for sure : )
     
  9. eaclou

    eaclou

    Joined:
    Mar 17, 2015
    Posts:
    53
    Thanks! here's a video I put together today to show an example of body mutation. Right now it's very sensitive to the mutation settings so it can take some fine-tuning in order to get decent results, but it's interesting how you can get pretty different creatures from run to run.

    It also seems very dependent on early breakthroughs (settles on a basic strategy and then refines it), so you can guide the evolution by starting with a basic body template and let it just work on varying that configuration slightly. Speciation has proven almost necessary for body mutation, as it can allow time for new body plans to be tested and optimized -- otherwise they just get discarded right away.

     
    chelnok likes this.
  10. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Haha, that was quite bizarre at places : )
     
  11. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    @eaclou Impressive stuff!

    @neoshaman This looks like a thread you'd be interested in, I thought I should tag you.
     
  12. manpower13

    manpower13

    Joined:
    Dec 22, 2013
    Posts:
    140
    @eaclou Looks really nice, followed this thread from scratch, but it still amazes me ;)
     
  13. eaclou

    eaclou

    Joined:
    Mar 17, 2015
    Posts:
    53
    Thanks guys!

    I've been out of town for a couple weeks but am back now. I'm planning on developing a cleaner, more thought-through implementation of the project at some point in the future, considering I was basically learning programming while developing this so the code is really messy and ugly. With that in mind, I want to start spending more time planning out the next iteration, so I thought this would be a good time to take stock of where the project is now.

    I'll probably release the unity project I have now with source code with the caveat that it is the opposite of user-friendly, and not really appropriate for the general consumer. However, if people want to play around with it I'm going to record a long video(s) with voice-over demonstrating how to use it in its current form. Who knows, maybe I'll get some useful feedback or ideas from the brave souls who want to mess around with it.

    I've updated the first post with an overview and description of the project as it is now, so hopefully it is a little less unintelligible.
     
  14. eaclou

    eaclou

    Joined:
    Mar 17, 2015
    Posts:
    53
    I recorded a sample walkthrough of the project in its current state. These are much longer videos than I normally post but they go into a lot more detail about how to design and then train a creature.

    This was the first time I've tried recording a voiceover for a video recording so it can be a little rough in places (next time I'll hire a famous voiceover actor instead) so apologies for sound quality and some rambling, but hopefully the brave souls who watch them will get a much better sense of how everything works together.





    If you do end up watching them, please let me know what areas were confusing or hard to understand, or any other feedback you feel like sharing. Thanks!
     
  15. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Nothing wrong with the voiceover, might be a bit low but other than that easy to listen to : )
     
  16. eaclou

    eaclou

    Joined:
    Mar 17, 2015
    Posts:
    53
    Here's a video that I recorded a little while ago but didn't post -- It demonstrates how multiple training sessions can produce quite distinct results even when using the same settings.

    In this case, the same 2D quadraped body is used for 4 separate training runs (but using the same settings) and the resultant gaits that were settled on turned out to be quite different and funny:

     
  17. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    I did a night dive a few days ago and saw lots of "stringy" creatures that was looking and swimming exactly as some or the ones you posted, just less blocky ; ) As soon as i saw them it got me thinking about your videos : D
     
  18. LethalPlatypus

    LethalPlatypus

    Joined:
    Sep 6, 2015
    Posts:
    1
    This is really impressive. I've got a similar NEAT unity thing going, but not nearly as far as yours.

    I really like your neural network activation visualization. I wrote a simple layout tool that handles hidden/etc. type nodes and renders them with consistent spacing, etc. Feel free to take a look https://github.com/uneaty/uneaty.visualization (specifically https://github.com/uneaty/uneaty.visualization/blob/master/Assets/Scripts/NeuralNetworkNode.cs has the node layout logic)

    I hope this didn't die.
     
  19. junkomix

    junkomix

    Joined:
    Jul 30, 2018
    Posts:
    1
    Hello. I am recently studying artificial life and I found your amazing works. I feel like you already did what I have in my mind. Do you think I can try your Creature Editor and the Creature Trainer in my project? Or do you have any plan to share your code/scene file/ project? Or I can buy it? Thank you.