本文整理汇总了Java中org.ojalgo.TestUtils.assertEquals方法的典型用法代码示例。如果您正苦于以下问题:Java TestUtils.assertEquals方法的具体用法?Java TestUtils.assertEquals怎么用?Java TestUtils.assertEquals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ojalgo.TestUtils
的用法示例。
在下文中一共展示了TestUtils.assertEquals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMPSafiro
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
* Defines a problem of 28 rows and 32 columns. Seems to be the same model as afiro at netlib. Netlib also
* provides the solution.
* <a href="http://www-new.mcs.anl.gov/otc/Guide/TestProblems/LPtest/netlib/afiro.html">[email protected]</a>
* OK! 2010-04-19 lp_solve => -464.75314286
*/
public void testMPSafiro() {
final File tmpFile = new File(PATH + "afiro.mps");
final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();
TestUtils.assertTrue(tmpModel.validate());
final BigDecimal tmpExpVal = new BigDecimal("-.46475314286e+3");
final double tmpActVal = tmpModel.minimise().getValue();
TestUtils.assertEquals(tmpExpVal.doubleValue(), tmpActVal, PRECISION);
if (!tmpModel.validate(PRECISION)) {
TestUtils.fail(SOLUTION_NOT_VALID);
}
}
示例2: testStratCombPortfolioMixer
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testStratCombPortfolioMixer() {
final FinancePortfolio tmpTarget = new SimplePortfolio(THIRD, THIRD, THIRD).normalise();
final FinancePortfolio tmpStrat1 = new SimplePortfolio(HALF, HALF, ZERO);
final FinancePortfolio tmpStrat2 = new SimplePortfolio(HALF, ZERO, HALF);
final FinancePortfolio tmpStrat3 = new SimplePortfolio(ZERO, HALF, HALF);
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);
}
示例3: doCompare
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
void doCompare(final InverterTask<Double> fixed, final int dimension) {
try {
final MatrixStore<Double> tmpMatrix = this.makeSPD(dimension);
final MatrixStore<Double> tmpExpInv = fixed.invert(tmpMatrix);
final List<MatrixDecomposition<Double>> tmpList = MatrixDecompositionTests.getAllPrimitive();
for (final MatrixDecomposition<Double> tmpDecomp : tmpList) {
if (tmpDecomp instanceof InverterTask) {
@SuppressWarnings("unchecked")
final InverterTask<Double> tmpTask = (InverterTask<Double>) tmpDecomp;
final MatrixStore<Double> tmpActInv = tmpTask.invert(tmpMatrix);
TestUtils.assertEquals(tmpDecomp.getClass().getName(), tmpExpInv, tmpActInv);
}
}
} catch (final RecoverableCondition exception) {
TestUtils.fail(exception.getMessage());
}
}
示例4: testData
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
* @see org.ojalgo.matrix.BasicMatrixTest#testData()
*/
@Override
public void testData() {
final BasicMatrix tmpA = SimpleCholeskyCase.getOriginal();
final BasicMatrix tmpL = SimpleCholeskyCase.getFactorL();
final BasicMatrix tmpR = SimpleCholeskyCase.getFactorR();
myExpMtrx = tmpL;
myActMtrx = tmpR.transpose();
TestUtils.assertEquals(myExpMtrx, myActMtrx, EVALUATION);
myExpMtrx = tmpA;
myActMtrx = tmpL.multiply(tmpR);
TestUtils.assertEquals(myExpMtrx, myActMtrx, EVALUATION);
}
示例5: _testCoshAndBackAgain
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void _testCoshAndBackAgain() {
final double[] tmpArguments = new double[] { PrimitiveMath.NEG, PrimitiveMath.ZERO, PrimitiveMath.ONE };
for (int s = 0; s < tmpArguments.length; s++) {
for (int i = 0; i < tmpArguments.length; i++) {
for (int j = 0; j < tmpArguments.length; j++) {
for (int k = 0; k < tmpArguments.length; k++) {
final Quaternion tmpOriginal = Quaternion.of(tmpArguments[s], tmpArguments[i], tmpArguments[j], tmpArguments[k]);
final Quaternion tmpOp = QuaternionFunction.COSH.invoke(tmpOriginal);
final Quaternion tmpInv = QuaternionFunction.ACOSH.invoke(tmpOriginal);
final Quaternion tmpInvOp = QuaternionFunction.ACOSH.invoke(tmpOp);
final Quaternion tmpOpInv = QuaternionFunction.COSH.invoke(tmpInv);
TestUtils.assertEquals(tmpOriginal, tmpInvOp);
TestUtils.assertEquals(tmpOriginal, tmpOpInv);
}
}
}
}
}
示例6: _testCosAndBackAgain
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void _testCosAndBackAgain() {
final double[] tmpArguments = new double[] { PrimitiveMath.NEG, PrimitiveMath.ZERO, PrimitiveMath.ONE };
for (int s = 0; s < tmpArguments.length; s++) {
for (int i = 0; i < tmpArguments.length; i++) {
for (int j = 0; j < tmpArguments.length; j++) {
for (int k = 0; k < tmpArguments.length; k++) {
final Quaternion tmpOriginal = Quaternion.of(tmpArguments[s], tmpArguments[i], tmpArguments[j], tmpArguments[k]);
final Quaternion tmpOp = QuaternionFunction.COS.invoke(tmpOriginal);
final Quaternion tmpInv = QuaternionFunction.ACOS.invoke(tmpOriginal);
final Quaternion tmpInvOp = QuaternionFunction.ACOS.invoke(tmpOp);
final Quaternion tmpOpInv = QuaternionFunction.COS.invoke(tmpInv);
TestUtils.assertEquals(tmpOriginal, tmpInvOp);
TestUtils.assertEquals(tmpOriginal, tmpOpInv);
}
}
}
}
}
示例7: testVarianceOfInvestorViewPortfolios
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testVarianceOfInvestorViewPortfolios() {
final BasicMatrix tmpViews = BlackLittermanTest.getInvestorPortfoliosMatrix();
final BasicMatrix tmpCovar = BlackLittermanTest.getCovariances();
final BasicMatrix tmpExp = BlackLittermanTest.getVarianceOfInvestorViewPortfolios();
final BasicMatrix tmpAct = tmpViews.multiply(tmpCovar).multiply(tmpViews.transpose());
for (int i = 0; i < tmpExp.countRows(); i++) {
final int row = i;
final int row1 = i;
final int col = i;
TestUtils.assertEquals(TypeUtils.toBigDecimal(tmpExp.get(row, 0)), TypeUtils.toBigDecimal(tmpAct.get(row1, col)), EVAL_CNTXT);
}
}
示例8: testStratCombPortfolioMixerRandom
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
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);
}
示例9: testP20160608
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
/**
* <a href="https://github.com/optimatika/ojAlgo/issues/23">GitHub Issue 23</a> The problem was that since
* the model allows shorting the pure profit maximisation is unbounded (initial LP). The algorithm did not
* handle the case where "target" could be >= the max possible when shorting not allowed (bounded LP).
*/
public void testP20160608() {
final BasicMatrix.Factory<PrimitiveMatrix> matrixFactory = PrimitiveMatrix.FACTORY;
final PrimitiveMatrix cov = matrixFactory.rows(new double[][] { { 0.01, 0.0018, 0.0011 }, { 0.0018, 0.0109, 0.0026 }, { 0.0011, 0.0026, 0.0199 } });
final PrimitiveMatrix ret = matrixFactory.columns(new double[] { 0.0427, 0.0015, 0.0285 });
final MarketEquilibrium marketEquilibrium = new MarketEquilibrium(cov);
final MarkowitzModel markowitz = new MarkowitzModel(marketEquilibrium, ret);
markowitz.setShortingAllowed(true);
markowitz.setTargetReturn(BigDecimal.valueOf(0.0427));
List<BigDecimal> tmpWeights = markowitz.getWeights();
TestUtils.assertTrue(markowitz.optimiser().getState().isFeasible());
final NumberContext tmpTestPrecision = StandardType.PERCENT.newPrecision(4);
// Solution reachable without shorting, but since it is allowed the optimal solution is different
TestUtils.assertEquals(0.82745, tmpWeights.get(0).doubleValue(), tmpTestPrecision); // 0.82745
TestUtils.assertEquals(-0.09075, tmpWeights.get(1).doubleValue(), tmpTestPrecision); // -0.09075
TestUtils.assertEquals(0.26329, tmpWeights.get(2).doubleValue(), tmpTestPrecision); // 0.26329
TestUtils.assertEquals(0.0427, markowitz.getMeanReturn(), tmpTestPrecision);
TestUtils.assertEquals(0.0084, markowitz.getReturnVariance(), tmpTestPrecision);
// Also verify that it's posible to reach 10% return by shorting
markowitz.setTargetReturn(BigDecimal.valueOf(0.1));
TestUtils.assertEquals(0.1, markowitz.getMeanReturn(), tmpTestPrecision);
TestUtils.assertTrue(markowitz.optimiser().getState().isFeasible());
// Min risk portfolio, very high risk aversion means minimum risk.
markowitz.setTargetReturn(null);
markowitz.setRiskAversion(new BigDecimal(1000000));
tmpWeights = markowitz.getWeights();
TestUtils.assertTrue(markowitz.optimiser().getState().isFeasible());
TestUtils.assertEquals(0.4411, tmpWeights.get(0).doubleValue(), tmpTestPrecision); // 0.4411
TestUtils.assertEquals(0.3656, tmpWeights.get(1).doubleValue(), tmpTestPrecision); // 0.3656
TestUtils.assertEquals(0.1933, tmpWeights.get(2).doubleValue(), tmpTestPrecision); // 0.1933
}
示例10: testGetNumberOfDimensions
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testGetNumberOfDimensions() {
TestUtils.assertEquals(1, STRUCTURE_1D.length);
TestUtils.assertEquals(2, STRUCTURE_2D.length);
TestUtils.assertEquals(3, STRUCTURE_3D.length);
TestUtils.assertEquals(4, STRUCTURE_4D.length);
}
示例11: testDailyComparison
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testDailyComparison() {
final String tmpYahooSymbol = "AAPL";
final String tmpGoogleSymbol = "NASDAQ:AAPL";
final YahooSymbol tmpYahooSource = new YahooSymbol(tmpYahooSymbol, CalendarDateUnit.DAY);
final CalendarDateSeries<Double> tmpYahooPrices = tmpYahooSource.getPriceSeries();
final GoogleSymbol tmpGoogleSource = new GoogleSymbol(tmpGoogleSymbol, CalendarDateUnit.DAY);
final CalendarDateSeries<Double> tmpGooglePrices = tmpGoogleSource.getPriceSeries();
CoordinationSet<Double> tmpCoordinator = new CoordinationSet<>();
tmpCoordinator.put(tmpYahooPrices);
tmpCoordinator.put(tmpGooglePrices);
tmpCoordinator.complete();
tmpCoordinator = tmpCoordinator.prune();
final CalendarDateSeries<Double> tmpPrunedYahoo = tmpCoordinator.get(tmpYahooSymbol);
final CalendarDateSeries<Double> tmpPrunedGoogle = tmpCoordinator.get(tmpGoogleSymbol);
TestUtils.assertEquals("count", tmpPrunedYahoo.size(), tmpPrunedGoogle.size());
TestUtils.assertEquals("Last Value", tmpPrunedYahoo.lastValue(), tmpPrunedGoogle.lastValue(), NumberContext.getGeneral(8, 14));
// Doesn't work. Goggle and Yahoo seemsto have different data
// JUnitUtils.assertEquals("First Value", tmpPrunedYahoo.firstValue(), tmpPrunedGoogle.firstValue(), PrimitiveMath.IS_ZERO);
// for (final CalendarDate tmpKey : tmpCoordinator.getAllContainedKeys()) {
// final double tmpYahooValue = tmpPrunedYahoo.get(tmpKey);
// final double tmpGoogleValue = tmpPrunedGoogle.get(tmpKey);
// if (tmpYahooValue != tmpGoogleValue) {
// BasicLogger.logDebug("Date={} Yahoo={} Google={}", tmpKey, tmpYahooValue, tmpGoogleValue);
// }
// }
}
示例12: doTestCleaning
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
private static void doTestCleaning(final double[][] original) {
final NumberContext tmpEvalCntx = NumberContext.getGeneral(6, 12);
final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(original);
final SingularValue<Double> tmpSVD = SingularValue.make(tmpOriginal);
tmpSVD.decompose(tmpOriginal);
final double tmpRefCond = tmpSVD.getCondition();
final int tmpRefRank = tmpSVD.getRank();
final double tmpRefNorm = tmpSVD.getFrobeniusNorm();
final PrimitiveMatrix tmpCorrelations = FinanceUtils.toCorrelations(tmpOriginal, true);
final PrimitiveMatrix tmpVolatilities = FinanceUtils.toVolatilities(tmpOriginal, true);
final PrimitiveMatrix tmpCovariances = FinanceUtils.toCovariances(tmpVolatilities, tmpCorrelations);
tmpSVD.decompose(PrimitiveDenseStore.FACTORY.copy(tmpCovariances));
final double tmpNewCond = tmpSVD.getCondition();
final int tmpNewRank = tmpSVD.getRank();
final double tmpNewNorm = tmpSVD.getFrobeniusNorm();
TestUtils.assertTrue("Improved the condition", tmpNewCond <= tmpRefCond);
TestUtils.assertTrue("Improved the rank", tmpNewRank >= tmpRefRank);
TestUtils.assertEquals("Full rank", original.length, tmpNewRank);
TestUtils.assertEquals("Roughly the same frob norm", tmpRefNorm, tmpNewNorm, tmpEvalCntx);
if (DEBUG) {
BasicLogger.debug("Original", tmpOriginal);
BasicLogger.debug("Cleaned", tmpCovariances);
BasicLogger.debug("Difference", tmpOriginal.subtract(PrimitiveDenseStore.FACTORY.copy(tmpCovariances)), tmpEvalCntx);
}
}
示例13: testInverseOfRandomCase
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testInverseOfRandomCase() {
final NumberContext tmpEqualsNumberContext = new NumberContext(7, 10);
final int tmpDim = 99;
final PhysicalStore<Double> tmpRandom = PrimitiveDenseStore.FACTORY.copy(MatrixUtils.makeRandomComplexStore(tmpDim, tmpDim));
final PhysicalStore<Double> tmpIdentity = PrimitiveDenseStore.FACTORY.makeEye(tmpDim, tmpDim);
final MatrixDecomposition.Solver<Double>[] tmpAllDecomps = TestSolveAndInvert.getAllSquare();
final LU<Double> tmpRefDecomps = new RawLU();
tmpRefDecomps.decompose(tmpRandom);
final MatrixStore<Double> tmpExpected = tmpRefDecomps.getInverse();
for (final MatrixDecomposition.Solver<Double> tmpDecomp : tmpAllDecomps) {
final String tmpName = tmpDecomp.getClass().getName();
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug(tmpName);
}
tmpDecomp.decompose(tmpRandom);
final MatrixStore<Double> tmpActual = tmpDecomp.getInverse();
TestUtils.assertEquals(tmpName, tmpExpected, tmpActual, tmpEqualsNumberContext);
TestUtils.assertEquals(tmpName, tmpIdentity, tmpActual.multiply(tmpRandom), tmpEqualsNumberContext);
TestUtils.assertEquals(tmpName, tmpIdentity, tmpRandom.multiply(tmpActual), tmpEqualsNumberContext);
}
}
示例14: testMath272
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
public void testMath272() {
final LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 2, 2, 1 }, 0);
final Collection<LinearConstraint> constraints = new ArrayList<>();
constraints.add(new LinearConstraint(new double[] { 1, 1, 0 }, Relationship.GEQ, 1));
constraints.add(new LinearConstraint(new double[] { 1, 0, 1 }, Relationship.GEQ, 1));
constraints.add(new LinearConstraint(new double[] { 0, 1, 0 }, Relationship.GEQ, 1));
final SimplexSolver solver = new SimplexSolver();
final PointValuePair solution = solver.optimize(f, constraints, GoalType.MINIMIZE, true);
TestUtils.assertEquals(0.0, solution.getPoint()[0], .0000001);
TestUtils.assertEquals(1.0, solution.getPoint()[1], .0000001);
TestUtils.assertEquals(1.0, solution.getPoint()[2], .0000001);
TestUtils.assertEquals(3.0, solution.getValue(), .0000001);
}
示例15: testProblem
import org.ojalgo.TestUtils; //导入方法依赖的package包/类
@Override
public void testProblem() {
final BasicMatrix tmpMatrix = P20061119Case.getProblematic();
final Eigenvalue<Double> tmpEigenvalue = Eigenvalue.PRIMITIVE.make();
final PhysicalStore<Double> tmpPrimitiveStore = PrimitiveDenseStore.FACTORY.copy(tmpMatrix);
tmpEigenvalue.decompose(tmpPrimitiveStore);
TestUtils.assertEquals(tmpPrimitiveStore, tmpEigenvalue, EVALUATION);
}