Java Code Examples for org.apache.commons.math3.complex.Complex#add()

The following examples show how to use org.apache.commons.math3.complex.Complex#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cascade.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public Complex response(final double normalizedFrequency) {
    final double w = 2 * Math.PI * normalizedFrequency;
    final Complex czn1 = ComplexUtils.polar2Complex(1., -w);
    final Complex czn2 = ComplexUtils.polar2Complex(1., -2 * w);
    Complex ch = new Complex(1);
    Complex cbot = new Complex(1);

    for (int i = 0; i < mNumBiquads; i++) {
        final Biquad stage = mBiquads[i];

        Complex ct = new Complex(stage.getB0() / stage.getA0()); // NOPMD
        ct = ct.add(czn1.multiply(stage.getB1() / stage.getA0()));
        ct = ct.add(czn2.multiply(stage.getB2() / stage.getA0()));

        Complex cb = new Complex(1); // NOPMD
        cb = cb.add(czn1.multiply(stage.getA1() / stage.getA0()));
        cb = cb.add(czn2.multiply(stage.getA2() / stage.getA0()));

        ch = ch.multiply(ct);
        cbot = cbot.multiply(cb);
    }

    return ch.divide(cbot);
}
 
Example 2
Source File: BandPassTransform.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
private static ComplexPair transform(final Complex in, final double a, final double b) {
    if (in.isInfinite()) {
        return new ComplexPair(new Complex(-1), new Complex(1));
    }

    final Complex c = new Complex(1).add(in).divide(new Complex(1).subtract(in)); // bilinear

    final double a2 = a * a;
    final double b2 = b * b;
    final double ab = a * b;
    final double ab2 = 2 * ab;
    Complex v = new Complex(0).add(c.multiply(4 * (b2 * (a2 - 1) + 1)));
    v = v.add(8 * (b2 * (a2 - 1) - 1));
    v = v.multiply(c);
    v = v.add(4 * (b2 * (a2 - 1) + 1));
    v = v.sqrt();

    final Complex u = v.multiply(-1).add(c.multiply(ab2)).add(ab2);

    v = v.add(c.multiply(ab2)).add(ab2);

    final Complex d = new Complex(0).add(c.multiply(2 * (b - 1))).add(2 * (1 + b));

    return new ComplexPair(u.divide(d), v.divide(d));
}
 
Example 3
Source File: ZernikeMoments.java    From cineast with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: DigitalOption.java    From finmath-lib with Apache License 2.0 5 votes vote down vote up
@Override
public Complex apply(final Complex argument) {
	final Complex iargument = argument.multiply(Complex.I);
	final Complex exponent = iargument.add(1.0);
	final Complex numerator = (new Complex(strike)).pow(exponent.subtract(1.0)).multiply(exponent);
	final Complex denominator = (argument.multiply(argument)).subtract(iargument);

	return numerator.divide(denominator);
}
 
Example 5
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 */
public Complex[] solveAll(Complex coefficients[], Complex initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    if (coefficients == null) {
        throw new NullArgumentException();
    }
    final int n = coefficients.length - 1;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.POLYNOMIAL);
    }
    // Coefficients for deflated polynomial.
    final Complex c[] = new Complex[n + 1];
    for (int i = 0; i <= n; i++) {
        c[i] = coefficients[i];
    }

    // Solve individual roots successively.
    final Complex root[] = new Complex[n];
    for (int i = 0; i < n; i++) {
        final Complex subarray[] = new Complex[n - i + 1];
        System.arraycopy(c, 0, subarray, 0, subarray.length);
        root[i] = solve(subarray, initial);
        // Polynomial deflation using synthetic division.
        Complex newc = c[n - i];
        Complex oldc = null;
        for (int j = n - i - 1; j >= 0; j--) {
            oldc = c[j];
            c[j] = newc;
            newc = oldc.add(newc.multiply(root[i]));
        }
    }

    return root;
}
 
Example 6
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 */
public Complex[] solveAll(Complex coefficients[], Complex initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    if (coefficients == null) {
        throw new NullArgumentException();
    }
    final int n = coefficients.length - 1;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.POLYNOMIAL);
    }
    // Coefficients for deflated polynomial.
    final Complex c[] = new Complex[n + 1];
    for (int i = 0; i <= n; i++) {
        c[i] = coefficients[i];
    }

    // Solve individual roots successively.
    final Complex root[] = new Complex[n];
    for (int i = 0; i < n; i++) {
        final Complex subarray[] = new Complex[n - i + 1];
        System.arraycopy(c, 0, subarray, 0, subarray.length);
        root[i] = solve(subarray, initial);
        // Polynomial deflation using synthetic division.
        Complex newc = c[n - i];
        Complex oldc = null;
        for (int j = n - i - 1; j >= 0; j--) {
            oldc = c[j];
            c[j] = newc;
            newc = oldc.add(newc.multiply(root[i]));
        }
    }

    return root;
}
 
