本文整理汇总了Java中org.ujmp.core.Matrix.setAsDouble方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.setAsDouble方法的具体用法?Java Matrix.setAsDouble怎么用?Java Matrix.setAsDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ujmp.core.Matrix
的用法示例。
在下文中一共展示了Matrix.setAsDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ImportMatrix
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public static Matrix ImportMatrix(String txtPath) {
List<String> list = BResult_delete4.GetNameOrder(txtPath);
int m = list.size();
String[] listStrings = list.get(0).split(" ");
int n = listStrings.length;
Matrix matrix = Matrix.Factory.ones(m, n);
int i = 0;
for (String string : list) {
listStrings = list.get(i).split(" ");
int j = 0;
for (String str : listStrings) {
matrix.setAsDouble(Double.parseDouble(str), i, j);
j++;
}
i++;
}
return matrix;
}
示例2: NormByRow
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
/**
* 用于把矩阵按行归一化
*
* @param oriMatrix
* @return
*/
public static Matrix NormByRow(Matrix oriMatrix) {
long[] size = oriMatrix.getSize();
long m = size[0];
long n = size[1];
Matrix normedMatrix = Matrix.Factory.zeros(m, n);
for (int i = 0; i < m; i++) {
double summary = 0.0;
for (int j = 0; j < n; j++) {
summary = summary + oriMatrix.getAsDouble(i, j);
}
if (summary == 0)
continue;
else {
for (int j = 0; j < n; j++) {
normedMatrix.setAsDouble(oriMatrix.getAsDouble(i, j) / summary, i, j);
}
}
}
return normedMatrix;
}
示例3: calc
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public final void calc(final SparseMatrix source1, final Matrix source2, final Matrix target) {
VerifyUtil.verify2D(source1);
VerifyUtil.verify2D(source2);
VerifyUtil.verify2D(target);
VerifyUtil.verifyEquals(source1.getColumnCount(), source2.getRowCount(),
"matrices have wrong sizes");
VerifyUtil.verifyEquals(target.getRowCount(), source1.getRowCount(),
"matrices have wrong sizes");
VerifyUtil.verifyEquals(target.getColumnCount(), source2.getColumnCount(),
"matrices have wrong sizes");
target.clear();
for (long[] c1 : source1.availableCoordinates()) {
final double v1 = source1.getAsDouble(c1);
if (v1 != 0.0d) {
for (long col2 = source2.getColumnCount(); --col2 != -1;) {
final double v2 = source2.getAsDouble(c1[1], col2);
final double temp = v1 * v2;
if (temp != 0.0d) {
final double v3 = target.getAsDouble(c1[0], col2);
target.setAsDouble(v3 + temp, c1[0], col2);
}
}
}
}
}
示例4: calc
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public Matrix[] calc(Matrix source) {
try {
DenseMatrix m = null;
if (source instanceof MTJDenseDoubleMatrix2D) {
m = ((MTJDenseDoubleMatrix2D) source).getWrappedObject();
} else {
m = new MTJDenseDoubleMatrix2D(source).getWrappedObject();
}
no.uib.cipr.matrix.SVD svd = no.uib.cipr.matrix.SVD.factorize(m);
Matrix u = new MTJDenseDoubleMatrix2D(svd.getU());
Matrix v = new MTJDenseDoubleMatrix2D(svd.getVt()).transpose();
double[] svs = svd.getS();
Matrix s = SparseDoubleMatrix2D.Factory.zeros(source.getSize());
for (int i = (int) Math.min(s.getRowCount(), s.getColumnCount()); --i >= 0;) {
s.setAsDouble(svs[i], i, i);
}
return new Matrix[] { u, s, v };
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: testSparseSetToZero
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testSparseSetToZero() throws Exception {
Matrix m = createMatrix(2, 2);
if (isTestSparse() && m.isSparse()) {
m = createMatrix(800000, 900000);
m.setAsDouble(1.0, 3, 4);
m.setAsDouble(2.0, 334, 2214);
m.setAsDouble(3.0, 335, 2215);
m.setAsDouble(4.0, 334232, 3434);
assertEquals(1.0, m.getAsDouble(3, 4), TOLERANCE);
assertEquals(2.0, m.getAsDouble(334, 2214), TOLERANCE);
assertEquals(3.0, m.getAsDouble(335, 2215), TOLERANCE);
assertEquals(4.0, m.getAsDouble(334232, 3434), TOLERANCE);
m.setAsDouble(0.0, 335, 2215);
assertEquals(1.0, m.getAsDouble(3, 4), TOLERANCE);
assertEquals(2.0, m.getAsDouble(334, 2214), TOLERANCE);
assertEquals(0.0, m.getAsDouble(335, 2215), TOLERANCE);
assertEquals(4.0, m.getAsDouble(334232, 3434), TOLERANCE);
}
}
示例6: testQRFatSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testQRFatSmall() throws Exception {
Matrix a = createMatrixWithAnnotation(4, 6);
if (!isSupported(a, MatrixLibraries.QR, MatrixLayout.FAT, Size.SMALL, null)) {
return;
}
for (int r = 0, v = 1; r < a.getRowCount(); r++) {
for (int c = 0; c < a.getColumnCount(); c++) {
a.setAsDouble(v++, r, c);
}
}
Matrix[] qr = a.qr();
Matrix prod = qr[0].mtimes(qr[1]);
assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
if (a instanceof Erasable) {
((Erasable) a).erase();
}
if (prod instanceof Erasable) {
((Erasable) prod).erase();
}
}
示例7: testMinusScalarSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testMinusScalarSmall() throws Exception {
Matrix m = createMatrixWithAnnotation(2, 2);
m.setAsDouble(1.0, 0, 0);
m.setAsDouble(2.0, 0, 1);
m.setAsDouble(3.0, 1, 0);
m.setAsDouble(4.0, 1, 1);
Matrix r = m.minus(1.0);
assertEquals(getLabel(), 0.0, r.getAsDouble(0, 0), TOLERANCE);
assertEquals(getLabel(), 1.0, r.getAsDouble(0, 1), TOLERANCE);
assertEquals(getLabel(), 2.0, r.getAsDouble(1, 0), TOLERANCE);
assertEquals(getLabel(), 3.0, r.getAsDouble(1, 1), TOLERANCE);
assertEquals(getLabel(), 1.0, m.getAsDouble(0, 0), TOLERANCE);
assertEquals(getLabel(), 2.0, m.getAsDouble(0, 1), TOLERANCE);
assertEquals(getLabel(), 3.0, m.getAsDouble(1, 0), TOLERANCE);
assertEquals(getLabel(), 4.0, m.getAsDouble(1, 1), TOLERANCE);
if (m instanceof Erasable) {
((Erasable) m).erase();
}
if (r instanceof Erasable) {
((Erasable) r).erase();
}
}
示例8: testQRTallLarge
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testQRTallLarge() throws Exception {
if (!isTestLarge()) {
return;
}
Matrix a = createMatrixWithAnnotation(168, 143);
for (int r = 0, v = 1; r < a.getRowCount(); r++) {
for (int c = 0; c < a.getColumnCount(); c++) {
a.setAsDouble(v++, r, c);
}
}
Matrix[] qr = a.qr();
Matrix prod = qr[0].mtimes(qr[1]);
assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
if (a instanceof Erasable) {
((Erasable) a).erase();
}
if (prod instanceof Erasable) {
((Erasable) prod).erase();
}
}
示例9: testSVDTallSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testSVDTallSmall() throws Exception {
Matrix a = createMatrixWithAnnotation(6, 4);
if (!isSupported(a, MatrixLibraries.SVD, MatrixLayout.TALL, Size.SMALL, null)) {
return;
}
for (int r = 0, v = 1; r < a.getRowCount(); r++) {
for (int c = 0; c < a.getColumnCount(); c++) {
a.setAsDouble(v++, r, c);
}
}
Matrix[] svd = a.svd();
Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
if (a instanceof Erasable) {
((Erasable) a).erase();
}
}
示例10: setMatrixCell
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
private double setMatrixCell(Matrix m, int row, FunctionSummand summand,boolean negate) {
if (summand.isConstant()) return summand.getValue();
else {
//Add entry to matrix
if (!(summand.getTerm() instanceof AtomFunctionVariable)) throw new IllegalArgumentException("Expected sum of simple variables but got: " + summand);
int col = getIndex((AtomFunctionVariable)summand.getTerm());
double val = summand.getCoefficient();
m.setAsDouble(negate?-val:val, row, col);
return 0.0;
}
}
示例11: setRandSymmetric
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public final static void setRandSymmetric(Matrix a) {
Random random = new Random();
int rows = (int) a.getRowCount();
int cols = (int) a.getColumnCount();
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols && c <= r; c++) {
double f = random.nextDouble();
a.setAsDouble(f, r, c);
a.setAsDouble(f, c, r);
}
}
}
示例12: testCoordinateIterator2D
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testCoordinateIterator2D() throws Exception {
Matrix m = createMatrixWithAnnotation(3, 3);
m.setAsDouble(1.0, 2, 2);
Iterator<long[]> ci = m.allCoordinates().iterator();
long[] c1 = ci.next();
assertTrue(getLabel(), Coordinates.equals(c1, new long[] { 0, 0 }));
long[] c2 = ci.next();
assertTrue(getLabel(), Coordinates.equals(c2, new long[] { 0, 1 }));
long[] c3 = ci.next();
assertTrue(getLabel(), Coordinates.equals(c3, new long[] { 0, 2 }));
long[] c4 = ci.next();
assertTrue(getLabel(), Coordinates.equals(c4, new long[] { 1, 0 }));
long[] c5 = ci.next();
assertTrue(getLabel(), Coordinates.equals(c5, new long[] { 1, 1 }));
long[] c6 = ci.next();
assertTrue(getLabel(), Coordinates.equals(c6, new long[] { 1, 2 }));
long[] c7 = ci.next();
assertTrue(getLabel(), Coordinates.equals(c7, new long[] { 2, 0 }));
long[] c8 = ci.next();
assertTrue(getLabel(), Coordinates.equals(c8, new long[] { 2, 1 }));
long[] c9 = ci.next();
assertTrue(getLabel(), Coordinates.equals(c9, new long[] { 2, 2 }));
assertFalse(getLabel(), ci.hasNext());
if (m instanceof Erasable) {
((Erasable) m).erase();
}
}
示例13: createMatrix
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
private void createMatrix() {
Matrix source = getSource();
Matrix m = Matrix.Factory.zeros(source.getSize());
for (long c = 0; c < source.getColumnCount(); c++) {
double sum = 0;
for (long r = 0; r < source.getRowCount(); r++) {
sum += ignoreNaN ? MathUtil.ignoreNaN(source.getAsDouble(r, c)) : source
.getAsDouble(r, c);
m.setAsDouble(sum, r, c);
}
}
cumsum = m;
}
示例14: testPlusMatrixSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testPlusMatrixSmall() throws Exception {
Matrix m1 = createMatrixWithAnnotation(2, 2);
Matrix m2 = createMatrixWithAnnotation(2, 2);
m1.setAsDouble(1.0, 0, 0);
m1.setAsDouble(2.0, 0, 1);
m1.setAsDouble(3.0, 1, 0);
m1.setAsDouble(4.0, 1, 1);
m2.setAsDouble(1.0, 0, 0);
m2.setAsDouble(1.0, 0, 1);
m2.setAsDouble(1.0, 1, 0);
m2.setAsDouble(1.0, 1, 1);
Matrix r = m1.plus(m2);
assertEquals(getLabel(), 2.0, r.getAsDouble(0, 0), TOLERANCE);
assertEquals(getLabel(), 3.0, r.getAsDouble(0, 1), TOLERANCE);
assertEquals(getLabel(), 4.0, r.getAsDouble(1, 0), TOLERANCE);
assertEquals(getLabel(), 5.0, r.getAsDouble(1, 1), TOLERANCE);
assertEquals(getLabel(), 1.0, m1.getAsDouble(0, 0), TOLERANCE);
assertEquals(getLabel(), 2.0, m1.getAsDouble(0, 1), TOLERANCE);
assertEquals(getLabel(), 3.0, m1.getAsDouble(1, 0), TOLERANCE);
assertEquals(getLabel(), 4.0, m1.getAsDouble(1, 1), TOLERANCE);
assertEquals(getLabel(), 1.0, m2.getAsDouble(0, 0), TOLERANCE);
assertEquals(getLabel(), 1.0, m2.getAsDouble(0, 1), TOLERANCE);
assertEquals(getLabel(), 1.0, m2.getAsDouble(1, 0), TOLERANCE);
assertEquals(getLabel(), 1.0, m2.getAsDouble(1, 1), TOLERANCE);
if (m1 instanceof Erasable) {
((Erasable) m1).erase();
}
if (m2 instanceof Erasable) {
((Erasable) m2).erase();
}
if (r instanceof Erasable) {
((Erasable) r).erase();
}
}
示例15: train
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public void train(ListDataSet dataSet) throws Exception {
List<Sample> samples = new FastArrayList<Sample>(dataSet);
for (int t = 0; t < tMax; t++) {
double epsilon = epsilonStart * Math.pow(epsilonEnd / epsilonStart, (double) t / tMax);
double delta = deltaStart * Math.pow(deltaEnd / deltaStart, (double) t / tMax);
System.out.println((int) ((double) t / tMax * 100) + "%");
Collections.shuffle(samples);
for (Sample s : samples) {
Matrix input = s.getAsMatrix(getInputLabel());
// find best match
double bestDistance = Double.MAX_VALUE;
int bestRow = -1;
int bestCol = -1;
Matrix distanceMatrix = Matrix.Factory.zeros(rows, cols);
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
Matrix m = weightVectors[row][col];
if (m == null) {
m = Matrix.Factory.randn(input.getSize());
weightVectors[row][col] = m;
}
double distance = input.euklideanDistanceTo(m, true);
distanceMatrix.setAsDouble(distance, row, col);
if (distance < bestDistance) {
bestDistance = distance;
bestRow = row;
bestCol = col;
}
}
}
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
double dist = Math.sqrt((row - bestRow) * (row - bestRow) + (col - bestCol)
* (col - bestCol));
double h = MathUtil.gauss(0, delta, dist);
Matrix w = weightVectors[row][col];
w = w.plus(input.minus(w).times(epsilon * h));
weightVectors[row][col] = w;
}
}
if (t == tMax - 1) {
s.put("Projection", distanceMatrix);
}
}
}
}