Genetic / Evolutionary Algorithm - Artist

My task:

Create a program for copying an image (specified as an input) using only primitives (for example, a triangle or something else). The program should use an evolutionary algorithm to create an output image.


My question is:

I need to invent an algorithm for creating populations and test them (how many - in% - they correspond to the input image). I have a thought; You can find it below.

So what do I want from you: advice (if you find that my idea is not so bad) or inspiration (maybe you have a better idea?)


My idea:

Say that I will only use triangles to create the output image.

My first population is P pictures (generated using T randomly generated triangles - called Elements).

I check my fitness function for every photo in the population and select E from them, as the elite and the rest of the population are simply deleted:

To compare 2 pictures we check every pixel in picture A and compare his R,G,B with the same pixel (the same coordinates) in picture B. I use this: SingleDif = sqrt[ (Ar - Br)^2 + (Ag - Bg)^2 + (Ab - Bb)^2] then i sum all differences (from all pixels) - lets call it SumDif and use: PictureDif = (DifMax - SumDif)/DifMax where DifMax = pictureHeight * pictureWidth * 255*3 

The best ones are used to create the following population as follows:

  picture MakeChild(picture Mother, picture Father) { picture child; for( int i = 0; i < T; ++i ) { j //this is a random number from 0 to 1 - created now if( j < 0.5 ) child.element(i) = Mother.element(i); else child.element(i) = Father.element(i) if( j < some small % ) mutate( child.element(i) ); } return child; } 

So it's pretty simple. Only the mutation needs comment: therefore, there is always a slight chance that the element X in the child will differ from X in its parent. To do this, we make random changes in the element of the child (we change its color by a random number or add a random number to its coordinate (x, y) - or its node).

So this is my idea ... I have not tested it, I have not encoded it. Please check out my idea - what do you think of this?

+6
source share
1 answer

I would make the number of patches of each child dynamic and get a mutation operation to insert / remove patches with some (low) probability. Of course, this can lead to redundancy and bloating in the child’s genome. In these situations, it is usually recommended to use the length of a single genome as a parameter of the fitness function, so that people receive a reward (with a higher fitness value) for using fewer patches. So, for example, if the PictureDifs of individuals A and B are the same, but A has fewer patches than B, then A has higher suitability.

Another problem is the reproductive operator that you proposed (namely, the crossover). For the evolutionary process to work efficiently, you need to achieve a reasonable balance of exploration and exploitation. One way to do this is to have a set of reproductive operators that demonstrate a good fitness correlation [1], which means that the child’s fitness must be close to the suitability of his parent (s).

In the case of single parent playback, you only need to find the correct mutation parameters. However, when it comes to multi-user playback (crossover), one of the most commonly used methods is to create 2 children (instead of 1) from the same 2 parents. For the first child, each gene comes from the mother with a probability of 0.2 and from the father with a probability of 0.8, and for the second child, the opposite. Of course, after the crossover, you can make a mutation.

Oh and one more thing for mutation operators when you say

... make random changes to an element in a child element (change its color to a random number or add a random number to its coordinate (x, y) - or its node)

It is recommended to use a Gaussian distribution to change color, coordinate, etc.

[1] Evolutionary Computing: A Unified Approach by Kenneth A. De Jong, p. 69

+2
source

All Articles