Search in sources :

Example 11 with Primitive64Array

use of org.ojalgo.array.Primitive64Array in project ojAlgo by optimatika.

the class Process1D method getValues.

public Primitive64Array getValues() {
    final int tmpLength = myProcesses.length;
    final Primitive64Array retVal = Primitive64Array.make(tmpLength);
    for (int p = 0; p < tmpLength; p++) {
        retVal.set(p, myProcesses[p].getValue());
    }
    return retVal;
}
Also used : Primitive64Array(org.ojalgo.array.Primitive64Array)

Example 12 with Primitive64Array

use of org.ojalgo.array.Primitive64Array in project ojAlgo by optimatika.

the class PrimitiveDenseStore method applyCholesky.

public void applyCholesky(final int iterationPoint, final BasicArray<Double> multipliers) {
    final double[] tmpData = data;
    final double[] tmpColumn = ((Primitive64Array) multipliers).data;
    if ((myColDim - iterationPoint - 1) > ApplyCholesky.THRESHOLD) {
        final DivideAndConquer tmpConquerer = new DivideAndConquer() {

            @Override
            protected void conquer(final int first, final int limit) {
                ApplyCholesky.invoke(tmpData, myRowDim, first, limit, tmpColumn);
            }
        };
        tmpConquerer.invoke(iterationPoint + 1, myColDim, ApplyCholesky.THRESHOLD);
    } else {
        ApplyCholesky.invoke(tmpData, myRowDim, iterationPoint + 1, myColDim, tmpColumn);
    }
}
Also used : DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer) Primitive64Array(org.ojalgo.array.Primitive64Array)

Example 13 with Primitive64Array

use of org.ojalgo.array.Primitive64Array in project ojAlgo by optimatika.

the class PrimitiveSeries method sample.

public PrimitiveSeries sample(final int interval) {
    if (interval <= 1) {
        throw new IllegalArgumentException();
    } else {
        final int tmpSampleSize = this.size() / interval;
        final int tmpLastIndex = this.size() - 1;
        final Primitive64Array tmpValues = Primitive64Array.make(tmpSampleSize);
        for (int i = 0; i < tmpSampleSize; i++) {
            tmpValues.set(i, tmpLastIndex - (i * interval));
        }
        return PrimitiveSeries.wrap(this);
    }
}
Also used : Primitive64Array(org.ojalgo.array.Primitive64Array)

Example 14 with Primitive64Array

use of org.ojalgo.array.Primitive64Array in project ojAlgo by optimatika.

the class RandomNumberTest method testGeometricMeanAndStandardDeviation.

@Test
@Tag("unstable")
public void testGeometricMeanAndStandardDeviation() {
    final int tmpSize = 1000;
    final double tmpFactoryExpected = 1.05;
    final double tmpFactoryStdDev = PrimitiveFunction.ABS.invoke(new Normal(0.0, (tmpFactoryExpected - ONE)).doubleValue());
    final Normal tmpFactoryDistr = new Normal(tmpFactoryExpected, tmpFactoryStdDev);
    TestUtils.assertEquals("Factory Expected", tmpFactoryExpected, tmpFactoryDistr.getExpected(), 1E-14 / PrimitiveMath.THREE);
    TestUtils.assertEquals("Factory Std Dev", tmpFactoryStdDev, tmpFactoryDistr.getStandardDeviation(), 1E-14 / PrimitiveMath.THREE);
    final Primitive64Array tmpRawValues = Primitive64Array.make(tmpSize);
    final Primitive64Array tmpLogValues = Primitive64Array.make(tmpSize);
    for (int i = 0; i < tmpSize; i++) {
        tmpRawValues.data[i] = tmpFactoryDistr.doubleValue();
        tmpLogValues.data[i] = PrimitiveFunction.LOG.invoke(tmpRawValues.data[i]);
    }
    final SampleSet tmpLogValuesSet = SampleSet.wrap(tmpLogValues);
    final LogNormal tmpLogDistribut = new LogNormal(tmpLogValuesSet.getMean(), tmpLogValuesSet.getStandardDeviation());
    final double tmpGeometricMean = tmpLogDistribut.getGeometricMean();
    final double tmpGeometricStandardDeviation = tmpLogDistribut.getGeometricStandardDeviation();
    double tmpRawProduct = ONE;
    for (int i = 0; i < tmpSize; i++) {
        tmpRawProduct *= tmpRawValues.data[i];
    }
    TestUtils.assertEquals(tmpGeometricMean, PrimitiveFunction.POW.invoke(tmpRawProduct, ONE / tmpSize), 1E-14 / PrimitiveMath.THREE);
    double tmpLogSum = ZERO;
    for (int i = 0; i < tmpSize; i++) {
        tmpLogSum += tmpLogValues.data[i];
    }
    TestUtils.assertEquals(tmpGeometricMean, PrimitiveFunction.EXP.invoke(tmpLogSum / tmpSize), 1E-14 / PrimitiveMath.THREE);
    final double tmpLogGeoMean = PrimitiveFunction.LOG.invoke(tmpGeometricMean);
    double tmpVal;
    double tmpSumSqrDiff = ZERO;
    for (int i = 0; i < tmpSize; i++) {
        tmpVal = tmpLogValues.data[i] - tmpLogGeoMean;
        tmpSumSqrDiff += (tmpVal * tmpVal);
    }
    TestUtils.assertEquals(tmpGeometricStandardDeviation / tmpGeometricStandardDeviation, PrimitiveFunction.EXP.invoke(PrimitiveFunction.SQRT.invoke(tmpSumSqrDiff / tmpSize)) / tmpGeometricStandardDeviation, 0.00005);
// Check that the geometric standard deviation is within ±0.005% of what it should be.
}
Also used : Primitive64Array(org.ojalgo.array.Primitive64Array) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 15 with Primitive64Array

use of org.ojalgo.array.Primitive64Array in project ojAlgo by optimatika.

the class SampleSetTest method testQuartileSize2.

@Test
public void testQuartileSize2() {
    final Primitive64Array tmpSamples = Primitive64Array.wrap(new double[] { 100.0, 200.0 });
    final SampleSet tmpSampleSet = SampleSet.wrap(tmpSamples);
    TestUtils.assertEquals(100.0, tmpSampleSet.getQuartile1());
    TestUtils.assertEquals(150.0, tmpSampleSet.getQuartile2());
    TestUtils.assertEquals(200.0, tmpSampleSet.getQuartile3());
}
Also used : Primitive64Array(org.ojalgo.array.Primitive64Array) Test(org.junit.jupiter.api.Test)

Aggregations

Primitive64Array (org.ojalgo.array.Primitive64Array)20 Test (org.junit.jupiter.api.Test)13 DivideAndConquer (org.ojalgo.concurrent.DivideAndConquer)3 Tag (org.junit.jupiter.api.Tag)2 BigDecimal (java.math.BigDecimal)1 SimplePortfolio (org.ojalgo.finance.portfolio.SimplePortfolio)1 Result (org.ojalgo.optimisation.Optimisation.Result)1 LogNormal (org.ojalgo.random.LogNormal)1 Normal (org.ojalgo.random.Normal)1 SampleSet (org.ojalgo.random.SampleSet)1 NumberContext (org.ojalgo.type.context.NumberContext)1