malge 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -1
- data/VERSION +1 -1
- data/lib/malge/errorfittedfunction.rb +1 -2
- data/lib/malge/leastsquare.rb +16 -1
- data/malge.gemspec +2 -2
- data/test/test_leastsquare.rb +11 -0
- metadata +3 -3
data/CHANGES
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
= vasputils changelog
|
2
2
|
|
3
|
-
== Master (for 0.0.
|
3
|
+
== Master (for 0.0.6)
|
4
|
+
|
5
|
+
== Version 0.0.5)
|
6
|
+
* @raw_pairs and @diff_abs_pairs in Malge::ErrorFittedFunction change to publicly readable.
|
7
|
+
* Add Malge::LeastSquare.least_square_proportional.
|
4
8
|
|
5
9
|
== Version 0.0.4
|
6
10
|
* Add Malge::ErrorFittedFunction and inherited classes.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
@@ -7,7 +7,7 @@
|
|
7
7
|
#this class assume true value with the expected most precise value and
|
8
8
|
#use absolute value of difference between a data point and the assumed true value.
|
9
9
|
class Malge::ErrorFittedFunction
|
10
|
-
attr_reader :coefficients
|
10
|
+
attr_reader :coefficients, :raw_pairs, :diff_abs_pairs
|
11
11
|
|
12
12
|
class TypeError < Exception; end
|
13
13
|
class SizeMismatchError < Exception; end
|
@@ -24,7 +24,6 @@ class Malge::ErrorFittedFunction
|
|
24
24
|
end
|
25
25
|
|
26
26
|
@raw_pairs = data_pairs
|
27
|
-
#pp finest_y
|
28
27
|
@diff_abs_pairs = data_pairs.map { |pair| [pair[0], (pair[1] - finest_y).abs] }
|
29
28
|
@diff_abs_pairs.delete_at(-1)
|
30
29
|
fit
|
data/lib/malge/leastsquare.rb
CHANGED
@@ -8,7 +8,6 @@ module Malge::LeastSquare
|
|
8
8
|
|
9
9
|
class UnableCalculationError < Exception; end
|
10
10
|
|
11
|
-
|
12
11
|
#Return values of [a_0, a_1] in y = a_0 x^0 + a_1 x^1.
|
13
12
|
#Argument 'data_pairs' should be Array of Array's. For example,
|
14
13
|
# [
|
@@ -39,6 +38,22 @@ module Malge::LeastSquare
|
|
39
38
|
[a_0, a_1]
|
40
39
|
end
|
41
40
|
|
41
|
+
def self.least_square_proportional(data_pairs)
|
42
|
+
a = 0.0 #x^2
|
43
|
+
d = 0.0 #x*y
|
44
|
+
n = data_pairs.size
|
45
|
+
#pp data_pairs
|
46
|
+
data_pairs.each do |pairs|
|
47
|
+
x = pairs[0].to_f
|
48
|
+
y = pairs[1].to_f
|
49
|
+
a += x**2
|
50
|
+
#b += y**2
|
51
|
+
d += x*y
|
52
|
+
end
|
53
|
+
#raise if d == 0.0
|
54
|
+
d/a
|
55
|
+
end
|
56
|
+
|
42
57
|
#Return variance when fitted to y = a_0 x^0 + a_1 x^1.
|
43
58
|
#Argument 'data_pairs' should be Array of Array's. For example,
|
44
59
|
# [
|
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.5"
|
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-15"
|
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 = [
|
data/test/test_leastsquare.rb
CHANGED
@@ -56,6 +56,17 @@ class TC_Malge < Test::Unit::TestCase
|
|
56
56
|
assert_equal( 4.0, Malge::LeastSquare::variance_1st_degree(data_pairs))
|
57
57
|
end
|
58
58
|
|
59
|
+
def test_least_square_proportional
|
60
|
+
data_pairs =
|
61
|
+
[
|
62
|
+
[ 1.000, -2.000],
|
63
|
+
[ 1.000, -1.000],
|
64
|
+
]
|
65
|
+
result = Malge::LeastSquare.least_square_proportional(data_pairs)
|
66
|
+
assert_in_delta(-1.5, result, TOLERANCE)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
59
70
|
def test_a_exp_bx
|
60
71
|
data_pairs = [
|
61
72
|
[0.0, 4.0],
|
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.5
|
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-
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
segments:
|
142
142
|
- 0
|
143
|
-
hash:
|
143
|
+
hash: -274079459
|
144
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
145
|
none: false
|
146
146
|
requirements:
|