malge 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -1
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/lib/malge.rb +6 -1
- data/lib/malge/errorfittedfunction.rb +87 -0
- data/lib/malge/errorfittedfunction/aexpbx.rb +39 -0
- data/lib/malge/errorfittedfunction/aexpbx32.rb +40 -0
- data/lib/malge/errorfittedfunction/axinv.rb +32 -0
- data/lib/malge/errorfittedfunction/axinv32.rb +32 -0
- data/malge.gemspec +16 -3
- data/test/test_errorfittedfunction.rb +87 -0
- data/test/test_errorfittedfunction_aexpbx.rb +73 -0
- data/test/test_errorfittedfunction_aexpbx32.rb +92 -0
- data/test/test_errorfittedfunction_axinv.rb +57 -0
- data/test/test_errorfittedfunction_axinv32.rb +71 -0
- metadata +58 -12
data/CHANGES
CHANGED
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/malge.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
module Malge; end
|
2
2
|
|
3
|
-
require "malge/
|
3
|
+
require "malge/errorfittedfunction.rb"
|
4
|
+
require "malge/errorfittedfunction/aexpbx.rb"
|
5
|
+
require "malge/errorfittedfunction/aexpbx32.rb"
|
6
|
+
require "malge/errorfittedfunction/axinv.rb"
|
7
|
+
require "malge/errorfittedfunction/axinv32.rb"
|
4
8
|
require "malge/leastsquare.rb"
|
5
9
|
require "malge/matrix.rb"
|
10
|
+
require "malge/simultaneousequations.rb"
|
6
11
|
require "malge/vector.rb"
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#coding: utf-8
|
3
|
+
|
4
|
+
#Class for function to which x[i] and y[i] fit.
|
5
|
+
#This class include mathematical dealing for errors.
|
6
|
+
#Not simple fitting;
|
7
|
+
#this class assume true value with the expected most precise value and
|
8
|
+
#use absolute value of difference between a data point and the assumed true value.
|
9
|
+
class Malge::ErrorFittedFunction
|
10
|
+
attr_reader :coefficients
|
11
|
+
|
12
|
+
class TypeError < Exception; end
|
13
|
+
class SizeMismatchError < Exception; end
|
14
|
+
class NotImplementedError < Exception; end
|
15
|
+
|
16
|
+
#Generate error fitted function from x[i] and y[i].
|
17
|
+
#Errors are generated y[i] and y_true assumed by the expected most precise y[i].
|
18
|
+
def initialize(data_pairs)
|
19
|
+
|
20
|
+
raise TypeError unless data_pairs.class == Array
|
21
|
+
data_pairs.each do |pair|
|
22
|
+
raise TypeError unless pair.class == Array
|
23
|
+
raise SizeMismatchError unless pair.size == 2
|
24
|
+
end
|
25
|
+
|
26
|
+
@raw_pairs = data_pairs
|
27
|
+
#pp finest_y
|
28
|
+
@diff_abs_pairs = data_pairs.map { |pair| [pair[0], (pair[1] - finest_y).abs] }
|
29
|
+
@diff_abs_pairs.delete_at(-1)
|
30
|
+
fit
|
31
|
+
end
|
32
|
+
|
33
|
+
##Return expected error
|
34
|
+
#def expected_errors(x)
|
35
|
+
# raise NotImplementedError, "Define #{__method__}() in the inherited class."
|
36
|
+
#end
|
37
|
+
|
38
|
+
#Return expected error at x, condition variable, on the fitted function.
|
39
|
+
#Note that this method does not return the error between actual and true value.
|
40
|
+
def expected_error(x)
|
41
|
+
raise NotImplementedError, "Define #{__method__}() in the inherited class."
|
42
|
+
end
|
43
|
+
|
44
|
+
#Return variance of distribution between each pair
|
45
|
+
#of expected error and y[i], actual data point.
|
46
|
+
#Note that this method does not return variance of difference
|
47
|
+
#between each pair of TRUE value and y[i].
|
48
|
+
#Ignore last value of x[i] and y[i].
|
49
|
+
def variance
|
50
|
+
sum = 0.0
|
51
|
+
#pp @diff_abs_pairs
|
52
|
+
@diff_abs_pairs.each do |pair|
|
53
|
+
#pp pair
|
54
|
+
sum += (pair[1] - expected_error(pair[0]) )**2
|
55
|
+
end
|
56
|
+
sum
|
57
|
+
end
|
58
|
+
|
59
|
+
#Return value of 'x', assumed condition value, correspond to extpected value of 'y'.
|
60
|
+
def x(y)
|
61
|
+
raise NotImplementedError, "Define #{__method__}() in the inherited class."
|
62
|
+
end
|
63
|
+
|
64
|
+
#Return the value of y[i] at which the most precise data is expected to be obtained.
|
65
|
+
def finest_y
|
66
|
+
raise NotImplementedError, "Define #{__method__}() in the inherited class."
|
67
|
+
|
68
|
+
#In the most case, it would be sufficient to select belows.
|
69
|
+
@raw_pairs.max_by { |pair| pair[0] }[1]
|
70
|
+
@raw_pairs.min_by { |pair| pair[0] }[1]
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
#Fit the data pairs to a certain function.
|
76
|
+
#Call from initalize().
|
77
|
+
#You need to design to set @coefficients.
|
78
|
+
def fit
|
79
|
+
#raise NotImplementedError, "Define fit() in the inherited class."
|
80
|
+
raise NotImplementedError, "Define #{__method__}() in the inherited class."
|
81
|
+
end
|
82
|
+
|
83
|
+
#Return the most precise y[i].
|
84
|
+
#This depends on each data and function.
|
85
|
+
#E.g., does a higher or lower value lead precise?
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
#Assumed y = a[0] * exp(a[1] *x)
|
5
|
+
#
|
6
|
+
#NOTE: @coefficients[0] might become negative value.
|
7
|
+
# Need discussion for dealing?
|
8
|
+
class Malge::ErrorFittedFunction::AExpBX < Malge::ErrorFittedFunction
|
9
|
+
|
10
|
+
def fit
|
11
|
+
inv_pairs = @diff_abs_pairs.map {|pair|
|
12
|
+
x = pair[0]
|
13
|
+
y = Math::log(pair[1])
|
14
|
+
[x,y]
|
15
|
+
}
|
16
|
+
@coefficients = Malge::LeastSquare.least_square_1st_degree(inv_pairs)
|
17
|
+
@coefficients[0] = Math::exp @coefficients[0]
|
18
|
+
end
|
19
|
+
|
20
|
+
def expected_error(x)
|
21
|
+
@coefficients[0] * Math::exp( @coefficients[1] * x)
|
22
|
+
end
|
23
|
+
|
24
|
+
#y = a[0] * exp(a[1] *x)
|
25
|
+
#a[0] * exp(a[1] *x) = y
|
26
|
+
#exp(a[1] *x) = y/a[0]
|
27
|
+
#a[1] *x = log( y/a[0])
|
28
|
+
#x = log( y/a[0])/a[1]
|
29
|
+
def x(y)
|
30
|
+
return Math::log( y / @coefficients[0])/@coefficients[1]
|
31
|
+
end
|
32
|
+
|
33
|
+
def finest_y
|
34
|
+
@raw_pairs.max_by { |pair| pair[0] }[1]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
#Assumed y = a[0] * exp(a[1] *x)
|
5
|
+
#
|
6
|
+
#NOTE: @coefficients[0] might become negative value.
|
7
|
+
# Need discussion for dealing?
|
8
|
+
class Malge::ErrorFittedFunction::AExpBX32 < Malge::ErrorFittedFunction
|
9
|
+
|
10
|
+
def fit
|
11
|
+
inv_pairs = @diff_abs_pairs.map {|pair|
|
12
|
+
x = pair[0] ** (3.0/2.0)
|
13
|
+
y = Math::log(pair[1])
|
14
|
+
[x,y]
|
15
|
+
}
|
16
|
+
@coefficients = Malge::LeastSquare.least_square_1st_degree(inv_pairs)
|
17
|
+
@coefficients[0] = Math::exp @coefficients[0]
|
18
|
+
end
|
19
|
+
|
20
|
+
def expected_error(x)
|
21
|
+
@coefficients[0] * Math::exp( @coefficients[1] * x **(3.0/2.0))
|
22
|
+
end
|
23
|
+
|
24
|
+
#y = a[0] * exp(a[1] *x^(3/2))
|
25
|
+
#a[0] * exp(a[1] *x^(3/2)) = y
|
26
|
+
#exp(a[1] *x^(3/2)) = y/a[0]
|
27
|
+
#a[1] *x^(3/2) = log( y/a[0])
|
28
|
+
#x^(3/2) = log( y/a[0])/a[1]
|
29
|
+
#x = (log( y/a[0])/a[1])^(2/3)
|
30
|
+
def x(y)
|
31
|
+
return (Math::log( y / @coefficients[0])/@coefficients[1]) **(2.0/3.0)
|
32
|
+
end
|
33
|
+
|
34
|
+
def finest_y
|
35
|
+
@raw_pairs.max_by { |pair| pair[0] }[1]
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
@@ -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::AXInv < 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
|
+
|
@@ -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::AXInv32 < 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
|
+
|
data/malge.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "malge"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
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-
|
12
|
+
s.date = "2013-02-14"
|
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 = [
|
@@ -25,19 +25,29 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"lib/malge.rb",
|
28
|
+
"lib/malge/errorfittedfunction.rb",
|
29
|
+
"lib/malge/errorfittedfunction/aexpbx.rb",
|
30
|
+
"lib/malge/errorfittedfunction/aexpbx32.rb",
|
31
|
+
"lib/malge/errorfittedfunction/axinv.rb",
|
32
|
+
"lib/malge/errorfittedfunction/axinv32.rb",
|
28
33
|
"lib/malge/leastsquare.rb",
|
29
34
|
"lib/malge/matrix.rb",
|
30
35
|
"lib/malge/simultaneousequations.rb",
|
31
36
|
"lib/malge/vector.rb",
|
32
37
|
"malge.gemspec",
|
33
38
|
"test/helper.rb",
|
39
|
+
"test/test_errorfittedfunction.rb",
|
40
|
+
"test/test_errorfittedfunction_aexpbx.rb",
|
41
|
+
"test/test_errorfittedfunction_aexpbx32.rb",
|
42
|
+
"test/test_errorfittedfunction_axinv.rb",
|
43
|
+
"test/test_errorfittedfunction_axinv32.rb",
|
34
44
|
"test/test_leastsquare.rb",
|
35
45
|
"test/test_simultaneousequations.rb"
|
36
46
|
]
|
37
47
|
s.homepage = "http://github.com/ippei94da/malge"
|
38
48
|
s.licenses = ["MIT"]
|
39
49
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = "1.8.
|
50
|
+
s.rubygems_version = "1.8.23"
|
41
51
|
s.summary = "Math ALGEbra library."
|
42
52
|
|
43
53
|
if s.respond_to? :specification_version then
|
@@ -48,17 +58,20 @@ Gem::Specification.new do |s|
|
|
48
58
|
s.add_development_dependency(%q<bundler>, ["~> 1.2.2"])
|
49
59
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
50
60
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<psych>, [">= 0"])
|
51
62
|
else
|
52
63
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
53
64
|
s.add_dependency(%q<bundler>, ["~> 1.2.2"])
|
54
65
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
55
66
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<psych>, [">= 0"])
|
56
68
|
end
|
57
69
|
else
|
58
70
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
59
71
|
s.add_dependency(%q<bundler>, ["~> 1.2.2"])
|
60
72
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
61
73
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
74
|
+
s.add_dependency(%q<psych>, [">= 0"])
|
62
75
|
end
|
63
76
|
end
|
64
77
|
|
@@ -0,0 +1,87 @@
|
|
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 Malge::ErrorFittedFunction::Dummy00 < Malge::ErrorFittedFunction
|
9
|
+
def fit; end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Malge::ErrorFittedFunction::Dummy01 < Malge::ErrorFittedFunction
|
13
|
+
def expected_error(x)
|
14
|
+
@coefficients[0] + @coefficients[1] * x
|
15
|
+
end
|
16
|
+
|
17
|
+
#Assume: y = 1.0 + 2.0 * x
|
18
|
+
#x = 1/2( y - 1.0)
|
19
|
+
def x(y)
|
20
|
+
return 1.0/2.0 * (y - 1.0)
|
21
|
+
end
|
22
|
+
|
23
|
+
#Assume: y = 1.0 + 2.0 * x
|
24
|
+
def fit
|
25
|
+
@coefficients = [1.0, 2.0]
|
26
|
+
end
|
27
|
+
|
28
|
+
def finest_y
|
29
|
+
#max
|
30
|
+
finest_pair = @raw_pairs.max_by { |pair| pair[0] }
|
31
|
+
finest_pair[1]
|
32
|
+
|
33
|
+
#@raw_pairs[x][1]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
class TC_ErrorFittedFunction < Test::Unit::TestCase
|
39
|
+
def setup
|
40
|
+
#@eff00 = Malge::ErrorFittedFunction::Dummy00.new([], [])
|
41
|
+
@eff01 = Malge::ErrorFittedFunction::Dummy01.new(
|
42
|
+
#2x+1 = 1, -1
|
43
|
+
#2x+1 = 3, +2
|
44
|
+
#2x+1 = 5, -1
|
45
|
+
#[0.0, 1.0, 2.0],
|
46
|
+
#[0.0, 5.0, 4.0]
|
47
|
+
[
|
48
|
+
[0.0, 0.0],
|
49
|
+
[1.0, 5.0],
|
50
|
+
[2.0, 4.0],
|
51
|
+
]
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_variance
|
56
|
+
assert_equal(13.0, @eff01.variance)
|
57
|
+
#diff_abs = [4,1]
|
58
|
+
#expected = [1,3]
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_expected_error
|
62
|
+
assert_equal(1.0, @eff01.expected_error(0.0))
|
63
|
+
assert_equal(3.0, @eff01.expected_error(1.0))
|
64
|
+
assert_equal(5.0, @eff01.expected_error(2.0))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_initialize
|
68
|
+
assert_raise(Malge::ErrorFittedFunction::NotImplementedError){
|
69
|
+
Malge::ErrorFittedFunction.new([])
|
70
|
+
}
|
71
|
+
assert_raise(Malge::ErrorFittedFunction::SizeMismatchError){
|
72
|
+
Malge::ErrorFittedFunction.new([[1,2], [1,3, 3]])
|
73
|
+
}
|
74
|
+
assert_raise(Malge::ErrorFittedFunction::TypeError){
|
75
|
+
Malge::ErrorFittedFunction.new([2, [1,2,3]])
|
76
|
+
}
|
77
|
+
assert_raise(Malge::ErrorFittedFunction::TypeError){
|
78
|
+
Malge::ErrorFittedFunction.new([[1,2], 1])
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_finest_y
|
83
|
+
assert_equal(4.0, @eff01.finest_y)
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,73 @@
|
|
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 Malge::ErrorFittedFunction::AExpBX
|
9
|
+
public :fit
|
10
|
+
end
|
11
|
+
|
12
|
+
class TC_ErrorFittedFunction_AExpBX < Test::Unit::TestCase
|
13
|
+
TOLERANCE = 1.0E-10
|
14
|
+
def setup
|
15
|
+
@aebx00 = Malge::ErrorFittedFunction::AExpBX.new(
|
16
|
+
[
|
17
|
+
[ 0.0, 104.0],
|
18
|
+
[ 1.0, 102.0],
|
19
|
+
[ 2.0, 101.0],
|
20
|
+
[ 3.0, 100.0],
|
21
|
+
]
|
22
|
+
)
|
23
|
+
|
24
|
+
@aebx01 = Malge::ErrorFittedFunction::AExpBX.new(
|
25
|
+
[
|
26
|
+
[ 0.0, 104.0],
|
27
|
+
[ 1.0, 98.0],
|
28
|
+
[ 2.0, 101.0],
|
29
|
+
[ 3.0, 100.0],
|
30
|
+
]
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
#def test_initialize
|
35
|
+
#end
|
36
|
+
|
37
|
+
def test_fit
|
38
|
+
corrects = [4.0, - Math::log(2.0)]
|
39
|
+
results = @aebx00.coefficients
|
40
|
+
assert_equal(2, results.size)
|
41
|
+
assert_in_delta(corrects[0] , results[0], TOLERANCE)
|
42
|
+
assert_in_delta(corrects[1] , results[1], TOLERANCE)
|
43
|
+
|
44
|
+
results = @aebx01.coefficients
|
45
|
+
corrects = [4.0, - Math::log(2.0)]
|
46
|
+
assert_equal(2, results.size)
|
47
|
+
assert_in_delta(corrects[0] , results[0], TOLERANCE)
|
48
|
+
assert_in_delta(corrects[1] , results[1], TOLERANCE)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_expected_error
|
52
|
+
assert_in_delta(4.0, @aebx00.expected_error(0.0), TOLERANCE)
|
53
|
+
assert_in_delta(2.0, @aebx00.expected_error(1.0), TOLERANCE)
|
54
|
+
assert_in_delta(1.0, @aebx00.expected_error(2.0), TOLERANCE)
|
55
|
+
assert_in_delta(0.5, @aebx00.expected_error(3.0), TOLERANCE)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_finest_y
|
59
|
+
assert_equal(100.0, @aebx00.finest_y)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_variance
|
63
|
+
assert_in_delta( 0.0, @aebx00.variance, TOLERANCE)
|
64
|
+
#diff_abs = [4,1]
|
65
|
+
#expected = [1,3]
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_x
|
69
|
+
assert_in_delta(1.0, @aebx00.x(2.0), TOLERANCE)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,92 @@
|
|
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 Malge::ErrorFittedFunction::AExpBX32
|
9
|
+
public :fit
|
10
|
+
end
|
11
|
+
|
12
|
+
class TC_ErrorFittedFunction_AExpBX32 < Test::Unit::TestCase
|
13
|
+
TOLERANCE = 1.0E-09 #very large error in calculation at x()
|
14
|
+
def setup
|
15
|
+
@aebx00 = Malge::ErrorFittedFunction::AExpBX32.new(
|
16
|
+
[
|
17
|
+
[ 0.0, 100.0 + 3.0* 2.0**(-2.0 * 0 )],
|
18
|
+
[ 1.0, 100.0 + 3.0* 2.0**(-2.0 * 1.0 ) ],
|
19
|
+
[ 2.0, 100.0 + 3.0* 2.0**(-2.0 * (2.0**(3.0/2.0)))],
|
20
|
+
[ 3.0, 100.0 ],
|
21
|
+
]
|
22
|
+
)
|
23
|
+
|
24
|
+
@aebx01 = Malge::ErrorFittedFunction::AExpBX32.new(
|
25
|
+
[
|
26
|
+
[ 0.0, 100.0 + 3.0* 2.0**(-2.0 * 0 )],
|
27
|
+
[ 1.0, 100.0 - 3.0* 2.0**(-2.0 * 1.0 ) ],
|
28
|
+
[ 2.0, 100.0 + 3.0* 2.0**(-2.0 * (2.0**(3.0/2.0)))],
|
29
|
+
[ 3.0, 100.0 ],
|
30
|
+
]
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
#def test_initialize
|
35
|
+
#end
|
36
|
+
|
37
|
+
def test_fit
|
38
|
+
corrects = [3.0, - 2.0*Math::log(2.0)]
|
39
|
+
results = @aebx00.coefficients
|
40
|
+
assert_equal(2, results.size)
|
41
|
+
assert_in_delta(corrects[0] , results[0], TOLERANCE)
|
42
|
+
assert_in_delta(corrects[1] , results[1], TOLERANCE)
|
43
|
+
|
44
|
+
corrects = [3.0, - 2.0*Math::log(2.0)]
|
45
|
+
results = @aebx01.coefficients
|
46
|
+
assert_equal(2, results.size)
|
47
|
+
assert_in_delta(corrects[0] , results[0], TOLERANCE)
|
48
|
+
assert_in_delta(corrects[1] , results[1], TOLERANCE)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_expected_error
|
52
|
+
corrects =
|
53
|
+
[
|
54
|
+
3.0* 2.0**(-2.0 * 0.0) ,
|
55
|
+
3.0* 2.0**(-2.0 * 1.0),
|
56
|
+
3.0* 2.0**(-2.0 * (2.0**(3.0/2.0)))
|
57
|
+
]
|
58
|
+
assert_in_delta(corrects[0], @aebx00.expected_error(0.0), TOLERANCE)
|
59
|
+
assert_in_delta(corrects[1], @aebx00.expected_error(1.0), TOLERANCE)
|
60
|
+
assert_in_delta(corrects[2], @aebx00.expected_error(2.0), TOLERANCE)
|
61
|
+
|
62
|
+
corrects =
|
63
|
+
[
|
64
|
+
3.0* 2.0**(-2.0 * 0.0) ,
|
65
|
+
3.0* 2.0**(-2.0 * 1.0),
|
66
|
+
3.0* 2.0**(-2.0 * (2.0**(3.0/2.0)))
|
67
|
+
]
|
68
|
+
assert_in_delta(corrects[0], @aebx01.expected_error(0.0), TOLERANCE)
|
69
|
+
assert_in_delta(corrects[1], @aebx01.expected_error(1.0), TOLERANCE)
|
70
|
+
assert_in_delta(corrects[2], @aebx01.expected_error(2.0), TOLERANCE)
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_finest_y
|
75
|
+
assert_equal(100.0, @aebx00.finest_y)
|
76
|
+
assert_equal(100.0, @aebx01.finest_y)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_variance
|
80
|
+
assert_in_delta( 0.0, @aebx00.variance, TOLERANCE)
|
81
|
+
assert_in_delta( 0.0, @aebx01.variance, TOLERANCE)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_x
|
85
|
+
assert_in_delta(0.0, @aebx00.x(3.00), TOLERANCE)
|
86
|
+
assert_in_delta(1.0, @aebx00.x(0.75), TOLERANCE)
|
87
|
+
assert_in_delta(0.0, @aebx01.x(3.00), TOLERANCE)
|
88
|
+
assert_in_delta(1.0, @aebx01.x(0.75), TOLERANCE)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
@@ -0,0 +1,57 @@
|
|
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 Malge::ErrorFittedFunction::AXInv
|
9
|
+
# public :fit
|
10
|
+
#end
|
11
|
+
|
12
|
+
class TC_ErrorFittedFunction_AXInv < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
@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
|
+
[
|
21
|
+
[1.0, 8.0],
|
22
|
+
[2.0, 6.0],
|
23
|
+
[4.0, 5.0],
|
24
|
+
[8.0, 4.0],
|
25
|
+
]
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
#def test_initialize
|
30
|
+
#end
|
31
|
+
|
32
|
+
#def test_fit
|
33
|
+
#end
|
34
|
+
|
35
|
+
def test_expected_error
|
36
|
+
assert_equal(4.0, @axi01.expected_error(1.0))
|
37
|
+
assert_equal(2.0, @axi01.expected_error(2.0))
|
38
|
+
assert_equal(1.0, @axi01.expected_error(4.0))
|
39
|
+
assert_equal(0.5, @axi01.expected_error(8.0))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_finest_y
|
43
|
+
assert_equal(4.0, @axi01.finest_y)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_variance
|
47
|
+
assert_equal( 0.0, @axi01.variance)
|
48
|
+
#diff_abs = [4,1]
|
49
|
+
#expected = [1,3]
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_x
|
53
|
+
assert_equal(2.0, @axi01.x(2.0))
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,71 @@
|
|
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 Malge::ErrorFittedFunction::AXInv32
|
9
|
+
# public :fit
|
10
|
+
#end
|
11
|
+
|
12
|
+
class TC_ErrorFittedFunction_AXInv32 < Test::Unit::TestCase
|
13
|
+
TOLERANCE = 1.0E-10
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@axi00 = Malge::ErrorFittedFunction::AXInv32.new(
|
17
|
+
[
|
18
|
+
[ 1, 164.0],
|
19
|
+
[ 4, 108.0],
|
20
|
+
[16, 101.0],
|
21
|
+
[64, 100.0],
|
22
|
+
]
|
23
|
+
)
|
24
|
+
|
25
|
+
@axi01 = Malge::ErrorFittedFunction::AXInv32.new(
|
26
|
+
[
|
27
|
+
[ 1, 164.0],
|
28
|
+
[ 4, 92.0],
|
29
|
+
[16, 101.0],
|
30
|
+
[64, 100.0],
|
31
|
+
]
|
32
|
+
)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
#def test_initialize
|
37
|
+
#end
|
38
|
+
|
39
|
+
def test_fit
|
40
|
+
corrects = [0.0, 64.0]
|
41
|
+
results = @axi00.coefficients
|
42
|
+
assert_in_delta(corrects[0], results[0], TOLERANCE)
|
43
|
+
assert_in_delta(corrects[1], results[1], TOLERANCE)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_expected_error
|
47
|
+
assert_equal(64.0, @axi00.expected_error(1.0))
|
48
|
+
assert_equal( 8.0, @axi00.expected_error(4.0))
|
49
|
+
assert_equal( 1.0, @axi00.expected_error(16.0))
|
50
|
+
|
51
|
+
assert_equal(64.0, @axi01.expected_error(1.0))
|
52
|
+
assert_equal( 8.0, @axi01.expected_error(4.0))
|
53
|
+
assert_equal( 1.0, @axi01.expected_error(16.0))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_finest_y
|
57
|
+
assert_equal(100.0, @axi00.finest_y)
|
58
|
+
assert_equal(100.0, @axi01.finest_y)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_variance
|
62
|
+
assert_equal( 0.0, @axi00.variance)
|
63
|
+
assert_equal( 0.0, @axi01.variance)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_x
|
67
|
+
assert_in_delta(16.0, @axi00.x(1.0), TOLERANCE)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
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.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '3.12'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.12'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: bundler
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 1.2.2
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.2.2
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: jeweler
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 1.8.3
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.8.3
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: simplecov
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,7 +69,28 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: psych
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
58
94
|
description: ! "Mathematical library to deal with basic problems in algebla.\n "
|
59
95
|
email: ippei94da@gmail.com
|
60
96
|
executables: []
|
@@ -71,12 +107,22 @@ files:
|
|
71
107
|
- Rakefile
|
72
108
|
- VERSION
|
73
109
|
- lib/malge.rb
|
110
|
+
- lib/malge/errorfittedfunction.rb
|
111
|
+
- lib/malge/errorfittedfunction/aexpbx.rb
|
112
|
+
- lib/malge/errorfittedfunction/aexpbx32.rb
|
113
|
+
- lib/malge/errorfittedfunction/axinv.rb
|
114
|
+
- lib/malge/errorfittedfunction/axinv32.rb
|
74
115
|
- lib/malge/leastsquare.rb
|
75
116
|
- lib/malge/matrix.rb
|
76
117
|
- lib/malge/simultaneousequations.rb
|
77
118
|
- lib/malge/vector.rb
|
78
119
|
- malge.gemspec
|
79
120
|
- test/helper.rb
|
121
|
+
- test/test_errorfittedfunction.rb
|
122
|
+
- test/test_errorfittedfunction_aexpbx.rb
|
123
|
+
- test/test_errorfittedfunction_aexpbx32.rb
|
124
|
+
- test/test_errorfittedfunction_axinv.rb
|
125
|
+
- test/test_errorfittedfunction_axinv32.rb
|
80
126
|
- test/test_leastsquare.rb
|
81
127
|
- test/test_simultaneousequations.rb
|
82
128
|
homepage: http://github.com/ippei94da/malge
|
@@ -94,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
140
|
version: '0'
|
95
141
|
segments:
|
96
142
|
- 0
|
97
|
-
hash:
|
143
|
+
hash: 215000701
|
98
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
145
|
none: false
|
100
146
|
requirements:
|
@@ -103,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
149
|
version: '0'
|
104
150
|
requirements: []
|
105
151
|
rubyforge_project:
|
106
|
-
rubygems_version: 1.8.
|
152
|
+
rubygems_version: 1.8.23
|
107
153
|
signing_key:
|
108
154
|
specification_version: 3
|
109
155
|
summary: Math ALGEbra library.
|