kb/data/en.wikipedia.org/wiki/Fly_algorithm-2.md

8.3 KiB
Raw Blame History

title chunk source category tags date_saved instance
Fly algorithm 3/3 https://en.wikipedia.org/wiki/Fly_algorithm reference science, encyclopedia 2026-05-05T09:57:41.802183+00:00 kb-cron

algorithm fly-algorithm is input: number of flies (N), input projection data (preference)

output: the fly population (F), 
        the projections estimated from F (pestimated)
        the 3-D volume corresponding to the voxelisation of F (VF)

postcondition: the difference between pestimated and preference is minimal.

START
  1. // Initialisation
  2. // Set the position of the N flies, i.e. create initial guess
  3. for each fly i in fly population F do
  4.   F(i)x ← random(0, 1)
    
  5.   F(i)y ← random(0, 1)
    
  6.   F(i)z ← random(0, 1)
    
  7.   Add F(i)'s projection in pestimated
    
  8. // Compute the population's performance (i.e. the global fitness)
  9. Gfitness(F) ← Errormetrics(preference, pestimated)
  10. fkill ← Select a random fly of F
  11. Remove fkill's contribution from pestimated
  12. // Compute the population's performance without fkill
  13. Gfitness(F-{fkill}) ← Errormetrics(preference, pestimated)
  14. // Compare the performances, i.e. compute the fly's local fitness
  15. Lfitness(fkill) ← Gfitness(F-{fkill}) - Gfitness(F)
  16. If the local fitness is greater than 0, // Thresholded-selection of a bad fly that can be killed
  17.   then go to Step 26.   // fkill is a good fly (the population's performance is better when fkill is included): we should not kill it
    
  18.   else go to Step 28.   // fkill is a bad fly (the population's performance is worse when fkill is included): we can get rid of it
    
  19. Restore the fly's contribution, then go to Step 12.
  20. Select a genetic operator
  21. If the genetic operator is mutation,
  22.   then go to Step 34.
    
  23.   else go to Step 50.
    
  24. freproduce ← Select a random fly of F
  25. Remove freproduce's contribution from pestimated
  26. // Compute the population's performance without freproduce
  27. Gfitness(F-{freproduce}) ← Errormetrics(preference, pestimated)
  28. // Compare the performances, i.e. compute the fly's local fitness
  29. Lfitness(freproduce) ← Gfitness(F-{freproduce}) - Gfitness(F)
  30. Restore the fly's contribution
  31. If the local fitness is lower than or equal to 0, // Thresholded-selection of a good fly that can reproduce
  32.   else go to Step 34.   // freproduce is a bad fly: we should not allow it to reproduce
    
  33.   then go to Step 53.   // freproduce is a good fly: we can allow it to reproduce
    
  34. // New blood / Immigration
  35. Replace fkill by a new fly with a random position, go to Step 57.
  36. // Mutation
  37. Copy freproduce into fkill
  38. Slightly and randomly alter fkill's position
  39. Add the new fly's contribution to the population
  40. If stop the reconstruction,
  41.   then go to Step 63.
    
  42.   else go to Step 10.
    
  43. // Extract solution
  44. VF ← voxelisation of F
  45. return VF

END

== Example: Digital arts ==

In this example, an input image is to be approximated by a set of tiles (for example as in an ancient mosaic). A tile has an orientation (angle θ), a three colour components (R, G, B), a size (w, h) and a position (x, y, z). If there are N tiles, there are 9N unknown floating point numbers to guess. In other words for 5,000 tiles, there are 45,000 numbers to find. Using a classical evolutionary algorithm where the answer of the optimisation problem is the best individual, the genome of an individual would be made up of 45,000 genes. This approach would be extremely costly in term of complexity and computing time. The same applies for any classical optimisation algorithm. Using the Fly Algorithm, every individual mimics a tile and can be individually evaluated using its local fitness to assess its contribution to the population's performance (the global fitness). Here an individual has 9 genes instead of 9N, and there are N individuals. It can be solved as a reconstruction problem as follows:

    r
    e
    c
    o
    n
    s
    t
    r
    u
    c
    t
    i
    o
    n
    =
    
      a
      r
      g
      
      m
      i
      n
    
    
    
      
        
          ∑
          
            x
            =
            0
          
        
        
          x
          <
          W
        
      
    
    
      
        
          ∑
          
            y
            =
            0
          
        
        
          y
          <
          H
        
      
    
    
      |
    
    i
    n
    p
    u
    t
    (
    x
    ,
    y
    )
    
    P
    [
    F
    ]
    (
    x
    ,
    y
    )
    
      |
    
  

{\displaystyle reconstruction=\operatorname {arg\,min} {\overset {x<W}{\underset {x=0}{\sum }}}{\overset {y<H}{\underset {y=0}{\sum }}}|input(x,y)-P[F](x,y)|}

where

    i
    n
    p
    u
    t
  

{\displaystyle input}

is the input image,

    x
  

{\displaystyle x}

and

    y
  

{\displaystyle y}

are the pixel coordinates along the horizontal and vertical axis respectively,

    W
  

{\displaystyle W}

and

    H
  

{\displaystyle H}

are the image width and height in number of pixels respectively,

    F
  

{\displaystyle F}

is the fly population, and

    P
  

{\displaystyle P}

is a projection operator that creates an image from flies. This projection operator

    P
  

{\displaystyle P}

can take many forms. In her work, Z. Ali Aboodd uses OpenGL to generate different effects (e.g. mosaics, or spray paint). For speeding up the evaluation of the fitness functions, OpenCL is used too. The algorithm starts with a population

    F
  

{\displaystyle F}

that is randomly generated (see Line 3 in the algorithm above).

    F
  

{\displaystyle F}

is then assessed using the global fitness to compute

      G
      
        f
        i
        t
        n
        e
        s
        s
      
    
    (
    F
    )
    =
    
      
        
          ∑
          
            x
            =
            0
          
        
        
          x
          <
          W
        
      
    
    
      
        
          ∑
          
            y
            =
            0
          
        
        
          y
          <
          H
        
      
    
    
      |
    
    i
    n
    p
    u
    t
    (
    x
    ,
    y
    )
    
    P
    [
    F
    ]
    (
    x
    ,
    y
    )
    
      |
    
  

{\displaystyle G_{fitness}(F)={\overset {x<W}{\underset {x=0}{\sum }}}{\overset {y<H}{\underset {y=0}{\sum }}}|input(x,y)-P[F](x,y)|}

(see Line 10).

      G
      
        f
        i
        t
        n
        e
        s
        s
      
    
  

{\displaystyle G_{fitness}}

is the objective function that has to be minimized.

== See also == Mathematical optimization Metaheuristic Search algorithm Stochastic optimization Evolutionary computation Evolutionary algorithm Genetic algorithm Mutation (genetic algorithm) Crossover (genetic algorithm) Selection (genetic algorithm)

== References ==