Example 7
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 */
public Complex[] solveAll(Complex coefficients[], Complex initial) {
    if (coefficients == null) {
        throw new NullArgumentException();
    }
    final int n = coefficients.length - 1;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.POLYNOMIAL);
    }
    // Coefficients for deflated polynomial.
    final Complex c[] = new Complex[n + 1];
    for (int i = 0; i <= n; i++) {
        c[i] = coefficients[i];
    }

    // Solve individual roots successively.
    final Complex root[] = new Complex[n];
    for (int i = 0; i < n; i++) {
        final Complex subarray[] = new Complex[n - i + 1];
        System.arraycopy(c, 0, subarray, 0, subarray.length);
        root[i] = solve(subarray, initial);
        // Polynomial deflation using synthetic division.
        Complex newc = c[n - i];
        Complex oldc = null;
        for (int j = n - i - 1; j >= 0; j--) {
            oldc = c[j];
            c[j] = newc;
            newc = oldc.add(newc.multiply(root[i]));
        }
    }

    return root;
}
 
Example 8
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 */
public Complex[] solveAll(Complex coefficients[], Complex initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    if (coefficients == null) {
        throw new NullArgumentException();
    }
    final int n = coefficients.length - 1;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.POLYNOMIAL);
    }
    // Coefficients for deflated polynomial.
    final Complex c[] = new Complex[n + 1];
    for (int i = 0; i <= n; i++) {
        c[i] = coefficients[i];
    }

    // Solve individual roots successively.
    final Complex root[] = new Complex[n];
    for (int i = 0; i < n; i++) {
        final Complex subarray[] = new Complex[n - i + 1];
        System.arraycopy(c, 0, subarray, 0, subarray.length);
        root[i] = solve(subarray, initial);
        // Polynomial deflation using synthetic division.
        Complex newc = c[n - i];
        Complex oldc = null;
        for (int j = n - i - 1; j >= 0; j--) {
            oldc = c[j];
            c[j] = newc;
            newc = oldc.add(newc.multiply(root[i]));
        }
    }

    return root;
}
 
Example 9
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 */
public Complex[] solveAll(Complex coefficients[], Complex initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    if (coefficients == null) {
        throw new NullArgumentException();
    }
    final int n = coefficients.length - 1;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.POLYNOMIAL);
    }
    // Coefficients for deflated polynomial.
    final Complex c[] = new Complex[n + 1];
    for (int i = 0; i <= n; i++) {
        c[i] = coefficients[i];
    }

    // Solve individual roots successively.
    final Complex root[] = new Complex[n];
    for (int i = 0; i < n; i++) {
        final Complex subarray[] = new Complex[n - i + 1];
        System.arraycopy(c, 0, subarray, 0, subarray.length);
        root[i] = solve(subarray, initial);
        // Polynomial deflation using synthetic division.
        Complex newc = c[n - i];
        Complex oldc = null;
        for (int j = n - i - 1; j >= 0; j--) {
            oldc = c[j];
            c[j] = newc;
            newc = oldc.add(newc.multiply(root[i]));
        }
    }

    return root;
}
 
Example 10
Source File: ZernikePolynomialsTest.java    From cineast with MIT License 5 votes vote down vote up
/**
 * Tests if orthogonality relation that exists between two Zernike Polynoms holds true
 * for all n between 1 and 5.
 */
