本文整理汇总了Java中cern.colt.matrix.DoubleMatrix2D.columns方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix2D.columns方法的具体用法?Java DoubleMatrix2D.columns怎么用?Java DoubleMatrix2D.columns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cern.colt.matrix.DoubleMatrix2D
的用法示例。
在下文中一共展示了DoubleMatrix2D.columns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: computeLogMi
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
static boolean computeLogMi(FeatureGenerator featureGen, double lambda[],
DoubleMatrix2D Mi_YY,
DoubleMatrix1D Ri_Y, boolean takeExp,boolean reuseM, boolean initMDone) {
if (reuseM && initMDone) {
Mi_YY = null;
} else {
initMDone = false;
}
if (Mi_YY != null) Mi_YY.assign(0);
Ri_Y.assign(0);
initMDone = computeLogMiInitDone(featureGen,lambda,Mi_YY,Ri_Y,0);
if (takeExp) {
for(int r = Ri_Y.size()-1; r >= 0; r--) {
Ri_Y.setQuick(r,expE(Ri_Y.getQuick(r)));
if (Mi_YY != null)
for(int c = Mi_YY.columns()-1; c >= 0; c--) {
Mi_YY.setQuick(r,c,expE(Mi_YY.getQuick(r,c)));
}
}
}
return initMDone;
}
示例4: correlation
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* Modifies the given covariance matrix to be a correlation matrix (in-place).
* The correlation matrix is a square, symmetric matrix consisting of nothing but correlation coefficients.
* The rows and the columns represent the variables, the cells represent correlation coefficients.
* The diagonal cells (i.e. the correlation between a variable and itself) will equal 1, for the simple reason that the correlation coefficient of a variable with itself equals 1.
* The correlation of two column vectors x and y is given by <tt>corr(x,y) = cov(x,y) / (stdDev(x)*stdDev(y))</tt> (Pearson's correlation coefficient).
* A correlation coefficient varies between -1 (for a perfect negative relationship) to +1 (for a perfect positive relationship).
* See the <A HREF="http://www.cquest.utoronto.ca/geog/ggr270y/notes/not05efg.html"> math definition</A>
* and <A HREF="http://www.stat.berkeley.edu/users/stark/SticiGui/Text/gloss.htm#correlation_coef"> another def</A>.
* Compares two column vectors at a time. Use dice views to compare two row vectors at a time.
*
* @param covariance a covariance matrix, as, for example, returned by method {@link #covariance(DoubleMatrix2D)}.
* @return the modified covariance, now correlation matrix (for convenience only).
*/
public static DoubleMatrix2D correlation(DoubleMatrix2D covariance) {
for (int i=covariance.columns(); --i >= 0; ) {
for (int j=i; --j >= 0; ) {
double stdDev1 = Math.sqrt(covariance.getQuick(i,i));
double stdDev2 = Math.sqrt(covariance.getQuick(j,j));
double cov = covariance.getQuick(i,j);
double corr = cov / (stdDev1*stdDev2);
covariance.setQuick(i,j,corr);
covariance.setQuick(j,i,corr); // symmetric
}
}
for (int i=covariance.columns(); --i >= 0; ) covariance.setQuick(i,i,1);
return covariance;
}
示例5: getSumDeviations
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static double getSumDeviations(DoubleMatrix2D proj, int[] groups) {
int idx = 0;
int currGroup;
double[][] projD = proj.toArray();
do {
double[] avgGroup = new double[proj.columns()];
int grpSize = 0;
currGroup = groups[idx];
while (idx < groups.length && groups[idx] == currGroup) {
avgGroup = MatrixOp.sum(avgGroup, projD[idx]);
idx++;
grpSize++;
}
idx -= grpSize;
MatrixOp.mult(avgGroup, 1.0 / (double) grpSize);
while (idx < groups.length && groups[idx] == currGroup) {
projD[idx] = MatrixOp.diff(projD[idx], avgGroup);
idx++;
}
} while (idx < groups.length);
double sumSqLen = 0;
for (double[] ds : projD) {
sumSqLen += asinh(MatrixOp.mult(ds, ds));
}
return sumSqLen;
}
示例6: getMedianDev
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static double getMedianDev(DoubleMatrix2D proj, int[] groups) {
int idx = 0;
int currGroup;
double[][] projD = proj.toArray();
do {
double[] avgGroup = new double[proj.columns()];
int grpSize = 0;
currGroup = groups[idx];
while (idx < groups.length && groups[idx] == currGroup) {
avgGroup = MatrixOp.sum(avgGroup, projD[idx]);
idx++;
grpSize++;
}
idx -= grpSize;
MatrixOp.mult(avgGroup, 1.0 / (double) grpSize);
while (idx < groups.length && groups[idx] == currGroup) {
projD[idx] = MatrixOp.diff(projD[idx], avgGroup);
idx++;
}
} while (idx < groups.length);
double[] len = new double[groups.length];
for (int i = 0; i < groups.length; i++) {
len[i] = Math.sqrt(MatrixOp.mult(projD[i], projD[i]));
}
Arrays.sort(len);
return len[len.length / 2];
}
示例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: normalizePiz
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* Normalizes matrix of p(i|z) such that \forall_z: \sum_i p(i|z) = 1.
*
* @param piz normalized matrix of p(i|z)
*/
@Override
protected void normalizePiz(DoubleMatrix2D piz) {
for (int i = 0; i < piz.columns(); i++) {
DoubleMatrix1D tmp = piz.viewColumn(i);
double norm = tmp.aggregate(Functions.plus, Functions.identity);
if (norm != 0.0) {
tmp.assign(Functions.mult(1 / norm));
}
}
}
示例10: normalizePuz
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* Normalizes matrix of p(z|u) such that \forall_z: \sum_u p(z|u) = 1.
*
* @param pu_z normalized matrix of p(z|u)
*/
protected void normalizePuz(DoubleMatrix2D pu_z) {
for (int z = 0; z < pu_z.columns(); z++) {
final DoubleMatrix1D pu_Z = pu_z.viewColumn(z);
pu_Z.assign(mult(1 / pu_Z.aggregate(plus, identity)));
}
}
示例11: 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());
}
}
示例12: isNonNegative
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* A matrix <tt>A</tt> is <i>non-negative</i> if <tt>A[i,j] >= 0</tt> holds for all cells.
* <p>
* Note: Ignores tolerance.
*/
public boolean isNonNegative(DoubleMatrix2D A) {
int rows = A.rows();
int columns = A.columns();
for (int row = rows; --row >=0; ) {
for (int column = columns; --column >= 0; ) {
if (! (A.getQuick(row,column) >= 0)) return false;
}
}
return true;
}
示例13: writeMatrix
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public void writeMatrix(DoubleMatrix2D matrix) throws IOException {
this.out.write("[");
for (int i = 0; i < matrix.rows(); i++) {
if (i > 0) {
this.out.write(";\n");
}
for (int j = 0; j < matrix.columns(); j++) {
if (j > 0) {
this.out.write(", ");
}
this.out.write(Double.toString(matrix.getQuick(i, j)));
}
}
this.out.write("];");
}
示例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: isUpperTriangular
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* A matrix <tt>A</tt> is <i>upper triangular</i> if <tt>A[i,j]==0</tt> whenever <tt>i > j</tt>.
* Matrix may but need not be square.
*/
public boolean isUpperTriangular(DoubleMatrix2D A) {
double epsilon = tolerance();
int rows = A.rows();
int columns = A.columns();
for (int column = columns; --column >= 0; ) {
for (int row = rows; --row > column; ) {
//if (A.getQuick(row,column) != 0) return false;
if (!(Math.abs(A.getQuick(row,column)) <= epsilon)) return false;
}
}
return true;
}