Search in sources :

Example 1 with Uniform

use of org.ojalgo.random.Uniform in project ojAlgo-finance by optimatika.

the class StrategyMixer method testStratCombPortfolioMixerRandom.

@Test
@Tag("unstable")
public void testStratCombPortfolioMixerRandom() {
    final FinancePortfolio tmpTarget = new SimplePortfolio(QUARTER, QUARTER, QUARTER, QUARTER).normalise();
    final Uniform tmpGen = new Uniform();
    final FinancePortfolio tmpStrat1 = new SimplePortfolio(tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue()).normalise();
    final FinancePortfolio tmpStrat2 = new SimplePortfolio(tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue()).normalise();
    final FinancePortfolio tmpStrat3 = new SimplePortfolio(tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue()).normalise();
    final PortfolioMixer tmpMixer = new PortfolioMixer(tmpTarget, tmpStrat1, tmpStrat2, tmpStrat3);
    final int tmpExpectedNumberOfStrategies = 2;
    final List<BigDecimal> tmpStrategyWeights = tmpMixer.mix(tmpExpectedNumberOfStrategies);
    int tmpUseCount = 0;
    double tmpTotalWeight = 0D;
    for (final BigDecimal tmpWeight : tmpStrategyWeights) {
        if (tmpWeight.signum() != 0) {
            tmpUseCount++;
            tmpTotalWeight += tmpWeight.doubleValue();
        }
    }
    TestUtils.assertEquals(tmpExpectedNumberOfStrategies, tmpUseCount);
    TestUtils.assertEquals(PrimitiveMath.ONE, tmpTotalWeight, 1E-14 / PrimitiveMath.THREE / PrimitiveMath.HUNDRED);
}
Also used : Uniform(org.ojalgo.random.Uniform) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 2 with Uniform

use of org.ojalgo.random.Uniform in project ojAlgo by optimatika.

the class P20050125Case method getProblematic.

public static RationalMatrix getProblematic() {
    int DIM = 3;
    final RationalMatrix tmpMtrx = RationalMatrix.FACTORY.makeFilled(DIM, DIM * DIM, new Uniform());
    return tmpMtrx.multiply(tmpMtrx.transpose());
}
Also used : Uniform(org.ojalgo.random.Uniform)

Example 3 with Uniform

use of org.ojalgo.random.Uniform in project ojAlgo by optimatika.

the class ApproximationCase method testFirstOrderApproximation.

@Test
public void testFirstOrderApproximation() {
    final int tmpArity = 9;
    final PhysicalStore<Double> tmpLinear = PrimitiveDenseStore.FACTORY.makeFilled(tmpArity, 1, new Uniform(-1, 2));
    final PhysicalStore<Double> tmpPoint = PrimitiveDenseStore.FACTORY.makeFilled(tmpArity, 1, new Uniform(-10, 20));
    final LinearFunction<Double> tmpOrgFunc = LinearFunction.makePrimitive(tmpLinear);
    final FirstOrderApproximation<Double> tmpApprFunc = tmpOrgFunc.toFirstOrderApproximation(tmpPoint);
    final PhysicalStore<Double> tmpX = PrimitiveDenseStore.FACTORY.makeFilled(tmpArity, 1, new Uniform(-10, 20));
    TestUtils.assertEquals(tmpOrgFunc.invoke(tmpX), tmpApprFunc.invoke(tmpX), new NumberContext(7, 14));
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) Uniform(org.ojalgo.random.Uniform) Test(org.junit.jupiter.api.Test)

Example 4 with Uniform

use of org.ojalgo.random.Uniform in project ojAlgo by optimatika.

the class BufferArrayTest method testRandomGetSet.

@Test
public void testRandomGetSet() {
    final int tmpCount = 5000;
    final BasicArray<Double> tmpArray = BufferArray.make(tmpCount);
    TestUtils.assertEquals(tmpCount, tmpArray.count());
    final Uniform tmpUniform = new Uniform();
    for (int i = 0; i < 100; i++) {
        final long tmpIndex = Uniform.randomInteger(tmpCount);
        final double tmpExpected = tmpUniform.doubleValue();
        tmpArray.set(tmpIndex, tmpExpected);
        final double tmpActual = tmpArray.doubleValue(tmpIndex);
        TestUtils.assertEquals(tmpExpected, tmpActual);
    }
}
Also used : Uniform(org.ojalgo.random.Uniform) Test(org.junit.jupiter.api.Test)

Example 5 with Uniform

use of org.ojalgo.random.Uniform in project ojAlgo by optimatika.

the class Password method makeClearText.

public static String makeClearText(final int length) {
    final char[] retVal = new char[length];
    final Uniform tmpRandom = new Uniform(0, 128);
    for (int c = 0; c < length; c++) {
        int tmpChar = ASCII.NBSP;
        do {
            tmpChar = tmpRandom.intValue();
        } while (!ASCII.isAlphanumeric(tmpChar));
        retVal[c] = (char) tmpChar;
    }
    return String.valueOf(retVal);
}
Also used : Uniform(org.ojalgo.random.Uniform)

Aggregations

Uniform (org.ojalgo.random.Uniform)14 Test (org.junit.jupiter.api.Test)8 NumberContext (org.ojalgo.type.context.NumberContext)4 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Tag (org.junit.jupiter.api.Tag)1 RecoverableCondition (org.ojalgo.RecoverableCondition)1 BasicMatrix (org.ojalgo.matrix.BasicMatrix)1 PrimitiveMatrix (org.ojalgo.matrix.PrimitiveMatrix)1 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)1 SolverTask (org.ojalgo.matrix.task.SolverTask)1 ComplexNumber (org.ojalgo.scalar.ComplexNumber)1