@Test
@DisplayName("Test Orthogonality")
void testOrthogonality() {
    final double increment = 0.25e-2;
    final double n_max = 5;
    for (int n1=1;n1<=n_max;n1++) {
        for (int m1=0; m1<=n1;m1++) {
            for (int n2=1;n2<=n_max;n2++) {
                for (int m2=0;m2<=n2;m2++) {
                    if (((n1-Math.abs(m1)) % 2 == 0) && ((n2-Math.abs(m2)) % 2 == 0)) {
                        Complex result = new Complex(0, 0);

                        /* Initialize ZernikeBasisFunctions for n1,m1 and n2,m2. */
                        final ZernikeBasisFunction ZF1 = new ZernikeBasisFunction(n1, m1);
                        final ZernikeBasisFunction ZF2 = new ZernikeBasisFunction(n2, m2);
                        final double expected = ((Math.PI) / (n1 + 1)) * MathHelper.kronecker(n1,n2) * MathHelper.kronecker(m1,m2);

                        /* Calculate integral (approximation). */
                        for (double theta = 0.0; theta <= 2 * Math.PI; theta += increment) {
                            for (double r = 0.0; r <= 1.0f; r += increment) {
                                Complex v = new Complex(r * FastMath.cos(theta), r * FastMath.sin(theta));
                                Complex res1 = ZF1.value(v);
                                Complex res2 = ZF2.value(v);
                                result = result.add(res1.conjugate().multiply(res2).multiply(r * increment * increment));
                            }
                        }

                        /* Result of integral must be equal to expected value. */
                        assertEquals(expected, result.abs(), 1e-2);
                    }
                }
            }
        }
    }
}
 
Example 11
Source File: TransformerModel.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public StateVariable toSv1(StateVariable sv2) {
    Complex s2 = new Complex(-sv2.p, -sv2.q); // s2=p2+jq2
    Complex u2 = ComplexUtils.polar2Complex(sv2.u, Math.toRadians(sv2.theta));
    Complex v2 = u2.divide(SQUARE_3); // v2=u2/sqrt(3)
    Complex i2 = s2.divide(v2.multiply(3)).conjugate(); // i2=conj(s2/(3*v2))
    Complex v1p = v2.add(z.multiply(i2)); // v1'=v2+z*i2
    Complex i1p = i2.negate().add(y.multiply(v1p)); // i1'=-i2+v1'*y
    Complex i1 = i1p.multiply(ratio); // i1=i1p*ration
    Complex v1 = v1p.divide(ratio); // v1=v1p/ration
    Complex s1 = v1.multiply(3).multiply(i1.conjugate()); // s1=3*v1*conj(i1)
    Complex u1 = v1.multiply(SQUARE_3);
    return new StateVariable(-s1.getReal(), -s1.getImaginary(), u1.abs(), Math.toDegrees(u1.getArgument()));
}
 
Example 12
Source File: DigitalOption.java    From finmath-lib with Apache License 2.0 5 votes vote down vote up
@Override
public Complex apply(final Complex argument) {
	final Complex iargument = argument.multiply(Complex.I);
	final Complex exponent = iargument.add(1.0);
	final Complex numerator = (new Complex(strike)).pow(exponent.subtract(1.0)).multiply(exponent);
	final Complex denominator = (argument.multiply(argument)).subtract(iargument);

	return numerator.divide(denominator);
}
 
Example 13
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 */
public Complex[] solveAll(Complex coefficients[], Complex initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    if (coefficients == null) {
        throw new NullArgumentException();
    }
    final int n = coefficients.length - 1;
    if (n == 0) {
        throw new NoDataException(LocalizedFormats.POLYNOMIAL);
    }
    // Coefficients for deflated polynomial.
    final Complex c[] = new Complex[n + 1];
    for (int i = 0; i <= n; i++) {
        c[i] = coefficients[i];
    }

    // Solve individual roots successively.
    final Complex root[] = new Complex[n];
    for (int i = 0; i < n; i++) {
        final Complex subarray[] = new Complex[n - i + 1];
        System.arraycopy(c, 0, subarray, 0, subarray.length);
        root[i] = solve(subarray, initial);
        // Polynomial deflation using synthetic division.
        Complex newc = c[n - i];
        Complex oldc = null;
        for (int j = n - i - 1; j >= 0; j--) {
            oldc = c[j];
            c[j] = newc;
            newc = oldc.add(newc.multiply(root[i]));
        }
    }

    return root;
}
 
Example 14
Source File: Biquad.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public Complex response(final double normalizedFrequency) {
    final double a0 = getA0();
    final double a1 = getA1();
    final double a2 = getA2();
    final double b0 = getB0();
    final double b1 = getB1();
    final double b2 = getB2();

    final double w = 2 * Math.PI * normalizedFrequency;
    final Complex czn1 = ComplexUtils.polar2Complex(1., -w);
    final Complex czn2 = ComplexUtils.polar2Complex(1., -2 * w);
    Complex ch = new Complex(1);
    Complex cbot = new Complex(1);

    Complex ct = new Complex(b0 / a0);

    ct = ct.add(czn1.multiply(b1 / a0));
    ct = ct.add(czn2.multiply(b2 / a0));

    Complex cb = new Complex(1);
    cb = cb.add(czn1.multiply(a1 / a0));
    cb = cb.add(czn2.multiply(a2 / a0));

    ch = ch.multiply(ct);
    cbot = cbot.multiply(cb);

    return ch.divide(cbot);
}
 
