本文整理汇总了Java中org.apache.commons.math3.linear.FieldMatrix.getColumnDimension方法的典型用法代码示例。如果您正苦于以下问题:Java FieldMatrix.getColumnDimension方法的具体用法?Java FieldMatrix.getColumnDimension怎么用?Java FieldMatrix.getColumnDimension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.linear.FieldMatrix
的用法示例。
在下文中一共展示了FieldMatrix.getColumnDimension方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例5: 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();
}
}
示例6: 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;
}