package Jama.test;
import Jama.*;
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
/** TestMatrix tests the functionality of the Jama Matrix class and associated decompositions.
<P>
Run the test from the command line using
<BLOCKQUOTE><PRE><CODE>
java Jama.test.TestMatrix
</CODE></PRE></BLOCKQUOTE>
Detailed output is provided indicating the functionality being tested
and whether the functionality is correctly implemented. Exception handling
is also tested.
<P>
The test is designed to run to completion and give a summary of any implementation errors
encountered. The final output should be:
<BLOCKQUOTE><PRE><CODE>
TestMatrix completed.
Total errors reported: n1
Total warning reported: n2
</CODE></PRE></BLOCKQUOTE>
If the test does not run to completion, this indicates that there is a
substantial problem within the implementation that was not anticipated in the test design.
The stopping point should give an indication of where the problem exists.
**/
public class TestMatrix {
public static void main (String argv[]) {
Matrix A,B,C,Z,O,I,R,S,X,SUB,M,T,SQ,DEF,SOL;
// Uncomment this to test IO in a different locale.
// Locale.setDefault(Locale.GERMAN);
int errorCount=0;
int warningCount=0;
double tmp, s;
double[] columnwise = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.};
double[] rowwise = {1.,4.,7.,10.,2.,5.,8.,11.,3.,6.,9.,12.};
double[][] avals = {{1.,4.,7.,10.},{2.,5.,8.,11.},{3.,6.,9.,12.}};
double[][] rankdef = avals;
double[][] tvals = {{1.,2.,3.},{4.,5.,6.},{7.,8.,9.},{10.,11.,12.}};
double[][] subavals = {{5.,8.,11.},{6.,9.,12.}};
double[][] rvals = {{1.,4.,7.},{2.,5.,8.,11.},{3.,6.,9.,12.}};
double[][] pvals = {{4.,1.,1.},{1.,2.,3.},{1.,3.,6.}};
double[][] ivals = {{1.,0.,0.,0.},{0.,1.,0.,0.},{0.,0.,1.,0.}};
double[][] evals =
{{0.,1.,0.,0.},{1.,0.,2.e-7,0.},{0.,-2.e-7,0.,1.},{0.,0.,1.,0.}};
double[][] square = {{166.,188.,210.},{188.,214.,240.},{210.,240.,270.}};
double[][] sqSolution = {{13.},{15.}};
double[][] condmat = {{1.,3.},{7.,9.}};
int rows=3,cols=4;
int invalidld=5;/* should trigger bad shape for construction with val */
int raggedr=0; /* (raggedr,raggedc) should be out of bounds in ragged array */
int raggedc=4;
int validld=3; /* leading dimension of intended test Matrices */
int nonconformld=4; /* leading dimension which is valid, but nonconforming */
int ib=1,ie=2,jb=1,je=3; /* index ranges for sub Matrix */
int[] rowindexset = {1,2};
int[] badrowindexset = {1,3};
int[] columnindexset = {1,2,3};
int[] badcolumnindexset = {1,2,4};
double columnsummax = 33.;
double rowsummax = 30.;
double sumofdiagonals = 15;
double sumofsquares = 650;
/**
Constructors and constructor-like methods:
double[], int
double[][]
int, int
int, int, double
int, int, double[][]
constructWithCopy(double[][])
random(int,int)
identity(int)
**/
print("\nTesting constructors and constructor-like methods...\n");
try{
/** check that exception is thrown in packed constructor with invalid length **/
A = new Matrix(columnwise,invalidld);
errorCount = try_failure(errorCount,"Catch invalid length in packed constructor... ",
"exception not thrown for invalid input");
} catch ( IllegalArgumentException e ) {
try_success("Catch invalid length in packed constructor... ",
e.getMessage());
}
try{
/** check that exception is thrown in default constructor
if input array is 'ragged' **/
A = new Matrix(rvals);
tmp = A.get(raggedr,raggedc);
} catch ( IllegalArgumentException e ) {
try_success("Catch ragged input to default constructor... ",
e.getMessage());
} catch ( java.lang.ArrayIndexOutOfBoundsException e ) {
errorCount = try_failure(errorCount,"Catch ragged input to constructor... ",
"exception not thrown in construction...ArrayIndexOutOfBoundsException thrown later");
}
try{
/** check that exception is thrown in constructWithCopy
if input array is 'ragged' **/
A = Matrix.constructWithCopy(rvals);
tmp = A.get(raggedr,raggedc);
} catch ( IllegalArgumentException e ) {
try_success("Catch ragged input to constructWithCopy... ",e.getMessage());
} catch ( java.lang.ArrayIndexOutOfBoundsException e ) {
errorCount = try_failure(errorCount,"Catch ragged input to constructWithCopy... ","exception not thrown in construction...ArrayIndexOutOfBoundsException thrown later");
}
A = new Matrix(columnwise,validld);
B = new Matrix(avals);
tmp = B.get(0,0);
avals[0][0] = 0.0;
C = B.minus(A);
avals[0][0] = tmp;
B = Matrix.constructWithCopy(avals);
tmp = B.get(0,0);
avals[0][0] = 0.0;
if ( ( tmp - B.get(0,0) ) != 0.0 ) {
/** check that constructWithCopy behaves properly **/
errorCount = try_failure(errorCount,"constructWithCopy... ","copy not effected... data visible outside");
} else {
try_success("constructWithCopy... ","");
}
avals[0][0] = columnwise[0];
I = new Matrix(ivals);
try {
check(I,Matrix.identity(3,4));
try_success("identity... ","");
} catch ( java.lang.RuntimeException e ) {
errorCount = try_failure(errorCount,"identity... ","identity Matrix not successfully created");
}
/**
Access Methods:
getColumnDimension()
getRowDimension()
getArray()
getArrayCopy()
getColumnPackedCopy()
getRowPackedCopy()
get(int,int)
getMatrix(int,int,int,int)
getMatrix(int,int,int[])
getMatrix(int[],int,int)
getMatrix(int[],int[])
set(int,int,double)
setMatrix(int,int,int,int,Matrix)
setMatrix(int,int,int[],Matrix)
setMatrix(int[],int,int,Matrix)
setMatrix(int[],int[],Matrix)
**/
print("\nTesting access methods...\n");
/**
Various get methods:
**/
B = new Matrix(avals);
if (B.getRowDimension() != rows) {
errorCount = try_failure(errorCount,"getRowDimension... ","");
} else {
try_success("getRowDimension... ","");
}
if (B.getColumnDimension() != cols) {
errorCount = try_failure(errorCount,"getColumnDimension... ","");
} else {
try_success("getColumnDimension... ","");
}
B = new Matrix(avals);
double[][] barray = B.getArray();
if ( barray != avals ) {
errorCount = try_failure(errorCount,"getArray... ","");
} else {
try_success("getArray... ","");
}
barray = B.getArrayCopy();
if ( barray == avals ) {
errorCount = try_failure(errorCount,"getArrayCopy... ","data not (deep) copied");
}
try {
check(barray,avals);
try_success("getArrayCopy... ","");
} catch ( java.lang.RuntimeException e ) {
errorCount = try_failure(errorCount,"getArrayCopy... ","data not successfully (deep) copied");
}
double[] bpacked = B.getColumnPackedCopy();
try {
check(bpacked,columnwise);
try_success("getColumnPackedCopy... ","");
} catch ( java.lang.RuntimeException e ) {
errorCount = try_failure(errorCount,"getColumnPackedCopy... ","data not successfully (deep) co
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java 的 matrix类库 (1971个子文件)
ChangeLog 1KB
TestMatrix.class 20KB
Matrix.class 11KB
EigenvalueDecomposition.class 10KB
SingularValueDecomposition.class 6KB
MagicSquareExample.class 4KB
LUDecomposition.class 3KB
QRDecomposition.class 3KB
CholeskyDecomposition.class 2KB
Maths.class 421B
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
stylesheet.css 1KB
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
inherit.gif 57B
Jama-1.0.2.tar.gz 76KB
index-all.html 981KB
ReversedDepthFirstAdapter.html 307KB
DepthFirstAdapter.html 304KB
Parser.html 274KB
MatrixListToMatrixWrapper.html 210KB
SampleListToMatrixWrapper.html 206KB
DataSetInputMatrixWrapper.html 204KB
DataSetPredictedMatrixWrapper.html 204KB
DataSetTargetMatrixWrapper.html 204KB
MalletOutputMatrix.html 200KB
MalletInputMatrix.html 200KB
StanfordSentenceMatrix.html 199KB
TiledEhcacheMatrix2D.html 198KB
SparseEhcacheMatrix.html 196KB
Labeling2Matrix.html 195KB
LogMatrix.html 194KB
JDMPPluginsMatrix.html 193KB
AnalysisAdapter.html 188KB
Lexer.State.html 152KB
Lexer.html 152KB
ReversedDepthFirstAdapter.html 149KB
DepthFirstAdapter.html 148KB
overview-tree.html 148KB
Analysis.html 135KB
index-all.html 126KB
AlgorithmMenu.html 125KB
VariableMenu.html 125KB
DataSetMenu.html 125KB
ModuleMenu.html 125KB
SampleMenu.html 125KB
ScriptExamplesMenu.html 125KB
JDMPToolsMenu.html 124KB
serialized-form.html 110KB
AbstractListPanel.html 109KB
constant-values.html 106KB
MatrixListPanel.html 105KB
Translation.html 99KB
CommandWindow.html 93KB
Variable.html 93KB
VariableListTableCellRenderer.html 92KB
AlgorithmFrame.html 91KB
VariableFrame.html 91KB
DataSetFrame.html 91KB
ModuleFrame.html 91KB
SampleFrame.html 91KB
AlgorithmListPanel.html 90KB
VariableListPanel.html 90KB
DataSetListPanel.html 90KB
ModuleListPanel.html 90KB
SampleListPanel.html 90KB
AlgorithmMenuBar.html 89KB
VariableMenuBar.html 89KB
DataSetMenuBar.html 89KB
ModuleMenuBar.html 89KB
SampleMenuBar.html 89KB
VariablePanel.html 87KB
AlgorithmPanel.html 87KB
DataSetPanel.html 87KB
ModulePanel.html 87KB
SamplePanel.html 87KB
WekaClassifier.WekaClassifierType.html 83KB
Node.html 80KB
JDMP.html 79KB
共 1971 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
xianzixiang
- 粉丝: 6
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功