Class: OpenTox::Transform::LogAutoScale
- Inherits:
-
Object
- Object
- OpenTox::Transform::LogAutoScale
- Defined in:
- lib/transform.rb
Overview
LogAutoScaler for GSL vectors. Take log and scale.
Instance Attribute Summary collapse
-
#autoscaler ⇒ Object
Returns the value of attribute autoscaler.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#vs ⇒ Object
Returns the value of attribute vs.
Instance Method Summary collapse
-
#initialize(values) ⇒ LogAutoScale
constructor
A new instance of LogAutoScale.
-
#mvlog(values) ⇒ GSL::Vector
Transformed values.
-
#restore(values) ⇒ GSL::Vector
Transformed values.
Constructor Details
#initialize(values) ⇒ LogAutoScale
Returns a new instance of LogAutoScale.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/transform.rb', line 11 def initialize values @distance_to_zero = 1.0 begin raise "Cannot transform, values empty." if values.size==0 vs = values.clone @offset = vs.min - @distance_to_zero @autoscaler = OpenTox::Transform::AutoScale.new mvlog(vs) @vs = @autoscaler.vs rescue Exception => e LOGGER.debug "#{e.class}: #{e.}" LOGGER.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" end end |
Instance Attribute Details
#autoscaler ⇒ Object
Returns the value of attribute autoscaler.
8 9 10 |
# File 'lib/transform.rb', line 8 def autoscaler @autoscaler end |
#offset ⇒ Object
Returns the value of attribute offset.
8 9 10 |
# File 'lib/transform.rb', line 8 def offset @offset end |
#vs ⇒ Object
Returns the value of attribute vs.
8 9 10 |
# File 'lib/transform.rb', line 8 def vs @vs end |
Instance Method Details
#mvlog(values) ⇒ GSL::Vector
Returns transformed values.
41 42 43 |
# File 'lib/transform.rb', line 41 def mvlog values values.to_a.collect { |v| Math::log10(v - @offset) }.to_gv end |
#restore(values) ⇒ GSL::Vector
Returns transformed values.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/transform.rb', line 27 def restore values begin raise "Cannot transform, values empty." if values.size==0 vs = values.clone rv = @autoscaler.restore(vs) rv.to_a.collect { |v| (10**v) + @offset }.to_gv rescue Exception => e LOGGER.debug "#{e.class}: #{e.}" LOGGER.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" end end |