davidrichards-just_enumerable_stats 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 12
4
+ :patch: 13
@@ -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 be able to scale to a signoid" do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: davidrichards-just_enumerable_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Richards