当前位置: 首页>>代码示例>>Java>>正文


Java Complex类代码示例

本文整理汇总了Java中org.apache.commons.math3.complex.Complex的典型用法代码示例。如果您正苦于以下问题:Java Complex类的具体用法?Java Complex怎么用?Java Complex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Complex类属于org.apache.commons.math3.complex包,在下文中一共展示了Complex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNetOutput

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
@Override
public double[] getNetOutput() {
	int i = 3;
	double[] output = new double[2 * i];

	Complex power = getAclfNet().getBranch("Bus5->Bus6(1)").powerFrom2To();
	output[0] = power.getReal();
	output[1] = power.getImaginary();
	power = getAclfNet().getBranch("Bus4->Bus7(1)").powerFrom2To();
	output[2] = power.getReal();
	output[3] = power.getImaginary();
	power = getAclfNet().getBranch("Bus4->Bus9(1)").powerFrom2To();
	output[4] = power.getReal();
	output[5] = power.getImaginary();
	return output;
}
 
开发者ID:interpss,项目名称:DeepMachineLearning,代码行数:17,代码来源:InterfacePowerRandomChangeTrainCaseBuilder.java

示例2: otherSide

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
public SV otherSide(float r, float x, float g, float b, float ratio) {
    Complex z = new Complex(r, x); // z=r+jx
    Complex y = new Complex(g, b); // y=g+jb
    Complex s1 = new Complex(p, q); // s1=p1+jq1
    Complex u1 = ComplexUtils.polar2Complex(u, Math.toRadians(a));
    Complex v1 = u1.divide(Math.sqrt(3f)); // v1=u1/sqrt(3)

    Complex v1p = v1.multiply(ratio); // v1p=v1*rho
    Complex i1 = s1.divide(v1.multiply(3)).conjugate(); // i1=conj(s1/(3*v1))
    Complex i1p = i1.divide(ratio); // i1p=i1/rho
    Complex i2 = i1p.subtract(y.multiply(v1p)); // i2=i1p-y*v1p
    Complex v2 = v1p.subtract(z.multiply(i2)); // v2=v1p-z*i2
    Complex s2 = v2.multiply(3).multiply(i2.conjugate()); // s2=3*v2*conj(i2)

    Complex u2 = v2.multiply(Math.sqrt(3f));
    return new SV((float) -s2.getReal(), (float) -s2.getImaginary(), (float) u2.abs(), (float) Math.toDegrees(u2.getArgument()));
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:18,代码来源:SV.java

示例3: Gate

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
public Gate(final String id, double angle, final Tools.AngleType angle_type) {
	this.id = id;
	this.IO_ports = 1;
	
	if (angle_type == Tools.AngleType.DEGREES)
		angle = Math.toRadians(angle);
	
	Complex[][] data = new Complex[][] {
			{new Complex(1), new Complex(0)},
			{new Complex(0), new Complex(Tools.round(Math.cos(angle)), Tools.round(Math.sin(angle)))}
	};
	
	mat = new Array2DRowFieldMatrix<Complex>(data);
	
	if (!valid())
		throw new RuntimeException(
				"Matrix is not a valid quantum gate in Gate phase shift constructor");
}
 
开发者ID:QwertygidQ,项目名称:DeutschSim,代码行数:19,代码来源:Gate.java

示例4: valid

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
public boolean valid() {
	// Checks if this is a control matrix
	Complex[][] data = new Complex[][] {
			{new Complex(Tools.CONTROL_VALUE), new Complex(0)},
			{new Complex(0), new Complex(1)}
	};
	
	FieldMatrix<Complex> control = new Array2DRowFieldMatrix<Complex>(data);
	
	if (mat.equals(control))
		return true;
	
	final boolean is_dimension_power_of_2 = (mat.getColumnDimension() & (mat.getColumnDimension() - 1)) == 0;
	if (!mat.isSquare() || !is_dimension_power_of_2)
		return false;
	
	// Computes dagger of mat
	FieldMatrix<Complex> dagger = mat.transpose();
	dagger.walkInOptimizedOrder(new MatrixConjugator());
	
	// Checks if dagger * mat = identity matrix
	FieldMatrix<Complex> result = mat.multiply(dagger);
	Complex is_identity = result.walkInOptimizedOrder(new UnitaryChecker()); // 1+0i if true, 0+0i if false
	
	return is_identity.equals(new Complex(1));
}
 
开发者ID:QwertygidQ,项目名称:DeutschSim,代码行数:27,代码来源:Gate.java

示例5: kronecker

import org.apache.commons.math3.complex.Complex; //导入依赖的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;
}
 
开发者ID:QwertygidQ,项目名称:DeutschSim,代码行数:24,代码来源:Circuit.java

