Class: DRP::Weights::WeightFromCurrentDepth

Inherits:
AbstractWeight show all
Defined in:
lib/weights_and_max_depths.rb

Overview

weight_fcd 0..1 dynamic from current depth (uses max_depth) weight_fcd 0..1, :function dynamic fcd w/ function weight_fcd 0..1, 0..1 dynamic like previous but start and end of range mapped from codons weight_fcd 0..1, 0..1, :function like previous with function the function applies to the dynamic mapping of the current depth, and not the static mapping via codons of start and end which is always just linear weight_fcd { |max_depth| dynamic, expects a block which takes the ... max_depth and returns a proc which proc {|depth| ... } which takes the current depth }

Instance Method Summary collapse

Methods inherited from AbstractWeight

factory

Constructor Details

#initialize(args) ⇒ WeightFromCurrentDepth

Returns a new instance of WeightFromCurrentDepth.



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/weights_and_max_depths.rb', line 225

def initialize args
  @drp_instance = args.drp_instance
  @rule_method = args.rule_method
  @max_depth = @rule_method.max_depth - 1
  arg1, arg2, arg3 = args.user_args
  if arg1.kind_of? Range
    @range = arg1
    if arg2.kind_of? Range
      if (arg3.kind_of? Symbol) or (arg3.kind_of? String)
        @function = arg3
      end
      min = Utils::map(@range, @drp_instance.next_meta_codon)
      max = Utils::map(arg2, @drp_instance.next_meta_codon)
      @range = min..max
    elsif (arg2.kind_of? Symbol) or (arg2.kind_of? String)
      @function = arg2
    end
  else
    raise ArgumentError, 'bad argument to weight_fcd'
  end    
end

Instance Method Details

#valueObject



246
247
248
249
# File 'lib/weights_and_max_depths.rb', line 246

def value
  val = @rule_method.depth.to_f / @max_depth
  Utils::map(@range, val, @function)
end