Class: Chainer::DictSummary
- Inherits:
-
Object
- Object
- Chainer::DictSummary
- Defined in:
- lib/chainer/reporter.rb
Overview
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.
Instance Method Summary collapse
-
#add(d) ⇒ Object
Adds a dictionary of scalars.
-
#compute_mean ⇒ Object
Creates a dictionary of mean values.
-
#initialize ⇒ DictSummary
constructor
A new instance of DictSummary.
-
#make_statistics ⇒ Object
Creates a dictionary of statistics.
Constructor Details
#initialize ⇒ DictSummary
Returns a new instance of DictSummary.
102 103 104 |
# File 'lib/chainer/reporter.rb', line 102 def initialize @summaries = Hash.new { |h,k| h[k] = Summary.new } end |
Instance Method Details
#add(d) ⇒ Object
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.
111 112 113 114 115 116 117 118 |
# 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 ⇒ Object
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.
125 126 127 |
# 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 ⇒ Object
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.
136 137 138 139 140 141 142 143 144 |
# 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 |