roc 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/lib/roc.rb +1 -0
  2. data/roc.gemspec +1 -1
  3. data/samples/a.rb +3 -0
  4. data/test/roc.rb +24 -34
  5. metadata +2 -2
data/lib/roc.rb CHANGED
@@ -49,6 +49,7 @@ class ROCarray < Array
49
49
  ptot = self.join.count('P')
50
50
  return nil if ptot==0
51
51
  ntot = self.join.count('N')
52
+ return nil if ntot==0
52
53
  ystep = 1.0 / ptot
53
54
  xstep = 1.0 / ntot
54
55
  parr = self.inject([[0,0]]) do |points,rocpoint|
@@ -4,7 +4,7 @@
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "roc"
6
6
  spec.description = 'Receiver operator characteristic (ROC)'
7
- spec.version = "0.0.0"
7
+ spec.version = "1.0.0"
8
8
  spec.platform = Gem::Platform::RUBY
9
9
  spec.summary = "roc"
10
10
 
@@ -7,3 +7,6 @@
7
7
  r1.roc
8
8
  r1.auc
9
9
  r1.auc(0.1)
10
+ r2.roc
11
+ r2.auc
12
+ r2.auc(0.1)
@@ -4,51 +4,41 @@ $:.unshift('..')
4
4
  $:.unshift('../lib')
5
5
 
6
6
  require('test/unit')
7
- require('forkoff')
7
+ require('roc')
8
8
 
9
9
 
10
10
  class T < Test::Unit::TestCase
11
11
 
12
- # simple usage
13
- #
14
-
12
+ # simple usage
15
13
  def test_0010
16
- results = [0,1,2].forkoff!{|n| [n, Process.pid]}
17
- assert_equal(results, results.uniq, 'all ran in a different process')
14
+ r = ROCarray.new %w(P N P)
15
+ assert r.auc == 0.5
18
16
  end
19
17
 
20
- # it's faster
21
- #
18
+ # without positive samples, it should be nil
22
19
  def test_0020
23
- n = 4
24
- strategies = :forkoff, :each
25
-
26
- 4.times do
27
- result = {}
28
-
29
- strategies.each do |strategy|
30
- a = Time.now.to_f
31
- (0..4).send(strategy){|i| sleep 0.2}
32
- b = Time.now.to_f
33
- elapsed = b - a
34
- result[strategy] = elapsed
35
- end
36
-
37
- assert result[:forkoff] < result[:each], 'forkoff is faster than each for long running tasks'
38
- end
20
+ r = ROCarray.new %w(NN)
21
+ assert r.auc == nil
39
22
  end
40
23
 
41
- # in case of different execution times for different processes
42
- #
43
- def test_0030
44
- a = Time.now.to_f
45
- (0...4).forkoff(2) do |i|
46
- sleep i.modulo(2)
47
- end
48
- b = Time.now.to_f
49
- elapsed = b - a
50
- assert elapsed < 2
24
+ # without negative samples, it should be nil
25
+ def test_0025
26
+ r = ROCarray.new %w(PP)
27
+ assert r.auc == nil
51
28
  end
52
29
 
30
+ # only equal predictions -> 0.5
31
+ def test_0030
32
+ r = ROCarray.new %w(PPPPPPPPPPNNNNNNNNNN)
33
+ d = 1e-12
34
+ assert r.auc>0.5-d and r.auc<0.5+d
35
+ end
36
+
37
+ # initialization with prediction values
38
+ def test_0040
39
+ assert ROCarray.new([1.0 , 2.0 , 3.0],[0]).auc==0.0 and
40
+ ROCarray.new([1.0 , 2.0 , 3.0],[1]).auc==0.5 and
41
+ ROCarray.new([1.0 , 2.0 , 3.0],[2]).auc==1.0
42
+ end
53
43
 
54
44
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: roc
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.0
7
- date: 2009-10-21 00:00:00 +09:00
6
+ version: 1.0.0
7
+ date: 2009-11-28 00:00:00 +09:00
8
8
  summary: roc
9
9
  require_paths:
10
10
  - lib