示例6: top_level

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
private Complex top_level() {
	switch (current.type) {
	case INTEGER: // Fall-through
	case I:
	case E:
	case PI:
		return number();
	case MINUS:
		eat(Token.Type.MINUS);
		return top_level().negate();
	case LPAREN:
		eat(Token.Type.LPAREN);
		Complex value = sum();
		eat(Token.Type.RPAREN);
		return value;
	default:
		return function();
	}
}
 
开发者ID:QwertygidQ,项目名称:DeutschSim,代码行数:20,代码来源:Interpreter.java

示例7: nthRoot

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
public ValueType nthRoot(CalculatedValue g, int n)
{
    try
    {
        final List<Complex> roots = g.getComplex().nthRoot(n);
        for (Complex root : roots)
        {
            if (FastMath.abs(root.getImaginary()) < 1E-15)
            {
                return setValue(root.getReal());
            }
        }
        if (!roots.isEmpty())
        {
            return setComplexValue(roots.get(0));
        }
    }
    catch (Exception ex)
    {
        // nothing to do
    }
    return invalidate(ErrorType.NOT_A_NUMBER);
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:24,代码来源:CalculatedValue.java

示例8: createElementClassMap

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
private static Map<Class<?>, Integer> createElementClassMap() {
	Map<Class<?>, Integer> result = new HashMap<Class<?>, Integer>();
	result.put(Boolean.class, Dataset.BOOL);
	result.put(Byte.class, Dataset.INT8);
	result.put(Short.class, Dataset.INT16);
	result.put(Integer.class, Dataset.INT32);
	result.put(Long.class, Dataset.INT64);
	result.put(Float.class, Dataset.FLOAT32);
	result.put(Double.class, Dataset.FLOAT64);
	result.put(boolean.class, Dataset.BOOL);
	result.put(byte.class, Dataset.INT8);
	result.put(short.class, Dataset.INT16);
	result.put(int.class, Dataset.INT32);
	result.put(long.class, Dataset.INT64);
	result.put(float.class, Dataset.FLOAT32);
	result.put(double.class, Dataset.FLOAT64);
	result.put(Complex.class, Dataset.COMPLEX128);
	result.put(String.class, Dataset.STRING);
	result.put(Date.class, Dataset.DATE);
	result.put(Object.class, Dataset.OBJECT);
	return result;
}
 
开发者ID:eclipse,项目名称:january,代码行数:23,代码来源:DTypeUtils.java

示例9: getLength

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
/**
 * @param b
 * @return length of object
 */
public static final int getLength(final Object b) {
	if (b instanceof Number) {
		return 1;
	} else if (b instanceof Complex) {
		return 1;
	} else if (b instanceof List<?>) {
		List<?> jl = (List<?>) b;
		return jl.size();
	} else if (b.getClass().isArray()) {
		return Array.getLength(b);
	} else if (b instanceof IDataset) {
		IDataset db = (Dataset) b;
		return db.getSize();
	}

	throw new IllegalArgumentException("Cannot find length as object not supported");
}
 
开发者ID:eclipse,项目名称:january,代码行数:22,代码来源:DTypeUtils.java

示例10: testOp

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
@Test
public void testOp() {
	for (int i = 0, imax = operands.length; i < imax; i++) {
		Object[] vs = operands[i];
		Object ex = expected[i];
		String s = toString() + Arrays.toString(vs);
		if (ex instanceof Boolean) {
			assertEquals(s, ex, operation.booleanOperate((Long) vs[0], (Long) vs[1]));
		} else if (ex instanceof Long) {
			assertEquals(s, ex, operation.longOperate((Long) vs[0], (Long) vs[1]));
		} else if (ex instanceof Double) {
			TestUtils.assertEquals(s, (Double) ex, operation.doubleOperate((Double) vs[0], (Double) vs[1]));
		} else if (ex instanceof Complex) {
			Complex cz = (Complex) ex;
			double[] cpx = new double[2];
			operation.complexOperate(cpx, (Double) vs[0], (Double) vs[1], (Double) vs[2], (Double) vs[3]);
			TestUtils.assertEquals(s + ": real", cz.getReal(), cpx[0], 1e-14, 7e-17);
			TestUtils.assertEquals(s + ": imag", cz.getImaginary(), cpx[1]);
		}
	}
}
 
开发者ID:eclipse,项目名称:january,代码行数:22,代码来源:BinaryOperationTest.java

示例11: testOp

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
@Test
public void testOp() {
	for (int i = 0, imax = operands.length; i < imax; i++) {
		Object[] vs = operands[i];
		Object ex = expected[i];
		String s = toString() + Arrays.toString(vs);
		if (ex instanceof Boolean) {
			assertEquals(s, ex, operation.booleanOperate((Long) vs[0]));
		} else if (ex instanceof Long) {
			assertEquals(s, ex, operation.longOperate((Long) vs[0]));
		} else if (ex instanceof Double) {
			TestUtils.assertEquals(s, (Double) ex, operation.doubleOperate((Double) vs[0]));
		} else if (ex instanceof Complex) {
			Complex cz = (Complex) ex;
			double[] cpx = new double[2];
			operation.complexOperate(cpx, (Double) vs[0], (Double) vs[1]);
			TestUtils.assertEquals(s + ": real", cz.getReal(), cpx[0], 1e-14, 7e-17);
			TestUtils.assertEquals(s + ": imag", cz.getImaginary(), cpx[1]);
		}
	}
}
 
开发者ID:eclipse,项目名称:january,代码行数:22,代码来源:UnaryOperationTest.java

示例12: processSegment

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
/**
 *
 * @param shot
 */
@Override
public void processSegment(SegmentContainer shot) {

    BufferedImage image = shot.getAvgImg().getBufferedImage();

    List<Contour> contours = ContourHelper.getContours(image);
    List<Point2D_I32> contour = contours.get(0).internal.get(0);

    if (image != null) {
        FastFourierTransformer transformer = new FastFourierTransformer(DftNormalization.STANDARD);
        double[] distancefunction = ContourHelper.centroidDistance(contour, true);
        Complex[] signature = transformer.transform(distancefunction, TransformType.FORWARD);
        float[] descriptors = new float[DESCRIPTOR_LENGTH];
        for (int i = 1;i<DESCRIPTOR_LENGTH;i++) {
            descriptors[i] = (float) (signature[i].abs() / signature[0].abs());
        }
        this.persist(shot.getId(), new FloatVectorImpl(descriptors));
    }
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:24,代码来源:ShapeCentroidDistance.java

示例13: getSimilar

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
/**
 *
 * @param sc
 * @param qc
 * @return
 */
@Override
public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) {

    BufferedImage image = sc.getAvgImg().getBufferedImage();

    qc = setQueryConfig(qc);

    List<Contour> contours = ContourHelper.getContours(image);
    List<Point2D_I32> contour =  contours.get(0).internal.get(0);

    if (image != null) {
        FastFourierTransformer transformer = new FastFourierTransformer(DftNormalization.STANDARD);
        double[] distancefunction = ContourHelper.centroidDistance(contour, true);
        Complex[] signature = transformer.transform(distancefunction, TransformType.FORWARD);
        float[] descriptors = new float[DESCRIPTOR_LENGTH];
        for (int i = 1;i<DESCRIPTOR_LENGTH;i++) {
            descriptors[i] = (float) (signature[i].abs() / signature[0].abs());
        }
        return this.getSimilar(descriptors, qc);
    } else {
        return new ArrayList<>();
    }
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:30,代码来源:ShapeCentroidDistance.java

示例14: featureVectorsFromImage

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
/**
 * Extracts the Lightfield Fourier descriptors from a provided BufferedImage. The returned list contains
 * elements for each identified contour of adequate size.
 *
 * @param image Image for which to extract the Lightfield Fourier descriptors.
 * @param poseidx Poseidx of the extracted image.
 * @return List of descriptors for image.
 */
@Override
protected List<float[]> featureVectorsFromImage(BufferedImage image, int poseidx) {
    final List<ZernikeMoments> moments = ZernikeHelper.zernikeMomentsForShapes(image, RENDERING_SIZE /2, 10);
    final List<float[]> features = new ArrayList<>(moments.size());
    for (ZernikeMoments moment : moments) {
        float[] feature = new float[SIZE];
        int i = 0;
        for (Complex m : moment.getMoments()) {
            feature[i] = (float)m.abs();
            i++;
        }
        feature = MathHelper.normalizeL2InPlace(feature);
        feature[0] = poseidx;
        features.add(feature);
    }
    return features;
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:26,代码来源:LightfieldZernike.java

示例15: calculateZernikeMoment

import org.apache.commons.math3.complex.Complex; //导入依赖的package包/类
/**
 * Compute Zernike moments at specified order.
 *
 * @param w Width of the bounding box of the shape.
 * @param h Height of the bounding box of the shape.
 * @param n 1st order of the moment.
 * @param m 2nd order of the moment.
 *
 * @return Zernike moment of data in f[][].
 */
public static Complex calculateZernikeMoment(double[][] f, int w, int h, int n, int m){
    int diff = n-Math.abs(m);
    if ((n<0) || (Math.abs(m) > n) || (diff%2!=0)){
        throw new IllegalArgumentException("zer_mom: n="+n+", m="+m+", n-|m|="+diff);
    }

    final double c = -1;
    final double d = 1;


    ZernikeBasisFunction zernike = new ZernikeBasisFunction(n,m);
    Complex res = new Complex(0.0, 0.0);
    for (int i=0;i<w;i++){
        for (int j=0;j<h;j++) {
            Complex v = new Complex(c+(i*(d-c))/(w-1), d-(j*(d-c))/(h-1));
            res = res.add(zernike.value(v).conjugate().multiply(f[i][j]));
        }
    }

    return res.multiply((n+1)/Math.PI);
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:32,代码来源:ZernikeMoments.java


注:本文中的org.apache.commons.math3.complex.Complex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。