Example 15
Source File: DFT.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void fit(final double[] input) {

	if (this.numberOfDisieredCoefficients > input.length) {
		throw new IllegalArgumentException("There cannot be more DFT coefficents calcualated than there entrys in the basis instance.");
	}

	if (input.length == 0) {
		throw new IllegalArgumentException("The to transform instance can not be of length zero.");
	}

	if (this.rekursivFirstInstance) {
		this.startingpoint = 0;
	}
	// The buffer for the calculated DFT coefficeients
	this.dftCoefficientsInstance = new double[this.numberOfDisieredCoefficients * 2 - (this.startingpoint * 2)];

	// Variable used to make steps of size two in a loop that makes setps of size one
	int loopcounter = 0;

	for (int coefficient = this.startingpoint; coefficient < this.numberOfDisieredCoefficients; coefficient++) {

		Complex result = new Complex(0.0, 0.0);

		for (int entry = 0; entry < input.length; entry++) {

			// calculates the real and imaginary part of the entry according to the desired coefficient
			// c.f. p. 1510 "The BOSS is concerned with time series classification in the presence of noise" by Patrick Sch�fer
			double realpart = Math.cos(-(1.0 / input.length) * 2.0 * Math.PI * entry * coefficient);
			double imaginarypart = Math.sin(-(1.0 / input.length) * 2.0 * Math.PI * entry * coefficient);

			Complex tmp = new Complex(realpart, imaginarypart);
			tmp = tmp.multiply(input[entry]);

			result = result.add(tmp);
		}

		// saves the calculated coefficient in the buffer with first the real part and than the imaginary
		this.dftCoefficientsInstance[loopcounter] = result.getReal();
		this.dftCoefficientsInstance[loopcounter + 1] = result.getImaginary();
		loopcounter += 2;
	}
	if (this.rekursivFirstInstance && this.meanCorrected) {
		this.startingpoint = 1;
	}
	this.fittedInstance = true;
}
 
Example 16
Source File: CpfCaseBuilder14.java    From DeepMachineLearning with Apache License 2.0 4 votes vote down vote up
private double gotoLimit2(AclfNetwork net) throws InterpssException {
		
		int busi = 9;
		System.out.println("============ Go to Limit ============");
		LoadflowAlgorithm algo = CoreObjectFactory.createLoadflowAlgorithm(net);
		algo.loadflow();
//		LFOut.showlf(net);
		
		
		AclfBus bus = net.getBusList().get(9);
		Complex base = bus.getLoadPQ();
		oBase = bus.getLoadPQ();
		Complex delta = base.multiply(10);
		Complex result = base;

//		System.out.println("base = "+base+", delta = "+delta);
		bus.getContributeLoadList().get(0).setLoadCP(base.add(delta));
//		System.out.println("\tbus load pq = "+bus.getLoadPQ());
		
		int iter = 0;
		while(delta.abs() > 1e-10) {
			iter += 1;
			//��ǰ��������
//			System.out.println("base = "+base+", delta = "+delta);
			
			//��̽�е�
			delta = delta.multiply(0.5);
			bus.getContributeLoadList().get(0).setLoadCP(base.add(delta));
			//�����
//			System.out.println("bus 9 load pq = "+bus.getLoadPQ());
			
			//����̽�ɹ���...
			if (algo.loadflow()) {
				base = base.add(delta);
				result = base;
//				System.out.println("a success bus 9 load PQ = "+bus.getLoadPQ());
			}
//			System.out.println(AclfOutFunc.loadFlowSummary(net));
		}
		
//		System.out.println("iter = "+iter);
		bus.getContributeLoadList().get(0).setLoadCP(result);
//		System.out.println("after searching, bus 9 load PQ = "+result+", lf result = "+algo.loadflow());
//		System.out.println(AclfOutFunc.loadFlowSummary(net));
		
		return result.divide(oBase).abs();
	}
 
