📜 ⬆️ ⬇️

Generating Design Ideas with a Genetic Algorithm

I, like many technical people, have difficulties with drawing and graphic solutions in general. Of course, I can tell a beautiful solution from a bad one, but I find myself at a dead end when I need to draw something from scratch, be it the user interface of the application, a presentation or a postcard.
In my last article, I demonstrated how you can use a genetic algorithm to approximate an image according to a given pattern. In this article, I will show how to apply a genetic algorithm to generate images "from the head."




main idea


')
In the last article devoted to the approximation of an image by a set of polygons, we used the similarity of the image being compared to the original as a fitness function. What kind of fitness function to use if the original is missing, and we need to generate something completely new? The answer suggests itself - the level of positive emotions caused by the candidate image.
However, this raises a new question - how to measure it reliably. The simplest approach would be to ask the user to rate the image, but in my opinion it would be too tense for the logical part of the brain, as you would have to think a lot, think 4 or 5, remember what rating you put “that beautiful picture” to keep the hierarchy .
Since the fitness function is used to rank the decisions, sorting them in order of increasing dignity, it is proposed to lower the counting phase of the fitness function and go straight to sorting, using the human brain as a comparator.
Java source code of the application implementing this idea can be found here , the executable code can be downloaded here , JRE or JDK is required to run.
The application functions as follows:
  1. a random image population is generated
  2. images are sorted by the QuickSort algorithm, while a person performs a comparison of the images - a couple of pictures are shown to him and offered to choose the best of two
  3. after the completion of sorting, in accordance with the genetic algorithm, the next generation of pictures is generated by crossing the best representatives of the population
  4. Steps 2 and 3 are repeated endlessly, at any time you can save your favorite image through the context menu

The QuickSort algorithm was slightly modified to reduce the number of mouse clicks needed for a single sorting cycle:
sorting ceases as soon as the 6 best decisions are unambiguously determined that will be used to generate a new generation
the comparison results from previous cycles are cached, and if once a user has already compared some pair of pictures, the next iteration will take the results from the cache

From theory to practice


Abstract image

To begin, let's try to draw an abstract image that will please our eyes. We will build the image as a superposition of five random radial gradients with a transparency of 50%. Each gradient is characterized by a central point, a focal point, a radius, and a set of ten colors that fade into each other.
All these parameters are initiated by random values ​​and undergo an evolution under the influence of the user's taste preferences.
First-generation images usually look something like this:





However, after several generations, the image attractiveness improves many times:





Design clock widget

Consider a more practical example, create a design of virtual clocks that can be used as a widget.
We divide the clock into the following components and determine the parameters that will be subjected to selection.

Widget elementOptions
Housing
  • points describing the polygon, with every second being a control
  • line thickness and color
  • gradient fill options

Clock face
  • radius
  • line thickness and color
  • gradient fill options
  • thickness and color of arrows
  • proportions of the hands on the dial and each other

Big marks (12, 3, 6, 9 hours)
  • distance from center
  • view (dots, dashes, roman numerals, arabic numerals)
  • the size
  • Colour
  • font (if applicable)

Small marks (all others)The same set as the large marks


As in the case of radial gradients, the first generations of watches look like works of avant-garde art:





Over time, under the effect of artificial in every sense of the selection, quite worthy options begin to appear:







Conclusion


Thus demonstrated the practical applicability of the genetic algorithm in the design. The random nature of the algorithm allows you to generate ideas that you wouldn’t think of yourself, and crossing several good decisions over time brings together their best elements.
The described approach can be used for a wide range of design tasks, for example for:

The only inconvenience from my point of view is the need to sort the pictures by pairwise comparison, which, with a population size of 14 pieces, leads to the need to make 15-40 clicks per cycle.
A natural optimization would be the use of a neurocomputer interface like the Emotive EPOC . This would allow to display each picture once with the measurement of the level of positive emotions caused by the image, which in turn would increase the speed of evolution, would increase the size of the population for a wider coverage of the solution space.
image

Source: https://habr.com/ru/post/150966/


All Articles