Class: OpenTox::Transform::AutoScale
- Inherits:
-
Object
- Object
- OpenTox::Transform::AutoScale
- Defined in:
- lib/transform.rb
Overview
Auto-Scaler for GSL vectors. Center on mean and divide by standard deviation.
Instance Attribute Summary collapse
-
#mean ⇒ Object
Returns the value of attribute mean.
-
#stdev ⇒ Object
Returns the value of attribute stdev.
-
#vs ⇒ Object
Returns the value of attribute vs.
Instance Method Summary collapse
-
#autoscale(values) ⇒ GSL::Vector
Transformed values.
-
#initialize(values) ⇒ AutoScale
constructor
A new instance of AutoScale.
-
#restore(values) ⇒ GSL::Vector
Transformed values.
-
#transform(values) ⇒ GSL::Vector
Transformed values.
Constructor Details
#initialize(values) ⇒ AutoScale
Returns a new instance of AutoScale.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/transform.rb', line 54 def initialize values begin raise "Cannot transform, values empty." if values.size==0 vs = values.clone @mean = vs.to_scale.mean @stdev = vs.to_scale.standard_deviation_population @stdev = 0.0 if @stdev.nan? @vs = transform vs rescue Exception => e LOGGER.debug "#{e.class}: #{e.}" LOGGER.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" end end |
Instance Attribute Details
#mean ⇒ Object
Returns the value of attribute mean.
51 52 53 |
# File 'lib/transform.rb', line 51 def mean @mean end |
#stdev ⇒ Object
Returns the value of attribute stdev.
51 52 53 |
# File 'lib/transform.rb', line 51 def stdev @stdev end |
#vs ⇒ Object
Returns the value of attribute vs.
51 52 53 |
# File 'lib/transform.rb', line 51 def vs @vs end |
Instance Method Details
#autoscale(values) ⇒ GSL::Vector
Returns transformed values.
95 96 97 98 |
# File 'lib/transform.rb', line 95 def autoscale values vs_ss = values.clone.to_scale - @mean @stdev == 0.0 ? vs_ss.to_gsl : ( vs_ss * ( 1 / @stdev) ).to_gsl end |
#restore(values) ⇒ GSL::Vector
Returns transformed values.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/transform.rb', line 82 def restore values begin raise "Cannot transform, values empty." if values.size==0 rv_ss = values.clone.to_scale * @stdev unless @stdev == 0.0 (rv_ss + @mean).to_gsl rescue Exception => e LOGGER.debug "#{e.class}: #{e.}" LOGGER.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" end end |
#transform(values) ⇒ GSL::Vector
Returns transformed values.
70 71 72 73 74 75 76 77 78 |
# File 'lib/transform.rb', line 70 def transform values begin raise "Cannot transform, values empty." if values.size==0 autoscale values.clone rescue Exception => e LOGGER.debug "#{e.class}: #{e.}" LOGGER.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" end end |