Class: Charty::VectorAdapters::BaseAdapter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/charty/vector_adapters.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



35
36
37
# File 'lib/charty/vector_adapters.rb', line 35

def data
  @data
end

Class Method Details

.adapter_nameObject



26
27
28
# File 'lib/charty/vector_adapters.rb', line 26

def self.adapter_name
  name[/:?(\w+)Adapter\z/, 1]
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/charty/vector_adapters.rb', line 39

def ==(other)
  case other.adapter
  when BaseAdapter
    return false if other.index != index
    if respond_to?(:compare_data_equality)
      compare_data_equality(other.adapter)
    elsif other.adapter.respond_to?(:compare_data_equality)
      other.adapter.compare_data_equality(self)
    else
      case other.adapter
      when self.class
        data == other.data
      else
        false
      end
    end
  else
    super
  end
end

#inverse_log_scale(method) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/charty/vector_adapters.rb', line 115

def inverse_log_scale(method)
  Charty::Vector.new(
    self.map {|x| 10.0 ** x },
    index: index,
    name: name
  )
end

#log_scale(method) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/charty/vector_adapters.rb', line 107

def log_scale(method)
  Charty::Vector.new(
    self.map {|x| Math.log10(x) },
    index: index,
    name: name
  )
end

#meanObject



95
96
97
# File 'lib/charty/vector_adapters.rb', line 95

def mean
  Statistics.mean(data)
end

#percentile(q) ⇒ Object



103
104
105
# File 'lib/charty/vector_adapters.rb', line 103

def percentile(q)
  Statistics.percentile(data, q)
end

#stdev(population: false) ⇒ Object



99
100
101
# File 'lib/charty/vector_adapters.rb', line 99

def stdev(population: false)
  Statistics.stdev(data, population: population)
end

#values_at(*indices) ⇒ Object

Take values at the given positional indices (without indexing)



64
65
66
# File 'lib/charty/vector_adapters.rb', line 64

def values_at(*indices)
  indices.map {|i| data[i] }
end

#where_in_array(mask) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/charty/vector_adapters.rb', line 68

def where_in_array(mask)
  mask = check_mask_vector(mask)
  masked_data = []
  masked_index = []
  mask.each_with_index do |f, i|
    case f
    when true, 1
      masked_data << data[i]
      masked_index << index[i]
    end
  end
  return masked_data, masked_index
end