malge 0.0.5 → 0.0.6

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/CHANGES CHANGED
@@ -1,6 +1,14 @@
1
1
  = vasputils changelog
2
2
 
3
- == Master (for 0.0.6)
3
+ == Master (for 0.0.7)
4
+
5
+ == Version 0.0.6)
6
+ * Rename Malge::ErrorFittedFunction::AXInv to Malge::ErrorFittedFunction::AXInvPlusB
7
+ * Rename Malge::ErrorFittedFunction::AXInv32 to Malge::ErrorFittedFunction::AXInv32PlusB
8
+
9
+ * New Malge::ErrorFittedFunction::AXInv to fit purely inverse proportional function
10
+ * New Malge::ErrorFittedFunction::AXInv32 to fit purely inverse^{3/2} proportional function
11
+ * Change Malge::LeastSquare.least_square_proportional to return an array of one item.
4
12
 
5
13
  == Version 0.0.5)
6
14
  * @raw_pairs and @diff_abs_pairs in Malge::ErrorFittedFunction change to publicly readable.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -5,6 +5,8 @@ require "malge/errorfittedfunction/aexpbx.rb"
5
5
  require "malge/errorfittedfunction/aexpbx32.rb"
6
6
  require "malge/errorfittedfunction/axinv.rb"
7
7
  require "malge/errorfittedfunction/axinv32.rb"
8
+ require "malge/errorfittedfunction/axinvplusb.rb"
9
+ require "malge/errorfittedfunction/axinv32plusb.rb"
8
10
  require "malge/leastsquare.rb"
9
11
  require "malge/matrix.rb"
10
12
  require "malge/simultaneousequations.rb"
@@ -9,19 +9,17 @@ class Malge::ErrorFittedFunction::AXInv < Malge::ErrorFittedFunction
9
9
 
10
10
  def fit
11
11
  inv_pairs = @diff_abs_pairs.map {|pair| [1.0/pair[0], pair[1]]}
12
- @coefficients = Malge::LeastSquare.least_square_1st_degree(inv_pairs)
12
+ @coefficients = Malge::LeastSquare.least_square_proportional(inv_pairs)
13
13
  end
14
14
 
15
15
  def expected_error(x)
16
- #@coefficients[0] + @coefficients[1] * x
17
- @coefficients[0] + @coefficients[1] * (1.0/x)
16
+ @coefficients[0] / x
18
17
  end
19
18
 
20
- # y = a[0] + a[1]/x
21
- # y - a[0] = a[1]/x
22
- # x = a[1] / (y - a[0])
19
+ #y = a/x
20
+ #x = a/y
23
21
  def x(y)
24
- return @coefficients[1] / (y - @coefficients[0])
22
+ return @coefficients[0] / y
25
23
  end
26
24
 
27
25
  def finest_y
@@ -1,7 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
2
  # coding: utf-8
3
3
 
4
- #Assumed y = a[0] + a[1]/x^{3/2}
4
+ #Assumed y = a[0] /x^{3/2}
5
5
  #
6
6
  #NOTE: @coefficients[0] might become negative value.
7
7
  # Need discussion for dealing?
@@ -10,18 +10,20 @@ class Malge::ErrorFittedFunction::AXInv32 < Malge::ErrorFittedFunction
10
10
  def fit
11
11
  inv32_pairs =
12
12
  @diff_abs_pairs.map {|pair| [1.0/(pair[0] ** (3.0/2.0)), pair[1]]}
13
- @coefficients = Malge::LeastSquare.least_square_1st_degree(inv32_pairs)
13
+ @coefficients = Malge::LeastSquare.least_square_proportional(inv32_pairs)
14
14
  end
15
15
 
16
16
  def expected_error(x)
17
- @coefficients[0] + @coefficients[1] * (1.0/(x** (3.0/2.0)))
17
+ @coefficients[0] /(x** (3.0/2.0))
18
18
  end
19
19
 
20
- # y = a[0] + a[1]/x
21
- # y - a[0] = a[1]/x
22
- # x = a[1] / (y - a[0])
20
+ # y = a[0]/x^{3/2}
21
+ # y = a[0]/x^{3/2}
22
+ #x^{3/2} y = a[0]
23
+ # x^{3/2} = a[0]/y
24
+ # x = (a[0]/y)^{2/3}
23
25
  def x(y)
