Module: PopulationStatistics

Included in:
PopulationReport, PopulationReportStream
Defined in:
../algorithm/support/population_report.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) report_diversity

Returns the value of attribute report_diversity



4
5
6
# File '../algorithm/support/population_report.rb', line 4

def report_diversity
  @report_diversity
end

- (Object) report_histogram

Returns the value of attribute report_histogram



4
5
6
# File '../algorithm/support/population_report.rb', line 4

def report_histogram
  @report_histogram
end

- (Object) report_pareto_front

Returns the value of attribute report_pareto_front



4
5
6
# File '../algorithm/support/population_report.rb', line 4

def report_pareto_front
  @report_pareto_front
end

- (Object) report_statistics

Returns the value of attribute report_statistics



4
5
6
# File '../algorithm/support/population_report.rb', line 4

def report_statistics
  @report_statistics
end

Instance Method Details

- (Object) report(population)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File '../algorithm/support/population_report.rb', line 6

def report population
  post_initialize unless defined? @objective

  if defined? @report_diversity and @report_diversity == true
    diversity = Util.diversity( population ) { |individual| individual.genotype }
    self['diversity_genotypic'] << "#{diversity[0...10].inspect}#{ diversity.size>10 ? '...' : ''  } #{diversity.size} unique"   
  
    diversity =  Util.diversity( population ) { |individual| individual.phenotype }
    self['diversity_phenotypic'] << "#{diversity[0...10].inspect}#{ diversity.size>10 ? '...' : ''  } #{diversity.size} unique"
  end

  if defined? @report_statistics and @report_statistics == true   
    values = population.map { |individual| individual.send(@objective) }   
    min, max, avg, n = Util.statistics values  
    self[@objective.to_s] << "min: #{min} max: #{max} avg: #{avg} n: #{n}"

    min, max, avg, n = Util.statistics( population.map { |individual| individual.used_length } )
    self['used_length'] << "min: #{min} max: #{max} avg: #{avg} n: #{n}"

    min, max, avg, n = Util.statistics( population.map { |individual| individual.complexity } )
    self['complexity'] << "min: #{min} max: #{max} avg: #{avg} n: #{n}"
 
    min, max, avg, n = Util.statistics( population.map { |individual| individual.genotype.size } )
    self['genotype.size'] << "min: #{min} max: #{max} avg: #{avg} n: #{n}"
  end

  best = population.min do |a,b| 
    c = @sort_proc.call(a,b) 
    (c == 0)? a.complexity <=> b.complexity  : c 
  end
  self['best_phenotype'] << "\n#{best.phenotype}"
  self['best_phenotype_complexity'] << best.complexity
  self['best_phenotype_layer'] << best.layer
  self['best_phenotype_age'] << best.age  

  if defined? @report_histogram and @report_histogram == true         
    uniq = {}
    count = {}
    count.default = 0
    population.each do |individual| 
      uniq[individual.phenotype] = individual 
      count[individual.phenotype] += 1
    end
  
    sorted = uniq.values.sort { |a,b| @sort_proc.call(a,b) }
    text = "\n"
    sorted[0...10].each { |i| text += format_individual( count[i.phenotype], i ) + "\n" }
    text += "...\n" if sorted.size > 10
    if sorted.size > 15
      sorted[-5,5].each { |i| text += format_individual( count[i.phenotype], i ) + "\n" } 
    end
    self['z_histogram'] << text
  end

  if defined? @report_pareto_front and @report_pareto_front == true
    uniq = {}
    Pareto.nondominated( population ).each do |individual| 
      uniq[individual.phenotype] = individual 
    end

    text = "\n"
    sorted = uniq.values.sort { |a,b| @sort_proc.call(a,b) }
    sorted.each { |i| text += format_individual( '', i ) + ': ' + i.phenotype + "\n" }
    
    self['pareto_front'] << text
  end

end