scicom 0.2.3.1-java → 0.3.0-java
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.
- checksums.yaml +4 -4
- data/config.rb +12 -5
- data/cran/AppliedPredictiveModeling.jar +0 -0
- data/cran/AppliedPredictiveModeling.xml +25 -0
- data/cran/AssetPricing.jar +0 -0
- data/cran/AssetPricing.xml +25 -0
- data/doc/SciCom.tex +4 -0
- data/doc/SciCom.tex~ +14 -0
- data/doc/hearder.aux +10 -0
- data/doc/hearder.log +655 -0
- data/doc/hearder.pdf +0 -0
- data/doc/hearder.synctex.gz +0 -0
- data/doc/hearder.tex +87 -0
- data/doc/hearder.tex~ +78 -0
- data/lib/JRubyR/download_url_to_file.rb +132 -0
- data/lib/JRubyR/package.rb +286 -0
- data/lib/JRubyR/renjin.rb +28 -1
- data/test/test_dataframe.rb +1 -2
- data/test/test_linear_model.rb +3 -0
- data/test/test_list.rb +1 -1
- data/test/test_package.rb +66 -0
- data/test/test_tmp.rb +5 -5
- data/test/test_vector.rb +3 -0
- data/version.rb +1 -1
- metadata +67 -8
- data/README.md~ +0 -290
data/lib/JRubyR/renjin.rb
CHANGED
@@ -25,6 +25,7 @@ require 'java'
|
|
25
25
|
require 'securerandom'
|
26
26
|
|
27
27
|
require_relative 'rbsexp'
|
28
|
+
require_relative 'package'
|
28
29
|
# require_relative 'index'
|
29
30
|
|
30
31
|
|
@@ -97,7 +98,8 @@ class Renjin
|
|
97
98
|
|
98
99
|
factory = Java::JavaxScript.ScriptEngineManager.new()
|
99
100
|
@engine = factory.getEngineByName("Renjin")
|
100
|
-
|
101
|
+
super
|
102
|
+
|
101
103
|
end
|
102
104
|
|
103
105
|
#----------------------------------------------------------------------------------------
|
@@ -394,6 +396,31 @@ class Renjin
|
|
394
396
|
|
395
397
|
end
|
396
398
|
|
399
|
+
#----------------------------------------------------------------------------------------
|
400
|
+
#
|
401
|
+
#----------------------------------------------------------------------------------------
|
402
|
+
|
403
|
+
def install__package(name)
|
404
|
+
|
405
|
+
pm = PackageManager.new
|
406
|
+
pm.load_package(name)
|
407
|
+
|
408
|
+
end
|
409
|
+
|
410
|
+
#----------------------------------------------------------------------------------------
|
411
|
+
#
|
412
|
+
#----------------------------------------------------------------------------------------
|
413
|
+
|
414
|
+
def library(package)
|
415
|
+
|
416
|
+
Dir.chdir(SciCom.cran_dir)
|
417
|
+
filename = SciCom.cran_dir + "/#{package}.jar"
|
418
|
+
|
419
|
+
require filename
|
420
|
+
eval("library(#{package})")
|
421
|
+
|
422
|
+
end
|
423
|
+
|
397
424
|
#----------------------------------------------------------------------------------------
|
398
425
|
# Builds a Renjin vector from an MDArray. Should be private, but public for testing.
|
399
426
|
#----------------------------------------------------------------------------------------
|
data/test/test_dataframe.rb
CHANGED
@@ -163,7 +163,7 @@ class SciComTest < Test::Unit::TestCase
|
|
163
163
|
# engine, ..., etc.
|
164
164
|
mtcars[24, nil].pp
|
165
165
|
|
166
|
-
# To retrieve more than one
|
166
|
+
# To retrieve more than one row, we use a numeric index vector.
|
167
167
|
mtcars[R.c(3, 24), nil].pp
|
168
168
|
|
169
169
|
# Name Indexing
|
@@ -213,7 +213,6 @@ class SciComTest < Test::Unit::TestCase
|
|
213
213
|
df.colnames.pp
|
214
214
|
df.colnames(prefix: "sc").pp
|
215
215
|
|
216
|
-
|
217
216
|
# Renjin allows changes to variable properties
|
218
217
|
R.eval("colnames(#{df.r}) = c('name', 'age', 'height', 'weigth', 'race', 'SAT')")
|
219
218
|
R.eval("print(colnames(#{df.r}))")
|
data/test/test_linear_model.rb
CHANGED
@@ -46,6 +46,9 @@ class SciComTest < Test::Unit::TestCase
|
|
46
46
|
|
47
47
|
# This dataset comes from Baseball-Reference.com.
|
48
48
|
baseball = R.read__csv("baseball.csv")
|
49
|
+
# convert the second column of dataframe 'baseball' to a Ruby vector
|
50
|
+
# arr = baseball[[2]].get
|
51
|
+
# arr.print
|
49
52
|
# Lets look at the data available for Momeyball.
|
50
53
|
# (baseball.Year < R.d(2002)).pp
|
51
54
|
moneyball = baseball.subset(baseball.Year < 2002)
|
data/test/test_list.rb
CHANGED
@@ -54,7 +54,7 @@ class SciComTest < Test::Unit::TestCase
|
|
54
54
|
#
|
55
55
|
#--------------------------------------------------------------------------------------
|
56
56
|
|
57
|
-
should "access
|
57
|
+
should "access list elements with indexing [] and [[]]" do
|
58
58
|
|
59
59
|
# get the first element of the list, usign indexing.
|
60
60
|
# Both [] and [[]] indexing can be used with the same R rules.
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
5
|
+
# and distribute this software and its documentation, without fee and without a signed
|
6
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
7
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
8
|
+
# distributions.
|
9
|
+
#
|
10
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
11
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
12
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
13
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
#
|
15
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
16
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
17
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
18
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
19
|
+
# OR MODIFICATIONS.
|
20
|
+
##########################################################################################
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require "test/unit"
|
24
|
+
require 'shoulda'
|
25
|
+
|
26
|
+
require 'env'
|
27
|
+
require 'scicom'
|
28
|
+
|
29
|
+
class SciComTest < Test::Unit::TestCase
|
30
|
+
|
31
|
+
context "R environment" do
|
32
|
+
|
33
|
+
#--------------------------------------------------------------------------------------
|
34
|
+
#
|
35
|
+
#--------------------------------------------------------------------------------------
|
36
|
+
|
37
|
+
setup do
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
#--------------------------------------------------------------------------------------
|
42
|
+
#
|
43
|
+
#--------------------------------------------------------------------------------------
|
44
|
+
|
45
|
+
should "download the proper package" do
|
46
|
+
|
47
|
+
R.install__package("AssetPricing")
|
48
|
+
R.library("AssetPricing")
|
49
|
+
|
50
|
+
R.install__package("AppliedPredictiveModeling")
|
51
|
+
R.library("AppliedPredictiveModeling")
|
52
|
+
|
53
|
+
### Section 3.1 Case Study: Cell Segmentation in High-Content Screening
|
54
|
+
|
55
|
+
R.data('segmentationOriginal')
|
56
|
+
seg = R.segmentationOriginal
|
57
|
+
segTrain = seg.subset(Case: "Train")
|
58
|
+
segTrainX = segTrain[true, -(1..3)]
|
59
|
+
segTrainClass = segTrain.Class
|
60
|
+
segTrainClass.pp
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/test/test_tmp.rb
CHANGED
@@ -55,11 +55,11 @@ class SciComTest < Test::Unit::TestCase
|
|
55
55
|
#--------------------------------------------------------------------------------------
|
56
56
|
|
57
57
|
should "assign to a character vector" do
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
p
|
62
|
-
|
58
|
+
|
59
|
+
R.eval("r.i = 10L")
|
60
|
+
R.eval("print(r.i)") # will print the R int vector
|
61
|
+
p r.i # results in an error in the Ruby script
|
62
|
+
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
data/test/test_vector.rb
CHANGED
@@ -65,6 +65,9 @@ class SciComTest < Test::Unit::TestCase
|
|
65
65
|
assert_equal(4, log_var.length)
|
66
66
|
assert_equal(true, log_var.logical?)
|
67
67
|
|
68
|
+
str_var = R.c("hello there")
|
69
|
+
str_var.pp
|
70
|
+
|
68
71
|
# string vector: create string (character) vectors
|
69
72
|
chr_var = R.c("these are", "some strings")
|
70
73
|
assert_equal("character", chr_var.typeof.gz)
|
data/version.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
$gem_name = "scicom"
|
2
|
-
$version="0.
|
2
|
+
$version="0.3.0"
|
metadata
CHANGED
@@ -1,52 +1,84 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scicom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Rodrigo Botafogo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.5'
|
20
20
|
requirement: !ruby/object:Gem::Requirement
|
21
21
|
requirements:
|
22
|
-
- -
|
22
|
+
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
24
|
+
version: '3.5'
|
25
25
|
prerelease: false
|
26
26
|
type: :runtime
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mdarray
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.5'
|
31
34
|
- - '>='
|
32
35
|
- !ruby/object:Gem::Version
|
33
36
|
version: 0.5.5.2
|
34
37
|
requirement: !ruby/object:Gem::Requirement
|
35
38
|
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.5'
|
36
42
|
- - '>='
|
37
43
|
- !ruby/object:Gem::Version
|
38
44
|
version: 0.5.5.2
|
39
45
|
prerelease: false
|
40
46
|
type: :runtime
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: state_machine
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.2'
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.2.0
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.2'
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.2.0
|
65
|
+
prerelease: false
|
66
|
+
type: :runtime
|
41
67
|
- !ruby/object:Gem::Dependency
|
42
68
|
name: simplecov
|
43
69
|
version_requirements: !ruby/object:Gem::Requirement
|
44
70
|
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0.7'
|
45
74
|
- - '>='
|
46
75
|
- !ruby/object:Gem::Version
|
47
76
|
version: 0.7.1
|
48
77
|
requirement: !ruby/object:Gem::Requirement
|
49
78
|
requirements:
|
79
|
+
- - ~>
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.7'
|
50
82
|
- - '>='
|
51
83
|
- !ruby/object:Gem::Version
|
52
84
|
version: 0.7.1
|
@@ -56,11 +88,17 @@ dependencies:
|
|
56
88
|
name: yard
|
57
89
|
version_requirements: !ruby/object:Gem::Requirement
|
58
90
|
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0.8'
|
59
94
|
- - '>='
|
60
95
|
- !ruby/object:Gem::Version
|
61
96
|
version: 0.8.5.2
|
62
97
|
requirement: !ruby/object:Gem::Requirement
|
63
98
|
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0.8'
|
64
102
|
- - '>='
|
65
103
|
- !ruby/object:Gem::Version
|
66
104
|
version: 0.8.5.2
|
@@ -70,11 +108,17 @@ dependencies:
|
|
70
108
|
name: kramdown
|
71
109
|
version_requirements: !ruby/object:Gem::Requirement
|
72
110
|
requirements:
|
111
|
+
- - ~>
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '1.0'
|
73
114
|
- - '>='
|
74
115
|
- !ruby/object:Gem::Version
|
75
116
|
version: 1.0.1
|
76
117
|
requirement: !ruby/object:Gem::Requirement
|
77
118
|
requirements:
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '1.0'
|
78
122
|
- - '>='
|
79
123
|
- !ruby/object:Gem::Version
|
80
124
|
version: 1.0.1
|
@@ -118,7 +162,9 @@ files:
|
|
118
162
|
- lib/JRubyR/logical_value.rb
|
119
163
|
- lib/JRubyR/environment.rb
|
120
164
|
- lib/JRubyR/ruby_classes.rb
|
165
|
+
- lib/JRubyR/package.rb
|
121
166
|
- lib/JRubyR/function.rb
|
167
|
+
- lib/JRubyR/download_url_to_file.rb
|
122
168
|
- lib/JRubyR/dataframe.rb
|
123
169
|
- test/env.rb
|
124
170
|
- test/test_tmp.rb
|
@@ -146,15 +192,27 @@ files:
|
|
146
192
|
- test/test_assign_mdarray_2d.rb
|
147
193
|
- test/test_assign_mdarray_3d.rb
|
148
194
|
- test/test_assign_mdarray_4d.rb
|
195
|
+
- test/test_package.rb
|
149
196
|
- test/test_list.rb
|
150
197
|
- test/baseball.csv
|
151
198
|
- doc/PypeR.pdf
|
152
199
|
- doc/The R interface.docx
|
153
200
|
- doc/Stat 133 Class Notes (Phil Spector).pdf
|
154
|
-
-
|
201
|
+
- doc/SciCom.tex~
|
202
|
+
- doc/hearder.tex~
|
203
|
+
- doc/hearder.tex
|
204
|
+
- doc/hearder.log
|
205
|
+
- doc/hearder.aux
|
206
|
+
- doc/hearder.pdf
|
207
|
+
- doc/SciCom.tex
|
208
|
+
- doc/hearder.synctex.gz
|
155
209
|
- vendor/Renjin.pdf
|
210
|
+
- vendor/renjin-script-engine-0.7.0-RC7-SNAPSHOT-jar-with-dependencies.jar
|
156
211
|
- target/helper.jar
|
157
|
-
-
|
212
|
+
- cran/AssetPricing.xml
|
213
|
+
- cran/AssetPricing.jar
|
214
|
+
- cran/AppliedPredictiveModeling.xml
|
215
|
+
- cran/AppliedPredictiveModeling.jar
|
158
216
|
- README.md
|
159
217
|
- LICENSE.txt
|
160
218
|
homepage: http://github.com/rbotafogo/scicom/wiki
|
@@ -208,4 +266,5 @@ test_files:
|
|
208
266
|
- test/test_assign_mdarray_2d.rb
|
209
267
|
- test/test_assign_mdarray_3d.rb
|
210
268
|
- test/test_assign_mdarray_4d.rb
|
269
|
+
- test/test_package.rb
|
211
270
|
- test/test_list.rb
|
data/README.md~
DELETED
@@ -1,290 +0,0 @@
|
|
1
|
-
Announcement
|
2
|
-
============
|
3
|
-
|
4
|
-
MDArray version 0.5.5 has Just been released. MDArray is a multi dimensional array implemented
|
5
|
-
for JRuby inspired by NumPy (www.numpy.org) and Masahiro Tanaka´s Narray (narray.rubyforge.org).
|
6
|
-
MDArray stands on the shoulders of Java-NetCDF and Parallel Colt. At this point MDArray has
|
7
|
-
libraries for linear algebra, mathematical, trigonometric and descriptive statistics methods.
|
8
|
-
|
9
|
-
NetCDF-Java Library is a Java interface to NetCDF files, as well as to many other types of
|
10
|
-
scientific data formats. It is developed and distributed by Unidata (http://www.unidata.ucar.edu).
|
11
|
-
|
12
|
-
Parallel Colt (https://sites.google.com/site/piotrwendykier/software/parallelcolt is a
|
13
|
-
multithreaded version of Colt (http://acs.lbl.gov/software/colt/). Colt provides a set of
|
14
|
-
Open Source Libraries for High Performance Scientific and Technical Computing in Java.
|
15
|
-
Scientific and technical computing is characterized by demanding problem sizes and a need for
|
16
|
-
high performance at reasonably small memory footprint.
|
17
|
-
|
18
|
-
|
19
|
-
What´s new:
|
20
|
-
===========
|
21
|
-
|
22
|
-
Class MDMatrix and Linear Algebra Methods
|
23
|
-
-----------------------------------------
|
24
|
-
|
25
|
-
This version of MDArray introduces class MDMatrix. MDMatrix is a matrix class wrapping many
|
26
|
-
linear algebra methods from Parallel Colt (see below). MDMatrix support only the following
|
27
|
-
types: i) int; ii) long; iii) float and iv) double.
|
28
|
-
|
29
|
-
Differently from other libraries, in which matrix is a subclass of array, MDMatrix is a
|
30
|
-
twin class of MDArray. MDMatrix is a twin class of MDArray as every time an MDMatrix is
|
31
|
-
instantiated, an MDArray class is also instantiated. In reality, there is only one backing
|
32
|
-
store that can be viewed by either MDMatrix or MDArray.
|
33
|
-
|
34
|
-
Creation of MDMatrix follows the same API as MDArray API. For instance, creating a double
|
35
|
-
square matrix of size 5 x 5 can be done by:
|
36
|
-
|
37
|
-
matrix = MDMatrix.double([5, 5], [2.0, 0.0, 8.0, 6.0, 0.0,\
|
38
|
-
1.0, 6.0, 0.0, 1.0, 7.0,\
|
39
|
-
5.0, 0.0, 7.0, 4.0, 0.0,\
|
40
|
-
7.0, 0.0, 8.0, 5.0, 0.0,\
|
41
|
-
0.0, 10.0, 0.0, 0.0, 7.0])
|
42
|
-
|
43
|
-
Creating an int matrix filled with zero can be done by:
|
44
|
-
|
45
|
-
matrix = MDMatrix.int([4, 3])
|
46
|
-
|
47
|
-
MDMatrix also supports creation based on methods such as fromfunction, linspace, init_with,
|
48
|
-
arange, typed_arange and ones:
|
49
|
-
|
50
|
-
|
51
|
-
array = MDArray.typed_arange("double", 0, 15)
|
52
|
-
array = MDMatrix.fromfunction("double", [4, 4]) { |x, y| x + y }
|
53
|
-
|
54
|
-
An MDMatrix can also be created from an MDArray as follows:
|
55
|
-
|
56
|
-
d2 = MDArray.typed_arange("double", 0, 15)
|
57
|
-
double_matrix = MDMatrix.from_mdarray(d2)
|
58
|
-
|
59
|
-
An MDMatrix can only be created from MDArrays of one, two or three dimensions. However,
|
60
|
-
one can take a view from an MDArray to create an MDMatrix, as long as the view is at most
|
61
|
-
three dimensional:
|
62
|
-
|
63
|
-
# Instantiate an MDArray and shape it with 4 dimensions
|
64
|
-
> d1 = MDArray.typed_arange("double", 0, 420)
|
65
|
-
> d1.reshape!([5, 4, 3, 7])
|
66
|
-
# slice the array, getting a three dimensional array and from that, make a matrix
|
67
|
-
> matrix = MDMatrix.from_mdarray(d1.slice(0, 0))
|
68
|
-
# get a region from the array, with the first two dimensions of size 0, reduce it to a
|
69
|
-
# size two array and then build a two dimensional matrix
|
70
|
-
> matrix = MDMatrix.from_mdarray(d1.region(:spec => "0:0, 0:0, 0:2, 0:6").reduce)
|
71
|
-
|
72
|
-
printing the above two dimensional matrix gives us:
|
73
|
-
|
74
|
-
> matrix.print
|
75
|
-
3 x 7 matrix
|
76
|
-
0,00000 1,00000 2,00000 3,00000 4,00000 5,00000 6,00000
|
77
|
-
7,00000 8,00000 9,00000 10,0000 11,0000 12,0000 13,0000
|
78
|
-
14,0000 15,0000 16,0000 17,0000 18,0000 19,0000 20,0000
|
79
|
-
|
80
|
-
Every MDMatrix instance has a twin MDArray instance that uses the same backing store. This
|
81
|
-
allows the user to treat the data as either a matrix or an array and use methods either from
|
82
|
-
matrix or array. The above matrix can be printed as an array:
|
83
|
-
|
84
|
-
|
85
|
-
> matrix.mdarray.print
|
86
|
-
[[0.00 1.00 2.00 3.00 4.00 5.00 6.00]
|
87
|
-
[7.00 8.00 9.00 10.00 11.00 12.00 13.00]
|
88
|
-
[14.00 15.00 16.00 17.00 18.00 19.00 20.00]]
|
89
|
-
|
90
|
-
With an MDMatrix, many linear algebra methods can be easily calculated:
|
91
|
-
|
92
|
-
# basic operations on matrix can be done, such as, ‘+’, ‘-‘, ´*’, ‘/’
|
93
|
-
# make a 4 x 4 matrix and fill it with ´double´ 2.5
|
94
|
-
> a = MDMatrix.double([4, 4])
|
95
|
-
> a.fill(2.5)
|
96
|
-
> make a 4 x 4 matrix ´b´ from a given function (block)
|
97
|
-
> b = MDMatrix.fromfunction("double", [4, 4]) { |x, y| x + y }
|
98
|
-
# add both matrices
|
99
|
-
> c = a + b
|
100
|
-
# multiply by scalar
|
101
|
-
> c = a * 2
|
102
|
-
# divide two matrices. Matrix ´b´ has to be non-singular, otherwise an exception is
|
103
|
-
# raised.
|
104
|
-
# generate a non-singular matrix from a given matrix
|
105
|
-
> b.generate_non_singular!
|
106
|
-
> c = a / b
|
107
|
-
|
108
|
-
Linear algebra methods:
|
109
|
-
|
110
|
-
# create a matrix with the given data
|
111
|
-
> pos = MDArray.double([3, 3], [4, 12, -16, 12, 37, -43, -16, -43, 98])
|
112
|
-
> matrix = MDMatrix.from_mdarray(pos)
|
113
|
-
# Cholesky decomposition from wikipedia example
|
114
|
-
> chol = matrix.chol
|
115
|
-
> assert_equal(2, chol[0, 0])
|
116
|
-
> assert_equal(6, chol[1, 0])
|
117
|
-
> assert_equal(-8, chol[2, 0])
|
118
|
-
> assert_equal(5, chol[2, 1])
|
119
|
-
> assert_equal(3, chol[2, 2])
|
120
|
-
|
121
|
-
All other linear algebra methods are called the same way.
|
122
|
-
|
123
|
-
|
124
|
-
MDArray and SciRuby:
|
125
|
-
====================
|
126
|
-
|
127
|
-
MDArray subscribes fully to the SciRuby Manifesto (http://sciruby.com/).
|
128
|
-
|
129
|
-
“Ruby has for some time had no equivalent to the beautifully constructed NumPy, SciPy, and
|
130
|
-
matplotlib libraries for Python.
|
131
|
-
|
132
|
-
We believe that the time for a Ruby science and visualization package has come. Sometimes
|
133
|
-
when a solution of sugar and water becomes super-saturated, from it precipitates a pure,
|
134
|
-
delicious, and diabetes-inducing crystal of sweetness, induced by no more than the tap of a
|
135
|
-
finger. So is occurring now, we believe, with numeric and visualization libraries for Ruby.”
|
136
|
-
|
137
|
-
MDArray main properties are:
|
138
|
-
============================
|
139
|
-
|
140
|
-
+ Homogeneous multidimensional array, a table of elements (usually numbers), all of the
|
141
|
-
same type, indexed by a tuple of positive integers;
|
142
|
-
+ Support for many linear algebra methods (see bellow);
|
143
|
-
+ Easy calculation for large numerical multi dimensional arrays;
|
144
|
-
+ Basic types are: boolean, byte, short, int, long, float, double, string, structure;
|
145
|
-
+ Based on JRuby, which allows importing Java libraries;
|
146
|
-
+ Operator: +,-,*,/,%,**, >, >=, etc.;
|
147
|
-
+ Functions: abs, ceil, floor, truncate, is_zero, square, cube, fourth;
|
148
|
-
+ Binary Operators: &, |, ^, ~ (binary_ones_complement), <<, >>;
|
149
|
-
+ Ruby Math functions: acos, acosh, asin, asinh, atan, atan2, atanh, cbrt, cos, erf, exp,
|
150
|
-
gamma, hypot, ldexp, log, log10, log2, sin, sinh, sqrt, tan, tanh, neg;
|
151
|
-
+ Boolean operations on boolean arrays: and, or, not;
|
152
|
-
+ Fast descriptive statistics from Parallel Colt (complete list found bellow);
|
153
|
-
+ Easy manipulation of arrays: reshape, reduce dimension, permute, section, slice, etc.;
|
154
|
-
+ Support for reading and writing NetCDF-3 files;
|
155
|
-
+ Reading of two dimensional arrays from CSV files (mainly for debugging and simple testing
|
156
|
-
purposes);
|
157
|
-
+ StatList: a list that can grow/shrink and that can compute Parallel Colt descriptive
|
158
|
-
statistics;
|
159
|
-
+ Experimental lazy evaluation (still slower than eager evaluation).
|
160
|
-
|
161
|
-
Supported linear algebra methods:
|
162
|
-
=================================
|
163
|
-
|
164
|
-
+ backwardSolve: Solves the upper triangular system U*x=b;
|
165
|
-
+ chol: Constructs and returns the cholesky-decomposition of the given matrix.
|
166
|
-
+ cond: Returns the condition of matrix A, which is the ratio of largest to smallest singular value.
|
167
|
-
+ det: Returns the determinant of matrix A.
|
168
|
-
+ eig: Constructs and returns the Eigenvalue-decomposition of the given matrix.
|
169
|
-
+ forwardSolve: Solves the lower triangular system L*x=b;
|
170
|
-
+ inverse: Returns the inverse or pseudo-inverse of matrix A.
|
171
|
-
+ kron: Computes the Kronecker product of two real matrices.
|
172
|
-
+ lu: Constructs and returns the LU-decomposition of the given matrix.
|
173
|
-
+ mult: Inner product of two vectors; Sum(x[i] * y[i]).
|
174
|
-
+ mult: Linear algebraic matrix-vector multiplication; z = A * y.
|
175
|
-
+ mult: Linear algebraic matrix-matrix multiplication; C = A x B.
|
176
|
-
+ multOuter: Outer product of two vectors; Sets A[i,j] = x[i] * y[j].
|
177
|
-
+ norm1: Returns the one-norm of vector x, which is Sum(abs(x[i])).
|
178
|
-
+ norm1: Returns the one-norm of matrix A, which is the maximum absolute column sum.
|
179
|
-
+ norm2: Returns the two-norm (aka euclidean norm) of vector x; equivalent to Sqrt(mult(x,x)).
|
180
|
-
+ norm2: Returns the two-norm of matrix A, which is the maximum singular value; obtained from SVD.
|
181
|
-
+ normF: Returns the Frobenius norm of matrix A, which is Sqrt(Sum(A[i]2)).
|
182
|
-
+ normF: Returns the Frobenius norm of matrix A, which is Sqrt(Sum(A[i,j]2)).
|
183
|
-
+ normInfinity: Returns the infinity norm of vector x, which is Max(abs(x[i])).
|
184
|
-
+ normInfinity: Returns the infinity norm of matrix A, which is the maximum absolute row sum.
|
185
|
-
+ pow: Linear algebraic matrix power; B = Ak <==> B = A*A*...*A.
|
186
|
-
+ qr: Constructs and returns the QR-decomposition of the given matrix.
|
187
|
-
+ rank: Returns the effective numerical rank of matrix A, obtained from Singular Value Decomposition.
|
188
|
-
+ solve: Solves A*x = b.
|
189
|
-
+ solve: Solves A*X = B.
|
190
|
-
+ solveTranspose: Solves X*A = B, which is also A'*X' = B'.
|
191
|
-
+ svd: Constructs and returns the SingularValue-decomposition of the given matrix.
|
192
|
-
+ trace: Returns the sum of the diagonal elements of matrix A; Sum(A[i,i]).
|
193
|
-
+ trapezoidalLower: Modifies the matrix to be a lower trapezoidal matrix.
|
194
|
-
+ vectorNorm2: Returns the two-norm (aka euclidean norm) of vector X.vectorize();
|
195
|
-
+ xmultOuter: Outer product of two vectors; Returns a matrix with A[i,j] = x[i] * y[j].
|
196
|
-
+ xpowSlow: Linear algebraic matrix power; B = Ak <==> B = A*A*...*A.
|
197
|
-
|
198
|
-
Properties´ methods tested on matrices:
|
199
|
-
=======================================
|
200
|
-
|
201
|
-
+ density: Returns the matrix's fraction of non-zero cells; A.cardinality() / A.size().
|
202
|
-
+ generate_non_singular!: Modifies the given square matrix A such that it is diagonally dominant by row and column, hence non-singular, hence invertible.
|
203
|
-
+ diagonal?: A matrix A is diagonal if A[i,j] == 0 whenever i != j.
|
204
|
-
+ diagonally_dominant_by_column?: A matrix A is diagonally dominant by column if the absolute value of each diagonal element is larger than the sum of the absolute values of the off-diagonal elements in the corresponding column.
|
205
|
-
+ diagonally_dominant_by_row?: A matrix A is diagonally dominant by row if the absolute value of each diagonal element is larger than the sum of the absolute values of the off-diagonal elements in the corresponding row.
|
206
|
-
+ identity?: A matrix A is an identity matrix if A[i,i] == 1 and all other cells are zero.
|
207
|
-
+ lower_bidiagonal?: A matrix A is lower bidiagonal if A[i,j]==0 unless i==j || i==j+1.
|
208
|
-
+ lower_triangular?: A matrix A is lower triangular if A[i,j]==0 whenever i < j.
|
209
|
-
+ nonnegative?: A matrix A is non-negative if A[i,j] >= 0 holds for all cells.
|
210
|
-
+ orthogonal?: A square matrix A is orthogonal if A*transpose(A) = I.
|
211
|
-
+ positive?: A matrix A is positive if A[i,j] > 0 holds for all cells.
|
212
|
-
+ singular?: A matrix A is singular if it has no inverse, that is, iff det(A)==0.
|
213
|
-
+ skew_symmetric?: A square matrix A is skew-symmetric if A = -transpose(A), that is A[i,j] == -A[j,i].
|
214
|
-
+ square?: A matrix A is square if it has the same number of rows and columns.
|
215
|
-
+ strictly_lower_triangular?: A matrix A is strictly lower triangular if A[i,j]==0 whenever i <= j.
|
216
|
-
+ strictly_triangular?: A matrix A is strictly triangular if it is triangular and its diagonal elements all equal 0.
|
217
|
-
+ strictly_upper_triangular?: A matrix A is strictly upper triangular if A[i,j]==0 whenever i >= j.
|
218
|
-
+ symmetric?: A matrix A is symmetric if A = tranpose(A), that is A[i,j] == A[j,i].
|
219
|
-
+ triangular?: A matrix A is triangular iff it is either upper or lower triangular.
|
220
|
-
+ tridiagonal?: A matrix A is tridiagonal if A[i,j]==0 whenever Math.abs(i-j) > 1.
|
221
|
-
+ unit_triangular?: A matrix A is unit triangular if it is triangular and its diagonal elements all equal 1.
|
222
|
-
+ upper_bidiagonal?: A matrix A is upper bidiagonal if A[i,j]==0 unless i==j || i==j-1.
|
223
|
-
+ upper_triangular?: A matrix A is upper triangular if A[i,j]==0 whenever i > j.
|
224
|
-
+ zero?: A matrix A is zero if all its cells are zero.
|
225
|
-
+ lower_bandwidth: The lower bandwidth of a square matrix A is the maximum i-j for which A[i,j] is nonzero and i > j.
|
226
|
-
+ semi_bandwidth: Returns the semi-bandwidth of the given square matrix A.
|
227
|
-
+ upper_bandwidth: The upper bandwidth of a square matrix A is the maximum j-i for which A[i,j] is nonzero and j > i.
|
228
|
-
|
229
|
-
Descriptive statistics methods imported from Parallel Colt:
|
230
|
-
===========================================================
|
231
|
-
|
232
|
-
+ auto_correlation, correlation, covariance, durbin_watson, frequencies, geometric_mean,
|
233
|
-
+ harmonic_mean, kurtosis, lag1, max, mean, mean_deviation, median, min, moment, moment3,
|
234
|
-
+ moment4, pooled_mean, pooled_variance, product, quantile, quantile_inverse,
|
235
|
-
+ rank_interpolated, rms, sample_covariance, sample_kurtosis, sample_kurtosis_standard_error,
|
236
|
-
+ sample_skew, sample_skew_standard_error, sample_standard_deviation, sample_variance,
|
237
|
-
+ sample_weighted_variance, skew, split, standard_deviation, standard_error, sum,
|
238
|
-
+ sum_of_inversions, sum_of_logarithms, sum_of_powers, sum_of_power_deviations,
|
239
|
-
+ sum_of_squares, sum_of_squared_deviations, trimmed_mean, variance, weighted_mean,
|
240
|
-
+ weighted_rms, weighted_sums, winsorized_mean.
|
241
|
-
|
242
|
-
Double and Float methods from Parallel Colt:
|
243
|
-
============================================
|
244
|
-
|
245
|
-
+ acos, asin, atan, atan2, ceil, cos, exp, floor, greater, IEEEremainder, inv, less, lg,
|
246
|
-
+ log, log2, rint, sin, sqrt, tan.
|
247
|
-
|
248
|
-
Double, Float, Long and Int methods from Parallel Colt:
|
249
|
-
=======================================================
|
250
|
-
|
251
|
-
+ abs, compare, div, divNeg, equals, isEqual (is_equal), isGreater (is_greater),
|
252
|
-
+ isles (is_less), max, min, minus, mod, mult, multNeg (mult_neg), multSquare (mult_square),
|
253
|
-
+ neg, plus (add), plusAbs (plus_abs), pow (power), sign, square.
|
254
|
-
|
255
|
-
Long and Int methods from Parallel Colt
|
256
|
-
=======================================
|
257
|
-
|
258
|
-
+ and, dec, factorial, inc, not, or, shiftLeft (shift_left), shiftRightSigned
|
259
|
-
(shift_right_signed), shiftRightUnsigned (shift_right_unsigned), xor.
|
260
|
-
|
261
|
-
MDArray installation and download:
|
262
|
-
==================================
|
263
|
-
|
264
|
-
+ Install Jruby
|
265
|
-
+ jruby –S gem install mdarray
|
266
|
-
|
267
|
-
MDArray Homepages:
|
268
|
-
==================
|
269
|
-
|
270
|
-
+ http://rubygems.org/gems/mdarray
|
271
|
-
+ https://github.com/rbotafogo/mdarray/wiki
|
272
|
-
|
273
|
-
Contributors:
|
274
|
-
=============
|
275
|
-
Contributors are welcome.
|
276
|
-
|
277
|
-
MDArray History:
|
278
|
-
================
|
279
|
-
|
280
|
-
+ 14/11/2013: Version 0.5.5 - Support for linear algebra methods
|
281
|
-
+ 07/08/2013: Version 0.5.4 - Support for reading and writing NetCDF-3 files
|
282
|
-
+ 24/06/2013: Version 0.5.3 – Over 90% Performance improvements for methods imported
|
283
|
-
from Parallel Colt and over 40% performance improvements for all other methods
|
284
|
-
(implemented in Ruby);
|
285
|
-
+ 16/05/2013: Version 0.5.0 - All loops transferred to Java with over 50% performance
|
286
|
-
improvements. Descriptive statistics from Parallel Colt;
|
287
|
-
+ 19/04/2013: Version 0.4.3 - Fixes a simple, but fatal bug in 0.4.2. No new features;
|
288
|
-
+ 17/04/2013: Version 0.4.2 - Adds simple statistics and boolean operators;
|
289
|
-
+ 05/04/2013: Version 0.4.0 – Initial release.
|
290
|
-
|