24
- return (@coefficients[1] / (y - @coefficients[0])) ** (2.0/3.0)
26
+ return (@coefficients[0] / y ) ** (2.0/3.0)
25
27
  end
26
28
 
27
29
  def finest_y
@@ -0,0 +1,32 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ #Assumed y = a[0] + a[1]/x^{3/2}
5
+ #
6
+ #NOTE: @coefficients[0] might become negative value.
7
+ # Need discussion for dealing?
8
+ class Malge::ErrorFittedFunction::AXInv32PlusB < Malge::ErrorFittedFunction
9
+
10
+ def fit
11
+ inv32_pairs =
12
+ @diff_abs_pairs.map {|pair| [1.0/(pair[0] ** (3.0/2.0)), pair[1]]}
13
+ @coefficients = Malge::LeastSquare.least_square_1st_degree(inv32_pairs)
14
+ end
15
+
16
+ def expected_error(x)
17
+ @coefficients[0] + @coefficients[1] * (1.0/(x** (3.0/2.0)))
18
+ end
19
+
20
+ # y = a[0] + a[1]/x
21
+ # y - a[0] = a[1]/x
22
+ # x = a[1] / (y - a[0])
23
+ def x(y)
24
+ return (@coefficients[1] / (y - @coefficients[0])) ** (2.0/3.0)
25
+ end
26
+
27
+ def finest_y
28
+ @raw_pairs.max_by { |pair| pair[0] }[1]
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,32 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ #Assumed y = a[0] + a[1]/x
5
+ #
6
+ #NOTE: @coefficients[0] might become negative value.
7
+ # Need discussion for dealing?
8
+ class Malge::ErrorFittedFunction::AXInvPlusB < Malge::ErrorFittedFunction
9
+
10
+ def fit
11
+ inv_pairs = @diff_abs_pairs.map {|pair| [1.0/pair[0], pair[1]]}
12
+ @coefficients = Malge::LeastSquare.least_square_1st_degree(inv_pairs)
13
+ end
14
+
15
+ def expected_error(x)
16
+ #@coefficients[0] + @coefficients[1] * x
17
+ @coefficients[0] + @coefficients[1] * (1.0/x)
18
+ end
19
+
20
+ # y = a[0] + a[1]/x
21
+ # y - a[0] = a[1]/x
22
+ # x = a[1] / (y - a[0])
23
+ def x(y)
24
+ return @coefficients[1] / (y - @coefficients[0])
25
+ end
26
+
27
+ def finest_y
28
+ @raw_pairs.max_by { |pair| pair[0] }[1]
29
+ end
30
+
31
+ end
32
+
@@ -51,7 +51,7 @@ module Malge::LeastSquare
51
51
  d += x*y
52
52
  end
53
53
  #raise if d == 0.0
54
- d/a
54
+ [d/a]
55
55
  end
56
56
 
57
57
  #Return variance when fitted to y = a_0 x^0 + a_1 x^1.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "malge"
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ippei94da"]
12
- s.date = "2013-02-15"
12
+ s.date = "2013-02-16"
13
13
  s.description = "Mathematical library to deal with basic problems in algebla.\n "
14
14
  s.email = "ippei94da@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -30,6 +30,8 @@ Gem::Specification.new do |s|
30
30
  "lib/malge/errorfittedfunction/aexpbx32.rb",
31
31
  "lib/malge/errorfittedfunction/axinv.rb",
32
32
  "lib/malge/errorfittedfunction/axinv32.rb",
33
+ "lib/malge/errorfittedfunction/axinv32plusb.rb",
34
+ "lib/malge/errorfittedfunction/axinvplusb.rb",
33
35
  "lib/malge/leastsquare.rb",
34
36
  "lib/malge/matrix.rb",
35
37
  "lib/malge/simultaneousequations.rb",
@@ -41,6 +43,8 @@ Gem::Specification.new do |s|
41
43
  "test/test_errorfittedfunction_aexpbx32.rb",
42
44
  "test/test_errorfittedfunction_axinv.rb",
43
45
  "test/test_errorfittedfunction_axinv32.rb",
46
+ "test/test_errorfittedfunction_axinv32plusb.rb",
47
+ "test/test_errorfittedfunction_axinvplusb.rb",
44
48
  "test/test_leastsquare.rb",
45
49
  "test/test_simultaneousequations.rb"
