当前位置: 首页>>代码示例>>Java>>正文


Java DoubleMatrix2D.rows方法代码示例

本文整理汇总了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;
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:19,代码来源:ComplexSubstitutionModel.java

示例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);
	}
}
 
开发者ID:modsim,项目名称:vizardous,代码行数:22,代码来源:MatrixFile.java

示例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();
}
 
开发者ID:appliedtopology,项目名称:javaplex,代码行数:18,代码来源:MatlabWriter.java

示例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);
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:21,代码来源:SeqBlas.java

示例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;
}
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:17,代码来源:RobustMath.java

示例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);
    }
}
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:20,代码来源:RobustMath.java

示例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));

}
 
开发者ID:nolanlab,项目名称:vortex,代码行数:8,代码来源:Trajectories_Correl.java

示例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);
    }
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:12,代码来源:SVDecompositionColtResultTest.java

示例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));
        }
    }
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:16,代码来源:CPLSAIAFactorizationModelFactory.java

示例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());
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:9,代码来源:ColtDenseDoubleMatrix2D.java

示例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);
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:47,代码来源:QRDecomposition.java

示例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;
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:15,代码来源:LUDecompositionQuick.java

示例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;
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:19,代码来源:Property.java

示例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 &lt; 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;
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:17,代码来源:Property.java

示例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);
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:41,代码来源:SeqBlas.java


注:本文中的cern.colt.matrix.DoubleMatrix2D.rows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。