X Tutup
Skip to content

Commit 066be40

Browse files
committed
refactored run-time Clazz methods; Jama -> gov.nist.jama
1 parent 866e73b commit 066be40

File tree

13 files changed

+3374
-0
lines changed

13 files changed

+3374
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
})();
3+
4+
Clazz._coreLoaded = true;
5+
6+
7+

sources/net.sf.j2s.core/test/dev/js/core/corebottom2.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
;(function() {
2+
3+
if (Jmol._debugCode)return;
4+

sources/net.sf.j2s.core/test/dev/js/core/coretop2.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2012-11-09 Bruce Miller
2+
* Version 1.0.3 Released.
3+
* Patched hqr2 method in Jama.EigenvalueDecomposition
4+
to avoid infinite loop;
5+
Thanks Frederic Devernay <frederic.devernay@m4x.org>
6+
* Updated unchecked type coding in Matrix read.
7+
* Added serialization ID to Jama.Matrix and Decomposition classes.
8+
* Cleaned up javadoc documentation to Jama.Matrix and Decomposition classes.
9+
2005-07-13 Bruce Miller
10+
* Version 1.0.2 Released.
11+
12+
2005-07-12 Bruce Miller
13+
* Although SVD sometimes fails on cases m < n,
14+
the test code, apparently successfully, invokes
15+
SVD to compute rank on an m<n matrix. Deferring
16+
proposal to signal error on m < n, for now.
17+
Possible fix to generalize SVD to come later.
18+
19+
2005-03-04 Roldan Pozo
20+
* Updated CholeskyDecomposition to fix problem with scaling by
21+
diagonals; modified TestMatrix to better test this case.
22+
23+
2003-07-28 Cleve Moler
24+
* Updated SingularValueDecomposition to repair lack of convergience
25+
on rank deficient matrices.
26+
* Note that SVD still doesn't handle m < n
27+
Apparently this case can be handled by a pre-transposition,
28+
or more directly by a modification to the source, but this
29+
modified version isn't available yet.
30+
31+
2000-09-11 Bruce Miller <bruce.miller@nist.gov>
32+
* Version 1.0.1 Released.
33+
34+
2000-09-11 Bruce Miller <bruce.miller@nist.gov>
35+
* Jama.Matrix print methods which create a NumberFormat, now set its
36+
Locale to US so that the reader will recognize them even when the
37+
default locale is not US. Similar change to Jama.test.TestMatrix.
38+
(Thanks Ulrich Eberhardinger <u.eberhardinger@ipc.uni-stuttgart.de>)
39+
40+
1998-08-05 The Jama Team
41+
* Initial Version released (1.0.0)
42+
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
package gov.nist.jama;
2+
3+
/** Cholesky Decomposition.
4+
<P>
5+
For a symmetric, positive definite matrix A, the Cholesky decomposition
6+
is an lower triangular matrix L so that A = L*L'.
7+
<P>
8+
If the matrix is not symmetric or positive definite, the constructor
9+
returns a partial decomposition and sets an internal flag that may
10+
be queried by the isSPD() method.
11+
*/
12+
13+
public class CholeskyDecomposition implements java.io.Serializable {
14+
15+
/* ------------------------
16+
Class variables
17+
* ------------------------ */
18+
19+
/** Array for internal storage of decomposition.
20+
@serial internal array storage.
21+
*/
22+
private double[][] L;
23+
24+
/** Row and column dimension (square matrix).
25+
@serial matrix dimension.
26+
*/
27+
private int n;
28+
29+
/** Symmetric and positive definite flag.
30+
@serial is symmetric and positive definite flag.
31+
*/
32+
private boolean isspd;
33+
34+
/* ------------------------
35+
Constructor
36+
* ------------------------ */
37+
38+
/** Cholesky algorithm for symmetric and positive definite matrix.
39+
Structure to access L and isspd flag.
40+
@param Arg Square, symmetric matrix.
41+
*/
42+
43+
public CholeskyDecomposition (Matrix Arg) {
44+
45+
46+
// Initialize.
47+
double[][] A = Arg.getArray();
48+
n = Arg.getRowDimension();
49+
L = new double[n][n];
50+
isspd = (Arg.getColumnDimension() == n);
51+
// Main loop.
52+
for (int j = 0; j < n; j++) {
53+
double[] Lrowj = L[j];
54+
double d = 0.0;
55+
for (int k = 0; k < j; k++) {
56+
double[] Lrowk = L[k];
57+
double s = 0.0;
58+
for (int i = 0; i < k; i++) {
59+
s += Lrowk[i]*Lrowj[i];
60+
}
61+
Lrowj[k] = s = (A[j][k] - s)/L[k][k];
62+
d = d + s*s;
63+
isspd = isspd & (A[k][j] == A[j][k]);
64+
}
65+
d = A[j][j] - d;
66+
isspd = isspd & (d > 0.0);
67+
L[j][j] = Math.sqrt(Math.max(d,0.0));
68+
for (int k = j+1; k < n; k++) {
69+
L[j][k] = 0.0;
70+
}
71+
}
72+
}
73+
74+
/* ------------------------
75+
Temporary, experimental code.
76+
* ------------------------ *\
77+
78+
\** Right Triangular Cholesky Decomposition.
79+
<P>
80+
For a symmetric, positive definite matrix A, the Right Cholesky
81+
decomposition is an upper triangular matrix R so that A = R'*R.
82+
This constructor computes R with the Fortran inspired column oriented
83+
algorithm used in LINPACK and MATLAB. In Java, we suspect a row oriented,
84+
lower triangular decomposition is faster. We have temporarily included
85+
this constructor here until timing experiments confirm this suspicion.
86+
*\
87+
88+
\** Array for internal storage of right triangular decomposition. **\
89+
private transient double[][] R;
90+
91+
\** Cholesky algorithm for symmetric and positive definite matrix.
92+
@param A Square, symmetric matrix.
93+
@param rightflag Actual value ignored.
94+
@return Structure to access R and isspd flag.
95+
*\
96+
97+
public CholeskyDecomposition (Matrix Arg, int rightflag) {
98+
// Initialize.
99+
double[][] A = Arg.getArray();
100+
n = Arg.getColumnDimension();
101+
R = new double[n][n];
102+
isspd = (Arg.getColumnDimension() == n);
103+
// Main loop.
104+
for (int j = 0; j < n; j++) {
105+
double d = 0.0;
106+
for (int k = 0; k < j; k++) {
107+
double s = A[k][j];
108+
for (int i = 0; i < k; i++) {
109+
s = s - R[i][k]*R[i][j];
110+
}
111+
R[k][j] = s = s/R[k][k];
112+
d = d + s*s;
113+
isspd = isspd & (A[k][j] == A[j][k]);
114+
}
115+
d = A[j][j] - d;
116+
isspd = isspd & (d > 0.0);
117+
R[j][j] = Math.sqrt(Math.max(d,0.0));
118+
for (int k = j+1; k < n; k++) {
119+
R[k][j] = 0.0;
120+
}
121+
}
122+
}
123+
124+
\** Return upper triangular factor.
125+
@return R
126+
*\
127+
128+
public Matrix getR () {
129+
return new Matrix(R,n,n);
130+
}
131+
132+
\* ------------------------
133+
End of temporary code.
134+
* ------------------------ */
135+
136+
/* ------------------------
137+
Public Methods
138+
* ------------------------ */
139+
140+
/** Is the matrix symmetric and positive definite?
141+
@return true if A is symmetric and positive definite.
142+
*/
143+
144+
public boolean isSPD () {
145+
return isspd;
146+
}
147+
148+
/** Return triangular factor.
149+
@return L
150+
*/
151+
152+
public Matrix getL () {
153+
return new Matrix(L,n,n);
154+
}
155+
156+
/** Solve A*X = B
157+
@param B A Matrix with as many rows as A and any number of columns.
158+
@return X so that L*L'*X = B
159+
@exception IllegalArgumentException Matrix row dimensions must agree.
160+
@exception RuntimeException Matrix is not symmetric positive definite.
161+
*/
162+
163+
public Matrix solve (Matrix B) {
164+
if (B.getRowDimension() != n) {
165+
throw new IllegalArgumentException("Matrix row dimensions must agree.");
166+
}
167+
if (!isspd) {
168+
throw new RuntimeException("Matrix is not symmetric positive definite.");
169+
}
170+
171+
// Copy right hand side.
172+
double[][] X = B.getArrayCopy();
173+
int nx = B.getColumnDimension();
174+
175+
// Solve L*Y = B;
176+
for (int k = 0; k < n; k++) {
177+
for (int j = 0; j < nx; j++) {
178+
for (int i = 0; i < k ; i++) {
179+
X[k][j] -= X[i][j]*L[k][i];
180+
}
181+
X[k][j] /= L[k][k];
182+
}
183+
}
184+
185+
// Solve L'*X = Y;
186+
for (int k = n-1; k >= 0; k--) {
187+
for (int j = 0; j < nx; j++) {
188+
for (int i = k+1; i < n ; i++) {
189+
X[k][j] -= X[i][j]*L[i][k];
190+
}
191+
X[k][j] /= L[k][k];
192+
}
193+
}
194+
195+
196+
return new Matrix(X,n,nx);
197+
}
198+
private static final long serialVersionUID = 1;
199+
200+
}
201+

0 commit comments

Comments
 (0)
X Tutup