46
50
  ]
@@ -5,18 +5,9 @@ require "test/unit"
5
5
  require "malge.rb"
6
6
  require "malge/errorfittedfunction.rb"
7
7
 
8
- #class Malge::ErrorFittedFunction::AXInv
9
- # public :fit
10
- #end
11
-
12
8
  class TC_ErrorFittedFunction_AXInv < Test::Unit::TestCase
13
9
  def setup
14
10
  @axi01 = Malge::ErrorFittedFunction::AXInv.new(
15
- #2x+1 = 1, -1
16
- #2x+1 = 3, +2
17
- #2x+1 = 5, -1
18
- #[0.0, 1.0, 2.0],
19
- #[0.0, 5.0, 4.0]
20
11
  [
21
12
  [1.0, 8.0],
22
13
  [2.0, 6.0],
@@ -29,8 +20,9 @@ class TC_ErrorFittedFunction_AXInv < Test::Unit::TestCase
29
20
  #def test_initialize
30
21
  #end
31
22
 
32
- #def test_fit
33
- #end
23
+ def test_fit
24
+ assert_equal([4.0], @axi01.coefficients)
25
+ end
34
26
 
35
27
  def test_expected_error
36
28
  assert_equal(4.0, @axi01.expected_error(1.0))
@@ -40,7 +32,7 @@ class TC_ErrorFittedFunction_AXInv < Test::Unit::TestCase
40
32
  end
41
33
 
42
34
  def test_finest_y
43
- assert_equal(4.0, @axi01.finest_y)
35
+ assert_equal( 4.0, @axi01.finest_y)
44
36
  end
45
37
 
46
38
  def test_variance
@@ -5,10 +5,6 @@ require "test/unit"
5
5
  require "malge.rb"
6
6
  #require "malge/errorfittedfunction.rb"
7
7
 
8
- #class Malge::ErrorFittedFunction::AXInv32
9
- # public :fit
10
- #end
11
-
12
8
  class TC_ErrorFittedFunction_AXInv32 < Test::Unit::TestCase
13
9
  TOLERANCE = 1.0E-10
14
10
 
@@ -37,10 +33,10 @@ class TC_ErrorFittedFunction_AXInv32 < Test::Unit::TestCase
37
33
  #end
38
34
 
39
35
  def test_fit
40
- corrects = [0.0, 64.0]
36
+ corrects = [64.0]
41
37
  results = @axi00.coefficients
38
+ assert_equal(1, results.size)
42
39
  assert_in_delta(corrects[0], results[0], TOLERANCE)
43
- assert_in_delta(corrects[1], results[1], TOLERANCE)
44
40
  end
45
41
 
46
42
  def test_expected_error
@@ -0,0 +1,67 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "test/unit"
5
+ require "malge.rb"
6
+ #require "malge/errorfittedfunction.rb"
7
+
8
+ class TC_ErrorFittedFunction_AXInv32PlusB < Test::Unit::TestCase
9
+ TOLERANCE = 1.0E-10
10
+
11
+ def setup
12
+ @axi00 = Malge::ErrorFittedFunction::AXInv32PlusB.new(
13
+ [
14
+ [ 1, 164.0],
15
+ [ 4, 108.0],
16
+ [16, 101.0],
17
+ [64, 100.0],
18
+ ]
19
+ )
20
+
21
+ @axi01 = Malge::ErrorFittedFunction::AXInv32PlusB.new(
22
+ [
23
+ [ 1, 164.0],
24
+ [ 4, 92.0],
25
+ [16, 101.0],
26
+ [64, 100.0],
27
+ ]
28
+ )
29
+
30
+ end
31
+
32
+ #def test_initialize
33
+ #end
34
+
35
+ def test_fit
36
+ corrects = [0.0, 64.0]
37
+ results = @axi00.coefficients
38
+ assert_in_delta(corrects[0], results[0], TOLERANCE)
39
+ assert_in_delta(corrects[1], results[1], TOLERANCE)
40
+ end
41
+
42
+ def test_expected_error
43
+ assert_equal(64.0, @axi00.expected_error(1.0))
44
+ assert_equal( 8.0, @axi00.expected_error(4.0))
45
+ assert_equal( 1.0, @axi00.expected_error(16.0))
46
+
47
+ assert_equal(64.0, @axi01.expected_error(1.0))
48
+ assert_equal( 8.0, @axi01.expected_error(4.0))
49
+ assert_equal( 1.0, @axi01.expected_error(16.0))
50
+ end
51
+
52
+ def test_finest_y
53
+ assert_equal(100.0, @axi00.finest_y)
54
+ assert_equal(100.0, @axi01.finest_y)
55
+ end
56
+
57
+ def test_variance
58
+ assert_equal( 0.0, @axi00.variance)
59
+ assert_equal( 0.0, @axi01.variance)
60
+ end
61
+
62
+ def test_x
63
+ assert_in_delta(16.0, @axi00.x(1.0), TOLERANCE)
64
+ end
65
+
66
+ end
67
+
@@ -0,0 +1,50 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "test/unit"
5
+ require "malge.rb"
6
+ require "malge/errorfittedfunction.rb"
7
+
8
+ class TC_ErrorFittedFunction_AXInvPlusB < Test::Unit::TestCase
9
+ def setup
10
+ @axi01 = Malge::ErrorFittedFunction::AXInvPlusB.new(
11
+ [
12
+ [1.0, 8.0],
13
+ [2.0, 6.0],
14
+ [4.0, 5.0],
15
+ [8.0, 3.0],
16
+ ]
17
+ )
18
+ end
19
+
20
+ #def test_initialize
21
+ #end
22
+
23
+ def test_fit
24
+ assert_equal(1.0, @axi01.coefficients[0])
25
+ assert_equal(4.0, @axi01.coefficients[1])
26
+ end
27
+
28
+ def test_expected_error
29
+ assert_equal(5.0, @axi01.expected_error(1.0))
30
+ assert_equal(3.0, @axi01.expected_error(2.0))
31
+ assert_equal(2.0, @axi01.expected_error(4.0))
32
+ assert_equal(1.5, @axi01.expected_error(8.0))
33
+ end
34
+
35
+ def test_finest_y
36
+ assert_equal(3.0, @axi01.finest_y)
37
+ end
38
+
39
+ def test_variance
40
+ assert_equal( 0.0, @axi01.variance)
41
+ #diff_abs = [4,1]
42
+ #expected = [1,3]
43
+ end
44
+
45
+ def test_x
46
+ assert_equal(4.0, @axi01.x(2.0))
47
+ end
48
+
49
+ end
50
+
@@ -62,8 +62,9 @@ class TC_Malge < Test::Unit::TestCase
62
62
  [ 1.000, -2.000],
63
63
  [ 1.000, -1.000],
64
64
  ]
65
- result = Malge::LeastSquare.least_square_proportional(data_pairs)
66
- assert_in_delta(-1.5, result, TOLERANCE)
65
+ results = Malge::LeastSquare.least_square_proportional(data_pairs)
66
+ assert_equal(1, results.size)
67
+ assert_in_delta(-1.5, results[0], TOLERANCE)
67
68
  end
68
69
 
69
70
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: malge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-15 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -112,6 +112,8 @@ files:
112
112
  - lib/malge/errorfittedfunction/aexpbx32.rb
113
113
  - lib/malge/errorfittedfunction/axinv.rb
114
114
  - lib/malge/errorfittedfunction/axinv32.rb
115
+ - lib/malge/errorfittedfunction/axinv32plusb.rb
116
+ - lib/malge/errorfittedfunction/axinvplusb.rb
115
117
  - lib/malge/leastsquare.rb
116
118
  - lib/malge/matrix.rb
117
119
  - lib/malge/simultaneousequations.rb
@@ -123,6 +125,8 @@ files:
123
125
  - test/test_errorfittedfunction_aexpbx32.rb
124
126
  - test/test_errorfittedfunction_axinv.rb
125
127
  - test/test_errorfittedfunction_axinv32.rb
128
+ - test/test_errorfittedfunction_axinv32plusb.rb
129
+ - test/test_errorfittedfunction_axinvplusb.rb
126
130
  - test/test_leastsquare.rb
127
131
  - test/test_simultaneousequations.rb
128
132
  homepage: http://github.com/ippei94da/malge
@@ -140,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
144
  version: '0'
141
145
  segments:
142
146
  - 0
143
- hash: -274079459
147
+ hash: 684098349
144
148
  required_rubygems_version: !ruby/object:Gem::Requirement
145
149
  none: false
146
150
  requirements: