Genetic Algorithms for Automated Source Code Evolution: a C++11 tutorial

October 31, 2012

Genetic algorithms: a C++ tutorial

Join me in some recreational C++ programming. Our project is to make a genetic algorithm that will evolve the source code for a program that, when run, will compute and output the solution to something. Our target source language is a tiny language called Iota, made specially for this purpose. We’ll also talk about how our simulated evolution compares with natural biology. All you need is a C++11-compliant compiler, and the iota-machine.h header file that you can download from link below. If that sounds at all interesting, then let’s hack up some code…

Video link –>  http://vimeo.com/technotes/iota-genome

Download materials for Windows (.zip format, DOS line endings):

iota-dev-1.0.zip

Download materials for everybody else (.tar.gz format):

iota-dev-1.0.tar.gz

 

New Video! Randomize Properties in Blender

April 16, 2012

Update: New in Blender 2.64 — For randomizing material properties, the new Object Info node and its random number output could be an alternative to the driver technique described in this video.

This tutorial shows how to attach random number drivers to selected properties to make endless variations of an object in Blender 2.62.

Video Link >>>   Variations: Random Number Drivers in Blender

Go from this

a lego-like model in Blender

a lego-like model in Blender

to this

variations of lego-like blocks automatically generated

variations of lego-like blocks automatically generated

I found it easy to work with drivers on object and mesh properties. But I found it surprisingly difficult to get drivers to work on properties in material, texture, and node datablocks. This video will show you the secrets to coercing drivers to work anywhere:

  • learn multiple ways to create a driver; when one method fails, another will work
  • learn how to fix broken drivers after copying an object
  • workflow tips for managing many drivers, objects, and datablocks
This video is for the intermediate Blender user who already feels comfortable with the Blender UI, but no prior experience is expected with drivers or Python scripting. I’ll do my best to show you not just what buttons to click, but why.

 

Here is the copy-n-paste part referred to in the video:
import bpy
import random

# Random floating point number between lo and hi

def randf(lo, hi):
    return random.uniform(lo, hi)

# Random integer from lo (inclusive) to hi (inclusive)

def randi(lo, hi):
    return random.randint(lo, hi)

# Random values given mean and standard deviation

def gauss(mean, stdev):
    return random.gauss(mean, stdev)

bpy.app.driver_namespace["randf"] = randf
bpy.app.driver_namespace["randi"] = randi
bpy.app.driver_namespace["gauss"] = gauss

 

The Straggler

September 21, 2011

Released today! Just for fun — a silly little 30-second-long animated short film titled The Straggler (click the Vimeo link for 720p high-def):

Below is a screenshot of what the butterfly model looks like in Blender. One bone in the armature is a control bone that drives the wing flap movement, and another bone controls the angle of the legs that dangle under the body. I created an action in the action editor for one cycle of wing flap, much like you would animate a walk cycle in a critter that walks, and then spread some flapping actions on the timeline using the non-linear action editor. Each butterfly object is parented to a path object that defines its flight path.

Butterfly and rigging in Blender 2.59

Butterfly and rigging in Blender 2.59

The grass in the video background uses the Blender particle system to define how the clumps of grass will appear. Each grass blade is a simple mesh object, with five different grass blade textures UV-mapped onto a group of five slightly different grass blades. The little bush in the foreground was made and animated using Blender’s Sapling plug-in.

The music was composed using Rosegarden to edit the score and mix the tracks, and Timidity for synthesizing the instruments.

The comment form is disabled because of the amount of spam we’re receiving. To post a comment, send email to dave at millermattson.com.

 

New Video! Slope-dependent Textures in Blender

September 12, 2011

Released today! How to set up slope-dependent textures in Blender 2.59:

Link: http://vimeo.com/28922937

This tutorial shows how to use normal-mapped gradients as layer masks in Blender. It’s a quick way to splash one texture onto the steep surfaces of your model and a different texture onto the more horizontal surfaces. You can use it, for example, to put a rocky cliff texture onto the steep surfaces of a terrain mesh, and a green grassy texture on the less steep parts. In this short tutorial, we’ll use four simple objects to show how the technique works and how to set it up. If you just want the quick summary of the essential settings for the gradient mask, just skip to the final three minutes of the video for the recap. Happy Blending!

The comment form is disabled because of the amount of spam we’re receiving. To post a comment, send email to dave at millermattson.com.

 

“Morning Study” Wallpaper

August 28, 2011

