Class: SciYAG::Backends::StandardDeviationFilter
- Includes:
- Dobjects
- Defined in:
- lib/SciYAG/Backends/filters/average.rb
Instance Method Summary collapse
- #apply(f) ⇒ Object
-
#apply!(f) ⇒ Object
We simply replace the old vectors by the new ones.
-
#initialize ⇒ StandardDeviationFilter
constructor
A new instance of StandardDeviationFilter.
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 ⇒ StandardDeviationFilter
Returns a new instance of StandardDeviationFilter.
73 74 |
# File 'lib/SciYAG/Backends/filters/average.rb', line 73 def initialize end |
Instance Method Details
#apply(f) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/SciYAG/Backends/filters/average.rb', line 76 def apply(f) last_x = nil current_y = [] x_values = Dvector.new y_values = [] f.x.size.times do |i| xval = f.x[i] if (last_x && xval == last_x) current_y << f.y[i] else if last_x y_values << current_y x_values << last_x end current_y = [f.y[i]] last_x = f.x[i] end end if last_x y_values << current_y x_values << last_x end target_y = Dvector.new(x_values.size) ymin = target_y.dup ymax = target_y.dup x_values.size.times do |i| sum = 0.0 sq_sum = 0.0 for y in y_values[i] sum += y sq_sum += y**2 end nb = y_values[i].size target_y[i] = sum/nb stddev = Math::sqrt((sq_sum/nb) - target_y[i]**2) ymin[i] = target_y[i] - stddev ymax[i] = target_y[i] + stddev end errors = f.errors.dup.merge!({:ymin => ymin, :ymax => ymax, :x => x_values, :y => target_y}) return DataSet2D.new(f.creation_context, Function.new(x_values, target_y), errors, f.) end |
#apply!(f) ⇒ Object
We simply replace the old vectors by the new ones.
125 126 127 128 129 130 |
# File 'lib/SciYAG/Backends/filters/average.rb', line 125 def apply!(f) new_f = apply(f) f.x.replace(new_f.x) f.y.replace(new_f.y) f.errors = new_f.errors end |