本文整理汇总了Java中org.apache.commons.math3.linear.FieldMatrix.getRowDimension方法的典型用法代码示例。如果您正苦于以下问题:Java FieldMatrix.getRowDimension方法的具体用法?Java FieldMatrix.getRowDimension怎么用?Java FieldMatrix.getRowDimension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.linear.FieldMatrix
的用法示例。
在下文中一共展示了FieldMatrix.getRowDimension方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: kronecker
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
private static FieldMatrix<Complex> kronecker(FieldMatrix<Complex> lhs, FieldMatrix<Complex> rhs) {
FieldMatrix<Complex> result = new Array2DRowFieldMatrix<Complex>(ComplexField.getInstance(),
lhs.getRowDimension() * rhs.getRowDimension(), lhs.getColumnDimension() * rhs.getColumnDimension());
for (int i = 0; i < lhs.getRowDimension(); i++)
for (int j = 0; j < lhs.getColumnDimension(); j++)
for (int k = 0; k < rhs.getRowDimension(); k++)
for (int l = 0; l < rhs.getColumnDimension(); l++) {
int row = i * rhs.getRowDimension() + k, col = j * rhs.getColumnDimension() + l;
// The control value alters Kronecker product's behavior to create controlled gates
if (lhs.getEntry(i, j).getReal() == Tools.CONTROL_VALUE)
if (row == col)
result.setEntry(row, col, new Complex(Tools.CONTROL_VALUE));
else
result.setEntry(row, col, new Complex(0));
else
result.setEntry(row, col, lhs.getEntry(i, j).multiply(rhs.getEntry(k, l)));
}
return result;
}
示例2: assertEquals
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
/** verifies that two matrices are equal */
public static void assertEquals(FieldMatrix<? extends FieldElement<?>> expected,
FieldMatrix<? extends FieldElement<?>> observed) {
Assert.assertNotNull("Observed should not be null",observed);
if (expected.getColumnDimension() != observed.getColumnDimension() ||
expected.getRowDimension() != observed.getRowDimension()) {
StringBuilder messageBuffer = new StringBuilder();
messageBuffer.append("Observed has incorrect dimensions.");
messageBuffer.append("\nobserved is " + observed.getRowDimension() +
" x " + observed.getColumnDimension());
messageBuffer.append("\nexpected " + expected.getRowDimension() +
" x " + expected.getColumnDimension());
Assert.fail(messageBuffer.toString());
}
for (int i = 0; i < expected.getRowDimension(); ++i) {
for (int j = 0; j < expected.getColumnDimension(); ++j) {
FieldElement<?> eij = expected.getEntry(i, j);
FieldElement<?> oij = observed.getEntry(i, j);
Assert.assertEquals(eij, oij);
}
}
}
示例3: setMatrixToNextLayerTest
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
@Test
public void setMatrixToNextLayerTest() throws SeviException{
Layer l1 = new Layer(2, ActivationFunction.Sigmoid);
Layer l2 = new Layer(3, ActivationFunction.Sigmoid);
l1.connectTo(l2);
FieldMatrix<Complex> matrix1 = l1.getMatrixtoNextLayer();
l1.setMatrixtoNextLayer(matrix1);
FieldMatrix<Complex> matrix2 = l1.getMatrixtoNextLayer();
for(int x = 0; x < matrix1.getRowDimension(); x++) {
for(int y = 0; y < matrix1.getColumnDimension(); y++) {
assertTrue(matrix1.getEntry(x, y).equals(matrix2.getEntry(x, y)));
}
}
}
示例4: roundedK
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
/**
* Calculates {@code P(D_n < d)} using method described in [1] and doubles
* (see above).
*
* @param d statistic
* @return the two-sided probability of {@code P(D_n < d)}
* @throws MathArithmeticException if algorithm fails to convert {@code h}
* to a {@link org.apache.commons.math3.fraction.BigFraction} in expressing
* {@code d} as {@code (k - h) / m} for integer {@code k, m} and
* {@code 0 <= h < 1}.
*/
private double roundedK(double d) throws MathArithmeticException {
final int k = (int) FastMath.ceil(n * d);
final FieldMatrix<BigFraction> HBigFraction = this.createH(d);
final int m = HBigFraction.getRowDimension();
/*
* Here the rounding part comes into play: use
* RealMatrix instead of FieldMatrix<BigFraction>
*/
final RealMatrix H = new Array2DRowRealMatrix(m, m);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < m; ++j) {
H.setEntry(i, j, HBigFraction.getEntry(i, j).doubleValue());
}
}
final RealMatrix Hpower = H.power(n);
double pFrac = Hpower.getEntry(k - 1, k - 1);
for (int i = 1; i <= n; ++i) {
pFrac *= (double) i / (double) n;
}
return pFrac;
}
示例5: errorEstimation
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
/** Estimate error.
* <p>
* Error is estimated by interpolating back to previous state using
* the state Taylor expansion and comparing to real previous state.
* </p>
* @param previousState state vector at step start
* @param predictedState predicted state vector at step end
* @param predictedScaled predicted value of the scaled derivatives at step end
* @param predictedNordsieck predicted value of the Nordsieck vector at step end
* @return estimated normalized local discretization error
*/
private T errorEstimation(final T[] previousState,
final T[] predictedState,
final T[] predictedScaled,
final FieldMatrix<T> predictedNordsieck) {
T error = getField().getZero();
for (int i = 0; i < mainSetDimension; ++i) {
final T yScale = predictedState[i].abs();
final T tol = (vecAbsoluteTolerance == null) ?
yScale.multiply(scalRelativeTolerance).add(scalAbsoluteTolerance) :
yScale.multiply(vecRelativeTolerance[i]).add(vecAbsoluteTolerance[i]);
// apply Taylor formula from high order to low order,
// for the sake of numerical accuracy
T variation = getField().getZero();
int sign = predictedNordsieck.getRowDimension() % 2 == 0 ? -1 : 1;
for (int k = predictedNordsieck.getRowDimension() - 1; k >= 0; --k) {
variation = variation.add(predictedNordsieck.getEntry(k, i).multiply(sign));
sign = -sign;
}
variation = variation.subtract(predictedScaled[i]);
final T ratio = predictedState[i].subtract(previousState[i]).add(variation).divide(tol);
error = error.add(ratio.multiply(ratio));
}
return error.divide(mainSetDimension).sqrt();
}
示例6: conjugate
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
private FieldMatrix<Complex> conjugate(FieldMatrix<Complex> vec){
FieldMatrix<Complex> ret = vec.copy();
for(int i=0; i < vec.getRowDimension(); i++){
for(int y=0; y < vec.getColumnDimension(); y++){
ret.setEntry(i,y,vec.getEntry(i,y).conjugate());
}
}
return ret;
}
示例7: out
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
public static void out(FieldMatrix<Complex> field){
for(int row = 0; row < field.getRowDimension(); row++){
for(int column = 0; column < field.getColumnDimension(); column++){
Complex c =field.getEntry(row, column);
System.out.print(c.getReal()+ "(" + c.getImaginary() + "i)" + ", ");
}
System.out.println();
}
}
示例8: listFromCMFieldMatrix
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
/**
* Convert commons-math <code>FieldElement</code> to JAS
* <code>RingElem</code> to.
* @param <C> ring element type
* @param v commons-math FieldMatrix of CMFieldElement objects
* @return java.util.List of ring elements
*/
public static <C extends RingElem<C>> List<List<C>> listFromCMFieldMatrix(FieldMatrix<CMFieldElement<C>> v) {
if (v == null) {
return null;
}
ArrayList<List<C>> vv = new ArrayList<List<C>>(v.getRowDimension());
for (int i = 0; i < v.getRowDimension(); i++) {
FieldVector<CMFieldElement<C>> e = v.getRowVector(i + 1);
List<C> l = listFromCMFieldVector(e);
vv.add(l);
}
return vv;
}
示例9: roundedK
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
/**
* Calculates {@code P(D_n < d)} using method described in [1] and doubles
* (see above).
*
* @param d statistic
* @return the two-sided probability of {@code P(D_n < d)}
* @throws MathArithmeticException if algorithm fails to convert {@code h}
* to a {@link org.apache.commons.math3.fraction.BigFraction} in expressing
* {@code d} as {@code (k - h) / m} for integer {@code k, m} and
* {@code 0 <= h < 1}.
*/
private double roundedK(double d) throws MathArithmeticException {
final int k = (int) Math.ceil(n * d);
final FieldMatrix<BigFraction> HBigFraction = this.createH(d);
final int m = HBigFraction.getRowDimension();
/*
* Here the rounding part comes into play: use
* RealMatrix instead of FieldMatrix<BigFraction>
*/
final RealMatrix H = new Array2DRowRealMatrix(m, m);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < m; ++j) {
H.setEntry(i, j, HBigFraction.getEntry(i, j).doubleValue());
}
}
final RealMatrix Hpower = H.power(n);
double pFrac = Hpower.getEntry(k - 1, k - 1);
for (int i = 1; i <= n; ++i) {
pFrac *= (double) i / (double) n;
}
return pFrac;
}
示例10: initializeHighOrderDerivatives
import org.apache.commons.math3.linear.FieldMatrix; //导入方法依赖的package包/类
/** Initialize the high order scaled derivatives at step start.
* @param h step size to use for scaling
* @param t first steps times
* @param y first steps states
* @param yDot first steps derivatives
* @return Nordieck vector at start of first step (h<sup>2</sup>/2 y''<sub>n</sub>,
* h<sup>3</sup>/6 y'''<sub>n</sub> ... h<sup>k</sup>/k! y<sup>(k)</sup><sub>n</sub>)
*/
public Array2DRowFieldMatrix<T> initializeHighOrderDerivatives(final T h, final T[] t,
final T[][] y,
final T[][] yDot) {
// using Taylor series with di = ti - t0, we get:
// y(ti) - y(t0) - di y'(t0) = di^2 / h^2 s2 + ... + di^k / h^k sk + O(h^k)
// y'(ti) - y'(t0) = 2 di / h^2 s2 + ... + k di^(k-1) / h^k sk + O(h^(k-1))
// we write these relations for i = 1 to i= 1+n/2 as a set of n + 2 linear
// equations depending on the Nordsieck vector [s2 ... sk rk], so s2 to sk correspond
// to the appropriately truncated Taylor expansion, and rk is the Taylor remainder.
// The goal is to have s2 to sk as accurate as possible considering the fact the sum is
// truncated and we don't want the error terms to be included in s2 ... sk, so we need
// to solve also for the remainder
final T[][] a = MathArrays.buildArray(field, c1.length + 1, c1.length + 1);
final T[][] b = MathArrays.buildArray(field, c1.length + 1, y[0].length);
final T[] y0 = y[0];
final T[] yDot0 = yDot[0];
for (int i = 1; i < y.length; ++i) {
final T di = t[i].subtract(t[0]);
final T ratio = di.divide(h);
T dikM1Ohk = h.reciprocal();
// linear coefficients of equations
// y(ti) - y(t0) - di y'(t0) and y'(ti) - y'(t0)
final T[] aI = a[2 * i - 2];
final T[] aDotI = (2 * i - 1) < a.length ? a[2 * i - 1] : null;
for (int j = 0; j < aI.length; ++j) {
dikM1Ohk = dikM1Ohk.multiply(ratio);
aI[j] = di.multiply(dikM1Ohk);
if (aDotI != null) {
aDotI[j] = dikM1Ohk.multiply(j + 2);
}
}
// expected value of the previous equations
final T[] yI = y[i];
final T[] yDotI = yDot[i];
final T[] bI = b[2 * i - 2];
final T[] bDotI = (2 * i - 1) < b.length ? b[2 * i - 1] : null;
for (int j = 0; j < yI.length; ++j) {
bI[j] = yI[j].subtract(y0[j]).subtract(di.multiply(yDot0[j]));
if (bDotI != null) {
bDotI[j] = yDotI[j].subtract(yDot0[j]);
}
}
}
// solve the linear system to get the best estimate of the Nordsieck vector [s2 ... sk],
// with the additional terms s(k+1) and c grabbing the parts after the truncated Taylor expansion
final FieldLUDecomposition<T> decomposition = new FieldLUDecomposition<T>(new Array2DRowFieldMatrix<T>(a, false));
final FieldMatrix<T> x = decomposition.getSolver().solve(new Array2DRowFieldMatrix<T>(b, false));
// extract just the Nordsieck vector [s2 ... sk]
final Array2DRowFieldMatrix<T> truncatedX =
new Array2DRowFieldMatrix<T>(field, x.getRowDimension() - 1, x.getColumnDimension());
for (int i = 0; i < truncatedX.getRowDimension(); ++i) {
for (int j = 0; j < truncatedX.getColumnDimension(); ++j) {
truncatedX.setEntry(i, j, x.getEntry(i, j));
}
}
return truncatedX;
}