davidrichards-just_enumerable_stats 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -0
- data/VERSION.yml +1 -1
- data/lib/just_enumerable_stats.rb +5 -0
- data/spec/just_enumerable_stats_spec.rb +11 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unobtrusive_just_enumerable_stats_spec.rb +4 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -145,12 +145,23 @@ There are a few new features for scaling data:
|
|
145
145
|
=> [0.166666666666667, 0.333333333333333, 0.5]
|
146
146
|
>> a
|
147
147
|
=> [0.166666666666667, 0.333333333333333, 0.5]
|
148
|
+
>> a = [-5,0,5]
|
149
|
+
=> [-5, 0, 5]
|
150
|
+
>> a.scale_to_sigmoid
|
151
|
+
=> [0.00669285092428486, 0.5, 0.993307149075715]
|
152
|
+
>> a
|
153
|
+
=> [-5, 0, 5]
|
154
|
+
>> a.scale_to_sigmoid!
|
155
|
+
=> [0.00669285092428486, 0.5, 0.993307149075715]
|
156
|
+
>> a
|
157
|
+
=> [0.00669285092428486, 0.5, 0.993307149075715]
|
148
158
|
|
149
159
|
Basically:
|
150
160
|
|
151
161
|
* scale can scale by a number or with a block. The block is a transformation for a single element.
|
152
162
|
* scale_between sets the minimum and maximum values, and keeps each value proportionate to each other.
|
153
163
|
* normalize calculates the percentage of an element to the whole.
|
164
|
+
* scale_to_sigmoid uses the sigmoid function to scale a set between 0 and 1 with a Gaussian distribution on the numbers.
|
154
165
|
|
155
166
|
== Categories
|
156
167
|
|
data/VERSION.yml
CHANGED
@@ -721,6 +721,11 @@ module Enumerable
|
|
721
721
|
end
|
722
722
|
safe_alias :_jes_scale!
|
723
723
|
|
724
|
+
def _jes_scale_to_sigmoid
|
725
|
+
self._jes_scale { |e| 1 / (1 + Math.exp( -1 * (e))) }
|
726
|
+
end
|
727
|
+
safe_alias :_jes_scale_to_sigmoid
|
728
|
+
|
724
729
|
def _jes_scale_to_sigmoid!
|
725
730
|
self._jes_scale! { |e| 1 / (1 + Math.exp( -1 * (e))) }
|
726
731
|
end
|
@@ -552,7 +552,17 @@ describe "JustEnumerableStats" do
|
|
552
552
|
a[4].should be_close(0.98201, 1.0e-5)
|
553
553
|
end
|
554
554
|
|
555
|
-
it "should
|
555
|
+
it "should have a non-desctructive scale_to_sigmoid" do
|
556
|
+
a = [-4, -2, 0, 2, 4]
|
557
|
+
b = a.scale_to_sigmoid
|
558
|
+
b[0].should be_close(0.01798, 1.0e-5)
|
559
|
+
b[1].should be_close(0.11920, 1.0e-5)
|
560
|
+
b[2].should eql(0.5)
|
561
|
+
b[3].should be_close(0.88079, 1.0e-5)
|
562
|
+
b[4].should be_close(0.98201, 1.0e-5)
|
563
|
+
end
|
564
|
+
|
565
|
+
it "should be able to scale to a sigmoid" do
|
556
566
|
a = [-4, -2, 0, 2, 4]
|
557
567
|
a.scale_to_sigmoid!
|
558
568
|
a[0].should be_close(0.01798, 1.0e-5)
|
data/spec/spec_helper.rb
CHANGED
@@ -66,6 +66,7 @@ class BusyClass
|
|
66
66
|
def pearson_correlation(other); raise ArgumentError, "Should not be called"; end
|
67
67
|
def to_f!; raise ArgumentError, "Should not be called"; end
|
68
68
|
def scale!; raise ArgumentError, "Should not be called"; end
|
69
|
+
def scale_to_sigmoid; raise ArgumentError, "Should not be called"; end
|
69
70
|
def scale_to_sigmoid!; raise ArgumentError, "Should not be called"; end
|
70
71
|
def normalize; raise ArgumentError, "Should not be called"; end
|
71
72
|
def normalize!; raise ArgumentError, "Should not be called"; end
|
@@ -204,6 +204,10 @@ describe "JustEnumerableStats" do
|
|
204
204
|
lambda{@a._jes_scale!(1)}.should_not raise_error
|
205
205
|
end
|
206
206
|
|
207
|
+
it "should not use the native scale_to_sigmoid" do
|
208
|
+
lambda{@a._jes_scale_to_sigmoid}.should_not raise_error
|
209
|
+
end
|
210
|
+
|
207
211
|
it "should not use the native scale_to_sigmoid!" do
|
208
212
|
lambda{@a._jes_scale_to_sigmoid!}.should_not raise_error
|
209
213
|
end
|