Class: OpenTox::Algorithm::Transform::Inverter
- Inherits:
-
Object
- Object
- OpenTox::Algorithm::Transform::Inverter
- Defined in:
- lib/algorithm.rb
Overview
The transformer that inverts values. 1/x is used, after values have been moved >= 1.
Instance Attribute Summary collapse
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Inverter
constructor
@params Values to transform.
Constructor Details
#initialize(*args) ⇒ Inverter
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'lib/algorithm.rb', line 723 def initialize *args case args.size when 1 begin values=args[0] raise "Cannot transform, values empty." if @values.size==0 @values = values.collect { |v| -1.0 * v } @offset = 1.0 - @values.minmax[0] @offset = -1.0 * @offset if @offset>0.0 @values.collect! { |v| v - @offset } # slide >1 @values.collect! { |v| 1 / v } # invert to [0,1] rescue Exception => e LOGGER.debug "#{e.class}: #{e.}" LOGGER.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" end when 2 @offset = args[1].to_f @values = args[0].collect { |v| 1 / v } @values.collect! { |v| v + @offset } @values.collect! { |v| -1.0 * v } end end |
Instance Attribute Details
#offset ⇒ Object
Returns the value of attribute offset.
719 720 721 |
# File 'lib/algorithm.rb', line 719 def offset @offset end |
#values ⇒ Object
Returns the value of attribute values.
719 720 721 |
# File 'lib/algorithm.rb', line 719 def values @values end |