本文整理汇总了Java中cern.colt.matrix.DoubleMatrix2D.rows方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix2D.rows方法的具体用法?Java DoubleMatrix2D.rows怎么用?Java DoubleMatrix2D.rows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cern.colt.matrix.DoubleMatrix2D
的用法示例。
在下文中一共展示了DoubleMatrix2D.rows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blockDiagonalExponential
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
private static DoubleMatrix2D blockDiagonalExponential(double distance, DoubleMatrix2D mat) {
for (int i = 0; i < mat.rows(); i++) {
if ((i + 1) < mat.rows() && mat.getQuick(i, i + 1) != 0) {
double a = mat.getQuick(i, i);
double b = mat.getQuick(i, i + 1);
double expat = Math.exp(distance * a);
double cosbt = Math.cos(distance * b);
double sinbt = Math.sin(distance * b);
mat.setQuick(i, i, expat * cosbt);
mat.setQuick(i + 1, i + 1, expat * cosbt);
mat.setQuick(i, i + 1, expat * sinbt);
mat.setQuick(i + 1, i, -expat * sinbt);
i++; // processed two entries in loop
} else
mat.setQuick(i, i, Math.exp(distance * mat.getQuick(i, i))); // 1x1 block
}
return mat;
}
示例2: save
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* Saves a graph to a file
* @see edu.uci.ics.jung.io.GraphFile#save(edu.uci.ics.jung.graph.Graph, java.lang.String)
*/
public void save(Graph<V,E> graph, String filename) {
try {
BufferedWriter writer =
new BufferedWriter(new FileWriter(filename));
DoubleMatrix2D matrix = GraphMatrixOperations.<V,E>graphToSparseMatrix(graph,
mWeightKey);
for (int i=0;i<matrix.rows();i++) {
for (int j=0;j<matrix.columns();j++) {
writer.write(String.format("%4.2f ", matrix.getQuick(i,j)));
}
writer.write("\n");
}
writer.close();
} catch (Exception e) {
throw new RuntimeException("Error saving file: " + filename, e);
}
}
示例3: toMatrix
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static String toMatrix(DoubleMatrix2D matrix) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("[");
for (int i = 0; i < matrix.rows(); i++) {
if (i > 0) {
stringBuilder.append(";\n");
}
for (int j = 0; j < matrix.columns(); j++) {
if (j > 0) {
stringBuilder.append(", ");
}
stringBuilder.append(matrix.getQuick(i, j));
}
}
stringBuilder.append("]");
return stringBuilder.toString();
}
示例4: dsymv
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public void dsymv(boolean isUpperTriangular, double alpha, DoubleMatrix2D A, DoubleMatrix1D x, double beta, DoubleMatrix1D y) {
if (isUpperTriangular) A = A.viewDice();
Property.DEFAULT.checkSquare(A);
int size = A.rows();
if (size != x.size() || size!=y.size()) {
throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort() + ", " + y.toStringShort());
}
DoubleMatrix1D tmp = x.like();
for (int i = 0; i < size; i++) {
double sum = 0;
for (int j = 0; j <= i; j++) {
sum += A.getQuick(i,j) * x.getQuick(j);
}
for (int j = i + 1; j < size; j++) {
sum += A.getQuick(j,i) * x.getQuick(j);
}
tmp.setQuick(i, alpha * sum + beta * y.getQuick(i));
}
y.assign(tmp);
}
示例5: Mult
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
static DoubleMatrix1D Mult(DoubleMatrix2D M, DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, boolean transposeA, EdgeGenerator edgeGen) {
// z = alpha * A * y + beta*z
for (int i = 0; i < z.size(); z.set(i,z.get(i)*beta),i++);
for (int j = 0; j < M.columns(); j++) {
for (int i = (edgeGen==null)?j:edgeGen.first(j); i < M.rows(); i = (edgeGen==null)?i+1:edgeGen.next(j,i)) {
int r = i;
int c = j;
if (transposeA) {
r = j;
c = i;
}
z.set(r, z.getQuick(r) + M.getQuick(i,j)*y.getQuick(c)*alpha);
}
}
return z;
}
示例6: logMatrixMult
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static void logMatrixMult(DoubleMatrix2D result, DoubleMatrix2D A, DoubleMatrix2D B, DoubleMatrix1D ri, boolean noMatrixMult) {
DoubleDoubleFunction sumFunc = new SumFunc();
if (noMatrixMult)
result.assign(B);
else {
for (int i = 0; i < A.rows(); i++) {
for (int j = 0; j < B.columns(); j++) {
double value = LOG0;
for (int k = 0; k < B.rows(); k++) {
value = logSumExp(value, A.get(i,k)+B.get(k, j));
}
result.set(i, j, value);
}
}
}
for (int i = 0; i < A.rows(); i++) {
result.viewRow(i).assign(ri, sumFunc);
}
}
示例7: addRandom
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static void addRandom(DoubleMatrix2D in, DoubleMatrix2D out, double temperature) {
out.assign(in);
int randomIndexX = (int) (Math.random() * in.columns());
int randomIndexY = (int) (Math.random() * in.rows());
out.setQuick(randomIndexX, randomIndexY, in.getQuick(randomIndexX, randomIndexY) + ((Math.random() - 0.5) * temperature));
}
示例8: assertColtMatrixEquals
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
private void assertColtMatrixEquals(final DoubleMatrix2D m1, final com.opengamma.analytics.math.matrix.DoubleMatrix2D m2) {
final int m = m1.rows();
final int n = m1.columns();
assertEquals(m, m2.getNumberOfRows());
assertEquals(n, m2.getNumberOfColumns());
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
assertEquals(m1.get(i, j), m2.getEntry(i, j), EPS);
}
}
}
示例9: normalizePuz
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* Normalizes matrix of p(z|u) such that \forall_u: \sum_z p(z|u) = 1.
*
* @param pu_z normalized matrix of p(z|u)
*/
@Override
protected void normalizePuz(DoubleMatrix2D pu_z) {
for (int u = 0; u < pu_z.rows(); u++) {
DoubleMatrix1D tmp = pu_z.viewRow(u);
double norm = tmp.aggregate(Functions.plus, Functions.identity);
if (norm != 0.0) {
tmp.assign(Functions.mult(1 / norm));
}
}
}
示例10: ColtDenseDoubleMatrix2D
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public ColtDenseDoubleMatrix2D(DoubleMatrix2D m) {
super(m.rows(), m.columns());
if (m instanceof DenseDoubleMatrix2D) {
this.matrix = (DenseDoubleMatrix2D) m;
} else {
this.matrix = new DenseDoubleMatrix2D(m.toArray());
}
}
示例11: solve
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
Least squares solution of <tt>A*X = B</tt>; <tt>returns X</tt>.
@param B A matrix with as many rows as <tt>A</tt> and any number of columns.
@return <tt>X</tt> that minimizes the two norm of <tt>Q*R*X - B</tt>.
@exception IllegalArgumentException if <tt>B.rows() != A.rows()</tt>.
@exception IllegalArgumentException if <tt>!this.hasFullRank()</tt> (<tt>A</tt> is rank deficient).
*/
public DoubleMatrix2D solve(DoubleMatrix2D B) {
cern.jet.math.Functions F = cern.jet.math.Functions.functions;
if (B.rows() != m) {
throw new IllegalArgumentException("Matrix row dimensions must agree.");
}
if (!this.hasFullRank()) {
throw new IllegalArgumentException("Matrix is rank deficient.");
}
// Copy right hand side
int nx = B.columns();
DoubleMatrix2D X = B.copy();
// Compute Y = transpose(Q)*B
for (int k = 0; k < n; k++) {
for (int j = 0; j < nx; j++) {
double s = 0.0;
for (int i = k; i < m; i++) {
s += QR.getQuick(i,k)*X.getQuick(i,j);
}
s = -s / QR.getQuick(k,k);
for (int i = k; i < m; i++) {
X.setQuick(i,j, X.getQuick(i,j) + s*QR.getQuick(i,k));
}
}
}
// Solve R*X = Y;
for (int k = n-1; k >= 0; k--) {
for (int j = 0; j < nx; j++) {
X.setQuick(k,j, X.getQuick(k,j) / Rdiag.getQuick(k));
}
for (int i = 0; i < k; i++) {
for (int j = 0; j < nx; j++) {
X.setQuick(i,j, X.getQuick(i,j) - X.getQuick(k,j)*QR.getQuick(i,k));
}
}
}
return X.viewPart(0,0,n,nx);
}
示例12: isNonsingular
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
Returns whether the matrix is nonsingular.
@return true if <tt>matrix</tt> is nonsingular; false otherwise.
*/
protected boolean isNonsingular(DoubleMatrix2D matrix) {
int m = matrix.rows();
int n = matrix.columns();
double epsilon = algebra.property().tolerance(); // consider numerical instability
for (int j = Math.min(n,m); --j >= 0;) {
//if (matrix.getQuick(j,j) == 0) return false;
if (Math.abs(matrix.getQuick(j,j)) <= epsilon) return false;
}
return true;
}
示例13: isLowerBidiagonal
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* A matrix <tt>A</tt> is <i>lower bidiagonal</i> if <tt>A[i,j]==0</tt> unless <tt>i==j || i==j+1</tt>.
* Matrix may but need not be square.
*/
public boolean isLowerBidiagonal(DoubleMatrix2D A) {
double epsilon = tolerance();
int rows = A.rows();
int columns = A.columns();
for (int row = rows; --row >=0; ) {
for (int column = columns; --column >= 0; ) {
if (!(row==column || row==column+1)) {
//if (A.getQuick(row,column) != 0) return false;
if (!(Math.abs(A.getQuick(row,column)) <= epsilon)) return false;
}
}
}
return true;
}
示例14: isLowerTriangular
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* A matrix <tt>A</tt> is <i>lower triangular</i> if <tt>A[i,j]==0</tt> whenever <tt>i < j</tt>.
* Matrix may but need not be square.
*/
public boolean isLowerTriangular(DoubleMatrix2D A) {
double epsilon = tolerance();
int rows = A.rows();
int columns = A.columns();
for (int column = columns; --column >= 0; ) {
for (int row = Math.min(column,rows); --row >= 0; ) {
//if (A.getQuick(row,column) != 0) return false;
if (!(Math.abs(A.getQuick(row,column)) <= epsilon)) return false;
}
}
return true;
}
示例15: dtrmv
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public void dtrmv(boolean isUpperTriangular, boolean transposeA, boolean isUnitTriangular, DoubleMatrix2D A, DoubleMatrix1D x) {
if (transposeA) {
A = A.viewDice();
isUpperTriangular = !isUpperTriangular;
}
Property.DEFAULT.checkSquare(A);
int size = A.rows();
if (size != x.size()) {
throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort());
}
DoubleMatrix1D b = x.like();
DoubleMatrix1D y = x.like();
if (isUnitTriangular) {
y.assign(1);
}
else {
for (int i = 0; i < size; i++) {
y.setQuick(i, A.getQuick(i,i));
}
}
for (int i = 0; i < size; i++) {
double sum = 0;
if (!isUpperTriangular) {
for (int j = 0; j < i; j++) {
sum += A.getQuick(i,j) * x.getQuick(j);
}
sum += y.getQuick(i) * x.getQuick(i);
}
else {
sum += y.getQuick(i) * x.getQuick(i);
for (int j = i + 1; j < size; j++) {
sum += A.getQuick(i,j) * x.getQuick(j); }
}
b.setQuick(i,sum);
}
x.assign(b);
}