當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。