gslr 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +9 -2
- data/lib/gslr/ffi.rb +3 -0
- data/lib/gslr/model.rb +4 -0
- data/lib/gslr/ols.rb +16 -2
- data/lib/gslr/ridge.rb +3 -3
- data/lib/gslr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 659075d2214e0e64dd7689431a8b38492ff758b8369171d970c3d31ba9fe5ba9
|
4
|
+
data.tar.gz: e47f6cc7bedceb9f811444f38aa0bc0bc5cc9b8fbaeb0c9f20e853b03fa041f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35c109f3a1c866d29722e89ae7ee12350fad09599daf1b717baabeb58caf2541a81524174ae023ba72836d868770b2cfcaf409483fa81c60e7ed63ad083cfb43
|
7
|
+
data.tar.gz: 7afa7abd2f7217e133de5b8a8baa6e6b7093072eb89bd30eb257f4db73990d4fdacd251de3d89c44969fbf20de61aab081fc989faf977d94c403ad563e4313ff
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -49,6 +49,13 @@ model.coefficients
|
|
49
49
|
model.intercept
|
50
50
|
```
|
51
51
|
|
52
|
+
Get the covariance matrix and chi-squared
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
model.covariance
|
56
|
+
model.chi2
|
57
|
+
```
|
58
|
+
|
52
59
|
Pass weights
|
53
60
|
|
54
61
|
```ruby
|
@@ -97,7 +104,7 @@ Check out [the options](https://www.gnu.org/software/gsl/extras/native_win_build
|
|
97
104
|
sudo apt-get install libgsl-dev
|
98
105
|
```
|
99
106
|
|
100
|
-
|
107
|
+
### Heroku
|
101
108
|
|
102
109
|
Use the [Apt buildpack](https://github.com/heroku/heroku-buildpack-apt) and create an `Aptfile` with:
|
103
110
|
|
@@ -105,7 +112,7 @@ Use the [Apt buildpack](https://github.com/heroku/heroku-buildpack-apt) and crea
|
|
105
112
|
libgsl-dev
|
106
113
|
```
|
107
114
|
|
108
|
-
|
115
|
+
### Travis CI
|
109
116
|
|
110
117
|
Add to `.travis.yml`:
|
111
118
|
|
data/lib/gslr/ffi.rb
CHANGED
@@ -24,6 +24,9 @@ module GSLR
|
|
24
24
|
raise LoadError, "Could not find GSL"
|
25
25
|
end
|
26
26
|
|
27
|
+
# https://www.gnu.org/software/gsl/doc/html/err.html
|
28
|
+
extern "char * gsl_strerror(int gsl_errno)"
|
29
|
+
|
27
30
|
# https://www.gnu.org/software/gsl/doc/html/vectors.html
|
28
31
|
extern "gsl_vector * gsl_vector_alloc(size_t n)"
|
29
32
|
extern "void gsl_vector_free(gsl_vector * v)"
|
data/lib/gslr/model.rb
CHANGED
data/lib/gslr/ols.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module GSLR
|
2
2
|
class OLS < Model
|
3
|
+
attr_reader :covariance, :chi2
|
4
|
+
|
3
5
|
def fit(x, y, weight: nil)
|
4
6
|
# set data
|
5
7
|
xc, s1, s2 = set_matrix(x, intercept: @fit_intercept)
|
@@ -14,15 +16,17 @@ module GSLR
|
|
14
16
|
# fit
|
15
17
|
if weight
|
16
18
|
wc = set_vector(weight)
|
17
|
-
FFI.gsl_multifit_wlinear(xc, wc, yc, c, cov, chisq
|
19
|
+
check_status FFI.gsl_multifit_wlinear(xc, wc, yc, c, cov, chisq, work)
|
18
20
|
else
|
19
|
-
FFI.gsl_multifit_linear(xc, yc, c, cov, chisq
|
21
|
+
check_status FFI.gsl_multifit_linear(xc, yc, c, cov, chisq, work)
|
20
22
|
end
|
21
23
|
|
22
24
|
# read solution
|
23
25
|
c_ptr = FFI.gsl_vector_ptr(c, 0)
|
24
26
|
@coefficients = c_ptr[0, s2 * Fiddle::SIZEOF_DOUBLE].unpack("d*")
|
25
27
|
@intercept = @fit_intercept ? @coefficients.shift : 0.0
|
28
|
+
@covariance = read_matrix(cov, s2)
|
29
|
+
@chi2 = chisq[0, Fiddle::SIZEOF_DOUBLE].unpack1("d")
|
26
30
|
|
27
31
|
nil
|
28
32
|
ensure
|
@@ -33,5 +37,15 @@ module GSLR
|
|
33
37
|
FFI.gsl_matrix_free(cov) if cov
|
34
38
|
FFI.gsl_multifit_linear_free(work) if work
|
35
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def read_matrix(cov, s2)
|
44
|
+
ptr = FFI.gsl_matrix_ptr(cov, 0, 0)
|
45
|
+
row_size = s2 * Fiddle::SIZEOF_DOUBLE
|
46
|
+
s2.times.map do |i|
|
47
|
+
ptr[i * row_size, row_size].unpack("d*")
|
48
|
+
end
|
49
|
+
end
|
36
50
|
end
|
37
51
|
end
|
data/lib/gslr/ridge.rb
CHANGED
@@ -24,8 +24,8 @@ module GSLR
|
|
24
24
|
work = FFI.gsl_multifit_linear_alloc(s1, s2)
|
25
25
|
|
26
26
|
# fit
|
27
|
-
FFI.gsl_multifit_linear_svd(xc, work)
|
28
|
-
FFI.gsl_multifit_linear_solve(Math.sqrt(@alpha), xc, yc, c, rnorm
|
27
|
+
check_status FFI.gsl_multifit_linear_svd(xc, work)
|
28
|
+
check_status FFI.gsl_multifit_linear_solve(Math.sqrt(@alpha), xc, yc, c, rnorm, snorm, work)
|
29
29
|
|
30
30
|
# read solution
|
31
31
|
c_ptr = FFI.gsl_vector_ptr(c, 0)
|
@@ -83,7 +83,7 @@ module GSLR
|
|
83
83
|
end
|
84
84
|
|
85
85
|
yc = set_vector(y)
|
86
|
-
FFI.gsl_vector_add_constant(yc, -y_offset)
|
86
|
+
check_status FFI.gsl_vector_add_constant(yc, -y_offset)
|
87
87
|
|
88
88
|
[yc, y_offset]
|
89
89
|
end
|
data/lib/gslr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gslr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|