本文整理汇总了Java中org.ujmp.core.Matrix.times方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.times方法的具体用法?Java Matrix.times怎么用?Java Matrix.times使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ujmp.core.Matrix
的用法示例。
在下文中一共展示了Matrix.times方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTimesScalar
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testTimesScalar() {
Matrix matrix1 = Matrix.Factory.zeros(M1ROWS, M1ROWS);
for (int i = 0; i < M1ROWS; i++) {
matrix1.setAsDouble(1, i, i);
}
Matrix result = matrix1.times(PRODUCT);
for (int row = 0; row < result.getRowCount(); ++row) {
for (int col = 0; col < result.getColumnCount(); ++col) {
if (row == col) {
assertEquals(PRODUCT, result.getAsDouble(row, col), 0.001);
} else {
assertEquals(0.0, result.getAsDouble(row, col), 0.001);
}
}
}
}
示例2: testTimesScalarSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testTimesScalarSmall() 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.times(2.0);
assertEquals(getLabel(), 2.0, r.getAsDouble(0, 0), TOLERANCE);
assertEquals(getLabel(), 4.0, r.getAsDouble(0, 1), TOLERANCE);
assertEquals(getLabel(), 6.0, r.getAsDouble(1, 0), TOLERANCE);
assertEquals(getLabel(), 8.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();
}
}
示例3: test0MinusXMatrix
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void test0MinusXMatrix() throws Exception {
Matrix m1 = createMatrixWithAnnotation(5, 7);
Matrix m2 = createMatrixWithAnnotation(5, 7);
m2.randn(Ret.ORIG);
Matrix m3 = m1.minus(m2);
Matrix m4 = m2.times(-1);
assertEquals(getLabel(), m4, m3);
if (m1 instanceof Erasable) {
((Erasable) m1).erase();
}
if (m2 instanceof Erasable) {
((Erasable) m2).erase();
}
if (m3 instanceof Erasable) {
((Erasable) m3).erase();
}
if (m4 instanceof Erasable) {
((Erasable) m4).erase();
}
}
示例4: test0TimesXMatrix
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void test0TimesXMatrix() throws Exception {
Matrix m1 = createMatrixWithAnnotation(5, 7);
Matrix m2 = createMatrixWithAnnotation(5, 7);
m2.randn(Ret.ORIG);
Matrix m3 = m1.times(m2);
assertTrue(getLabel(), m3.isEmpty());
if (m1 instanceof Erasable) {
((Erasable) m1).erase();
}
if (m2 instanceof Erasable) {
((Erasable) m2).erase();
}
if (m3 instanceof Erasable) {
((Erasable) m3).erase();
}
}
示例5: testXTimes0Matrix
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testXTimes0Matrix() throws Exception {
Matrix m1 = createMatrixWithAnnotation(5, 7);
Matrix m2 = createMatrixWithAnnotation(5, 7);
m1.randn(Ret.ORIG);
Matrix m3 = m1.times(m2);
assertTrue(getLabel(), m3.isEmpty());
if (m1 instanceof Erasable) {
((Erasable) m1).erase();
}
if (m2 instanceof Erasable) {
((Erasable) m2).erase();
}
if (m3 instanceof Erasable) {
((Erasable) m3).erase();
}
}
示例6: test0Times0Matrix
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void test0Times0Matrix() throws Exception {
Matrix m1 = createMatrixWithAnnotation(5, 7);
Matrix m2 = createMatrixWithAnnotation(5, 7);
Matrix m3 = m1.times(m2);
assertTrue(getLabel(), m3.isEmpty());
if (m1 instanceof Erasable) {
((Erasable) m1).erase();
}
if (m2 instanceof Erasable) {
((Erasable) m2).erase();
}
if (m3 instanceof Erasable) {
((Erasable) m3).erase();
}
}
示例7: main
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// create a dense empty matrix with 4 rows and 4 columns
Matrix dense = DenseMatrix.Factory.zeros(4, 4);
// set entry at row 2 and column 3 to the value 5.0
dense.setAsDouble(5.0, 2, 3);
// set some other values
dense.setAsDouble(1.0, 0, 0);
dense.setAsDouble(3.0, 1, 1);
dense.setAsDouble(4.0, 2, 2);
dense.setAsDouble(-2.0, 3, 3);
dense.setAsDouble(-2.0, 1, 3);
// print the final matrix on the console
System.out.println(dense);
// create a sparse empty matrix with 4 rows and 4 columns
Matrix sparse = SparseMatrix.Factory.zeros(4, 4);
sparse.setAsDouble(2.0, 0, 0);
// basic calculations
Matrix transpose = dense.transpose();
Matrix sum = dense.plus(sparse);
Matrix difference = dense.minus(sparse);
Matrix matrixProduct = dense.mtimes(sparse);
Matrix scaled = dense.times(2.0);
Matrix inverse = dense.inv();
Matrix pseudoInverse = dense.pinv();
double determinant = dense.det();
Matrix[] singularValueDecomposition = dense.svd();
Matrix[] eigenValueDecomposition = dense.eig();
Matrix[] luDecomposition = dense.lu();
Matrix[] qrDecomposition = dense.qr();
Matrix choleskyDecomposition = dense.chol();
}
示例8: testTimesScalarLarge
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public final void testTimesScalarLarge() throws Exception {
if (!isTestLarge()) {
return;
}
Matrix m = createMatrixWithAnnotation(128, 113);
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.times(2.0);
assertEquals(getLabel(), 2.0, r.getAsDouble(0, 0), TOLERANCE);
assertEquals(getLabel(), 4.0, r.getAsDouble(0, 1), TOLERANCE);
assertEquals(getLabel(), 6.0, r.getAsDouble(1, 0), TOLERANCE);
assertEquals(getLabel(), 8.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();
}
}
示例9: testTimesMatrixSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testTimesMatrixSmall() throws Exception {
Matrix ref1 = DenseDoubleMatrix2D.Factory.randn(11, 10);
Matrix ref2 = DenseDoubleMatrix2D.Factory.randn(11, 10);
Matrix ref3 = ref1.times(Ret.LINK, true, ref2);
for (Class<? extends Matrix> mclass : ALLFLOATMATRIXCLASSES) {
Matrix m1 = getMatrix(mclass, ref1);
Matrix m2 = getMatrix(mclass, ref2);
Matrix m3 = m1.times(m2);
assertEquals(mclass.toString(), 0.0, ref3.minus(m3).getRMS(), TOLERANCE);
}
}
示例10: testTimesMatrixLarge
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testTimesMatrixLarge() throws Exception {
Matrix ref1 = DenseDoubleMatrix2D.Factory.randn(101, 100);
Matrix ref2 = DenseDoubleMatrix2D.Factory.randn(101, 100);
Matrix ref3 = ref1.times(Ret.LINK, true, ref2);
for (Class<? extends Matrix> mclass : ALLFLOATMATRIXCLASSES) {
Matrix m1 = getMatrix(mclass, ref1);
Matrix m2 = getMatrix(mclass, ref2);
Matrix m3 = m1.times(m2);
assertEquals(mclass.toString(), 0.0, ref3.minus(m3).getRMS(), TOLERANCE);
}
}
示例11: testTimesScalarSmall
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testTimesScalarSmall() throws Exception {
Matrix ref1 = DenseDoubleMatrix2D.Factory.randn(11, 10);
double ref2 = MathUtil.nextDouble();
Matrix ref3 = ref1.times(Ret.LINK, true, ref2);
for (Class<? extends Matrix> mclass : ALLFLOATMATRIXCLASSES) {
Matrix m1 = getMatrix(mclass, ref1);
Matrix m3 = m1.times(ref2);
assertEquals(mclass.toString(), 0.0, ref3.minus(m3).getRMS(), TOLERANCE);
}
}
示例12: testTimesScalarLarge
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
@Test
public void testTimesScalarLarge() throws Exception {
Matrix ref1 = DenseDoubleMatrix2D.Factory.randn(101, 100);
double ref2 = MathUtil.nextDouble();
Matrix ref3 = ref1.times(Ret.LINK, true, ref2);
for (Class<? extends Matrix> mclass : ALLFLOATMATRIXCLASSES) {
Matrix m1 = getMatrix(mclass, ref1);
Matrix m3 = m1.times(ref2);
assertEquals(mclass.toString(), 0.0, ref3.minus(m3).getRMS(), TOLERANCE);
}
}
示例13: calculateObjects
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public Map<String, Object> calculateObjects(Map<String, Object> input) {
Map<String, Object> result = new HashMap<String, Object>();
Matrix output = MathUtil.getMatrix(input.get(SOURCE1));
Matrix outputdeviation = MathUtil.getMatrix(input.get(SOURCE2));
Matrix product = output.times(output);
Matrix factor1 = product.times(-1).plus(1);
Matrix target = factor1.times(outputdeviation);
result.put(TARGET, target);
return result;
}
示例14: calculateObjects
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public Map<String, Object> calculateObjects(Map<String, Object> matrices) {
Map<String, Object> result = new HashMap<String, Object>();
Matrix weight = MathUtil.getMatrix(matrices.get(WEIGHT));
double eta = MathUtil.getMatrix(matrices.get(ETA)).doubleValue();
Matrix contactDeviation = MathUtil.getMatrix(matrices.get(CONTACTDEVIATION));
double sampleWeight = MathUtil.getMatrix(matrices.get(SAMPLEWEIGHT)).doubleValue();
Matrix transposedInput = MathUtil.getMatrix(matrices.get(INPUT)).toColumnVector(Ret.NEW);
switch (biasType) {
case SINGLE:
Matrix bias = Matrix.Factory.ones(transposedInput.getRowCount(), 1);
transposedInput = Matrix.Factory.horCat(transposedInput, bias);
break;
case MULTIPLE:
bias = Matrix.Factory.ones(transposedInput.getSize());
for (long[] c : transposedInput.allCoordinates()) {
if (MathUtil.isNaNOrInfinite(transposedInput.getAsDouble(c))) {
bias.setAsDouble(Double.NaN, c);
}
}
transposedInput = Matrix.Factory.horCat(transposedInput, bias);
break;
case NONE:
break;
}
double totalValueCount = transposedInput.getValueCount();
double missingValueCount = transposedInput.countMissing(Ret.NEW, ALL).doubleValue();
double boost = 1.0;
// if (useBoost) {
// boost = 1.0 / (totalValueCount - missingValueCount);
boost = totalValueCount / (totalValueCount - missingValueCount);
// }
Matrix product = contactDeviation.mtimes(transposedInput);
Matrix weightChange = product.times(eta * sampleWeight * boost);
Matrix newWeight = weight.minus(Ret.NEW, true, weightChange);
result.put(TARGET, newWeight);
return result;
}
示例15: trainAll
import org.ujmp.core.Matrix; //导入方法依赖的package包/类
public void trainAll(ListDataSet dataSet) {
// todo: normalize data
double lastRmse = Double.MAX_VALUE;
double averageImprovement = Double.NaN;
int featureCount = getFeatureCount(dataSet);
int classCount = getClassCount(dataSet);
Matrix parameters = Matrix.Factory.randn(featureCount + 1, classCount).divide(
featureCount + 1);
List<Matrix> inputs = new FastArrayList<Matrix>();
List<Matrix> targets = new FastArrayList<Matrix>();
for (int e = 0; e < ((double) dataSet.size() / batchSize) * epochs; e++) {
inputs.clear();
targets.clear();
for (int i = 0; i < batchSize; i++) {
int randomIndex = MathUtil.nextInteger(dataSet.size());
Sample s = dataSet.get(randomIndex);
inputs.add(s.getAsMatrix(Sample.INPUT).toColumnVector(Ret.NEW));
targets.add(s.getAsMatrix(Sample.TARGET).toColumnVector(Ret.NEW));
}
Matrix input = Matrix.Factory.vertCat(inputs);
Matrix bias = Matrix.Factory.ones(input.getRowCount(), 1);
Matrix x = Matrix.Factory.horCat(bias, input);
x = x.transpose();
Matrix target = Matrix.Factory.vertCat(targets);
target = target.transpose();
Matrix y = parameters.transpose().mtimes(x);
Matrix diff = y.minus(target);
Matrix squared = diff.power(Ret.NEW, 2);
double rmse = Math.sqrt(squared.getValueSum() / squared.getValueCount());
double improvement = Math.abs(lastRmse - rmse);
if (MathUtil.isNaNOrInfinite(averageImprovement)) {
averageImprovement = improvement;
}
averageImprovement = averageImprovement * 0.99 + 0.01 * improvement;
System.out.println(rmse);
Matrix gradient = x.mtimes(diff.transpose()).times(eta / batchSize);
setGradientMatrix(gradient);
parameters = parameters.minus(gradient);
parameters = parameters.times(1.0 - weightDecay);
if (averageImprovement < minImprovement) {
break;
}
lastRmse = rmse;
}
setParameterMatrix(parameters);
}