Class: Charty::VectorAdapters::BaseAdapter
- Inherits:
-
Object
- Object
- Charty::VectorAdapters::BaseAdapter
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
#data ⇒ Object
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_name ⇒ Object
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
117
118
119
120
121
122
123
|
# File 'lib/charty/vector_adapters.rb', line 117
def inverse_log_scale(method)
Charty::Vector.new(
self.map {|x| 10.0 ** x },
index: index,
name: name
)
end
|
#log_scale(method) ⇒ Object
109
110
111
112
113
114
115
|
# File 'lib/charty/vector_adapters.rb', line 109
def log_scale(method)
Charty::Vector.new(
self.map {|x| Math.log10(x) },
index: index,
name: name
)
end
|
#mean ⇒ Object
97
98
99
|
# File 'lib/charty/vector_adapters.rb', line 97
def mean
Statistics.mean(data)
end
|
#percentile(q) ⇒ Object
105
106
107
|
# File 'lib/charty/vector_adapters.rb', line 105
def percentile(q)
Statistics.percentile(data, q)
end
|
#stdev(population: false) ⇒ Object
101
102
103
|
# File 'lib/charty/vector_adapters.rb', line 101
def stdev(population: false)
Statistics.stdev(data, population: population)
end
|
#values_at(*indices) ⇒ Object
Take values at the given positional indices (without indexing)
66
67
68
|
# File 'lib/charty/vector_adapters.rb', line 66
def values_at(*indices)
indices.map {|i| data[i] }
end
|
#where_in_array(mask) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/charty/vector_adapters.rb', line 70
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
|