mdarray 0.5.4-java → 0.5.5-java
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +35 -16
- data/README.md +180 -234
- data/lib/colt/matrix/algebra.rb +466 -0
- data/lib/colt/matrix/colt_matrix.rb +161 -220
- data/lib/colt/matrix/creation.rb +374 -0
- data/lib/colt/matrix/{matrix_hierarchy.rb → hierarchy.rb} +78 -99
- data/lib/colt/matrix/property.rb +363 -0
- data/lib/mdarray/views.rb +46 -1
- data/test/colt/matrix/test_complete.rb +29 -0
- data/test/colt/{test_matrix.rb → matrix/test_creation.rb} +26 -3
- data/test/colt/{test_double_matrix2d.rb → matrix/test_matrix1d_floatingalgebra.rb} +86 -84
- data/test/colt/matrix/test_matrix2d_fixpointalgebra.rb +531 -0
- data/test/colt/matrix/test_matrix2d_floatingalgebra.rb +693 -0
- data/test/colt/matrix/test_operations.rb +120 -0
- data/test/colt/matrix/test_properties.rb +649 -0
- data/test/colt/test_complete.rb +1 -1
- data/test/complete.rb +12 -7
- data/test/mdarray/test_views.rb +55 -0
- data/vendor/{incanter.jar → mdarray.jar} +0 -0
- data/version.rb +1 -1
- metadata +22 -16
- data/lib/colt/matrix/matrix2D_floating_algebra.rb +0 -325
- data/test/colt/test_float_matrix2d.rb +0 -171
- data/vendor/commons-compiler.jar +0 -0
- data/vendor/janino.jar +0 -0
@@ -1,171 +0,0 @@
|
|
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 'mdarray'
|
27
|
-
|
28
|
-
class MDArrayTest < Test::Unit::TestCase
|
29
|
-
|
30
|
-
context "Colt Matrix" do
|
31
|
-
|
32
|
-
setup do
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
#-------------------------------------------------------------------------------------
|
38
|
-
#
|
39
|
-
#-------------------------------------------------------------------------------------
|
40
|
-
|
41
|
-
should "test matrix functions" do
|
42
|
-
|
43
|
-
b = MDMatrix.float([3], [1.5, 1, 1.3])
|
44
|
-
|
45
|
-
pos = MDArray.float([3, 3], [2, -1, 0, -1, 2, -1, 0, -1, 2])
|
46
|
-
matrix = MDMatrix.from_mdarray(pos)
|
47
|
-
result = matrix.chol
|
48
|
-
p "Cholesky decomposition"
|
49
|
-
result.print
|
50
|
-
printf("\n\n")
|
51
|
-
|
52
|
-
eig = matrix.eig
|
53
|
-
p "eigen decomposition"
|
54
|
-
p "eigenvalue matrix"
|
55
|
-
eig[0].print
|
56
|
-
printf("\n\n")
|
57
|
-
p "imaginary parts of the eigenvalues"
|
58
|
-
eig[1].print
|
59
|
-
printf("\n\n")
|
60
|
-
p "real parts of the eigenvalues"
|
61
|
-
eig[2].print
|
62
|
-
printf("\n\n")
|
63
|
-
p "eigenvector matrix"
|
64
|
-
eig[3].print
|
65
|
-
printf("\n\n")
|
66
|
-
|
67
|
-
lu = matrix.lu
|
68
|
-
p "lu decomposition"
|
69
|
-
p "is non singular: #{lu[0]}"
|
70
|
-
p "determinant: #{lu[1]}"
|
71
|
-
p "pivot vector: #{lu[2]}"
|
72
|
-
p "lower triangular matrix"
|
73
|
-
lu[3].print
|
74
|
-
printf("\n\n")
|
75
|
-
p "upper triangular matrix"
|
76
|
-
lu[4].print
|
77
|
-
printf("\n\n")
|
78
|
-
|
79
|
-
# Returns the condition of matrix A, which is the ratio of largest to
|
80
|
-
# smallest singular value.
|
81
|
-
p "condition of matrix"
|
82
|
-
p matrix.cond
|
83
|
-
|
84
|
-
# Solves the upper triangular system U*x=b;
|
85
|
-
p "solving the equation by backward_solve"
|
86
|
-
solve = lu[4].backward_solve(b)
|
87
|
-
solve.print
|
88
|
-
printf("\n\n")
|
89
|
-
|
90
|
-
# Solves the lower triangular system U*x=b;
|
91
|
-
p "solving the equation by forward_solve"
|
92
|
-
solve = lu[3].forward_solve(b)
|
93
|
-
solve.print
|
94
|
-
printf("\n\n")
|
95
|
-
|
96
|
-
qr = matrix.qr
|
97
|
-
p "QR decomposition"
|
98
|
-
p "Matrix has full rank: #{qr[0]}"
|
99
|
-
p "Householder vectors"
|
100
|
-
qr[1].print
|
101
|
-
printf("\n\n")
|
102
|
-
p "Orthogonal factor Q:"
|
103
|
-
qr[2].print
|
104
|
-
printf("\n\n")
|
105
|
-
p "Upper triangular factor, R"
|
106
|
-
qr[3].print
|
107
|
-
printf("\n\n")
|
108
|
-
|
109
|
-
m = MDArray.typed_arange("float", 0, 16)
|
110
|
-
m.reshape!([4, 4])
|
111
|
-
matrix1 = MDMatrix.from_mdarray(m)
|
112
|
-
# mat2 = matrix.chol
|
113
|
-
matrix1.print
|
114
|
-
printf("\n\n")
|
115
|
-
|
116
|
-
m = MDArray.typed_arange("float", 16, 32)
|
117
|
-
m.reshape!([4, 4])
|
118
|
-
matrix2 = MDMatrix.from_mdarray(m)
|
119
|
-
matrix2.print
|
120
|
-
printf("\n\n")
|
121
|
-
|
122
|
-
result = matrix1 * matrix2
|
123
|
-
p "matrix multiplication"
|
124
|
-
result.print
|
125
|
-
printf("\n\n")
|
126
|
-
|
127
|
-
result = matrix1.kron(matrix2)
|
128
|
-
p "Kronecker multiplication"
|
129
|
-
result.print
|
130
|
-
printf("\n\n")
|
131
|
-
|
132
|
-
print "determinant is: #{result.det}"
|
133
|
-
printf("\n\n")
|
134
|
-
|
135
|
-
p "norm1"
|
136
|
-
p result.norm1
|
137
|
-
|
138
|
-
p "norm2"
|
139
|
-
p result.norm2
|
140
|
-
|
141
|
-
p "Returns the Frobenius norm of matrix A, which is Sqrt(Sum(A[i,j]^2))"
|
142
|
-
p result.normF
|
143
|
-
|
144
|
-
p "Returns the infinity norm of matrix A, which is the maximum absolute row sum."
|
145
|
-
p result.norm_infinity
|
146
|
-
|
147
|
-
power3 = result ** 3
|
148
|
-
power3.print
|
149
|
-
printf("\n\n")
|
150
|
-
|
151
|
-
p result.trace
|
152
|
-
|
153
|
-
trap_lower = result.trapezoidal_lower
|
154
|
-
trap_lower.print
|
155
|
-
printf("\n\n")
|
156
|
-
|
157
|
-
p result.vector_norm2
|
158
|
-
|
159
|
-
result.normalize!
|
160
|
-
result.print
|
161
|
-
printf("\n\n")
|
162
|
-
|
163
|
-
p "summing all values of result: #{result.sum}"
|
164
|
-
|
165
|
-
result.mdarray.print
|
166
|
-
|
167
|
-
end
|
168
|
-
#=end
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
data/vendor/commons-compiler.jar
DELETED
Binary file
|
data/vendor/janino.jar
DELETED
Binary file
|