Generating Design Ideas Using a Genetic Algorithm

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




    main idea



    In a previous article on approximating an image with a set of polygons, as a fitness function, we used the similarity of the selected image to the original. What fitness function to use if the original is missing, and we need to create something completely new? The answer suggests itself - the level of positive emotions caused by the image of the candidate.
    However, this raises a new question - how to reliably measure it. The simplest approach would be to ask the user to rate the image, but in my opinion it would strain the logical part of the brain too much, because you would have to think a lot, doubt 4 or 5, remember which rating you put “over that beautiful picture” in order to observe the hierarchy .
    Since the fitness function is used to rank decisions, sort them in order of increasing dignity, it is proposed to omit the phase of calculating the fitness function and proceed immediately to sorting using the human brain as a comparator.
    The source code for a Java application that implements this idea can be found here , executable code can be downloaded here , it requires a JRE or JDK to run .
    The application operates as follows:
    1. random image population is generated
    2. Images are sorted by the QuickSort algorithm, and the person compares the images - he is shown a couple of pictures and is invited to choose the best of the two
    3. after sorting is completed, in accordance with the genetic algorithm, by crossing the best representatives of the population, the next generation of pictures is generated
    4. steps 2 and 3 are repeated endlessly, at any time you can save your favorite image through the context menu

    The QuickSort algorithm has been slightly modified to reduce the number of mouse clicks required for one sorting cycle:
    sorting stops as soon as the 6 best solutions that will be used to generate a new generation are uniquely determined, the
    results of comparisons from previous cycles are cached, and if once the user has already compared which a couple of pictures, at the next iteration, the results will be taken from the cache

    From theory to practice


    Abstract image

    First, let's try to draw an abstract image that will delight our eye. We will build the image as an overlay 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 seamlessly transition into each other.
    All these parameters are initiated by random values ​​and undergo evolution under the influence of taste preferences of the user.
    Images from the first generations usually look something like this:





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





    Widget Clock Design

    Consider a more practical example, create a virtual clock design that can be used as a widget.
    We divide the clock into the following components and determine the parameters that we will select.

    Widget elementParameters
    Housing
    • points describing the polygon, while every second is a control
    • line thickness and color
    • gradient fill options

    Clock face
    • radius
    • line thickness and color
    • gradient fill options
    • arrow thickness and color
    • the proportion of the hands relative to the dial and each other

    Large marks (12, 3, 6, 9 hours)
    • distance from center
    • view (dots, dashes, Roman numerals, Arabic numerals)
    • the size
    • color
    • font (if applicable)

    Small marks (all the rest)The same set as for 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 influence of artificial selection in all senses, quite worthy options begin to appear:







    Conclusion


    Thus, the practical applicability of the genetic algorithm in design is demonstrated. The random nature of the algorithm allows you to generate ideas that would not have occurred to you 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:
    • creating avatars in games or forensics in forensics
    • website creation
    • designing the shape of household items
    • car design

    The only inconvenience from my point of view is the need to sort pictures in pairs by 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 to use a neurocomputer interface like Emotive EPOC . This would make it possible to demonstrate each image once with a measurement of the level of positive emotions caused by the image, which in turn would increase the rate of evolution, would increase the population size for a wider coverage of the decision space.
    image

    Also popular now: