Class: OpenTox::Transform::LogAutoScale

Inherits:
Object
  • Object
show all
Defined in:
lib/transform.rb

Overview

LogAutoScaler for GSL vectors. Take log and scale.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ LogAutoScale

Returns a new instance of LogAutoScale.

Parameters:

  • Values (GSL::Vector)

    to transform using LogAutoScaling.



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.message}"
    LOGGER.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
  end
end

Instance Attribute Details

#autoscalerObject

Returns the value of attribute autoscaler.



8
9
10
# File 'lib/transform.rb', line 8

def autoscaler
  @autoscaler
end

#offsetObject

Returns the value of attribute offset.



8
9
10
# File 'lib/transform.rb', line 8

def offset
  @offset
end

#vsObject

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.

Parameters:

  • values (GSL::Vector)

    to transform.

Returns:

  • (GSL::Vector)

    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.

Parameters:

  • values (GSL::Vector)

    to restore.

Returns:

  • (GSL::Vector)

    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.message}"
    LOGGER.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
  end
end