本文整理匯總了Java中org.apache.commons.math3.linear.RealMatrix.copy方法的典型用法代碼示例。如果您正苦於以下問題:Java RealMatrix.copy方法的具體用法?Java RealMatrix.copy怎麽用?Java RealMatrix.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.linear.RealMatrix
的用法示例。
在下文中一共展示了RealMatrix.copy方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: centerKernelMatrix
import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
private static RealMatrix
centerKernelMatrix(final RealMatrix kernelMatrix) {
// get size of kernelMatrix
final int n = kernelMatrix.getRowDimension();
// get mean values for each row/column
final RealVector columnMeans =
MatrixFunctions.columnMeans(kernelMatrix);
final double matrixMean = MatrixFunctions.mean(kernelMatrix);
RealMatrix centeredKernelMatrix = kernelMatrix.copy();
for (int k = 0; k < n; k++) {
centeredKernelMatrix.setRowVector(k,
centeredKernelMatrix.getRowVector(k).subtract(columnMeans));
centeredKernelMatrix.setColumnVector(k, centeredKernelMatrix
.getColumnVector(k).subtract(columnMeans));
}
centeredKernelMatrix = centeredKernelMatrix.scalarAdd(matrixMean);
return centeredKernelMatrix;
}
示例2: correlation2Distance
import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public static RealMatrix correlation2Distance(RealMatrix rMat) {
// Copy to retain Dimensions
RealMatrix dMat = rMat.copy();
for (int row = 0; row < rMat.getRowDimension(); row++) {
for (int col = 0; col < rMat.getColumnDimension(); col++) {
double r = rMat.getEntry(row, col);
//Apply cosine theorem:
//https://stats.stackexchange.com/questions/165194/using-correlation-as-distance-metric-for-hierarchical-clustering
double d = Math.sqrt(2*(1-r));
dMat.setEntry(row, col, d);
}
}
return dMat;
}
示例3: testMatrixEquality
import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
@Test
public void testMatrixEquality() {
final RealMatrix m1 = MatrixUtils
.createRealMatrix(new double[][] { { 1, 2 }, { 1, 2 } });
final RealMatrix m2 = m1.copy();
assertEquals(m1, m2);
}