class Chainer::DictSummary

Online summarization of a sequence of dictionaries. “DictSummary“ computes the statistics of a given set of scalars online. It only computes the statistics for scalar values and variables of scalar values in the dictionaries.

Public Class Methods

new() click to toggle source
# File lib/chainer/reporter.rb, line 102
def initialize
  @summaries = Hash.new { |h,k| h[k] = Summary.new }
end

Public Instance Methods

add(d) click to toggle source

Adds a dictionary of scalars. Args:

d (dict): Dictionary of scalars to accumulate. Only elements of
          scalars, zero-dimensional arrays, and variables of
          zero-dimensional arrays are accumulated.
# File lib/chainer/reporter.rb, line 111
def add(d)
  d.each do |k, v|
    v = v.data if v.kind_of?(Chainer::Variable)
    if v.class.method_defined?(:to_i) || (v.class.method_defined?(:ndim) && v.ndim == 0)
      @summaries[k].add(v)
    end 
  end
end
compute_mean() click to toggle source

Creates a dictionary of mean values. It returns a single dictionary that holds a mean value for each entry added to the summary.

Returns:

dict: Dictionary of mean values.
# File lib/chainer/reporter.rb, line 125
def compute_mean
  @summaries.each_with_object({}) { |(name, summary), h| h[name] = summary.compute_mean }
end
make_statistics() click to toggle source

Creates a dictionary of statistics. It returns a single dictionary that holds mean and standard deviation values for every entry added to the summary. For an entry of name “'key'“, these values are added to the dictionary by names “'key'“ and “'key.std'“, respectively.

Returns:

dict: Dictionary of statistics of all entries.
# File lib/chainer/reporter.rb, line 136
def make_statistics
  stats = {}
  @summaries.each do |name, summary|
    mean, std = summary.make_statistics
    stats[name] = mean
    stats[name + '.std'] = std
  end
  stats
end