Here’s a new scene I made in Blender just for fun. Feel free to grab a wallpaper-size copy using the direct links below, completely free for non-commercial use under the terms of CC BY-NC-SA 3.0.

"Morning Study", Blender model

1920×1200
1920×1080
1440×900
1280×1024

 

The comment form is disabled because of the amount of spam we’re receiving. To post a comment, send email to dave at millermattson.com.

New Video Tutorial: Intro to C/C++ multicore CPU and GPU programming with OpenMP and OpenCL

June 14, 2011

Released Today! Our newest video tutorial, Intro to C/C++ multicore CPU and GPU programming with OpenMP and OpenCL, is now available for your viewing pleasure at the following link:

Link:  Got Cores? Use ’em!

This is a demonstration and discussion about using OpenMP and OpenCL for writing multicore CPU and GPU programs. This is for the intermediate C/C++ programmer who feels confident writing traditional single-threaded programs, and now wants to know more about the processes and tools that are out there to help in the transition to multicore.

We’ll take a simple little C/C++ program and run it first single-threaded, then adapt it to multicore CPU using OpenMP, then run it on the highly parallel graphics processor (GPU) using OpenCL. The goal is to foster “parallel thinking,” and to give you an idea of what kind of programming effort it takes, and what you can expect as a result.

 

Roll Top Desk Wallpaper

April 4, 2011

I always liked the look of a roll top desk, but never owned one. So I made a model in Blender, rendered an image, and installed it as my desktop wallpaper. Now when I’m sitting at my computer, I’m sitting at the roll top desk I always wanted.

Take a copy if you like — here are direct download links to some common wallpaper sizes. Completely free for non-commercial use under the terms of CC BY-NC-SA 3.0.

1920×1200
1920×1080
1680×1050
1600×1200
1440×900
1280×1024
1280×800

Comments are disabled due to the volume of spam we’re receiving. To post a comment or to get in touch for any reason, email dave at millermattson dot com.

New Video Tutorial: Assembly Language Output from gcc/g++

March 30, 2011

Released Today! Our newest video tutorial, Inspecting the Assembly Language Output from gcc/g++, is now available for your viewing pleasure at the following link:

Link:  Inspecting the Assembly Language Output from gcc/g++

You can look at the assembly language output from the gcc/g++ compiler to see what kind of code the compiler generates for your C++ source without linking or running your code.

For an example to show how the assembler listing can be used, we’ll look at the assembly language generated when compiling the following C++ snippet and try to answer the question, “Does the gcc/g++ compiler apply the Return Value Optimization (RVO) when compiling with optimization level zero (gcc -O0)?”

    class BigClass
    {
    public:
        char a[1000000];
    };

    BigClass getData(int a, int b)
    {
        return BigClass();  // opportunity for RVO
    }

    void testFunction(void)
    {
        BigClass myData = getData(1, 2);
    }

In this 20-minute video tutorial, we’ll discuss:

  • How the Return Value Optimization works
  • How to get an assembly language listing from the compiler
  • How to make sense of mangled names
  • Find where the stack frames are created and local stack space allocated
  • Addressing local data on the stack
  • Function call convention

 

New Video Tutorial: Make a Neural Net Simulator in C++

February 4, 2011

Released today! Our newest video programming tutorial, A Neural Net Simulator in C++, is now available for your viewing pleasure at the following link:

[ Update for 2013: Also see the new companion video for visualizations of how neural nets work and how to train them: The Care and Training of Your Backpropagation Neural Net.  ]

Neural Net in C++ Tutorial from David Miller on Vimeo.

If you’re a beginning to intermediate C++ programmer, this tutorial will guide you through the analysis, design, and coding of a command line console program that implements a neural net in C++. You’ll end up with a classic back propagation model with adjustable gradient descent learning and adjustable momentum. You’ll see how to teach your neural net to solve a simple task, then you can supply your own training data to train your net to do wonderful and amazing things.

Besides showing how a neural net works, we also discuss:

  • C++ class design
  • prototyping with portable C++
  • test early, test often
  • encapsulation, data hiding
  • static class members
  • accessor functions
  • const correctness
  • the assert() macro
  • the vector<> template container, and .size(), .back(), and .push_back() member functions
  • reference variables

This tutorial does not cover or require exception handling, memory management, STL iterators, inheritance, threads, or graphical input or output.

The finished neural net source code is also available for download here (see the video for instructions on what to do with it):

 

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org