Class: SciYAG::Backends::AverageDupFilter
- Includes:
- Dobjects
- Defined in:
- lib/SciYAG/Backends/filters/average.rb
Overview
A filter that sorts data and then averages the Y values of all the elements which have the same X value.
Instance Method Summary collapse
-
#apply(f) ⇒ Object
There you go: a simple sorting/averaging filter.
-
#apply!(f) ⇒ Object
We simply replace the old vectors by the new ones.
-
#initialize ⇒ AverageDupFilter
constructor
A new instance of AverageDupFilter.
Methods inherited from Filter
Methods included from Descriptions::DescriptionExtend
#base_ancestor?, #description, #description_hash, #description_hash_base, #description_list, #description_list_base, extend_object, #inherit, #init_param, #init_params, #lookup_description_extend_ancestor, #param, #param_noaccess, #register_description, #set_description, #set_description_hash_base, #set_description_list_base
Methods included from Descriptions::DescriptionInclude
#description, #fill_parser, #long_name, #parser_banner, #parser_options
Constructor Details
#initialize ⇒ AverageDupFilter
Returns a new instance of AverageDupFilter.
31 32 |
# File 'lib/SciYAG/Backends/filters/average.rb', line 31 def initialize end |
Instance Method Details
#apply(f) ⇒ Object
There you go: a simple sorting/averaging filter.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/SciYAG/Backends/filters/average.rb', line 35 def apply(f) h = {} for x,y in f if h.key? x h[x] << y else h[x] = [y] end end nx = Dvector.new ny = Dvector.new for x in h.keys.sort nx << x y = 0 for a in h[x] y += a end y/= h[x].size ny << y end return Function.new(nx,ny) end |
#apply!(f) ⇒ Object
We simply replace the old vectors by the new ones.
60 61 62 63 64 |
# File 'lib/SciYAG/Backends/filters/average.rb', line 60 def apply!(f) new_f = apply(f) f.x.replace(new_f.x) f.y.replace(new_f.y) end |