Example 17
Source File: CpfCaseBuilder39.java    From DeepMachineLearning with Apache License 2.0 4 votes vote down vote up
private double gotoLimit2(AclfNetwork net) throws InterpssException {
		
		int busi = 15;
		System.out.println("============ Go to Limit ============");
		LoadflowAlgorithm algo = CoreObjectFactory.createLoadflowAlgorithm(net);
		algo.loadflow();
//		LFOut.showlf(net);
		
		
		AclfBus bus = net.getBusList().get(busi);
		Complex base = bus.getLoadPQ();
		oBase = bus.getLoadPQ();
		Complex delta = base.multiply(100);
		Complex result = base;

//		System.out.println("base = "+base+", delta = "+delta);
		bus.getContributeLoadList().get(0).setLoadCP(base.add(delta));
		System.out.println("\tbus 16 load pq = "+bus.getLoadPQ());
		
		int iter = 0;
		while(delta.abs() > 1e-10) {
			iter += 1;
			//��ǰ��������
//			System.out.println("base = "+base+", delta = "+delta);
			
			//��̽�е�
			delta = delta.multiply(0.5);
			bus.getContributeLoadList().get(0).setLoadCP(base.add(delta));
			//�����
//			System.out.println("bus 9 load pq = "+bus.getLoadPQ());
			
			//����̽�ɹ���...
			if (algo.loadflow()) {
				base = base.add(delta);
				result = base;
//				System.out.println("a success bus 9 load PQ = "+bus.getLoadPQ());
			}
//			System.out.println(AclfOutFunc.loadFlowSummary(net));
		}
		
//		System.out.println("iter = "+iter);
		bus.getContributeLoadList().get(0).setLoadCP(result);
		System.out.println("after searching, bus 16 load PQ = "+result+", lf result = "+algo.loadflow());
//		System.out.println(AclfOutFunc.loadFlowSummary(net));
		
		return result.divide(oBase).abs();
	}
 
Example 18
Source File: LoadFlowCaseGenerator.java    From DeepMachineLearning with Apache License 2.0 4 votes vote down vote up
protected void gotoLimit(AclfNetwork net) throws InterpssException {
		
		int busi = 9;
		System.out.println("============ Go to Limit ============");
		LoadflowAlgorithm algo = CoreObjectFactory.createLoadflowAlgorithm(net);
		
		AclfBus bus = net.getBusList().get(9);
		Complex base = bus.getLoadPQ();
		Complex delta = base.multiply(10);
		Complex result = base;

		System.out.println("base = "+base+", delta = "+delta);
		if (bus.getContributeLoadList().size() == 0)
			return;//������cpf39����Э
		bus.getContributeLoadList().get(0).setLoadCP(base.add(delta));
		System.out.println("\tbus load pq = "+bus.getLoadPQ());
		
		int iter = 0;
		while(delta.abs() > 1e-10) {
			iter += 1;
			//��ǰ��������
			System.out.println("base = "+base+", delta = "+delta);
			
			//��̽�е�
			delta = delta.multiply(0.5);
			bus.getContributeLoadList().get(0).setLoadCP(base.add(delta));
			//�����
			System.out.println("bus load pq = "+bus.getLoadPQ());
			
			//����̽�ɹ���...
			if (algo.loadflow()) {
				base = base.add(delta);
				result = base;
				System.out.println("a success bus 9 load PQ = "+bus.getLoadPQ());
			}
//			System.out.println(AclfOutFunc.loadFlowSummary(net));
		}
		
		System.out.println("iter = "+iter);
		bus.getContributeLoadList().get(0).setLoadCP(result);
		System.out.println("after searching, bus 9 load PQ = "+result+", lf result = "+algo.loadflow());
		System.out.println(AclfOutFunc.loadFlowSummary(net));
		
	}
 
Example 19
Source File: VarianceGammaTest.java    From finmath-lib with Apache License 2.0 3 votes vote down vote up
public Complex characteristicFunctionByMonteCarlo(final Complex zeta, final RandomVariable processAtTime) {

		final int states = processAtTime.getRealizations().length;

		Complex runningSum = new Complex(0.0,0.0);

		for(int i = 0; i< states; i++) {
			runningSum = runningSum.add((Complex.I.multiply(zeta.multiply(processAtTime.get(i)))).exp());
		}

		return runningSum.divide(states);
	}
 
Example 20
Source File: VarianceGammaTest.java    From finmath-lib with Apache License 2.0 3 votes vote down vote up
public Complex characteristicFunctionByMonteCarlo(final Complex zeta, final RandomVariable processAtTime) {

		final int states = processAtTime.getRealizations().length;

		Complex runningSum = new Complex(0.0,0.0);

		for(int i = 0; i< states; i++) {
			runningSum = runningSum.add((Complex.I.multiply(zeta.multiply(processAtTime.get(i)))).exp());
		}

		return runningSum.divide(states);
	}