├── .gitignore ├── LICENSE.md ├── NEWS.md ├── NOTICE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── .gitignore ├── main ├── docs │ ├── .Rhistory │ ├── Doxyfile │ ├── Doxyfile.bak │ ├── bib │ │ ├── callc.bib │ │ ├── fin.bib │ │ ├── ift.bib │ │ ├── math.bib │ │ ├── optim.bib │ │ ├── prob.bib │ │ ├── rail.bib │ │ ├── random.bib │ │ ├── simul.bib │ │ ├── stat.bib │ │ └── vrt.bib │ ├── examples │ │ ├── charts │ │ │ ├── BoxTest.java │ │ │ ├── ChartTest1.java │ │ │ ├── ChartTest2.java │ │ │ ├── ContDistPlot.java │ │ │ ├── DistIntTest.java │ │ │ ├── EmpiricalChartTest.java │ │ │ ├── HistogramChartTest.java │ │ │ ├── HistogramTest1.java │ │ │ └── NormalChart.java │ │ ├── ift6561examples │ │ │ ├── AsianOption.java │ │ │ ├── AsianOptionGBMCV.java │ │ │ ├── CallCenter.dat │ │ │ ├── CallCenter.java │ │ │ ├── CallCenter.res │ │ │ ├── CallCenterCRN.java │ │ │ ├── CallableBond.java │ │ │ ├── CallableBondCMC.java │ │ │ ├── CallableBondCV.java │ │ │ ├── Collision.java │ │ │ ├── CollisionPoisson.java │ │ │ ├── DigitalShift.java │ │ │ ├── FDensity.java │ │ │ ├── Hedge.java │ │ │ ├── ISChart1.java │ │ │ ├── Lcgmodpow2.java │ │ │ ├── MathematicaSWB.java │ │ │ ├── OldAsianGBM.java │ │ │ ├── OldAsianRQMC.java │ │ │ ├── OldTestAsianOptionGBM0Hist.java │ │ │ ├── OrnsteinUhlenbeckWithIntegratedProcess.java │ │ │ ├── ProductBarrier.java │ │ │ ├── ProductBarrierIs.java │ │ │ ├── ProductExpCosRQMC.java │ │ │ ├── RuinIS.java │ │ │ ├── San13CMC.java │ │ │ ├── San13CMCCV.java │ │ │ ├── San13CMCDist.java │ │ │ ├── San13CMCgrad1.java │ │ │ ├── San13CMCgrad2.java │ │ │ ├── San13Dist.java │ │ │ ├── San13DistCRN.java │ │ │ ├── San13Prob.java │ │ │ ├── San13connect.java │ │ │ ├── San13connectCMC1.java │ │ │ ├── Sum2BarrierIS.java │ │ │ ├── TandemQueue.java │ │ │ ├── TandemQueue0.java │ │ │ ├── TestAsianOptionGBM0HistRQMC.java │ │ │ ├── TestAsianOptionGBM2QMC.java │ │ │ ├── TestAsianOptionGBMCV.java │ │ │ ├── TestAsianVGRQMC.java │ │ │ ├── TestAsianVGRQMC2017.java │ │ │ ├── TestOptionVGIS.java │ │ │ ├── TestOptionVGIS2017.java │ │ │ └── san13a.dat │ │ ├── latnetbuilder │ │ │ ├── Experiment.java │ │ │ ├── RunExperiments.java │ │ │ └── SobolTestFunc.java │ │ ├── latnetbuilder_results │ │ │ ├── input.txt │ │ │ ├── output.txt │ │ │ └── outputMachine.txt │ │ ├── markovchainrqmc │ │ │ ├── Brownian.java │ │ │ ├── BrownianTest.java │ │ │ └── BrownianTest.txt │ │ ├── probdistmulti │ │ │ └── norta │ │ │ │ ├── ExampleNortaInitDisc.java │ │ │ │ └── ExampleNortaInitDisc.txt │ │ ├── randvar │ │ │ ├── RandvarExample1.java │ │ │ └── normaltest.java │ │ └── tutorial │ │ │ ├── Asian.java │ │ │ ├── Asian.txt │ │ │ ├── AsianGBM.java │ │ │ ├── AsianGBM.res │ │ │ ├── AsianGBMQMC.java │ │ │ ├── AsianGBMQMC.res │ │ │ ├── AsianNew.java │ │ │ ├── AsianQMC.java │ │ │ ├── AsianQMC.txt │ │ │ ├── BankEv.java │ │ │ ├── BankEv.res │ │ │ ├── BankEv.txt │ │ │ ├── CallCenter.dat │ │ │ ├── CallCenter.java │ │ │ ├── CallCenter.res │ │ │ ├── CallCenter.txt │ │ │ ├── CallEv.dat │ │ │ ├── CallEv.java │ │ │ ├── CallEv.txt │ │ │ ├── Collision.java │ │ │ ├── Collision.res │ │ │ ├── Collision.txt │ │ │ ├── CompareOutputs.java │ │ │ ├── Inventory.java │ │ │ ├── Inventory.res │ │ │ ├── Inventory.txt │ │ │ ├── InventoryCRN.java │ │ │ ├── InventoryCRN.res │ │ │ ├── InventoryCRN.txt │ │ │ ├── NewTestAsianRQMC.java │ │ │ ├── Nonuniform.java │ │ │ ├── Nonuniform.res │ │ │ ├── Nonuniform.txt │ │ │ ├── NonuniformHist.tex │ │ │ ├── PreyPred.java │ │ │ ├── PreyPred.res │ │ │ ├── PreyPred.txt │ │ │ ├── QueueEv.java │ │ │ ├── QueueEv.res │ │ │ ├── QueueEv.txt │ │ │ ├── QueueLindley.java │ │ │ ├── QueueLindley.res │ │ │ ├── QueueLindley.txt │ │ │ ├── QueueObs.java │ │ │ ├── QueueObs.res │ │ │ ├── QueueObs.txt │ │ │ ├── RunClass.java │ │ │ ├── San13Dist.java │ │ │ ├── Snippet.java │ │ │ ├── Visits.txt │ │ │ ├── san13a.dat │ │ │ ├── tutorial.dox │ │ │ └── tutorial.old2016 │ ├── images │ │ ├── charts_exam_BoxTest.png │ │ ├── charts_overview_01.svg │ │ ├── charts_overview_02.svg │ │ ├── charts_overview_03.svg │ │ ├── charts_overview_04.svg │ │ ├── charts_overview_05.svg │ │ ├── charts_overview_06.svg │ │ ├── charts_overview_07.svg │ │ ├── examples_examples_01.svg │ │ ├── examples_examples_02.svg │ │ ├── rng_randomstream_01.svg │ │ └── simprocs_simprocess_01.svg │ ├── mathjax_config.js │ ├── ssj.bib │ └── ssj.css └── java │ └── umontreal │ └── ssj │ ├── charts │ ├── Axis.java │ ├── BoxChart.java │ ├── BoxSeriesCollection.java │ ├── CategoryChart.java │ ├── ContinuousDistChart.java │ ├── CustomHistogramDataset.java │ ├── DiscreteDistIntChart.java │ ├── EmpiricalChart.java │ ├── EmpiricalRenderer.java │ ├── EmpiricalSeriesCollection.java │ ├── HistogramChart.java │ ├── HistogramSeriesCollection.java │ ├── MultipleDatasetChart.java │ ├── PPPlot.java │ ├── PlotFormat.java │ ├── QQPlot.java │ ├── SSJCategorySeriesCollection.java │ ├── SSJXYSeriesCollection.java │ ├── ScatterChart.java │ ├── XYChart.java │ ├── XYLineChart.java │ ├── XYListSeriesCollection.java │ ├── YListChart.java │ ├── YListSeriesCollection.java │ └── overview.dox │ ├── discrepancy │ ├── BigDiscShiftBaker1.java │ ├── BigDiscShiftBaker1Lattice.java │ ├── BigDiscrepancy.java │ ├── DiscL2Hickernell.java │ ├── DiscL2Star.java │ ├── DiscL2Symmetric.java │ ├── DiscL2Unanchored.java │ ├── DiscShift1.java │ ├── DiscShift1Lattice.java │ ├── DiscShift2.java │ ├── DiscShift2Lattice.java │ ├── DiscShiftBaker1.java │ ├── DiscShiftBaker1Lattice.java │ ├── Discrepancy.java │ ├── DiscrepancyContainer.java │ ├── Palpha.java │ ├── Searcher.java │ ├── SearcherCBC.java │ ├── SearcherKorobov.java │ └── overview.dox │ ├── functionfit │ ├── BSpline.java │ ├── LeastSquares.java │ ├── PolInterp.java │ ├── SmoothingCubicSpline.java │ └── overview.dox │ ├── functions │ ├── AverageMathFunction.java │ ├── IdentityMathFunction.java │ ├── MathFunction.java │ ├── MathFunctionUtil.java │ ├── MathFunctionWithDerivative.java │ ├── MathFunctionWithFirstDerivative.java │ ├── MathFunctionWithIntegral.java │ ├── MultiFunction.java │ ├── PiecewiseConstantFunction.java │ ├── Polynomial.java │ ├── PowerMathFunction.java │ ├── ShiftedMathFunction.java │ ├── SqrtMathFunction.java │ ├── SquareMathFunction.java │ └── overview.dox │ ├── gof │ ├── FBar.java │ ├── FDist.java │ ├── GofFormat.java │ ├── GofStat.java │ ├── KernelDensity.java │ └── overview.dox │ ├── hups │ ├── AntitheticPointSet.java │ ├── BakerTransformedPointSet.java │ ├── CachedPointSet.java │ ├── ContainerPointSet.java │ ├── CycleBasedLFSR.java │ ├── CycleBasedPointSet.java │ ├── CycleBasedPointSetBase2.java │ ├── DigitalNet.java │ ├── DigitalNetBase2.java │ ├── DigitalNetBase2FromFile.java │ ├── DigitalNetFromFile.java │ ├── DigitalSequence.java │ ├── DigitalSequenceBase2.java │ ├── EmptyRandomization.java │ ├── F2wCycleBasedLFSR.java │ ├── F2wCycleBasedPolyLCG.java │ ├── F2wNetLFSR.java │ ├── F2wNetPolyLCG.java │ ├── F2wStructure.java │ ├── FaureSequence.java │ ├── HaltonSequence.java │ ├── HammersleyPointSet.java │ ├── IndependentPointsCached.java │ ├── KorobovLattice.java │ ├── KorobovLatticeSequence.java │ ├── LCGPointSet.java │ ├── LMScrambleShift.java │ ├── LatinHypercube.java │ ├── NestedUniformScrambling.java │ ├── NiedSequenceBase2.java │ ├── NiedXingSequenceBase2.java │ ├── PaddedPointSet.java │ ├── PointSet.java │ ├── PointSetIterator.java │ ├── PointSetRandomization.java │ ├── RQMCPointSet.java │ ├── RadicalInverse.java │ ├── RandShiftedMod1PointSet.java │ ├── RandomShift.java │ ├── RandomStart.java │ ├── Rank1Lattice.java │ ├── SMScrambleShift.java │ ├── SobolSequence.java │ ├── SortedAndCutPointSet.java │ ├── StratifiedUnitCube.java │ ├── StratifiedUnitCubeAnti.java │ ├── SubsetOfPointSet.java │ ├── dataLFSR │ │ ├── j1_k11.dat │ │ ├── j2_k17.dat │ │ └── j2_k19.dat │ ├── dataSer │ │ └── Nieder │ │ │ ├── NiedSequenceBase2.dat │ │ │ ├── NiedSequenceBase2.ser │ │ │ ├── NiedXingSequenceBase2Trans.dat │ │ │ └── NiedXingSequenceBase2Trans.ser │ └── overview.dox │ ├── latnetbuilder │ ├── DigitalNetSearch.java │ ├── OrdinaryLatticeSearch.java │ ├── PolynomialLatticeSearch.java │ ├── Search.java │ ├── overview.dox │ └── weights │ │ ├── GeometricWeights.java │ │ ├── OrderDependentWeights.java │ │ ├── PODWeights.java │ │ ├── ProductWeights.java │ │ ├── ProjectionDependentWeights.java │ │ ├── SingletonWeight.java │ │ ├── SingletonWeightComparable.java │ │ ├── Weights.java │ │ ├── WeightsComparable.java │ │ └── overview.dox │ ├── markovchainrqmc │ ├── ArrayOfComparableChains.java │ ├── ArrayOfDoubleChains.java │ ├── MarkovChain.java │ ├── MarkovChainComparable.java │ ├── MarkovChainDouble.java │ └── overview.dox │ ├── mcqmctools │ ├── MonteCarloExperiment.java │ ├── MonteCarloModel.java │ ├── MonteCarloModelCV.java │ ├── MonteCarloModelDensityKnown.java │ ├── MonteCarloModelDouble.java │ ├── MonteCarloModelDoubleArray.java │ ├── RQMCExperiment.java │ ├── RQMCExperimentSeries.java │ ├── anova │ │ ├── Anova.java │ │ ├── AnovaObserver.java │ │ ├── AnovaVarianceCollector.java │ │ ├── AnovaVarianceEstimator.java │ │ ├── BasicObservationCollector.java │ │ ├── CoordinateSet.java │ │ ├── CoordinateSetLong.java │ │ ├── Integrator.java │ │ ├── MeanVarExperiment.java │ │ ├── MonteCarloIntegrator.java │ │ ├── MonteCarloModelDoubleRQMC.java │ │ ├── MonteCarloModelRQMC.java │ │ ├── MonteCarloSampler.java │ │ ├── ObservationCollector.java │ │ ├── ObservationCollectorList.java │ │ ├── PartialVariance.java │ │ ├── PartialVarianceEstimator.java │ │ ├── QMCSampler.java │ │ ├── RQMCSampler.java │ │ ├── RandomIntegrator.java │ │ ├── RandomSampler.java │ │ ├── Replicator.java │ │ ├── Report.java │ │ ├── Sampler.java │ │ ├── SplitStream.java │ │ └── overview.dox │ └── overview.dox │ ├── overview.dox │ ├── probdist │ ├── AndersonDarlingDist.java │ ├── AndersonDarlingDistQuick.java │ ├── BernoulliDist.java │ ├── BetaDist.java │ ├── BetaSymmetricalDist.java │ ├── BinomialDist.java │ ├── CauchyDist.java │ ├── ChiDist.java │ ├── ChiSquareDist.java │ ├── ChiSquareDistQuick.java │ ├── ChiSquareNoncentralDist.java │ ├── ConstantDist.java │ ├── ConstantIntDist.java │ ├── ContinuousDistribution.java │ ├── CramerVonMisesDist.java │ ├── DiscreteDistribution.java │ ├── DiscreteDistributionInt.java │ ├── Distribution.java │ ├── DistributionFactory.java │ ├── EmpiricalDist.java │ ├── ErlangDist.java │ ├── ExponentialDist.java │ ├── ExponentialDistFromMean.java │ ├── ExtremeValueDist.java │ ├── FatigueLifeDist.java │ ├── FisherFDist.java │ ├── FoldedNormalDist.java │ ├── FrechetDist.java │ ├── GammaDist.java │ ├── GammaDistFromMoments.java │ ├── GeometricDist.java │ ├── GumbelDist.java │ ├── HalfNormalDist.java │ ├── HyperbolicSecantDist.java │ ├── HypergeometricDist.java │ ├── HypoExponentialDist.java │ ├── HypoExponentialDistEqual.java │ ├── HypoExponentialDistQuick.java │ ├── InverseDistFromDensity.java │ ├── InverseGammaDist.java │ ├── InverseGaussianDist.java │ ├── JohnsonSBDist.java │ ├── JohnsonSLDist.java │ ├── JohnsonSUDist.java │ ├── JohnsonSystem.java │ ├── KolmogorovSmirnovDist.java │ ├── KolmogorovSmirnovDistQuick.java │ ├── KolmogorovSmirnovPlusDist.java │ ├── LaplaceDist.java │ ├── LogarithmicDist.java │ ├── LogisticDist.java │ ├── LoglogisticDist.java │ ├── LognormalDist.java │ ├── LognormalDistFromMoments.java │ ├── NakagamiDist.java │ ├── NegativeBinomialDist.java │ ├── NormalDist.java │ ├── NormalDistQuick.java │ ├── NormalInverseGaussianDist.java │ ├── ParetoDist.java │ ├── PascalDist.java │ ├── Pearson5Dist.java │ ├── Pearson6Dist.java │ ├── PiecewiseLinearEmpiricalDist.java │ ├── PoissonDist.java │ ├── PowerDist.java │ ├── RayleighDist.java │ ├── StudentDist.java │ ├── StudentDistQuick.java │ ├── TriangularDist.java │ ├── TruncatedDist.java │ ├── UniformDist.java │ ├── UniformIntDist.java │ ├── WatsonGDist.java │ ├── WatsonUDist.java │ ├── WeibullDist.java │ └── overview.dox │ ├── probdistmulti │ ├── BiNormalDist.java │ ├── BiNormalDonnellyDist.java │ ├── BiNormalGenzDist.java │ ├── BiStudentDist.java │ ├── ContinuousDistribution2Dim.java │ ├── ContinuousDistributionMulti.java │ ├── DirichletDist.java │ ├── DiscreteDistributionIntMulti.java │ ├── MultiNormalDist.java │ ├── MultinomialDist.java │ ├── NegativeMultinomialDist.java │ ├── norta │ │ ├── NI1.java │ │ ├── NI2a.java │ │ ├── NI2b.java │ │ ├── NI3.java │ │ ├── NortaInitDisc.java │ │ └── overview.dox │ └── overview.dox │ ├── randvar │ ├── BernoulliGen.java │ ├── BetaGen.java │ ├── BetaRejectionLoglogisticGen.java │ ├── BetaStratifiedRejectionGen.java │ ├── BetaSymmetricalBestGen.java │ ├── BetaSymmetricalGen.java │ ├── BetaSymmetricalPolarGen.java │ ├── BinomialConvolutionGen.java │ ├── BinomialGen.java │ ├── CauchyGen.java │ ├── ChiGen.java │ ├── ChiRatioOfUniformsGen.java │ ├── ChiSquareGen.java │ ├── ChiSquareNoncentralGamGen.java │ ├── ChiSquareNoncentralGen.java │ ├── ChiSquareNoncentralPoisGen.java │ ├── ConstantGen.java │ ├── ErlangConvolutionGen.java │ ├── ErlangGen.java │ ├── ExponentialGen.java │ ├── ExponentialInverseFromDensityGen.java │ ├── ExtremeValueGen.java │ ├── FNoncentralGen.java │ ├── FatigueLifeGen.java │ ├── FisherFGen.java │ ├── FoldedNormalGen.java │ ├── FrechetGen.java │ ├── GammaAcceptanceRejectionGen.java │ ├── GammaGen.java │ ├── GammaRejectionLoglogisticGen.java │ ├── GeometricGen.java │ ├── GumbelGen.java │ ├── HalfNormalGen.java │ ├── HyperbolicSecantGen.java │ ├── HypergeometricGen.java │ ├── HypoExponentialGen.java │ ├── InverseFromDensityGen.java │ ├── InverseGammaGen.java │ ├── InverseGaussianGen.java │ ├── InverseGaussianMSHGen.java │ ├── JohnsonSBGen.java │ ├── JohnsonSLGen.java │ ├── JohnsonSUGen.java │ ├── JohnsonSystemG.java │ ├── KernelDensityGen.java │ ├── KernelDensityVarCorrectGen.java │ ├── LaplaceGen.java │ ├── LogarithmicGen.java │ ├── LogisticGen.java │ ├── LoglogisticGen.java │ ├── LognormalGen.java │ ├── LognormalSpecialGen.java │ ├── MixtureGen.java │ ├── NakagamiGen.java │ ├── NegativeBinomialGen.java │ ├── NormalACRGen.java │ ├── NormalBoxMullerGen.java │ ├── NormalGen.java │ ├── NormalInverseFromDensityGen.java │ ├── NormalInverseGaussianGen.java │ ├── NormalInverseGaussianIGGen.java │ ├── NormalKindermannRamageGen.java │ ├── NormalPolarGen.java │ ├── ParetoGen.java │ ├── PascalConvolutionGen.java │ ├── PascalGen.java │ ├── Pearson5Gen.java │ ├── Pearson6Gen.java │ ├── PoissonGen.java │ ├── PoissonTIACGen.java │ ├── PowerGen.java │ ├── RandUnuran.java │ ├── RandomVariateGen.java │ ├── RandomVariateGenInt.java │ ├── RandomVariateGenWithCache.java │ ├── RayleighGen.java │ ├── StudentGen.java │ ├── StudentNoncentralGen.java │ ├── StudentPolarGen.java │ ├── TriangularGen.java │ ├── UniformGen.java │ ├── UniformIntGen.java │ ├── WeibullGen.java │ └── overview.dox │ ├── randvarmulti │ ├── DirichletGen.java │ ├── IIDMultivariateGen.java │ ├── MultinormalCholeskyGen.java │ ├── MultinormalGen.java │ ├── MultinormalPCAGen.java │ ├── RandomMultivariateGen.java │ └── overview.dox │ ├── rng │ ├── AntitheticStream.java │ ├── BakerTransformedStream.java │ ├── BasicRandomStreamFactory.java │ ├── CloneableRandomStream.java │ ├── F2NL607.java │ ├── F2wPoly.java │ ├── LFSR113.java │ ├── LFSR258.java │ ├── MRG31k3p.java │ ├── MRG32k3a.java │ ├── MRG32k3aL.java │ ├── MT19937.java │ ├── RandMrg.java │ ├── RandRijndael.java │ ├── RandomPermutation.java │ ├── RandomStream.java │ ├── RandomStreamBase.java │ ├── RandomStreamFactory.java │ ├── RandomStreamInstantiationException.java │ ├── RandomStreamManager.java │ ├── RandomStreamWithCache.java │ ├── Rijndael_Algorithm.java │ ├── Rijndael_Properties.java │ ├── TruncatedRandomStream.java │ ├── WELL1024.java │ ├── WELL512.java │ ├── WELL607.java │ ├── WELL607base.java │ └── overview.dox │ ├── simevents │ ├── Accumulate.java │ ├── Continuous.java │ ├── ContinuousState.java │ ├── Event.java │ ├── LinkedListStat.java │ ├── ListWithStat.java │ ├── Sim.java │ ├── Simulator.java │ ├── eventlist │ │ ├── BinaryTree.java │ │ ├── DoublyLinked.java │ │ ├── EventList.java │ │ ├── Henriksen.java │ │ ├── RedblackTree.java │ │ ├── SplayTree.java │ │ └── overview.dox │ └── overview.dox │ ├── simexp │ ├── BatchMeansSim.java │ ├── RepSim.java │ ├── SimExp.java │ └── overview.dox │ ├── stat │ ├── FunctionOfMultipleMeansTally.java │ ├── HistogramChartToLatex.java │ ├── HistogramOnly.java │ ├── ObservationListener.java │ ├── PgfDataTable.java │ ├── ScaledHistogram.java │ ├── StatProbe.java │ ├── Tally.java │ ├── TallyHistogram.java │ ├── TallyStore.java │ ├── density │ │ ├── ConditionalDensityEstimator.java │ │ ├── DEDerivativeGaussian.java │ │ ├── DEHistogram.java │ │ ├── DEKernelDensity.java │ │ ├── DensityDerivativeEstimator.java │ │ ├── DensityEstimator.java │ │ ├── DensityEstimatorDoubleArray.java │ │ └── overview.dox │ ├── list │ │ ├── ArrayOfObservationListener.java │ │ ├── ListOfFunctionOfMultipleMeansTallies.java │ │ ├── ListOfStatProbes.java │ │ ├── ListOfTallies.java │ │ ├── ListOfTalliesWithCovariance.java │ │ ├── lincv │ │ │ ├── FunctionOfMultipleMeansTallyWithCV.java │ │ │ ├── ListOfTalliesWithCV.java │ │ │ └── overview.dox │ │ └── overview.dox │ ├── matrix │ │ ├── MatrixOfFunctionOfMultipleMeansTallies.java │ │ ├── MatrixOfObservationListener.java │ │ ├── MatrixOfStatProbes.java │ │ ├── MatrixOfTallies.java │ │ └── overview.dox │ └── overview.dox │ ├── stochprocess │ ├── BrownianMotion.java │ ├── BrownianMotionBridge.java │ ├── BrownianMotionPCA.java │ ├── BrownianMotionPCAEqualSteps.java │ ├── CIRProcess.java │ ├── CIRProcessEuler.java │ ├── GammaProcess.java │ ├── GammaProcessBridge.java │ ├── GammaProcessPCA.java │ ├── GammaProcessPCABridge.java │ ├── GammaProcessPCASymmetricalBridge.java │ ├── GammaProcessSymmetricalBridge.java │ ├── GeometricBrownianMotion.java │ ├── GeometricLevyProcess.java │ ├── GeometricNormalInverseGaussianProcess.java │ ├── GeometricVarianceGammaProcess.java │ ├── InverseGaussianProcess.java │ ├── InverseGaussianProcessBridge.java │ ├── InverseGaussianProcessMSH.java │ ├── InverseGaussianProcessPCA.java │ ├── MultivariateBrownianMotion.java │ ├── MultivariateBrownianMotionBridge.java │ ├── MultivariateBrownianMotionPCA.java │ ├── MultivariateBrownianMotionPCABigSigma.java │ ├── MultivariateGeometricBrownianMotion.java │ ├── MultivariateStochasticProcess.java │ ├── NormalInverseGaussianProcess.java │ ├── OrnsteinUhlenbeckProcess.java │ ├── OrnsteinUhlenbeckProcessEuler.java │ ├── OrnsteinUhlenbeckWithIntegratedProcess.java │ ├── StochasticProcess.java │ ├── VarianceGammaProcess.java │ ├── VarianceGammaProcessAlternate.java │ ├── VarianceGammaProcessDiff.java │ ├── VarianceGammaProcessDiffPCA.java │ ├── VarianceGammaProcessDiffPCABridge.java │ ├── VarianceGammaProcessDiffPCASymmetricalBridge.java │ └── overview.dox │ └── util │ ├── AbstractChrono.java │ ├── ArithmeticMod.java │ ├── BitMatrix.java │ ├── BitVector.java │ ├── Chrono.java │ ├── ChronoSingleThread.java │ ├── ChronoWall.java │ ├── ClassFinder.java │ ├── DMatrix.java │ ├── Introspection.java │ ├── JDBCManager.java │ ├── Misc.java │ ├── MultivariateFunction.java │ ├── NameConflictException.java │ ├── NativeUtils.java │ ├── Num.java │ ├── PrintfFormat.java │ ├── RatioFunction.java │ ├── RootFinder.java │ ├── Systeme.java │ ├── TableFormat.java │ ├── TextDataReader.java │ ├── TimeUnit.java │ ├── TransformingList.java │ ├── io │ ├── AbstractDataReader.java │ ├── AbstractDataWriter.java │ ├── BinaryDataReader.java │ ├── BinaryDataWriter.java │ ├── CachedDataWriter.java │ ├── DataField.java │ ├── DataReader.java │ ├── DataWriter.java │ ├── TextDataWriter.java │ └── overview.dox │ ├── overview.dox │ └── sort │ ├── BatchSort.java │ ├── BatchSortPow2.java │ ├── DoubleArrayComparator.java │ ├── HilbertCurveBatchSort.java │ ├── HilbertCurveMap.java │ ├── HilbertCurveSort.java │ ├── MultiDim01.java │ ├── MultiDimComparable.java │ ├── MultiDimComparator.java │ ├── MultiDimSort.java │ ├── MultiDimSort01.java │ ├── MultiDimSortComparable.java │ ├── OneDimSort.java │ ├── SplitSort.java │ └── overview.dox ├── randvar └── c │ └── RandUnuran.c ├── ssjutil └── c │ └── Chrono.c └── test └── java ├── ChronoTest.java ├── CompareOutputs.java ├── ExamplesTest.java ├── RunClass.java ├── UnuranTest.java └── umontreal └── ssj ├── hups └── DigitalNetBase2Test.java ├── latnetbuilder └── LatNetBuilderTest.java-hide └── randvar └── MixtureGenTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build 3 | /.nb-gradle 4 | .nb-gradle-properties 5 | hs_err* 6 | /bin 7 | .settings 8 | .project 9 | .classpath 10 | /out 11 | .html 12 | /target/ 13 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | This file is part of SSJ. 2 | 3 | Copyright (C) 2008-2021 The SSJ Authors, supervised by Pierre L'Ecuyer, Université de Montréal 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # SSJ release highlights 2 | --- 3 | 4 | 5 | ## SSJ 3.3.2 6 | 7 | Forthcoming. 8 | 9 | ## SSJ 3.3.1 10 | 11 | In this release, we have improved the documentation (mostly) for the hups package. We also made a few corrections and added a few methods in packages mcqmctools, stat, and hups. 12 | 13 | ## SSJ 3.3.0 14 | 15 | This release contains new packages, several new classes, an improved tutorial and improved documentation in general. 16 | 17 | - new packages: `mcqmctools`, `latnetbuilder`, `stat.density`, `discrepancy`. 18 | - several methods have been added in many places. 19 | - the main API page (introduction), the tutorial (with examples), and the documentation of several packages have been updated. 20 | 21 | ## SSJ 3.2.1 22 | 23 | This release contains bug fixes. 24 | 25 | - package `functionfit`: Fix bug when creating an approximate BSpline. 26 | - package `util`: bisection and brentDekker methods will now check the bounds of the interval first. 27 | - package `eventlist`: Removed free node stack and removed synchronization on the free node stack. This increases the performance when executing many simulations in multi-thread program. 28 | 29 | ## SSJ 3.2.0 30 | 31 | - Add new packages `markovchainrqmc` and `util.sort`. 32 | - Add new packages `stat.list.lincv` and `stat.matrix`. 33 | - Add new classes to package `stat` and `stat.list`. 34 | - Add new classes to package `hups`. 35 | - Add Rijndael's algorithm to package `rng`. 36 | - Add new classes to package `stochprocess`. 37 | 38 | ## SSJ 3.0.0-rc1 39 | 40 | This version of SSJ is not for production. 41 | 42 | We have just migrated the source code from a custom documentation system which generated Java files from LaTeX input files. Now the Java source code is readily editable. The documentation is in now Doxygen format, which supports mathematical formulas and BibTeX citations. 43 | 44 | Users of SSJ 2.6 who want to upgrade their code for SSJ 3 need to replace umontreal.iro.lecuyer with umontreal.ssj in the package imports. For example, 45 | 46 | import umontreal.iro.lecuyer.rng.MRG32k3a; // using SSJ 2 47 | 48 | becomes 49 | 50 | import umontreal.ssj.rng.MRG32k3a; // using SSJ 3 51 | 52 | 53 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | SSJ: Stochastic Simulation in Java 2 | 3 | The rights on some parts of SSJ are held by specific individuals or 4 | organizations, listed in the SPECIFIC ATTRIBUTIONS below. The rest of SSJ is 5 | subject to the following copyright: 6 | 7 | Copyright (C) 2008-2021 The SSJ Authors, supervised by Pierre L'Ecuyer, Université de Montréal 8 | 9 | SPECIFIC ATTRIBUTIONS 10 | 11 | The code from Rijndael_Properties.java and marked portions of the code from 12 | Rijndael_Algorithm.java are sujbect to the following copyright: 13 | 14 | Copyright (c) 1997, 1998 Systemics Ltd on behalf of the Cryptix Development Team. All rights reserved. 15 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Property file for SSJ 2 | 3 | ######################################################################## 4 | # Documentation 5 | ######################################################################## 6 | 7 | # Uncomment to build documentation with Doxygen 8 | buildDocs 9 | 10 | 11 | ######################################################################## 12 | # Cross-compilation 13 | ######################################################################## 14 | 15 | # Uncomment to enable cross-compilation or run gradle with option # "-PcrossCompile" 16 | #crossCompile 17 | 18 | 19 | ######################################################################## 20 | # Native Chrono support 21 | ######################################################################## 22 | 23 | # Uncomment to enable building the `GlobalCPUTimeChrono` JNI. 24 | #ssjutil.jni.build 25 | 26 | 27 | ######################################################################## 28 | # Native UNU.RAN support 29 | ######################################################################## 30 | 31 | # Uncomment to enable building the UNU.RAN JNI. 32 | #randvar.jni.build 33 | 34 | # Path to `include/unuran.h` and to `lib/libunuran.a`. 35 | #unuran.prefix = /opt/unuran 36 | 37 | # Equivalent to `unuran.prefix` for each target platform when cross-compilation 38 | # is enabled (with the `crossCompile` property). 39 | # Both properties default to `unuran.prefix`. 40 | #unuran.prefix.linux64 = /opt/unuran 41 | #unuran.prefix.win32 = /opt/unuran-mingw32 42 | 43 | 44 | ######################################################################## 45 | # Publishing to Bintray 46 | ######################################################################## 47 | 48 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umontreal-simul/ssj/98d9a6af7f68b1a96ffd8fb41d3d490020eead5d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umontreal-simul/ssj/98d9a6af7f68b1a96ffd8fb41d3d490020eead5d/gradlew -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /src/main/docs/.Rhistory: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umontreal-simul/ssj/98d9a6af7f68b1a96ffd8fb41d3d490020eead5d/src/main/docs/.Rhistory -------------------------------------------------------------------------------- /src/main/docs/bib/optim.bib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umontreal-simul/ssj/98d9a6af7f68b1a96ffd8fb41d3d490020eead5d/src/main/docs/bib/optim.bib -------------------------------------------------------------------------------- /src/main/docs/examples/charts/BoxTest.java: -------------------------------------------------------------------------------- 1 | package charts; 2 | import umontreal.ssj.charts.*; 3 | import umontreal.ssj.randvar.*; 4 | import umontreal.ssj.rng.*; 5 | import java.io.*; 6 | 7 | public class BoxTest 8 | { 9 | public static void main (String[] args) throws IOException { 10 | int count = 1000; 11 | double[] data1 = new double[count]; 12 | double[] data2 = new double[count]; 13 | 14 | RandomStream stream = new LFSR113(); 15 | RandomVariateGen log = new LognormalGen(stream); 16 | RandomVariateGen poi = new PoissonGen(stream, 5.0); 17 | 18 | for (int i = 0; i < count; i++) { 19 | data1[i] = log.nextDouble(); 20 | data2[i] = poi.nextDouble(); 21 | } 22 | 23 | BoxChart bc = new BoxChart("Boxplot1", "Series", "Y", data1, data2); 24 | bc.view(600, 400); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/docs/examples/charts/ChartTest1.java: -------------------------------------------------------------------------------- 1 | package charts; 2 | import umontreal.ssj.charts.XYLineChart; 3 | 4 | public class ChartTest1 5 | { 6 | private static double[][] getPoints1() { 7 | double[][] points = new double[2][200]; 8 | for (int i = 0; i < points[0].length; i++) { 9 | double x = i / 25.0; 10 | points[0][i] = x; 11 | points[1][i] = Math.sqrt (x); 12 | } 13 | return points; 14 | } 15 | 16 | private static double[][] getPoints2() { 17 | double[][] points = new double[2][21]; 18 | for (int i = 0; i < points[0].length; i++) { 19 | double x = -Math.PI + 2 * i * Math.PI / (points[0].length - 1); 20 | points[0][i] = x; 21 | points[1][i] = Math.cos (x); 22 | } 23 | return points; 24 | } 25 | 26 | private static double[][] getPoints3() { 27 | double[][] points = new double[2][11]; 28 | for (int i = 0; i < points[0].length; i++) { 29 | points[0][i] = -5 + i; 30 | points[1][i] = -3 + i; 31 | } 32 | return points; 33 | } 34 | 35 | public static void main(String[] args) { 36 | // Get data; data1 has length 2 and contains one array for 37 | // X-axis values, and one array for Y-axis values. 38 | double[][] data1 = getPoints1(); 39 | double[][] data2 = getPoints2(); 40 | double[][] data3 = getPoints3(); 41 | 42 | // Create a new chart with the previous data series. 43 | XYLineChart chart = new XYLineChart(null, "X", "Y", data1, data2, data3); 44 | chart.toLatexFile("ChartTest1.tex", 12, 8); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/docs/examples/charts/ChartTest2.java: -------------------------------------------------------------------------------- 1 | package charts; 2 | import umontreal.ssj.charts.*; 3 | import java.awt.Color; 4 | 5 | public class ChartTest2 6 | { 7 | private static double[][] getPoints1() { 8 | double[][] points = new double[2][40]; 9 | for (int i = 0; i < points[0].length; i++) { 10 | double x = i / 4.0; 11 | points[0][i] = x; 12 | points[1][i] = Math.sqrt(x); 13 | } 14 | return points; 15 | } 16 | 17 | private static double[][] getPoints2() { 18 | double[][] points = new double[2][21]; 19 | for (int i = 0; i < points[0].length; i++) { 20 | double x = -Math.PI + 2 * i * Math.PI / (points[0].length - 1); 21 | points[0][i] = x; 22 | points[1][i] = Math.cos(x); 23 | } 24 | return points; 25 | } 26 | 27 | private static double[][] getPoints3() { 28 | double[][] points = new double[2][11]; 29 | for (int i = 0; i < points[0].length; i++) { 30 | points[0][i] = -5 + i; 31 | points[1][i] = -3 + i; 32 | } 33 | return points; 34 | } 35 | 36 | public static void main(String[] args) { 37 | double[][] data1 = getPoints1(); 38 | double[][] data2 = getPoints2(); 39 | double[][] data3 = getPoints3(); 40 | 41 | // Create a new chart with the previous data series. 42 | XYLineChart chart = new XYLineChart(null, "X", "Y", data1, data2, data3); 43 | 44 | // Customizing axes 45 | Axis xaxis = chart.getXAxis(); 46 | Axis yaxis = chart.getYAxis(); 47 | String[] labels = { "-9", "$-\\lambda$", "$-\\sqrt{2}$", 48 | "0", "$\\frac{14}{\\pi}$", "\\LaTeX" }; 49 | double[] values = { -9, -5, -Math.sqrt(2), 0, 14.0 / Math.PI, 9 }; 50 | xaxis.setLabels(values, labels); 51 | yaxis.setLabels(1); 52 | 53 | // Data plots customizing 54 | XYListSeriesCollection collec = chart.getSeriesCollection(); 55 | collec.setColor(0, new Color(0, 64, 128)); 56 | collec.setName(0, "$f(x) = \\sqrt(x)$"); 57 | collec.setMarksType(0, ""); 58 | collec.setDashPattern(0, "dotted"); 59 | collec.setName(1, "$f(x) = \\cos(x)$"); 60 | collec.setMarksType(1, ""); 61 | collec.setColor(2, Color.ORANGE); 62 | collec.setPlotStyle(2, "ycomb,very thick"); 63 | collec.setMarksType(2, "*"); 64 | 65 | // Export to LaTex format 66 | chart.toLatexFile("ChartTest2.tex", 12, 8); // 12cm width, 8cm height 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/docs/examples/charts/ContDistPlot.java: -------------------------------------------------------------------------------- 1 | package charts; 2 | import umontreal.ssj.probdist.*; 3 | import umontreal.ssj.charts.*; 4 | 5 | public class ContDistPlot 6 | { 7 | public static void main (String[] args) { 8 | ContinuousDistribution dist = new NormalDist(); 9 | ContinuousDistChart plot = new ContinuousDistChart(dist, -3.5, 3.5, 1000); 10 | plot.viewDensity(600, 400); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/docs/examples/charts/DistIntTest.java: -------------------------------------------------------------------------------- 1 | package charts; 2 | import umontreal.ssj.probdist.*; 3 | import umontreal.ssj.charts.*; 4 | import java.io.*; 5 | 6 | public class DistIntTest 7 | { 8 | public static void main(String[] args) throws IOException { 9 | PoissonDist dist = new PoissonDist(50); 10 | DiscreteDistIntChart dic = new DiscreteDistIntChart(dist); 11 | 12 | // Export to Latex format 13 | String output = dic.toLatexProb(12, 8); // 12cm width, 8cm height 14 | Writer file = new FileWriter("DistIntTest.tex"); 15 | file.write(output); 16 | file.close(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/docs/examples/charts/EmpiricalChartTest.java: -------------------------------------------------------------------------------- 1 | package charts; 2 | import umontreal.ssj.rng.*; 3 | import umontreal.ssj.randvar.*; 4 | import umontreal.ssj.charts.*; 5 | import java.util.Arrays; 6 | import java.awt.Color; 7 | 8 | public class EmpiricalChartTest 9 | { 10 | private static double[] getPoints1() { 11 | RandomVariateGen gen = new UniformGen(new LFSR113()); 12 | final int N = 10; 13 | double[] data = new double[N]; 14 | for (int i = 0; i < N; i++) 15 | data[i] = gen.nextDouble(); 16 | Arrays.sort(data); 17 | return data; 18 | } 19 | 20 | private static double[] getPoints2() { 21 | RandomVariateGen gen = new BetaGen(new LFSR113(), 3, 1); 22 | final int N = 20; 23 | double[] data = new double[N]; 24 | for (int i = 0; i < N; i++) 25 | data[i] = gen.nextDouble(); 26 | Arrays.sort(data); 27 | return data; 28 | } 29 | 30 | public static void main(String[] args) { 31 | double[] data1 = getPoints1(); 32 | double[] data2 = getPoints2(); 33 | 34 | // Create a new chart with the previous data series. 35 | EmpiricalChart chart = new EmpiricalChart(null, null, null, data1, data2); 36 | 37 | // Data plots customizing 38 | EmpiricalSeriesCollection collec = chart.getSeriesCollection(); 39 | collec.setMarksType(0, "square*"); 40 | collec.setColor(0, Color.MAGENTA); 41 | 42 | chart.enableGrid(0.1, 0.1); // Enables grid 43 | chart.toLatexFile("EmpiricalChartTest.tex", 12, 8); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/docs/examples/charts/HistogramChartTest.java: -------------------------------------------------------------------------------- 1 | package charts; 2 | import umontreal.ssj.charts.*; 3 | import umontreal.ssj.rng.*; 4 | import umontreal.ssj.randvar.*; 5 | import java.awt.Color; 6 | 7 | public class HistogramChartTest 8 | { 9 | private static double[] getPoints1() { 10 | NormalGen gen = new NormalGen(new MRG32k3a(), 0, 2); 11 | final int N = 100000; 12 | double[] ad = new double[N]; 13 | for (int i = 0; i < N; i++) 14 | ad[i] = gen.nextDouble(); 15 | return ad; 16 | } 17 | 18 | private static double[] getPoints2() { 19 | ExponentialGen gen = new ExponentialGen(new MRG32k3a(), 1); 20 | final int N = 100000; 21 | double[] ad = new double[N]; 22 | for (int i = 0; i < N; i++) 23 | ad[i] = gen.nextDouble(); 24 | return ad; 25 | } 26 | 27 | public static void main(String[] args) { 28 | double[] data1 = getPoints1(); 29 | double[] data2 = getPoints2(); 30 | 31 | // Create a new chart with the previous data series. 32 | HistogramChart chart = new HistogramChart(null, null, null, data1, data2); 33 | 34 | // Customizes the data plots 35 | HistogramSeriesCollection collec = chart.getSeriesCollection(); 36 | collec.setColor(0, new Color(255, 0, 0, 128)); 37 | collec.setColor(1, new Color(0, 255, 0, 128)); 38 | collec.setBins(0, 40, -6, 6); 39 | 40 | // Define range bounds. 41 | double[] bounds = { -6, 6, 0, 30000 }; 42 | chart.setManualRange00(bounds, true, true); 43 | 44 | chart.toLatexFile("HistogramChartTest.tex", 12, 8); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/docs/examples/charts/HistogramTest1.java: -------------------------------------------------------------------------------- 1 | package charts; 2 | import umontreal.ssj.charts.*; 3 | import umontreal.ssj.rng.*; 4 | import umontreal.ssj.randvar.*; 5 | import java.awt.Color; 6 | 7 | public class HistogramTest1 8 | { 9 | private static double[] getData() { 10 | NormalGen gen = new NormalGen(new LFSR113()); 11 | final int N = 100000; 12 | double[] ad = new double[N]; 13 | for (int i = 0; i < N; i++) 14 | ad[i] = gen.nextDouble(); 15 | return ad; 16 | } 17 | 18 | public static void main(String[] args) { 19 | double[] data = getData(); 20 | 21 | HistogramChart chart; 22 | chart = new HistogramChart("Standard Normal", null, null, data); 23 | 24 | // Customizes the data plot 25 | HistogramSeriesCollection collec = chart.getSeriesCollection(); 26 | collec.setBins(0, 80); 27 | double[] bounds = { -4, 4, 0, 5000 }; 28 | chart.setManualRange(bounds); 29 | 30 | chart.view(800, 500); 31 | chart.toLatexFile("HistogramTest1.tex", 12, 8); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/docs/examples/charts/NormalChart.java: -------------------------------------------------------------------------------- 1 | package charts; 2 | import umontreal.ssj.charts.XYLineChart; 3 | 4 | public class NormalChart 5 | { 6 | private static double[][] getPoints() { 7 | // The density of the standard normal probability distribution 8 | // points contains one array for X values and one array for Y values 9 | final int N = 400; 10 | double[][] points = new double[2][N + 1]; 11 | final double CPI = Math.sqrt (2*Math.PI); 12 | for (int i = 0; i <= N; ++i) { 13 | double x = -3.5 + i * 7.0 / N; 14 | points[0][i] = x; 15 | points[1][i] = Math.exp (-x*x/2.0) / CPI; 16 | } 17 | return points; 18 | } 19 | 20 | public static void main(String[] args) { 21 | double[][] points = getPoints(); 22 | XYLineChart chart = new XYLineChart(null, "X", null, points); 23 | chart.setAutoRange00(true, true); // Axes pass through (0,0) 24 | chart.toLatexFile("NormalChart.tex", 12, 8); 25 | chart.view(800,500); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/CallCenter.dat: -------------------------------------------------------------------------------- 1 | 8.0 opening 2 | 13 numPeriods 3 | 4 100.0 numAgents and base arrival rate 4 | 6 150.0 5 | 8 150.0 6 | 8 180.0 7 | 8 200.0 8 | 7 150.0 9 | 8 150.0 10 | 8 150.0 11 | 6 120.0 12 | 6 100.0 13 | 4 80.0 14 | 4 70.0 15 | 4 60.0 16 | 10.0 alpha_0 17 | 0.1 p 18 | 0.001 nu 19 | 1.0 alpha 20 | 0.01 beta (mean service time = 100 sec) 21 | 20.0 s 22 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/CallCenter.res: -------------------------------------------------------------------------------- 1 | 2 | Num. calls expected = 1660.0 3 | 4 | REPORT on Tally stat. collector ==> Number of arrivals per day 5 | min max average standard dev. num. obs 6 | 460.000 4206.000 1639.507 513.189 1000 7 | 90.0% confidence interval for mean: ( 1612.789, 1666.225 ) 8 | 9 | REPORT on Tally stat. collector ==> Average waiting time per customer 10 | min max average standard dev. num. obs 11 | 0.000 570.757 11.834 34.078 1000 12 | 90.0% confidence interval for mean: ( 10.060, 13.608 ) 13 | 14 | REPORT on Tally stat. collector ==> Proportion of waiting times < s 15 | min max average standard dev. num. obs 16 | 0.277 1.155 0.853 0.169 1000 17 | 90.0% confidence interval for mean: ( 0.844, 0.862 ) 18 | 19 | REPORT on Tally stat. collector ==> Proportion of calls lost 20 | min max average standard dev. num. obs 21 | 0.000 0.844 0.034 0.061 1000 22 | 90.0% confidence interval for mean: ( 0.031, 0.037 ) 23 | 24 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/Lcgmodpow2.java: -------------------------------------------------------------------------------- 1 | package ift6561examples; 2 | 3 | import umontreal.ssj.util.PrintfFormat; 4 | 5 | public class Lcgmodpow2 { 6 | 7 | public void printValues(long m, long a, long c, long x0, int n) { 8 | long x = x0; 9 | for (int i=0; i < n; i++) { 10 | x = (a * x + c) % m; 11 | System.out.print("x_" + i + " ~=~ " + x + " &=& "); 12 | System.out.println(PrintfFormat.formatBase (2, x) + "_2 "); 13 | } 14 | } 15 | 16 | public static void main(String[] args) { 17 | Lcgmodpow2 rng = new Lcgmodpow2(); 18 | rng.printValues(4096 * 4096, 1140671485, 12820163, 12345, 10); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/ProductBarrier.java: -------------------------------------------------------------------------------- 1 | package ift6561examples; 2 | 3 | import umontreal.ssj.rng.*; 4 | import umontreal.ssj.probdist.*; 5 | import umontreal.ssj.mcqmctools.*; 6 | 7 | // This is question 4 of homework 2 of ift6561, A-2018. 8 | 9 | public class ProductBarrier implements MonteCarloModelDouble { 10 | 11 | double C, K, a, b; 12 | double mu1, sigma1; 13 | double mu2, sigma2; 14 | ContinuousDistribution dist1; // For W_1 15 | ContinuousDistribution dist2; // For W_2 16 | double payoff; // Value of X to return. 17 | 18 | // Constructor. 19 | public ProductBarrier(double C, double K, double a, double b, double mu1, double sigma1, 20 | double mu2, double sigma2) { 21 | this.C = C; 22 | this.K = K; 23 | this.a = a; 24 | this.b = b; 25 | dist1 = new LognormalDist(mu1, sigma1); 26 | dist2 = new LognormalDist(mu2, sigma2); 27 | } 28 | 29 | // Generates payoff X, without IS. 30 | public void simulate(RandomStream stream) { 31 | payoff = 0.0; 32 | double CW1 = C * dist1.inverseF(stream.nextDouble()); 33 | if (CW1 > a) 34 | return; 35 | double X = CW1 * dist2.inverseF(stream.nextDouble()); 36 | if (X > b) 37 | payoff = X - K; 38 | } 39 | 40 | // Returns payoff X 41 | public double getPerformance() { 42 | return payoff; 43 | } 44 | 45 | // Descriptor of model 46 | public String toString() { 47 | return "Simplified financial option with barriers, Devoir 2, A-2018, no IS"; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/ProductBarrierIs.java: -------------------------------------------------------------------------------- 1 | package ift6561examples; 2 | 3 | import java.io.*; 4 | import umontreal.ssj.rng.*; 5 | import umontreal.ssj.mcqmctools.MonteCarloExperiment; 6 | import umontreal.ssj.stat.*; 7 | 8 | // This is question 4 of homework 2 of ift6561, A-2018. 9 | 10 | public class ProductBarrierIs extends ProductBarrier { 11 | 12 | double maxU1; // U1 is generated in [0, maxU1) 13 | 14 | // Constructor. 15 | public ProductBarrierIs(double C, double K, double a, double b, double mu1, double sigma1, 16 | double mu2, double sigma2) { 17 | super(C, K, a, b, mu1, sigma1, mu2, sigma2); 18 | maxU1 = dist1.cdf(a / C); 19 | } 20 | 21 | // Generates and returns X, without IS. 22 | public void simulate(RandomStream stream) { 23 | double CW1 = C * dist1.inverseF(maxU1 * stream.nextDouble()); 24 | double minU2 = dist2.cdf(b / CW1); // U2 must be larger than this. 25 | double u2 = minU2 + (1.0 - minU2) * stream.nextDouble(); 26 | double X = CW1 * dist2.inverseF(u2); 27 | payoff = (X - K) * maxU1 * (1.0 - minU2); // Unbiased IS estimator. 28 | } 29 | 30 | // Descriptor of model 31 | public String toString() { 32 | return "Simplified financial option with barriers, with IS"; 33 | } 34 | 35 | public static void main(String[] args) throws IOException { 36 | double C = 100, K = 102, a = 100, b = 102; 37 | double mu1 = 0.01, sigma1 = 0.05; 38 | double mu2 = 0.01, sigma2 = 0.05; 39 | int n = 100000; 40 | RandomStream stream = new LFSR113(); 41 | Tally statX = new TallyStore("Option payoffs"); // To store the n observations of X. 42 | 43 | ProductBarrier pb = new ProductBarrier(C, K, a, b, mu1, sigma1, mu2, sigma2); 44 | System.out.println (MonteCarloExperiment.simulateRunsDefaultReportStudent(pb, n, stream, statX)); 45 | pb = new ProductBarrierIs(C, K, a, b, mu1, sigma1, mu2, sigma2); 46 | System.out.println (MonteCarloExperiment.simulateRunsDefaultReportStudent(pb, n, stream, statX)); 47 | 48 | b = 112; 49 | pb = new ProductBarrier(C, K, a, b, mu1, sigma1, mu2, sigma2); 50 | System.out.println (MonteCarloExperiment.simulateRunsDefaultReportStudent(pb, n, stream, statX)); 51 | pb = new ProductBarrierIs(C, K, a, b, mu1, sigma1, mu2, sigma2); 52 | System.out.println (MonteCarloExperiment.simulateRunsDefaultReportStudent(pb, n, stream, statX)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/ProductExpCosRQMC.java: -------------------------------------------------------------------------------- 1 | package ift6561examples; 2 | 3 | import java.io.*; 4 | import umontreal.ssj.hups.*; 5 | import umontreal.ssj.rng.*; 6 | import umontreal.ssj.mcqmctools.*; 7 | 8 | // This is question 3 of homework 2 of ift6561, A-2018. 9 | 10 | public class ProductExpCosRQMC implements MonteCarloModelDouble { 11 | 12 | int s; 13 | double a, b; 14 | double prod; 15 | 16 | // Constructor. 17 | public ProductExpCosRQMC(int s, double a, double b) { 18 | this.s = s; this.a = a; this.b = b; 19 | } 20 | 21 | // Generates and returns X, without IS. 22 | public void simulate (RandomStream stream) { 23 | prod = 1.0; 24 | double u; 25 | for (int j = 0; j < s; j++) { 26 | u = stream.nextDouble(); 27 | prod *= Math.exp(a * u) * Math.cos(b * u); 28 | } 29 | } 30 | 31 | // Generates and returns X, without IS. 32 | public double getPerformance () { 33 | return prod; 34 | } 35 | 36 | // Descriptor of this model. 37 | public String toString () { 38 | return "Test function for MC and RQMC: product of exponentials and cosine functions."; 39 | } 40 | 41 | public static void main(String[] args) throws IOException { 42 | int s = 3; 43 | int n = 100000; 44 | int m = 20; // Number of RQMC randomizations. 45 | RandomStream stream = new LFSR113(); 46 | DigitalNet p = new SobolSequence(16, 31, s); // n = 2^{16} points in s dim. 47 | // PointSetRandomization rand = new LMScrambleShift(stream); 48 | PointSetRandomization rand = new RandomShift(stream); 49 | 50 | System.out.println (RQMCExperiment.makeComparisonExperimentMCvsRQMC 51 | (new ProductExpCosRQMC(s, 2.0, 0.5), stream, p, rand, n, m)); 52 | System.out.println (RQMCExperiment.makeComparisonExperimentMCvsRQMC 53 | (new ProductExpCosRQMC(s, 2.0, 50.0), stream, p, rand, n, m)); 54 | System.out.println (RQMCExperiment.makeComparisonExperimentMCvsRQMC 55 | (new ProductExpCosRQMC(s, 10.0, 0.5), stream, p, rand, n, m)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/San13CMC.java: -------------------------------------------------------------------------------- 1 | package ift6561examples; 2 | 3 | import java.io.*; 4 | import umontreal.ssj.rng.*; 5 | import umontreal.ssj.stat.Tally; 6 | import umontreal.ssj.mcqmctools.*; 7 | /** 8 | * 9 | */ 10 | 11 | /** 12 | * @author Pierre L'Ecuyer 13 | * 14 | */ 15 | public class San13CMC extends San13Prob { 16 | 17 | double estimate; // Cond. prod. of exceeding x. 18 | 19 | public San13CMC(double x, String fileName) throws IOException { 20 | super(x, fileName); 21 | } 22 | 23 | public void simulate(RandomStream stream) { 24 | for (int k = 0; k < 13; k++) { 25 | V[k] = dist[k].inverseF(stream.nextDouble()); 26 | if (V[k] < 0.0) 27 | V[k] = 0.0; 28 | } 29 | double prod = 1.0; 30 | // Incomplete path lengths 31 | paths[0] = V[1] + V[10]; 32 | paths[1] = V[0] + V[2] + V[10]; 33 | if (paths[0] > paths[1]) 34 | paths[1] = paths[0]; 35 | prod *= dist[5].cdf(x - paths[1]); 36 | paths[2] = V[0] + V[10]; 37 | prod *= dist[4].cdf(x - paths[2]); 38 | paths[3] = V[0] + V[3] + V[7] + V[10]; 39 | prod *= dist[9].cdf(x - paths[3]); 40 | paths[4] = V[0] + V[3] + V[7] + V[12]; 41 | prod *= dist[8].cdf(x - paths[4]); 42 | paths[5] = V[0] + V[3] + V[11] + V[12]; 43 | prod *= dist[6].cdf(x - paths[5]); 44 | estimate = 1.0 - prod; 45 | } 46 | 47 | public double getValue() { 48 | return estimate; 49 | } 50 | 51 | public static void main(String[] args) throws IOException { 52 | int n = 1000000; 53 | San13CMC san = new San13CMC(90.0, "san13a.dat"); 54 | MonteCarloExperiment.simulateRunsDefaultReportStudent (san, n, new LFSR113(), 55 | new Tally ("SAN13 example with CMC"), 0.95, 4); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/San13CMCDist.java: -------------------------------------------------------------------------------- 1 | package ift6561examples; 2 | import java.io.*; 3 | 4 | import umontreal.ssj.charts.HistogramChart; 5 | import umontreal.ssj.rng.*; 6 | import umontreal.ssj.stat.TallyStore; 7 | import umontreal.ssj.mcqmctools.*; 8 | 9 | 10 | /** 11 | * Here we compute the empirical distribution of the CMC estimator. 12 | * MAKES NO SENSE !!!!!!!!!!! 13 | */ 14 | 15 | public class San13CMCDist extends San13CMC { 16 | 17 | // The constructor reads link length distributions in a file. 18 | public San13CMCDist(String fileName) throws IOException { 19 | super(0.0, fileName); 20 | } 21 | 22 | public double getValue() { 23 | return maxPath; 24 | } 25 | 26 | public String toString() { 27 | return "This one makes no sense !!!!\n\n" 28 | + "SAN network with 9 nodes and 13 links, from Elmaghraby (1977)\n" 29 | + "Estimate distribution of length of longest path.\n"; 30 | } 31 | 32 | public static void main(String[] args) throws IOException { 33 | int n = 100000; 34 | San13CMCDist san = new San13CMCDist("san13a.dat"); 35 | TallyStore statT = new TallyStore("TallyStore for SAN13CMC example"); 36 | MonteCarloExperiment.simulateRunsDefaultReportStudent (san, n, new LFSR113(), 37 | statT, 0.95, 4); 38 | statT.quickSort(); 39 | HistogramChart hist = new HistogramChart("Distribution of $T$", 40 | "Values of $T$", "Frequency", statT.getArray(), n); 41 | double[] bounds = { 0, 200, 0, 12000 }; 42 | hist.setManualRange(bounds); 43 | (hist.getSeriesCollection()).setBins(0, 40, 0, 200); 44 | hist.view(800, 500); 45 | String histLatex = hist.toLatex(12.0, 8.0); 46 | Writer file = new FileWriter("san13CMCchart.tex"); 47 | file.write(histLatex); 48 | file.close(); 49 | 50 | // Print p-th quantile 51 | double p = 0.99; 52 | int index = (int)Math.round (p * n); 53 | double xip = statT.getArray()[index]; 54 | System.out.printf("%5.3g -th quantile: %9.6g \n", p, xip); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/San13connect.java: -------------------------------------------------------------------------------- 1 | package ift6561examples; 2 | import java.io.*; 3 | // import java.util.Scanner; 4 | import umontreal.ssj.rng.*; 5 | // import umontreal.ssj.probdist.*; 6 | import umontreal.ssj.stat.*; 7 | import umontreal.ssj.mcqmctools.*; 8 | 9 | /** 10 | * This class simulates a specific stochastic activity network with 9 nodes and 11 | * 13 links, taken from Elmaghraby (1977) and used again in L'Ecuyer and Lemieux 12 | * (2000), "Variance Reduction via Lattice Rules". The goal here is to estimate the 13 | * probability that nodes 1 and 9 are disconncted. 14 | * This program is very specific to this example and uses a very naive way to 15 | * compute the shortest path, by enumerating all six paths! 16 | */ 17 | 18 | public class San13connect implements MonteCarloModelDouble { 19 | 20 | double[] r = new double[13]; 21 | boolean[] Y = new boolean[13]; 22 | // We consider the 6 paths that can lead to the sink. 23 | boolean connected; 24 | 25 | // The constructor. 26 | public San13connect(double rj) { 27 | for (int k = 0; k < 13; k++) r[k] = rj; 28 | // r[4] = 0.99; r[5] = 0.99; r[6] = 0.999; 29 | } 30 | 31 | public void simulate(RandomStream stream) { 32 | for (int k = 0; k < 13; k++) { 33 | Y[k] = (stream.nextDouble() < r[k]); 34 | } 35 | connected = false; 36 | // Path lengths 37 | if ((Y[1] & Y[5] & Y[10]) | 38 | (Y[0] & Y[2] & Y[5] & Y[10]) | 39 | (Y[0] & Y[4] & Y[10]) | 40 | (Y[0] & Y[3] & Y[7] & Y[9] & Y[10]) | 41 | (Y[0] & Y[3] & Y[7] & Y[8] & Y[12]) | 42 | (Y[0] & Y[3] & Y[6] & Y[11] & Y[12])) connected = true; 43 | } 44 | 45 | public double getPerformance() { 46 | if (connected) 47 | return 0.0; 48 | else 49 | return 1.0; 50 | } 51 | 52 | public String toString() { 53 | String s = "SAN network with 9 nodes and 13 links, from Elmaghraby (1977)\n" 54 | + "Estimate prob that nodes 1 and 9 are disconnected"; 55 | return s; 56 | } 57 | 58 | public static void main(String[] args) throws IOException { 59 | int n = 1000000 * 1000; 60 | double rj = 0.999; 61 | San13connect san = new San13connect(rj); 62 | Tally statC = new Tally("SAN13 reliability example"); 63 | MonteCarloExperiment.simulateRunsDefaultReportStudent (san, n, new LFSR113(), 64 | statC, 0.95, 4); 65 | System.out.println(statC.report(0.95, 8)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/San13connectCMC1.java: -------------------------------------------------------------------------------- 1 | package ift6561examples; 2 | import java.io.*; 3 | // import java.util.Scanner; 4 | import umontreal.ssj.rng.*; 5 | // import umontreal.ssj.probdist.*; 6 | import umontreal.ssj.stat.*; 7 | import umontreal.ssj.mcqmctools.*; 8 | 9 | 10 | /** 11 | * This class simulates a specific stochastic activity network with 9 nodes and 12 | * 13 links, taken from Elmaghraby (1977) and used again in L'Ecuyer and Lemieux 13 | * (2000), "Variance Reduction via Lattice Rules". The goal here is to estimate the 14 | * probability that nodes 1 and 9 are disconncted. 15 | * This program is very specific to this example and uses a very naive way to 16 | * compute the shortest path, by enumerating all six paths! 17 | */ 18 | 19 | public class San13connectCMC1 extends San13connect { 20 | 21 | double probConnected; 22 | 23 | // The constructor. 24 | public San13connectCMC1(double rj) { 25 | super(rj); 26 | } 27 | 28 | public void simulate(RandomStream stream) { 29 | for (int k = 0; k < 13; k++) { 30 | Y[k] = (stream.nextDouble() < r[k]); 31 | } 32 | boolean I2, I3; 33 | probConnected = 0.0; 34 | // Path lengths 35 | I3 = (Y[5] & Y[10]); 36 | I2 = ((Y[2] & Y[5] & Y[10]) | 37 | (Y[4] & Y[10]) | 38 | (Y[3] & Y[7] & Y[9] & Y[10]) | 39 | (Y[3] & Y[7] & Y[8] & Y[12]) | 40 | (Y[3] & Y[6] & Y[11] & Y[12])); 41 | if (I2) probConnected = r[0]; 42 | if (I3) probConnected += r[1] * (1.0 - probConnected); 43 | } 44 | 45 | public double getValue() 46 | { 47 | return 1.0 - probConnected; 48 | } 49 | 50 | public String toString() { 51 | String s = "SAN network with 9 nodes and 13 links, from Elmaghraby (1977)\n" 52 | + "Estimate prob that nodes 1 and 9 are disconnected"; 53 | return s; 54 | } 55 | 56 | public static void main(String[] args) throws IOException { 57 | int n = 1000000*1000; 58 | double rj = 0.999; 59 | San13connectCMC1 san = new San13connectCMC1(rj); 60 | Tally statC = new Tally("SAN13 reliability example"); 61 | MonteCarloExperiment.simulateRunsDefaultReportStudent (san, n, new LFSR113(), 62 | statC, 0.95, 4); 63 | System.out.println(statC.report(0.95, 8)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/docs/examples/ift6561examples/Sum2BarrierIS.java: -------------------------------------------------------------------------------- 1 | package ift6561examples; 2 | import umontreal.ssj.rng.*; 3 | import umontreal.ssj.probdist.*; 4 | import umontreal.ssj.stat.Tally; 5 | 6 | // code for example sum-barrier-is in introduction. 7 | public class Sum2BarrierIS { 8 | 9 | double a; double b; double K; 10 | double phiam1; // Phi(a-1) 11 | RandomStream stream = new MRG32k3a(); 12 | 13 | public Sum2BarrierIS (double a, double b, double K) { 14 | this.a = a; this.b = b; this.K = K; 15 | phiam1 = NormalDist.cdf01 (a - 1.0); 16 | } 17 | 18 | // Generate X with Monte Carlo 19 | public double simulateOneMCRun() { 20 | double y1 = 1.0 + NormalDist.inverseF01 (stream.nextDouble()); 21 | double y2 = 1.0 + NormalDist.inverseF01 (stream.nextDouble()); 22 | if (y1 < a && (y1 + y2) > b) 23 | return (y1 + y2 - K); 24 | else 25 | return 0; 26 | } 27 | 28 | // Generate X with Importance Sampling 29 | public double simulateOneISRun() { 30 | double y1 = 1.0 + NormalDist.inverseF01 (stream.nextDouble() * phiam1); 31 | double phi = NormalDist.cdf01 (b - 1.0 - y1); // Phi (b-1-y1) 32 | double y2 = 1.0 + NormalDist.inverseF01 (phi + stream.nextDouble() * (1.0 - phi)); 33 | return ((y1 + y2 - K) * phiam1 * (1.0 - phi)); 34 | } 35 | 36 | public static void main (String[] args) { 37 | int n = 100000; 38 | Sum2BarrierIS system = new Sum2BarrierIS (0.5, 2.0, 1.0); 39 | 40 | // with MC 41 | Tally mcTally = new Tally ("MC estimator"); 42 | for (int i=0; imx ? 1 : (x Replicates of Brownian Motion 27 | num. obs. min max average standard dev. 28 | 100 1.098 1.166 1.130 0.013 29 | 30 | 31 | 3- RQMC, 100 reps, 2^12 trajectories, 20 steps 32 | REPORT on Tally stat. collector ==> Replicates of Brownian Motion 33 | num. obs. min max average standard dev. 34 | 100 1.115 1.140 1.127 5.2E-3 35 | 36 | 37 | 4- Array-RQMC, 100 replications, 2^12 trajectories, 20 steps 38 | REPORT on Tally stat. collector ==> Replicates of Brownian Motion 39 | num. obs. min max average standard dev. 40 | 100 1.126 1.130 1.128 6.6E-4 41 | 42 | -------------------------------------------------------------------------------- /src/main/docs/examples/probdistmulti/norta/ExampleNortaInitDisc.java: -------------------------------------------------------------------------------- 1 | package probdistmulti.norta; 2 | 3 | import umontreal.ssj.probdist.*; 4 | import umontreal.ssj.probdistmulti.norta.*; 5 | 6 | public class ExampleNortaInitDisc 7 | { 8 | public static void main (String[] args) { 9 | final double rX = 0.43; // Target rank correlation rX 10 | final double tr = 1.0 - 1.0e-6; // Quantile upper limit 11 | 12 | // Define the two marginal distributions 13 | DiscreteDistributionInt dist1 = new NegativeBinomialDist(15.68, 0.3861); 14 | DiscreteDistributionInt dist2 = new NegativeBinomialDist(60.21, 0.6211); 15 | 16 | NI1 ni1Obj = new NI1(rX, dist1, dist2, tr, 1.0e-4); 17 | System.out.println("Result with method NI1: rho_Z = " 18 | + String.format("%.14g", ni1Obj.computeCorr())); 19 | NI2a ni2aObj = new NI2a(rX, dist1, dist2, tr, 0.005, 1.0e-4); 20 | System.out.println("Result with method NI2b: rho_Z = " 21 | + String.format("%.14g", ni2aObj.computeCorr())); 22 | NI2b ni2bObj = new NI2b(rX, dist1, dist2, tr, 5, 1.0e-4); 23 | System.out.println("Result with method NI2a: rho_Z = " 24 | + String.format("%.14g", ni2bObj.computeCorr())); 25 | NI3 ni3Obj = new NI3(rX, dist1, dist2, tr, 1.0e-4); 26 | System.out.println("Result with method NI3: rho_Z = " 27 | + String.format("%.14g", ni3Obj.computeCorr())); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/docs/examples/probdistmulti/norta/ExampleNortaInitDisc.txt: -------------------------------------------------------------------------------- 1 | Result with method NI1: rho_Z = 0.44691425135002 2 | Result with method NI2b: rho_Z = 0.44685851640499 3 | Result with method NI2a: rho_Z = 0.44683779468645 4 | Result with method NI3: rho_Z = 0.44691432915086 5 | -------------------------------------------------------------------------------- /src/main/docs/examples/randvar/RandvarExample1.java: -------------------------------------------------------------------------------- 1 | package randvar; 2 | 3 | import umontreal.ssj.probdist.*; 4 | import umontreal.ssj.rng.*; 5 | import umontreal.ssj.randvar.*; 6 | import java.util.Arrays; 7 | 8 | public class RandvarExample1 { 9 | 10 | // Generate and print n random variates with generator gen. 11 | private static void generate(RandomVariateGen gen, int n) { 12 | double u; 13 | for (int i = 0; i < n; i++) { 14 | u = gen.nextDouble(); 15 | System.out.printf("%12.6f%n", u); 16 | } 17 | System.out.println("----------------------"); 18 | } 19 | 20 | public static void main(String[] args) { 21 | 22 | // Create four parallel generators (three normal and one gamma). 23 | RandomVariateGen gen0 = new RandomVariateGen (new MRG31k3p(), new NormalDist()); 24 | RandomVariateGen gen1 = new NormalGen (new MRG31k3p()); 25 | RandomVariateGen gen2 = new NormalGen (new MRG31k3p(), 5.0, 121.4); 26 | RandomVariateGen gen3 = new GammaGen (new MRG31k3p(), 2.0, 10.0); 27 | RandomVariateGenInt gen4 = new PoissonGen (new MRG31k3p(), 10.0); 28 | 29 | System.out.println ("Some normal, gamma, and Poisson variates \n"); 30 | generate(gen0, 3); // Generate and prints 3 standard normal variates from gen0 31 | generate(gen1, 5); // then 5 more standard normals from gen1 32 | generate(gen2, 3); // then 3 normal variates with mean 5 and standard deviation 121.4 33 | generate(gen3, 2); // then 2 gamma variates with parameters (2, 10). 34 | int[] arrayP = gen4.nextArrayOfInt (10000); // Generate an array of 10000 Poisson variates of mean 10. 35 | Arrays.sort(arrayP); 36 | System.out.println ("50% quantile from Poisson(10) variates: " + arrayP[5000]); 37 | System.out.println ("90% quantile from Poisson(10) variates: " + arrayP[9000]); 38 | System.out.println ("99% quantile from Poisson(10) variates: " + arrayP[9900]); 39 | System.out.println ("99.9% quantile from Poisson(10) variates: " + arrayP[9990]); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/docs/examples/randvar/normaltest.java: -------------------------------------------------------------------------------- 1 | package randvar; 2 | 3 | import umontreal.ssj.rng.*; 4 | import umontreal.ssj.randvar.*; 5 | 6 | public class normaltest 7 | { 8 | public static void main (String[] args) { 9 | // Create 3 parallel streams of random numbers 10 | RandomStream stream1 = new MRG31k3p(); 11 | RandomStream stream2 = new MRG31k3p(); 12 | RandomStream stream3 = new MRG31k3p(); 13 | 14 | // Create 3 parallel streams of normal random variates 15 | RandomVariateGen gen1 = new NormalGen (stream1); 16 | RandomVariateGen gen2 = new NormalGen (stream2); 17 | RandomVariateGen gen3 = new NormalGen (stream3); 18 | 19 | final int n = 5; 20 | genere (gen1, n); 21 | genere (gen2, n); 22 | genere (gen3, n); 23 | } 24 | 25 | private static void genere (RandomVariateGen gen, int n) { 26 | double u; 27 | for (int i = 0; i < n; i++) { 28 | u = gen.nextDouble(); 29 | System.out.printf ("%12.6f%n", u); 30 | } 31 | System.out.println ("----------------------"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Asian.txt: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> Stats on value of Asian option 2 | num. obs. min max average standard dev. 3 | 100000 0.000 386.378 13.119 22.696 4 | 95.0% confidence interval for mean (student): ( 12.978, 13.260 ) 5 | 6 | Total CPU time: 0:0:0.19 7 | 8 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/AsianGBM.res: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> Stats on value of Asian option 2 | num. obs. min max average variance standard dev. 3 | 1000000 0.000 386.378 13.163 517.086 22.740 4 | 95.0% conf. interval for the mean (Student approx.): ( 13.118, 13.207 ) 5 | 6 | Total CPU time: 0:0:1.30 7 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/AsianGBMQMC.res: -------------------------------------------------------------------------------- 1 | Ordinary MC: 2 | 3 | REPORT on Tally stat. collector ==> value of Asian option 4 | num. obs. min max average variance standard dev. 5 | 100000 0.000 386.378 13.119 515.128 22.696 6 | 95.0% conf. interval for the mean (Student approx.): ( 12.978, 13.260 ) 7 | 8 | Total CPU time: 0:0:0.20 9 | ------------------------ 10 | 11 | QMC with Sobol point set with 65536 points and affine matrix scramble: 12 | 13 | REPORT on Tally stat. collector ==> RQMC averages for Asian option under GBM 14 | num. obs. min max average variance standard dev. 15 | 20 13.108 13.133 13.120 3.1E-5 5.6E-3 16 | 95.0% conf. interval for the mean (Student approx.): ( 13.118, 13.123 ) 17 | 18 | Total CPU time: 0:0:1.3 19 | 20 | Variance ratio: 250.2 21 | Efficiency ratio: 645.9 22 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/AsianQMC.txt: -------------------------------------------------------------------------------- 1 | Ordinary MC: 2 | 3 | REPORT on Tally stat. collector ==> value of Asian option 4 | num. obs. min max average standard dev. 5 | 100000 0.000 386.378 13.119 22.696 6 | 95.0% confidence interval for mean (student): ( 12.978, 13.260 ) 7 | 8 | Total CPU time: 0:0:0.19 9 | ------------------------ 10 | 11 | QMC with Sobol point set with 65536 points and affine matrix scramble: 12 | 13 | REPORT on Tally stat. collector ==> QMC averages for Asian option 14 | num. obs. min max average standard dev. 15 | 20 13.108 13.133 13.120 5.6E-3 16 | 95.0% confidence interval for mean (student): ( 13.118, 13.123 ) 17 | 18 | Total CPU time: 0:0:1.28 19 | 20 | Variance ratio: 250.2 21 | Efficiency ratio: 489.9 22 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/BankEv.res: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> Nb. served per day 2 | num. obs. min max average variance standard dev. 3 | 100 152.000 285.000 240.590 369.012 19.210 4 | 5 | REPORT on Tally stat. collector ==> Average wait per day (hours) 6 | num. obs. min max average variance standard dev. 7 | 100 0.816 35.613 4.793 26.890 5.186 8 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/BankEv.txt: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> Nb. served per day 2 | num. obs. min max average standard dev. 3 | 100 152.000 285.000 240.590 19.210 4 | 5 | REPORT on Tally stat. collector ==> Average wait per day (hours) 6 | num. obs. min max average standard dev. 7 | 100 0.816 35.613 4.793 5.186 8 | 9 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/CallCenter.dat: -------------------------------------------------------------------------------- 1 | 8.0 opening 2 | 13 numPeriods 3 | 4 100.0 numAgents and base arrival rate 4 | 6 150.0 5 | 8 150.0 6 | 8 180.0 7 | 8 200.0 8 | 7 150.0 9 | 8 150.0 10 | 8 150.0 11 | 6 120.0 12 | 6 100.0 13 | 4 80.0 14 | 4 70.0 15 | 4 60.0 16 | 400.0 alpha_0 17 | 0.1 p 18 | 0.001 nu 19 | 1.0 alpha 20 | 0.01 beta (mean service time = 100 sec) 21 | 20.0 s 22 | 23 | 24 | ========================================================== 25 | Commentaire: 26 | Vous pourriez avoir une erreur 27 | 28 | "java.util.InputMismatchException" 29 | 30 | avec CallCenter.java si votre système Java est configuré pour lire 31 | des nombres réels en virgule-flottante (par exemple un nombre réel 32 | s'écrit: 8,5 pour presque tous les pays dans le monde) au lieu 33 | de la convention anglo-saxonne point-flottant 34 | (où un nombre réel s'écrit: 8.5). Dans ce cas, soit changez tous les 35 | point-flottants ci-dessus en virgule-flottantes, soit ajoutez 36 | l'instruction 37 | 38 | Locale.setDefault(Locale.US); 39 | 40 | ou 41 | 42 | Locale.setDefault(Locale.ROOT); 43 | 44 | avant la lecture du fichier CallCenter.dat. 45 | Locale se trouve dans java.util. 46 | 47 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/CallCenter.res: -------------------------------------------------------------------------------- 1 | 2 | Number of calls expected per day = 1660.0 3 | 4 | Report for CallCenter: 5 | num obs. min max average variance std. dev. conf. int. 6 | Number of arrivals per day 10000 1317.000 2061.000 1660.366 8764.756 93.620 90.0% ( 1658.826, 1661.906) 7 | Average waiting time per customer 10000 0.619 17.822 4.713 3.987 1.997 90.0% ( 4.680, 4.746) 8 | Proportion of waiting times < s 10000 0.769 1.076 0.925 1.6E-3 0.040 90.0% ( 0.924, 0.925) 9 | Proportion of calls lost 10000 3.0E-3 0.058 0.020 4.6E-5 6.7E-3 90.0% ( 0.020, 0.020) 10 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/CallCenter.txt: -------------------------------------------------------------------------------- 1 | 2 | Num. calls expected = 1660.0 3 | 4 | Report for CallCenter: 5 | num obs. min max average std. dev. conf. int. 6 | Number of arrivals per day 1000 460.000 4206.000 1639.507 513.189 90.0% ( 1612.789, 1666.225) 7 | Average waiting time per customer 1000 0.000 570.757 11.834 34.078 90.0% ( 10.060, 13.608) 8 | Proportion of waiting times < s 1000 0.277 1.155 0.853 0.169 90.0% ( 0.844, 0.862) 9 | Proportion of calls lost 1000 0.000 0.844 0.034 0.061 90.0% ( 0.031, 0.037) 10 | 11 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/CallEv.dat: -------------------------------------------------------------------------------- 1 | 1000 numDays 2 | 8.0 opening 3 | 13 numPeriods 4 | 4 100.0 numAgents and base arrival rate 5 | 6 150.0 6 | 8 150.0 7 | 8 180.0 8 | 8 200.0 9 | 7 150.0 10 | 8 150.0 11 | 8 150.0 12 | 6 120.0 13 | 6 100.0 14 | 4 80.0 15 | 4 70.0 16 | 4 60.0 17 | 10.0 alpha_0 18 | 0.1 p 19 | 0.001 nu 20 | 1.0 alpha 21 | 0.01 beta (mean service time = 100 sec) 22 | 20.0 s 23 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/CallEv.txt: -------------------------------------------------------------------------------- 1 | 2 | Num. calls expected = 1660.0 3 | 4 | REPORT on Tally stat. collector ==> Number of arrivals per day 5 | num. obs. min max average standard dev. 6 | 1000 460.000 4206.000 1639.507 513.189 7 | 90.0% confidence interval for mean (student): ( 1612.789, 1666.225 ) 8 | 9 | REPORT on Tally stat. collector ==> Average waiting time per customer 10 | num. obs. min max average standard dev. 11 | 1000 0.000 570.757 11.834 34.078 12 | 90.0% confidence interval for mean (student): ( 10.060, 13.608 ) 13 | 14 | REPORT on Tally stat. collector ==> Proportion of waiting times < s 15 | num. obs. min max average standard dev. 16 | 1000 0.277 1.155 0.853 0.169 17 | 90.0% confidence interval for mean (student): ( 0.844, 0.862 ) 18 | 19 | REPORT on Tally stat. collector ==> Proportion of calls lost 20 | num. obs. min max average standard dev. 21 | 1000 0.000 0.844 0.034 0.061 22 | 90.0% confidence interval for mean (student): ( 0.031, 0.037 ) 23 | 24 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Collision.java: -------------------------------------------------------------------------------- 1 | package tutorial; 2 | 3 | import umontreal.ssj.probdist.PoissonDist; 4 | import umontreal.ssj.rng.*; 5 | import umontreal.ssj.stat.*; 6 | import umontreal.ssj.util.Chrono; 7 | 8 | public class Collision { 9 | int k; // Number of locations. 10 | int m; // Number of items. 11 | double lambda; // Theoretical expectation of C (asymptotic). 12 | boolean[] used; // Locations already used. 13 | int maxCounts; // Values of C >= maxCounts are aggregated. 14 | int[] counts; // Counts the number of occurrences of each value of C. 15 | PoissonDist poisson; // Will be a Poisson distribution with mean lambda. 16 | 17 | public Collision (int k, int m, int maxCounts) { 18 | this.k = k; 19 | this.m = m; 20 | lambda = (double) m * m / (2.0 * k); 21 | used = new boolean[k]; 22 | this.maxCounts = maxCounts; 23 | counts = new int[maxCounts + 1]; 24 | poisson = new PoissonDist(lambda); 25 | } 26 | 27 | // Generates and returns the number of collisions. 28 | public int simulate (RandomStream stream) { 29 | int C = 0; 30 | for (int i = 0; i < k; i++) used[i] = false; 31 | for (int j = 0; j < m; j++) { 32 | int loc = stream.nextInt (0, k-1); 33 | if (used[loc]) C++; 34 | else used[loc] = true; 35 | } 36 | return C; 37 | } 38 | 39 | // Performs n indep. runs using stream and collects statistics in statC. 40 | public void simulateRuns(int n, RandomStream stream, Tally statC) { 41 | statC.init(); 42 | int C; 43 | for (int c = 0; c < maxCounts; c++) 44 | counts[c] = 0; 45 | for (int i = 0; i < n; i++) { 46 | C = simulate(stream); 47 | statC.add(C); 48 | if (C > maxCounts) 49 | C = maxCounts; 50 | counts[C]++; 51 | } 52 | } 53 | 54 | public static void main (String[] args) { 55 | int k = 10000; int m = 500; 56 | int maxCounts = 30; 57 | int n = 10000000; 58 | Collision col = new Collision(k, m, maxCounts); 59 | Tally statC = new Tally("Statistics on collisions"); 60 | // System.out.println(col.toString()); 61 | Chrono timer = new Chrono(); 62 | col.simulateRuns(n, new MRG32k3a(), statC); 63 | System.out.println("Total CPU time: " + timer.format() + "\n"); 64 | statC.setConfidenceIntervalStudent(); 65 | System.out.println(statC.report(0.95, 3)); 66 | System.out.println ("Theoretical mean: lambda = " + col.lambda + "\n"); 67 | 68 | System.out.println("Counters:\n" 69 | + " c count Poisson expect.\n"); 70 | for (int c = 0; c <= col.maxCounts; c++) { 71 | System.out.printf(" %2d %10d %12.1f%n", c, col.counts[c], 72 | n * col.poisson.prob(c)); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Collision.res: -------------------------------------------------------------------------------- 1 | Total CPU time: 0:2:10.30 2 | 3 | REPORT on Tally stat. collector ==> Statistics on collisions 4 | num. obs. min max average variance standard dev. 5 | 10000000 0.000 35.000 12.270 11.486 3.389 6 | 95.0% confidence interval for mean (student): ( 12.268, 12.272 ) 7 | 8 | Theoretical mean: lambda = 12.5 9 | 10 | Counters: 11 | c count Poisson expect. 12 | 13 | 0 38 37.3 14 | 1 434 465.8 15 | 2 2723 2911.4 16 | 3 11484 12131.0 17 | 4 37026 37909.5 18 | 5 94979 94773.7 19 | 6 203417 197445.2 20 | 7 367006 352580.7 21 | 8 580943 550907.3 22 | 9 810835 765149.1 23 | 10 1011875 956436.4 24 | 11 1142790 1086859.5 25 | 12 1177523 1132145.3 26 | 13 1112732 1088601.3 27 | 14 973037 971965.4 28 | 15 786828 809971.2 29 | 16 593843 632790.0 30 | 17 420342 465286.7 31 | 18 278264 323115.8 32 | 19 173779 212576.2 33 | 20 102864 132860.1 34 | 21 57597 79083.4 35 | 22 30800 44933.8 36 | 23 15519 24420.5 37 | 24 7390 12719.0 38 | 25 3384 6359.5 39 | 26 1526 3057.5 40 | 27 620 1415.5 41 | 28 251 631.9 42 | 29 104 272.4 43 | 30 47 113.5 44 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Collision.txt: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> Statistics on collisions 2 | num. obs. min max average standard dev. 3 | 100000 1.000 29.000 12.271 3.380 4 | 95.0% confidence interval for mean (student): ( 12.250, 12.292 ) 5 | 6 | Theoretical mean: 12.5 7 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/CompareOutputs.java: -------------------------------------------------------------------------------- 1 | package tutorial; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.junit.runners.Parameterized; 6 | import org.junit.runners.Parameterized.*; 7 | import java.io.File; 8 | import java.io.IOException; 9 | import java.util.regex.Pattern; 10 | import java.util.Collection; 11 | import java.util.Arrays; 12 | 13 | @RunWith(Parameterized.class) 14 | public class CompareOutputs { 15 | 16 | final static Pattern ignorePat = Pattern.compile(".*(\\bCPU time|\\bEfficiency ratio).*"); 17 | 18 | @Parameters 19 | public static Collection data() { 20 | return Arrays.asList(new Object[][] { 21 | { "tutorial", AsianGBM.class, null }, 22 | { "tutorial", AsianGBMQMC.class, null }, 23 | { "tutorial", BankEv.class, null }, 24 | { "tutorial", CallCenter.class, new String[]{"tutorial/CallCenter.dat"} }, 25 | // { "tutorial", Collision.class, null }, 26 | { "tutorial", InventoryCRN.class, null }, 27 | { "tutorial", Inventory.class, null }, 28 | // { "tutorial", Nonuniform.class, null }, 29 | { "tutorial", PreyPred.class, null }, 30 | { "tutorial", QueueEv.class, null }, 31 | { "tutorial", QueueLindley.class, null }, 32 | { "tutorial", QueueObs.class, null }, 33 | // { "probdistmulti/norta", ExampleNortaInitDisc.class, null } 34 | }); 35 | } 36 | 37 | private String prefix; 38 | private Class targetClass; 39 | private String[] args; 40 | 41 | // Constructor. 42 | public CompareOutputs(String prefix, Class targetClass, String[] args) { 43 | this.prefix = prefix; 44 | this.targetClass = targetClass; 45 | this.args = args; 46 | } 47 | 48 | @Test 49 | public void runTutorialClass() throws RunClass.RunClassException, IOException { 50 | String expected = RunClass.readFile(new File(prefix, targetClass.getSimpleName() + ".res")); 51 | String actual = RunClass.run(targetClass, args); 52 | RunClass.compareLineByLine(targetClass.getName(), expected, actual, ignorePat); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Inventory.res: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> stats on profit 2 | num. obs. min max average variance standard dev. 3 | 500 83.969 85.753 84.961 0.105 0.324 4 | 90.0% conf. interval for the mean (Student approx.): ( 84.938, 84.985 ) 5 | 6 | Total CPU time: 0:0:0.17 7 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Inventory.txt: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> stats on profit 2 | num. obs. min max average standard dev. 3 | 500 83.969 85.753 84.961 0.324 4 | 90.0% confidence interval for mean (student): ( 84.938, 84.985 ) 5 | 6 | Total CPU time: 0:0:0.14 7 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/InventoryCRN.java: -------------------------------------------------------------------------------- 1 | package tutorial; 2 | import umontreal.ssj.stat.Tally; 3 | import umontreal.ssj.util.Chrono; 4 | 5 | // Class to simulate and compare two different (S,s) policies with CRNs. 6 | public class InventoryCRN extends Inventory { 7 | 8 | Tally statDiff = new Tally ("stats on difference"); 9 | 10 | public InventoryCRN (double lambda, double c, double h, 11 | double K, double k, double p) { 12 | super (lambda, c, h, K, k, p); 13 | } 14 | 15 | public void simulateDiff (int n, int m, int s1, int S1, int s2, int S2) { 16 | statDiff.init(); 17 | for (int i = 0; i < n; i++) { 18 | double value1 = simulate (m, s1, S1); 19 | double value2 = simulate (m, s2, S2); 20 | statDiff.add (value2 - value1); 21 | } 22 | } 23 | 24 | public void simulateDiffCRN (int n, int m, int s1, int S1, int s2, int S2) { 25 | statDiff.init(); 26 | streamDemand.resetStartStream(); 27 | streamOrder.resetStartStream(); 28 | for (int i = 0; i < n; i++) { 29 | double value1 = simulate (m, s1, S1); 30 | streamDemand.resetStartSubstream(); 31 | streamOrder.resetStartSubstream(); 32 | double value2 = simulate (m, s2, S2); 33 | statDiff.add (value2 - value1); 34 | streamDemand.resetNextSubstream(); 35 | streamOrder.resetNextSubstream(); 36 | } 37 | } 38 | 39 | public static void main (String[] args) { 40 | InventoryCRN system = new InventoryCRN (100.0, 2.0, 0.1, 10.0, 1.0, 0.95); 41 | Chrono timer = new Chrono(); 42 | 43 | system.simulateDiff (500, 2000, 80, 198, 80, 200); 44 | system.statDiff.setConfidenceIntervalStudent(); 45 | System.out.println (system.statDiff.report (0.9, 3)); 46 | double varianceIndep = system.statDiff.variance(); 47 | System.out.println ("Total CPU time: " + timer.format() + "\n"); 48 | 49 | timer.init(); 50 | system.simulateDiffCRN (500, 2000, 80, 198, 80, 200); 51 | System.out.println (system.statDiff.report (0.9, 3)); 52 | double varianceCRN = system.statDiff.variance(); 53 | System.out.println ("Total CPU time: " + timer.format()); 54 | System.out.printf ("Variance ratio: %8.4g%n", varianceIndep/varianceCRN); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/InventoryCRN.res: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> stats on difference 2 | num. obs. min max average variance standard dev. 3 | 500 -1.032 1.822 0.320 0.233 0.483 4 | 90.0% conf. interval for the mean (Student approx.): ( 0.285, 0.356 ) 5 | 6 | Total CPU time: 0:0:0.22 7 | 8 | REPORT on Tally stat. collector ==> stats on difference 9 | num. obs. min max average variance standard dev. 10 | 500 -0.017 0.649 0.308 0.012 0.108 11 | 90.0% conf. interval for the mean (Student approx.): ( 0.300, 0.316 ) 12 | 13 | Total CPU time: 0:0:0.19 14 | Variance ratio: 19.95 15 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/InventoryCRN.txt: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> stats on difference 2 | num. obs. min max average standard dev. 3 | 5000 -4.961 5.737 0.266 1.530 4 | 90.0% confidence interval for mean (student): ( 0.230, 0.302 ) 5 | 6 | Total CPU time: 0:0:0.19 7 | 8 | REPORT on Tally stat. collector ==> stats on difference 9 | num. obs. min max average standard dev. 10 | 5000 -1.297 2.124 0.315 0.352 11 | 90.0% confidence interval for mean (student): ( 0.307, 0.324 ) 12 | 13 | Total CPU time: 0:0:0.16 14 | Variance ratio: 18.85 15 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Nonuniform.res: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> null 2 | num. obs. min max average variance standard dev. 3 | 100000 0.0 9890.2 685.6 606102.1 778.5 4 | 5 | 0.10 quantile: 9.4 6 | 0.50 quantile: 439.1 7 | 0.90 quantile: 1693.5 8 | 0.99 quantile: 3501.5 9 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Nonuniform.txt: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> null 2 | num. obs. min max average standard dev. 3 | 10000 0.000 15839.396 1000.890 1285.771 4 | 5 | 0.10 quantile: 9.485 6 | 0.50 quantile: 545.338 7 | 0.90 quantile: 2628.177 8 | 0.99 quantile: 5860.238 9 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/PreyPred.java: -------------------------------------------------------------------------------- 1 | package tutorial; 2 | import umontreal.ssj.simevents.*; 3 | 4 | public class PreyPred { 5 | double r = 0.005, c = 0.00001, 6 | s = 0.01, d = 0.000005, h = 5.0; 7 | double x0 = 2000.0, z0 = 150.0; 8 | double horizon = 501.0; 9 | Simulator sim = new Simulator(); 10 | Continuous x; 11 | Continuous z; 12 | 13 | public static void main (String[] args) { new PreyPred(); } 14 | 15 | public PreyPred() { 16 | x = new Preys(sim); 17 | z = new Preds(sim); 18 | sim.init(); 19 | new EndOfSim(sim).schedule (horizon); 20 | new PrintPoint(sim).schedule (h); 21 | (sim.continuousState()).selectRungeKutta4 (h); 22 | x.startInteg (x0); 23 | z.startInteg (z0); 24 | sim.start(); 25 | } 26 | 27 | public class Preys extends Continuous { 28 | public Preys(Simulator sim) { super(sim); } 29 | 30 | public double derivative (double t) { 31 | return (r * value() - c * value() * z.value()); 32 | } 33 | } 34 | 35 | public class Preds extends Continuous { 36 | public Preds(Simulator sim) { super(sim); } 37 | 38 | public double derivative (double t) { 39 | return (-s * value() + d * x.value() * value()); 40 | } 41 | } 42 | 43 | class PrintPoint extends Event { 44 | public PrintPoint(Simulator sim) { super(sim); } 45 | public void actions() { 46 | System.out.println (sim.time() + " " + x.value() + " " + z.value()); 47 | this.schedule (h); 48 | } 49 | } 50 | 51 | class EndOfSim extends Event { 52 | public EndOfSim(Simulator sim) { super(sim); } 53 | public void actions() { sim.stop(); } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/QueueEv.java: -------------------------------------------------------------------------------- 1 | package tutorial; 2 | import umontreal.ssj.simevents.*; 3 | import umontreal.ssj.rng.*; 4 | import umontreal.ssj.randvar.*; 5 | import umontreal.ssj.stat.*; 6 | import java.util.LinkedList; 7 | 8 | public class QueueEv { 9 | 10 | RandomVariateGen genArr; 11 | RandomVariateGen genServ; 12 | LinkedList waitList = new LinkedList (); 13 | LinkedList servList = new LinkedList (); 14 | Tally custWaits = new Tally ("Waiting times"); 15 | Accumulate totWait = new Accumulate ("Size of queue"); 16 | 17 | class Customer { double arrivTime, servTime; } 18 | 19 | public QueueEv (double lambda, double mu) { 20 | genArr = new ExponentialGen (new MRG32k3a(), lambda); 21 | genServ = new ExponentialGen (new MRG32k3a(), mu); 22 | } 23 | 24 | public void simulate (double timeHorizon) { 25 | Sim.init(); 26 | new EndOfSim().schedule (timeHorizon); 27 | new Arrival().schedule (genArr.nextDouble()); 28 | Sim.start(); 29 | } 30 | 31 | class Arrival extends Event { 32 | public void actions() { 33 | new Arrival().schedule (genArr.nextDouble()); // Next arrival. 34 | Customer cust = new Customer(); // Cust just arrived. 35 | cust.arrivTime = Sim.time(); 36 | cust.servTime = genServ.nextDouble(); 37 | if (servList.size() > 0) { // Must join the queue. 38 | waitList.addLast (cust); 39 | totWait.update (waitList.size()); 40 | } else { // Starts service. 41 | custWaits.add (0.0); 42 | servList.addLast (cust); 43 | new Departure().schedule (cust.servTime); 44 | } 45 | } 46 | } 47 | 48 | class Departure extends Event { 49 | public void actions() { 50 | servList.removeFirst(); 51 | if (waitList.size() > 0) { 52 | // Starts service for next one in queue. 53 | Customer cust = waitList.removeFirst(); 54 | totWait.update (waitList.size()); 55 | custWaits.add (Sim.time() - cust.arrivTime); 56 | servList.addLast (cust); 57 | new Departure().schedule (cust.servTime); 58 | } 59 | } 60 | } 61 | 62 | class EndOfSim extends Event { 63 | public void actions() { 64 | Sim.stop(); 65 | } 66 | } 67 | 68 | public static void main (String[] args) { 69 | QueueEv queue = new QueueEv (1.0, 2.0); 70 | queue.simulate (1000.0); 71 | System.out.println (queue.custWaits.report()); 72 | System.out.println (queue.totWait.report()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/QueueEv.res: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> Waiting times 2 | num. obs. min max average variance standard dev. 3 | 1037 0.000 6.262 0.495 0.697 0.835 4 | 5 | REPORT on Accumulate stat. collector ==> Size of queue 6 | from time to time min max average 7 | 0.00 1000.00 0.000 10.000 0.513 8 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/QueueEv.txt: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> Waiting times 2 | num. obs. min max average standard dev. 3 | 1037 0.000 6.262 0.495 0.835 4 | 5 | REPORT on Accumulate stat. collector ==> Size of queue 6 | from time to time min max average 7 | 0.00 1000.00 0.000 10.000 0.513 8 | 9 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/QueueLindley.java: -------------------------------------------------------------------------------- 1 | package tutorial; 2 | import umontreal.ssj.stat.*; 3 | import umontreal.ssj.rng.*; 4 | import umontreal.ssj.probdist.ExponentialDist; 5 | import umontreal.ssj.util.Chrono; 6 | 7 | public class QueueLindley { 8 | 9 | RandomStream streamArr = new MRG32k3a(); 10 | RandomStream streamServ = new MRG32k3a(); 11 | Tally averageWaits = new Tally ("Average waits"); 12 | 13 | public double simulate (int numCust, double lambda, double mu) { 14 | double Wi = 0.0; 15 | double sumWi = 0.0; 16 | for (int i = 2; i <= numCust; i++) { 17 | Wi += ExponentialDist.inverseF (mu, streamServ.nextDouble()) - 18 | ExponentialDist.inverseF (lambda, streamArr.nextDouble()); 19 | if (Wi < 0.0) Wi = 0.0; 20 | sumWi += Wi; 21 | } 22 | return sumWi / numCust; 23 | } 24 | 25 | public void simulateRuns (int n, int numCust, double lambda, double mu) { 26 | averageWaits.init(); 27 | for (int i=0; i Average waits 2 | num. obs. min max average variance standard dev. 3 | 100 0.428 0.591 0.506 7.5E-4 0.027 4 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/QueueLindley.txt: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> Average waits 2 | num. obs. min max average standard dev. 3 | 100 0.428 0.591 0.506 0.027 4 | 5 | Total CPU time: 0:0:0.18 6 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/QueueObs.res: -------------------------------------------------------------------------------- 1 | Customer 0 waited 0.0 time units. 2 | Customer 5 waited 0.7326681134344923 time units. 3 | Customer 10 waited 0.5885316645668064 time units. 4 | Customer 15 waited 1.043252136439675 time units. 5 | Customer 20 waited 0.0 time units. 6 | Customer 25 waited 1.1931739005489084 time units. 7 | Customer 30 waited 0.46021574329744774 time units. 8 | Customer 35 waited 0.0 time units. 9 | Customer 40 waited 0.0 time units. 10 | Customer 45 waited 0.0 time units. 11 | Customer 50 waited 0.252307672226395 time units. 12 | Customer 55 waited 0.07427782294905083 time units. 13 | Customer 60 waited 0.5994090559375538 time units. 14 | Customer 65 waited 0.0 time units. 15 | Customer 70 waited 0.0 time units. 16 | Customer 75 waited 0.0 time units. 17 | Customer 80 waited 0.0 time units. 18 | Customer 85 waited 0.007945837364173702 time units. 19 | Customer 90 waited 0.0 time units. 20 | Customer 95 waited 0.0 time units. 21 | Customer 100 waited 0.5757258813866157 time units. 22 | Customer 5 waited 0.0 time units. 23 | Customer 10 waited 0.0 time units. 24 | Customer 15 waited 0.0 time units. 25 | Customer 20 waited 0.3735196841043573 time units. 26 | Customer 25 waited 0.7395881102279829 time units. 27 | Customer 30 waited 0.0 time units. 28 | Customer 35 waited 0.0 time units. 29 | Customer 40 waited 0.0 time units. 30 | Customer 45 waited 0.0 time units. 31 | Customer 50 waited 0.0 time units. 32 | Customer 55 waited 0.0 time units. 33 | Customer 60 waited 0.0 time units. 34 | Customer 65 waited 0.0 time units. 35 | Customer 70 waited 0.0 time units. 36 | Customer 75 waited 0.0031920235804928088 time units. 37 | Customer 80 waited 0.0 time units. 38 | Customer 85 waited 0.0 time units. 39 | Customer 90 waited 0.0 time units. 40 | Customer 95 waited 0.0 time units. 41 | Customer 100 waited 0.6060216943922617 time units. 42 | 43 | 44 | REPORT on Tally stat. collector ==> Average wait 45 | num. obs. min max average variance standard dev. 46 | 2 0.200 0.405 0.303 0.021 0.145 47 | 48 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/QueueObs.txt: -------------------------------------------------------------------------------- 1 | Customer 0 waited 0.0 time units. 2 | Customer 5 waited 0.7326681134344923 time units. 3 | Customer 10 waited 0.5885316645668064 time units. 4 | Customer 15 waited 1.043252136439675 time units. 5 | Customer 20 waited 0.0 time units. 6 | Customer 25 waited 1.1931739005489084 time units. 7 | Customer 30 waited 0.46021574329744774 time units. 8 | Customer 35 waited 0.0 time units. 9 | Customer 40 waited 0.0 time units. 10 | Customer 45 waited 0.0 time units. 11 | Customer 50 waited 0.252307672226395 time units. 12 | Customer 55 waited 0.07427782294905083 time units. 13 | Customer 60 waited 0.5994090559375538 time units. 14 | Customer 65 waited 0.0 time units. 15 | Customer 70 waited 0.0 time units. 16 | Customer 75 waited 0.0 time units. 17 | Customer 80 waited 0.0 time units. 18 | Customer 85 waited 0.007945837364173702 time units. 19 | Customer 90 waited 0.0 time units. 20 | Customer 95 waited 0.0 time units. 21 | Customer 100 waited 0.5757258813866157 time units. 22 | Customer 5 waited 0.0 time units. 23 | Customer 10 waited 0.0 time units. 24 | Customer 15 waited 0.0 time units. 25 | Customer 20 waited 0.3735196841043573 time units. 26 | Customer 25 waited 0.7395881102279829 time units. 27 | Customer 30 waited 0.0 time units. 28 | Customer 35 waited 0.0 time units. 29 | Customer 40 waited 0.0 time units. 30 | Customer 45 waited 0.0 time units. 31 | Customer 50 waited 0.0 time units. 32 | Customer 55 waited 0.0 time units. 33 | Customer 60 waited 0.0 time units. 34 | Customer 65 waited 0.0 time units. 35 | Customer 70 waited 0.0 time units. 36 | Customer 75 waited 0.0031920235804928088 time units. 37 | Customer 80 waited 0.0 time units. 38 | Customer 85 waited 0.0 time units. 39 | Customer 90 waited 0.0 time units. 40 | Customer 95 waited 0.0 time units. 41 | Customer 100 waited 0.6060216943922617 time units. 42 | 43 | 44 | REPORT on Tally stat. collector ==> Average wait 45 | num. obs. min max average standard dev. 46 | 2 0.200 0.405 0.303 0.145 47 | 48 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Snippet.java: -------------------------------------------------------------------------------- 1 | package tutorial; 2 | 3 | public class Snippet { 4 | public static void main(String[] args) { 5 | // package tutorial; 6 | 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/Visits.txt: -------------------------------------------------------------------------------- 1 | REPORT on Tally stat. collector ==> Nb. of visitors lost per day 2 | num. obs. min max average standard dev. 3 | 100 3.000 48.000 21.780 10.639 4 | 90.0% confidence interval for mean (student): ( 20.014, 23.546 ) 5 | 6 | -------------------------------------------------------------------------------- /src/main/docs/examples/tutorial/san13a.dat: -------------------------------------------------------------------------------- 1 | NormalDist (13.0, 3.25) 2 | NormalDist (5.5, 1.375) 3 | ExponentialDistFromMean (7.0) 4 | NormalDist (5.2, 1.3) 5 | ExponentialDistFromMean (16.5) 6 | ExponentialDistFromMean (14.7) 7 | ExponentialDistFromMean (10.3) 8 | ExponentialDistFromMean (6.0) 9 | ExponentialDistFromMean (4.0) 10 | ExponentialDistFromMean (20.0) 11 | NormalDist (3.2, 0.8) 12 | NormalDist (3.2, 0.8) 13 | ExponentialDistFromMean (16.5) 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/docs/images/charts_exam_BoxTest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umontreal-simul/ssj/98d9a6af7f68b1a96ffd8fb41d3d490020eead5d/src/main/docs/images/charts_exam_BoxTest.png -------------------------------------------------------------------------------- /src/main/docs/mathjax_config.js: -------------------------------------------------------------------------------- 1 | MathJax.Hub.Config({ 2 | tex2jax: { 3 | skipTags: ["script","noscript","style","textarea","pre"] 4 | } 5 | }); -------------------------------------------------------------------------------- /src/main/docs/ssj.css: -------------------------------------------------------------------------------- 1 | /* LaTeX-like elements */ 2 | .SSJ-minipage { display: inline-block; } 3 | .SSJ-bigskip { margin-top: 3ex; } 4 | .SSJ-medskip { margin-top: 2ex; } 5 | .SSJ-smallskip { margin-top: 1ex; } 6 | .SSJ-fbox { border: 2px solid #ccc; } 7 | 8 | 9 | /* Tables */ 10 | 11 | /* defaults */ 12 | .SSJ-table { border-collapse: collapse; margin: 1ex; } 13 | .SSJ-table td { padding: 3px; border: none; } 14 | 15 | /* font (inherit from ) */ 16 | code .SSJ-table { font-family: monospace; } 17 | 18 | /* alignment */ 19 | .SSJ-table td.l { text-align: left; } 20 | .SSJ-table td.c { text-align: center; } 21 | .SSJ-table td.r { text-align: right; } 22 | 23 | /* borders */ 24 | .SSJ-table td.bl { border-left: 1px solid black; } 25 | .SSJ-table td.br { border-right: 1px solid black; } 26 | .SSJ-table td.bb { border-bottom: 1px solid black; } 27 | .SSJ-table td.bt { border-top: 1px solid black; } 28 | .SSJ-table tr.bb td { border-bottom: 1px solid black; } 29 | .SSJ-table tr.bt td { border-top: 1px solid black; } 30 | 31 | /* force bottom border on last table row */ 32 | .SSJ-has-hlines tr:last-child td { border-bottom: 1px solid black; } 33 | 34 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/discrepancy/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.discrepancy 3 | * 4 | * Methods to compute various types of discrepancies for quasi-Monte Carlo point sets. 5 | * 6 | * These old classes are specialized to specific types of discrepancies and are not necessarily 7 | * the most efficient and general. For more recent and efficient tools, see the @ref latnetbuilder package. 8 | * 9 | */ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functionfit/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.functionfit 3 | * 4 | * Function fit utilities. 5 | * 6 | * This package provides basic facilities for curve fitting and interpolation 7 | * with polynomials as, for example, least square fit, spline interpolation, 8 | * and smoothing splines. 9 | * 10 | */ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/IdentityMathFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: IdentityMathFunction 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.functions; 26 | 27 | /** 28 | * Represents the identity function @f$f(x)=x@f$. 29 | * 30 | *
31 | */ 32 | public class IdentityMathFunction implements MathFunction 33 | 34 | , 35 | MathFunctionWithFirstDerivative, MathFunctionWithDerivative, 36 | MathFunctionWithIntegral { 37 | public double evaluate (double x) { 38 | return x; 39 | } 40 | 41 | public double derivative (double x) { 42 | return 1; 43 | } 44 | 45 | public double derivative (double x, int n) { 46 | return n > 1 ? 0 : 1; 47 | } 48 | 49 | public double integral (double a, double b) { 50 | return (b*b - a*a) / 2; 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/MathFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: MathFunction 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.functions; 26 | 27 | /** 28 | * This interface should be implemented by classes which represent univariate 29 | * mathematical functions. It is used to pass an arbitrary function of one 30 | * variable as argument to another function. For example, it is used in 31 | * @ref umontreal.ssj.util.RootFinder to find the zeros of a function. 32 | * 33 | *
34 | */ 35 | public interface MathFunction { 36 | 37 | /** 38 | * Returns the value of the function evaluated at @f$x@f$. 39 | * @param x value at which the function is evaluated 40 | * @return function evaluated at `x` 41 | */ 42 | public double evaluate (double x); 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/MathFunctionWithDerivative.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: MathFunctionWithDerivative 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.functions; 26 | 27 | /** 28 | * Represents a mathematical function whose @f$n@f$th derivative can be 29 | * computed using #derivative(double,int). 30 | * 31 | *
32 | */ 33 | public interface MathFunctionWithDerivative extends MathFunction { 34 | 35 | /** 36 | * Computes (or estimates) the @f$n@f$th derivative of the function at point 37 | * `x`. For @f$n=0@f$, this returns the result of 38 | * umontreal.ssj.functions.MathFunction.evaluate(double). 39 | * @param x the point to evaluate the derivate to. 40 | * @param n the order of the derivative. 41 | * @return the resulting derivative. 42 | * 43 | * @exception IllegalArgumentException if `n` is negative or 0. 44 | */ 45 | public double derivative (double x, int n); 46 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/MathFunctionWithFirstDerivative.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: MathFunctionWithFirstDerivative 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.functions; 26 | 27 | /** 28 | * Represents a mathematical function whose derivative can be computed using 29 | * #derivative(double). 30 | * 31 | *
32 | */ 33 | public interface MathFunctionWithFirstDerivative extends MathFunction { 34 | 35 | /** 36 | * Computes (or estimates) the first derivative of the function at point `x`. 37 | * @param x the point to evaluate the derivative to. 38 | * @return the value of the derivative. 39 | */ 40 | public double derivative (double x); 41 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/MathFunctionWithIntegral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: MathFunctionWithIntegral 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.functions; 26 | 27 | /** 28 | * Represents a mathematical function whose integral can be computed by the 29 | * #integral(double,double) method. 30 | * 31 | *
32 | */ 33 | public interface MathFunctionWithIntegral extends MathFunction { 34 | 35 | /** 36 | * Computes (or estimates) the integral of the function over the interval 37 | * @f$[a, b]@f$. 38 | * @param a the starting point of the interval. 39 | * @param b the ending point of the interval. 40 | * @return the value of the integral. 41 | */ 42 | public double integral (double a, double b); 43 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/MultiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: MultiFunction 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Richard Simard 9 | * @since May 2013 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.functions; 26 | 27 | /** 28 | * This interface should be implemented by classes which represent 29 | * *multivariate* mathematical functions. It is used to pass an arbitrary 30 | * function of a vector variable as argument to another function. 31 | * 32 | *
33 | */ 34 | public interface MultiFunction { 35 | 36 | /** 37 | * Returns the value of the function evaluated at @f$X@f$. 38 | * @param X point at which the function is evaluated 39 | * @return value of function at `X` 40 | */ 41 | public double evaluate (double[] X); 42 | 43 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/PiecewiseConstantFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: PiecewiseConstantFunction 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.functions; 26 | 27 | import java.util.Arrays; 28 | 29 | /** 30 | * Represents a piecewise-constant function. 31 | * 32 | *
33 | */ 34 | public class PiecewiseConstantFunction implements MathFunction { 35 | private double[] x; 36 | private double[] y; 37 | 38 | /** 39 | * Constructs a new piecewise-constant function with @f$X@f$ and @f$Y@f$ 40 | * coordinates given by `x` and `y`. 41 | * @param x the @f$X@f$ coordinates. 42 | * @param y the @f$Y@f$ coordinates. 43 | */ 44 | public PiecewiseConstantFunction (double[] x, double[] y) { 45 | if (x.length != y.length) 46 | throw new IllegalArgumentException(); 47 | this.x = x.clone (); 48 | this.y = y.clone (); 49 | } 50 | 51 | /** 52 | * Returns the @f$X@f$ coordinates of the function. 53 | * @return the @f$X@f$ coordinates of the function. 54 | */ 55 | public double[] getX() { 56 | return x.clone (); 57 | } 58 | 59 | /** 60 | * Returns the @f$Y@f$ coordinates of the function. 61 | * @return the @f$Y@f$ coordinates of the function. 62 | */ 63 | public double[] getY() { 64 | return y.clone (); 65 | } 66 | 67 | 68 | public double evaluate (double x) { 69 | final int idx = Arrays.binarySearch (this.x, x); 70 | if (idx >= 0) 71 | return y[idx]; 72 | final int insertionPoint = -(idx + 1); 73 | return y[insertionPoint]; 74 | } 75 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/ShiftedMathFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: ShiftedMathFunction 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.functions; 26 | 27 | /** 28 | * Represents a function computing @f$f(x) - \delta@f$ for a user-defined 29 | * function @f$f(x)@f$ and shift @f$\delta@f$. 30 | * 31 | *
32 | */ 33 | public class ShiftedMathFunction implements MathFunction 34 | 35 | , 36 | MathFunctionWithFirstDerivative, MathFunctionWithDerivative, 37 | MathFunctionWithIntegral { 38 | MathFunction func; 39 | double delta; 40 | 41 | /** 42 | * Constructs a new function shifting the function `func` by a shift `delta`. 43 | * @param func the function. 44 | * @param delta the shift. 45 | */ 46 | public ShiftedMathFunction (MathFunction func, double delta) { 47 | if (func == null) 48 | throw new NullPointerException (); 49 | this.func = func; 50 | this.delta = delta; 51 | } 52 | 53 | /** 54 | * Returns the function @f$f(x)@f$. 55 | * @return the function. 56 | */ 57 | public MathFunction getFunction () { 58 | return func; 59 | } 60 | 61 | /** 62 | * Returns the shift @f$\delta@f$ = `delta`. 63 | * @return the shift. 64 | */ 65 | public double getDelta () { 66 | return delta; 67 | } 68 | 69 | 70 | public double evaluate (double x) { 71 | return func.evaluate (x) - delta; 72 | } 73 | 74 | public double derivative (double x) { 75 | return MathFunctionUtil.derivative (func, x); 76 | } 77 | 78 | public double derivative (double x, int n) { 79 | return MathFunctionUtil.derivative (func, x, n); 80 | } 81 | 82 | public double integral (double a, double b) { 83 | return MathFunctionUtil.integral (func, a, b) - (b - a)*getDelta(); 84 | } 85 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/SqrtMathFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: SqrtMathFunction 3 | * Description: function computing the square root of another function 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.functions; 26 | 27 | /** 28 | * Represents a function computing the square root of another function 29 | * @f$f(x)@f$. 30 | * 31 | *
32 | */ 33 | public class SqrtMathFunction implements MathFunction { 34 | private MathFunction func; 35 | 36 | /** 37 | * Computes and returns the square root of the function `func`. 38 | * @param func the function to compute square root for. 39 | */ 40 | public SqrtMathFunction (MathFunction func) { 41 | super (); 42 | if (func == null) 43 | throw new NullPointerException(); 44 | this.func = func; 45 | } 46 | 47 | /** 48 | * Returns the function associated with this object. 49 | * @return the associated function. 50 | */ 51 | public MathFunction getFunction() { 52 | return func; 53 | } 54 | 55 | 56 | public double evaluate (double x) { 57 | return Math.sqrt (func.evaluate (x)); 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/functions/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.functions 3 | * 4 | * Univariate functions as Java objects. 5 | * 6 | * This package contains a few utilities classes representing univariate 7 | * mathematical functions. They are useful, for example, when one wants to 8 | * pass an arbitrary function of one variable as argument to a method. They 9 | * allow one to apply mathematical operations like squaring, power, etc. on 10 | * generic functions. There are also utilities for numerical differentiation 11 | * and integration. 12 | */ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/hups/EmptyRandomization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: EmptyRandomization 3 | * Description: implements an empty PointSetRandomization 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.hups; 26 | // import umontreal.ssj.rng.MRG32k3a; 27 | import umontreal.ssj.rng.RandomStream; 28 | 29 | /** 30 | * This class implements an empty 31 | * @ref umontreal.ssj.hups.PointSetRandomization. The method 32 | * #randomize(PointSet) does nothing. The internal stream is never used. This 33 | * class can be used in methods where a randomization is needed but you don’t 34 | * want one. 35 | * 36 | *
37 | */ 38 | public class EmptyRandomization implements PointSetRandomization { 39 | protected RandomStream stream; // = new MRG32k3a(); 40 | 41 | /** 42 | * This method does nothing. 43 | * @param p Point set to randomize 44 | */ 45 | public void randomize (PointSet p) { 46 | // Does nothing 47 | } 48 | 49 | /** 50 | * Sets the internal @ref umontreal.ssj.rng.RandomStream to `stream`. 51 | * @param stream stream to use in the randomization 52 | */ 53 | public void setStream (RandomStream stream) { 54 | this.stream = stream; 55 | } 56 | 57 | /** 58 | * Returns the internal @ref umontreal.ssj.rng.RandomStream. 59 | * @return stream used in the randomization 60 | */ 61 | public RandomStream getStream() { 62 | return stream; 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/hups/PointSetRandomization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface: PointSetRandomization 3 | * Description: Used to randomize a PointSet 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001--2018 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.hups; 26 | import umontreal.ssj.rng.RandomStream; 27 | 28 | /** 29 | * This interface is for a *randomization* that can be used to 30 | * randomize a @ref umontreal.ssj.hups.PointSet. 31 | * One can implement method #randomize(PointSet) in any way. This method 32 | * must use an internal @ref umontreal.ssj.rng.RandomStream. This stream can 33 | * be set in the constructor, but the methods #getStream and 34 | * #setStream(RandomStream) must also be implemented. 35 | * 36 | * The method #randomize(PointSet) can be implemented using combinations of 37 | * the randomization methods from the point set such as 38 | * umontreal.ssj.hups.PointSet.addRandomShift, 39 | * umontreal.ssj.hups.DigitalNet.leftMatrixScramble, 40 | * umontreal.ssj.hups.DigitalNet.stripedMatrixScramble, etc. 41 | * 42 | *
43 | */ 44 | public interface PointSetRandomization { 45 | 46 | /** 47 | * This method must randomize `p`. 48 | * @param p Point set to randomize 49 | */ 50 | public void randomize (PointSet p); 51 | 52 | /** 53 | * Sets the internal @ref umontreal.ssj.rng.RandomStream to `stream`. 54 | * @param stream stream to use in the randomization 55 | */ 56 | public void setStream (RandomStream stream); 57 | 58 | /** 59 | * Returns the internal @ref umontreal.ssj.rng.RandomStream. 60 | * @return stream used in the randomization 61 | */ 62 | public RandomStream getStream(); 63 | 64 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/hups/dataLFSR/j1_k11.dat: -------------------------------------------------------------------------------- 1 | #-------------------------------------------------------# 2 | # Equidistributed LFSR generator with one composent 3 | # Criteria : DELTA(k,k,k/2) <= 1 4 | #-------------------------------------------------------# 5 | # Format : 6 | # 7 | # Number Of Component (only at the beginning of the file) 8 | # 9 | # Comments (value of the criteria) 10 | # s 11 | # Non-zeros coefficients of the polynomial 12 | #-------------------------------------------------------# 13 | 14 | 15 | 1 16 | 17 | # DELTA = 1 18 | 5 19 | 11 5 3 1 0 20 | 21 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/hups/dataLFSR/j2_k17.dat: -------------------------------------------------------------------------------- 1 | #-------------------------------------------------------# 2 | # Equidistributed LFSR Generator with 2 composents 3 | # Criteria : DELTA(k,k,k/2) <= 1 4 | #-------------------------------------------------------# 5 | # Format : 6 | # 7 | # Number Of Component (only at the beginning of the file 8 | # 9 | # Comments (value of the criteria) 10 | # s1 s2 11 | # Non-zeros coefficients of the first polynomial 12 | # Non-zeros coefficients of the second polynomial 13 | #-------------------------------------------------------# 14 | 15 | 2 16 | 17 | #DELTA = 1 18 | 4 2 19 | 7 1 0 20 | 10 4 3 1 0 21 | 22 | #DELTA = 1 23 | 1 4 24 | 7 1 0 25 | 10 4 3 1 0 26 | 27 | #DELTA = 1 28 | 5 7 29 | 6 1 0 30 | 11 4 2 1 0 31 | 32 | #DELTA = 1 33 | 2 3 34 | 6 1 0 35 | 11 5 3 2 0 36 | 37 | #DELTA = 1 38 | 2 8 39 | 6 1 0 40 | 11 2 0 41 | 42 | #DELTA = 1 43 | 1 4 44 | 6 1 0 45 | 11 4 2 1 0 46 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/hups/dataLFSR/j2_k19.dat: -------------------------------------------------------------------------------- 1 | #-------------------------------------------------------# 2 | # Equidistributed LFSR Generator with 2 composents 3 | # Criteria : DELTA(k,k,k/2) <= 1 4 | #-------------------------------------------------------# 5 | # Format : 6 | # 7 | # Number Of Component (only at the beginning of the file 8 | # 9 | # Comments (value of the criteria) 10 | # s1 s2 11 | # Non-zeros coefficients of the first polynomial 12 | # Non-zeros coefficients of the second polynomial 13 | #-------------------------------------------------------# 14 | 15 | 2 16 | 17 | #DELTA = 1 18 | 5 4 19 | 9 4 0 20 | 10 4 3 1 0 21 | 22 | #DELTA = 1 23 | 2 4 24 | 9 4 0 25 | 10 3 0 26 | 27 | #DELTA = 1 28 | 1 5 29 | 6 1 0 30 | 13 6 4 1 0 31 | 32 | #DELTA = 1 33 | 2 4 34 | 6 1 0 35 | 13 6 4 1 0 36 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/hups/dataSer/Nieder/NiedSequenceBase2.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umontreal-simul/ssj/98d9a6af7f68b1a96ffd8fb41d3d490020eead5d/src/main/java/umontreal/ssj/hups/dataSer/Nieder/NiedSequenceBase2.ser -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/hups/dataSer/Nieder/NiedXingSequenceBase2Trans.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/umontreal-simul/ssj/98d9a6af7f68b1a96ffd8fb41d3d490020eead5d/src/main/java/umontreal/ssj/hups/dataSer/Nieder/NiedXingSequenceBase2Trans.ser -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/latnetbuilder/OrdinaryLatticeSearch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: OrdinaryLatticeSearch 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2018 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Maxime Godin and Pierre Marion 9 | * @since August 2018 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | 26 | package umontreal.ssj.latnetbuilder; 27 | 28 | import umontreal.ssj.hups.Rank1Lattice; 29 | 30 | import java.util.ArrayList; 31 | 32 | /** 33 | * Class for the search of good rank-1 ordinary lattice rules using LatNet Builder. 34 | */ 35 | public class OrdinaryLatticeSearch extends Search{ 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public Rank1Lattice search() throws RuntimeException 42 | { 43 | ArrayList res = executeCommandLine(); 44 | int numPoints = Integer.parseInt(res.get(1).split(" //")[0]); 45 | int dimension = Integer.parseInt(res.get(2).split(" //")[0]); 46 | int[] genVec = new int[dimension]; 47 | for(int coord = 0; coord < dimension; ++coord){ 48 | genVec[coord] = Integer.parseInt(res.get(5 + coord).split(" //")[0]); 49 | } 50 | this.merit = Double.parseDouble(res.get(5 + dimension).split(" //")[0]); 51 | this.time = Double.parseDouble(res.get(6 + dimension).split(" //")[0]); 52 | this.successful = true; 53 | return new Rank1Lattice(numPoints, genVec, dimension); 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Override 60 | public String pointSetType() 61 | { 62 | return "lattice"; 63 | } 64 | 65 | /** 66 | * {@inheritDoc} 67 | */ 68 | @Override 69 | public String interlacing() 70 | { 71 | return "1"; 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | */ 77 | @Override 78 | public String construction(){ 79 | return "ordinary"; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/latnetbuilder/PolynomialLatticeSearch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: PolynomialLatticeSearch 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2018 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Maxime Godin and Pierre Marion 9 | * @since August 2018 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | 26 | package umontreal.ssj.latnetbuilder; 27 | 28 | /** 29 | * Class for the search of good polynomial lattice rules using LatNet Builder. 30 | */ 31 | public class PolynomialLatticeSearch extends DigitalNetSearch{ 32 | 33 | String pointSetType; 34 | 35 | /** 36 | * Constructor. 37 | * @param pointSetType Point set type (lattice or net). Used to switch between 38 | * the two implementation of polynomial lattice rules in LatNet Builder. 39 | */ 40 | public PolynomialLatticeSearch(String pointSetType){ 41 | super("polynomial"); 42 | this.pointSetType = pointSetType; 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public String pointSetType(){ 50 | return pointSetType; 51 | } 52 | 53 | /** 54 | * Changes the point set type to use when searching. 55 | * @param pointSetType Point set type (lattice or net). 56 | */ 57 | public void changePointSetTypeView(String pointSetType) 58 | { 59 | this.pointSetType = pointSetType; 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | public void setConstruction(String construction) { 67 | return; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/latnetbuilder/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.latnetbuilder 3 | * 4 | * Tools to search for good quasi-Monte Carlo point sets and sequences 5 | * defined as integration lattices, polynomial lattices, and digital nets (and sequences). 6 | * 7 | * @anchor REF_latnetbuilder_overview_sec_overview 8 | * 9 | * This package provides an interface to the *LatNet Builder* software to search for good 10 | * quasi-Monte Carlo point sets and sequences (or HUPS) of various types 11 | * (lattices, polynomial lattices, digital nets, etc.) for arbitrary dimension and cardinality, 12 | * various uniformity criteria, etc. 13 | * For this package to work, the `LatNet Builder` software must be installed and the path to it must be set correctly 14 | * inside the class @ref Search. 15 | * @remark This would need to be made more easily portable in the future. 16 | * 17 | * See @cite vLEC12a, @cite vLEC16a, and 18 | * [https://github.com/umontreal-simul/latnetbuilder](https://github.com/umontreal-simul/latnetbuilder) 19 | * for more details on `LatNet Builder` and its ancestor `Lattice Builder`. 20 | * 21 | * Important note: `LatNet Builder` 22 | * does not run directly under the *Windows* operating system, 23 | * because it is uses the NTL library, which does not run under Windows. 24 | * Running it under Windows requires some sort of virtual machine, as explained in the 25 | * `LatNet Builder` documentation. 26 | * 27 | * 28 | * # Examples 29 | * 30 | * @anchor REF_latnetbuilder_overview_sec_examples 31 | * 32 | * The following examples show how to use this package. (To do... ) 33 | * 34 | * 35 | */ 36 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/latnetbuilder/weights/SingletonWeight.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.latnetbuilder.weights; 2 | 3 | /** 4 | * Implements a single instance of a weight for search-algorithms for quasi-Monte Carlo point sets 5 | * as, e.g., those implemented in *LatNet Builder*. The template parameter 'T' indicates the data type of the 6 | * underlying index. Common choices are integers (e.g. the order for @ref OrderDependentWeights) or 7 | * @ref CoordinateSet (e.g. the projection for @ref ProjectionDependentWeights), etc. 8 | * 9 | * @author florian 10 | * 11 | *@param indicates the data type of the index of the weight (e.g. @ref CoordinateSet, @ref Integer,...). 12 | */ 13 | 14 | public class SingletonWeight { 15 | 16 | 17 | protected T index; 18 | protected double weight; 19 | 20 | /** 21 | * Constructs a weight with given 'index' and 'weight'. 22 | * @param ind the desired index. 23 | * @param w the desired value for the weight. 24 | */ 25 | SingletonWeight(T ind, double w){ 26 | index = ind; 27 | weight = w; 28 | } 29 | 30 | /** 31 | * Returns the current 'index'. 32 | * @return the index of the weight. 33 | */ 34 | public T getIndex() { 35 | return index; 36 | } 37 | 38 | /** 39 | * Sets the index of the weight to 'ind'. 40 | * @param ind the desired value for the 'index'. 41 | */ 42 | public void setIndex(T ind) { 43 | index = ind; 44 | } 45 | 46 | /** 47 | * Returns the current value of the weight. 48 | * @return the value of the weight. 49 | */ 50 | public double getWeight() { 51 | return weight; 52 | } 53 | 54 | /** 55 | * Sets the value of the weight to 'w'. 56 | * @param w desired value for the weight 57 | */ 58 | public void setWeight(double w) { 59 | weight = w; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/latnetbuilder/weights/SingletonWeightComparable.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.latnetbuilder.weights; 2 | 3 | /** 4 | * Implements single instances of weights. The template parameter 'T' indicates the 5 | * data type of the associated index, for instance, 'Integer' for the order of 6 | * an @ref OrderDependentWeight. In contrast to its superclass @ref SingletonWeight, 7 | * weights from this class can be compared via an ordering defined on 'T'. 8 | * 9 | * @author florian 10 | * 11 | * @param indicates the data type of the index of the weight (e.g. @ref Integer,...). 12 | * This data type needs to be comparable. 13 | */ 14 | 15 | public class SingletonWeightComparable> extends SingletonWeight implements Comparable>{ 16 | 17 | /** 18 | * Constructs a single comparable weight with given 'index' and 'weight'. 19 | * @param ind the desired index. 20 | * @param w the desired value for the weight. 21 | */ 22 | SingletonWeightComparable(T ind, double w){ 23 | super(ind,w); 24 | } 25 | 26 | 27 | 28 | /** 29 | * Method to be able to compare the current weight to another based on the ordering 30 | * defined on 'T'. This enables sorting the weights by their index. 31 | */ 32 | public int compareTo (SingletonWeightComparable w) { 33 | return getIndex().compareTo(w.getIndex()); 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/markovchainrqmc/MarkovChainComparable.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.markovchainrqmc; 2 | import umontreal.ssj.util.sort.MultiDimComparable; 3 | 4 | /** 5 | * A subclass of `MarkovChain` for which there is a total ordering between the 6 | * states, induced by the implementation of the 7 | * @ref umontreal.ssj.util.MultiDimComparable interface. A list or 8 | * array of `MarkovChainComparable` objects can be sorted according to their states at a 9 | * given step, using a @ref umontreal.ssj.util.MultiDimComparator and an 10 | * external sorting method. 11 | * 12 | * The method `compareTo(MarkovChainComparable m, int i)` must return a 13 | * negative integer, zero, or a positive integer, and `this` Markov chain 14 | * is considered smaller than, equal to, or greater than the other chain `m` in dimension 15 | * `i`. The meaning of smaller, equal or larger is very flexible as well as 16 | * the meaning of dimension. 17 | * 18 | * Concrete subclasses must implement `compareTo` and must initialize 19 | * the variable `stateDim` in the constructor to the value of the state 20 | * dimension. It can be understood as the largest integer `j` for which the 21 | * method `compareTo(m,j)` can be called. They must also implement abstract 22 | * methods of `MarkovChain`. 23 | * 24 | *
25 | */ 26 | public abstract class MarkovChainComparable extends MarkovChain 27 | implements MultiDimComparable 28 | { 29 | 30 | public int stateDim; // Dimension of the state 31 | 32 | /** 33 | * Returns the dimension of the state. 34 | */ 35 | public int getStateDimension() { 36 | return stateDim; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/MonteCarloModel.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools; 2 | 3 | import umontreal.ssj.rng.*; 4 | 5 | /** 6 | * An interface for a simple simulation model for which Monte Carlo (MC) or RQMC 7 | * experiments are to be performed. It generalizes @ref MonteCarloModelDouble. 8 | * This interface allows the output (performance) from the model to be of arbitrary type `E`. 9 | * It could be a scalar, an array, etc. 10 | */ 11 | 12 | public interface MonteCarloModel { 13 | 14 | // Optional 15 | // public void simulate (); 16 | 17 | /** 18 | * Simulates the model for one run. 19 | */ 20 | public void simulate (RandomStream stream); 21 | 22 | /** 23 | * Recovers and returns the realization of the performance measure, of type E. 24 | */ 25 | public E getPerformance(); 26 | 27 | /** 28 | * Returns a short description of the model and its parameters. 29 | */ 30 | public String toString(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/MonteCarloModelCV.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools; 2 | 3 | /** 4 | * An extension of @ref MonteCarloModelDouble that also implements a vector of control variates. 5 | */ 6 | 7 | public interface MonteCarloModelCV extends MonteCarloModelDouble { 8 | 9 | /** 10 | * Recovers the realizations of the control variates for the the last run. 11 | */ 12 | public double[] getValuesCV(); 13 | 14 | /** 15 | * Returns the number of control variates. 16 | */ 17 | public int getNumberCV(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/MonteCarloModelDensityKnown.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools; 2 | 3 | 4 | /** 5 | * An interface for a simulation model for which Monte Carlo (MC) and RQMC 6 | * experiments are to be performed. This interface is used by the classes 7 | * MCExperimentDensity and RQMCExperimentDensity, among others, 8 | * to run the model. The interface assumes that the output from the model is a random 9 | * variable X with known density and pdf (for the purpose of the experiment). 10 | */ 11 | 12 | public interface MonteCarloModelDensityKnown extends MonteCarloModelDouble { 13 | 14 | /** 15 | * Recovers the density of X evaluated at x. 16 | * @param x the point at which the density is evaluated. 17 | * @return density \f$f(x)\f$. 18 | */ 19 | public double density(double x); 20 | 21 | /** 22 | * Recovers the cumulative density function (cdf) of \f$X\f$ evaluated at \f$x\f$ 23 | * @param x the point at which the cdf shall be evaluated. 24 | * @return the cdf at \f$x\f$. 25 | */ 26 | public double cdf(double x); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/MonteCarloModelDouble.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools; 2 | import umontreal.ssj.rng.*; 3 | 4 | /** 5 | * An interface for a very simple simulation model for which Monte Carlo (MC) and RQMC 6 | * experiments are to be performed. This interface is used by the classes 7 | * @ref MonteCarloExperiment and @ref RQMCExperiment, among others, to run the model. 8 | * This interface assumes that the simulation requires a single `RandomStream` and that 9 | * the output (sample performance) from the model is a real-valued random variable @f$X@f$. 10 | * We could have asked `simulate` to return the performance to avoid a 11 | * separate call to `getPerformance`, but we decided not, 12 | * because in some situations one may not always need the performance computed 13 | * by `getPerformance`, which might be costly to compute for nothing, 14 | * but only some other output information. 15 | * This also applies to @ref MonteCarloModel. 16 | */ 17 | 18 | public interface MonteCarloModelDouble { 19 | 20 | // Optional 21 | // public void simulate (); 22 | 23 | /** 24 | * Simulates the model for one run 25 | */ 26 | public void simulate (RandomStream stream); 27 | 28 | /** 29 | * Recovers and returns the realization of the performance measure, of type `double`. 30 | */ 31 | public double getPerformance(); 32 | 33 | /** 34 | * Returns a short description of the model and its parameters. 35 | */ 36 | public String toString(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/MonteCarloModelDoubleArray.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools; 2 | import umontreal.ssj.rng.*; 3 | 4 | /** 5 | * Similar to @ref MonteCarloModelDouble except that the returned performance is an array of real numbers. 6 | * The dimension of that array must be returned by `getPerformanceDim()`. 7 | */ 8 | 9 | public interface MonteCarloModelDoubleArray { 10 | 11 | // Optional 12 | // public void simulate (); 13 | 14 | /** 15 | * Simulates the model for one run. 16 | */ 17 | public void simulate (RandomStream stream); 18 | 19 | /** 20 | * Recovers and returns the realization of the vector of performance measures. 21 | */ 22 | public double[] getPerformance(); 23 | 24 | /** 25 | * Returns the dimension of the array of performance measures. 26 | */ 27 | public int getPerformanceDim(); 28 | 29 | /** 30 | * Returns a short description of the model and its parameters. 31 | */ 32 | public String toString(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/AnovaObserver.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | /** 4 | * ANOVA observer. 5 | * An AnovaVarianceCollector object notifies its observers when it is updated. 6 | * 7 | */ 8 | public interface AnovaObserver { 9 | public void anovaUpdated(AnovaVarianceCollector anova); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/BasicObservationCollector.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | /** 4 | * Does nothing but counting the total number of observations. 5 | * Provides useful functionality for deriving classes. 6 | * 7 | * Deriving classes overriding methods, e.g. init() or add(), must call their parent's versions. 8 | * 9 | */ 10 | public class BasicObservationCollector implements ObservationCollector { 11 | 12 | protected String label; 13 | protected int nObservations; 14 | 15 | public BasicObservationCollector() { 16 | this(null); 17 | } 18 | 19 | /** 20 | * @param label label describing the collector 21 | * 22 | */ 23 | public BasicObservationCollector(String label) { 24 | this.label = label; 25 | nObservations = 0; 26 | } 27 | 28 | public String getLabel() { 29 | return label; 30 | } 31 | 32 | public int getNumObservations() { 33 | return nObservations; 34 | } 35 | 36 | /** 37 | * Resets the collector. Forgets all previous observations. 38 | * 39 | */ 40 | public void init() { 41 | nObservations = 0; 42 | } 43 | 44 | /** 45 | * Updates the number of observations. 46 | * 47 | */ 48 | public void observe(E observation) { 49 | nObservations++; 50 | } 51 | 52 | /** 53 | * Returns a report of measurements on the data collected by the collector. 54 | * 55 | */ 56 | public Report report() { 57 | String collectorLabel = (label == null) ? this.getClass().getSimpleName() : label; 58 | Report r = new Report(collectorLabel); 59 | r.add("number of observations", getNumObservations()); 60 | return r; 61 | } 62 | 63 | public String toString() { 64 | return "Basic Observation Collector"; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/Integrator.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import umontreal.ssj.mcqmctools.MonteCarloModel; 4 | import umontreal.ssj.mcqmctools.MonteCarloModelDouble; 5 | import umontreal.ssj.stat.Tally; 6 | import umontreal.ssj.stat.list.ListOfTallies; 7 | 8 | public interface Integrator { 9 | 10 | /** 11 | * Returns the number of points per integral. 12 | * 13 | */ 14 | public int getNumPoints(); 15 | 16 | /** 17 | * Returns the total number of times the model is simulated per call to an integrate() 18 | * method. 19 | * 20 | */ 21 | public int getTotalSimulations(); 22 | 23 | /** 24 | * Integrates a model by means of simulation. 25 | * 26 | * The output values are added to the statistical collector \c statValue. 27 | * 28 | */ 29 | public void integrate (MonteCarloModelDouble model, Tally statValue); 30 | 31 | /** 32 | * Shorthand to integrate without having to pass a Tally object. 33 | * 34 | */ 35 | public double integrate (MonteCarloModelDouble model); 36 | 37 | /** 38 | * Integrates a model by means of simulation. 39 | * 40 | * The output values are added to the statistical collector \c statValue. 41 | * 42 | */ 43 | public void integrate (MonteCarloModel model, ListOfTallies stat); 44 | 45 | /** 46 | * Shorthand to integrate without having to pass a ListOfTallies object. 47 | * 48 | */ 49 | public void integrate (MonteCarloModel model, double[] values); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/MonteCarloModelDoubleRQMC.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import umontreal.ssj.mcqmctools.*; 4 | 5 | /** 6 | * An interface for a simple simulation model for which Monte Carlo (MC) or RQMC 7 | * experiments are to be performed. It generalizes @ref MonteCarloModelDouble. 8 | * This interface allows the output (performance) from the model to be of arbitrary type @ref E. 9 | * It could be a scalar, an array, etc. 10 | */ 11 | 12 | public interface MonteCarloModelDoubleRQMC extends MonteCarloModelDouble { 13 | 14 | // Optional 15 | // public void simulate (); 16 | 17 | /** 18 | * Returns the number of uniforms required to simulate this model. 19 | */ 20 | public int getDimension (); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/MonteCarloModelRQMC.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import umontreal.ssj.mcqmctools.*; 4 | 5 | /** 6 | * An interface for a simple simulation model for which Monte Carlo (MC) or RQMC 7 | * experiments are to be performed. It generalizes @ref MonteCarloModelDouble. 8 | * This interface allows the output (performance) from the model to be of arbitrary type @ref E. 9 | * It could be a scalar, an array, etc. 10 | */ 11 | 12 | public interface MonteCarloModelRQMC extends MonteCarloModel { 13 | 14 | // Optional 15 | // public void simulate (); 16 | 17 | /** 18 | * Returns the number of uniforms required to simulate this model. 19 | */ 20 | public int getDimension (); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/ObservationCollector.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | public interface ObservationCollector { 4 | 5 | /** 6 | * Clears all observations. 7 | * 8 | */ 9 | public void init(); 10 | 11 | /** 12 | * Adds an observation. 13 | * 14 | */ 15 | public void observe(E obs); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/ObservationCollectorList.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class ObservationCollectorList extends ArrayList> 6 | implements ObservationCollector { 7 | 8 | public ObservationCollectorList() { 9 | super(); 10 | } 11 | 12 | public ObservationCollectorList(int initialCapacity) { 13 | super(initialCapacity); 14 | } 15 | 16 | public void init() { 17 | for (ObservationCollector collector : this) 18 | collector.init(); 19 | } 20 | 21 | public void observe(E obs) { 22 | for (ObservationCollector collector : this) 23 | collector.observe(obs); 24 | } 25 | 26 | public String toString() { 27 | String s = "List of Observation Collectors: "; 28 | for (ObservationCollector collector : this) 29 | s = s + collector.toString() + ", "; 30 | return s; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/PartialVariance.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import umontreal.ssj.stat.Tally; 4 | 5 | 6 | /** 7 | * Represents the partial variance of a function with respect to a given coordinate set. 8 | * 9 | */ 10 | public class PartialVariance extends Tally implements Comparable { 11 | 12 | protected CoordinateSet coords; 13 | protected Tally totalVar; 14 | 15 | protected PartialVariance(CoordinateSet coords) { 16 | this(coords, null); 17 | } 18 | 19 | protected PartialVariance(CoordinateSet coords, Tally totalVar) { 20 | super("variance for coordinates " + coords); 21 | this.coords = coords; 22 | this.totalVar = totalVar; 23 | } 24 | 25 | /** 26 | * Returns the coordinate set associated with the current partial variance. 27 | * 28 | */ 29 | public CoordinateSet getCoordinates() { 30 | return coords; 31 | } 32 | 33 | /** 34 | * Returns the sensitivity index (fraction of the total variance) of the coordinate set under 35 | * consideration. 36 | * 37 | * Throws an IllegalStateException if the total variance is not set. 38 | * Should be overridden in deriving classes. 39 | */ 40 | public double sensitivityIndex() { 41 | 42 | if (totalVar == null) 43 | throw new IllegalStateException("trying to access the sensitivity index without" 44 | + " a reference to the total variance"); 45 | 46 | return average() / totalVar.average(); 47 | } 48 | 49 | /** 50 | * Returns 1, 0 or -1 if the current partial variance is larger, equal or smaller than the 51 | * partial variance \c var, respectively. 52 | * 53 | */ 54 | public int compareTo(PartialVariance var) { 55 | double v = average(); 56 | double vx = var.average(); 57 | return v > vx ? 1 : v < vx ? -1 : 0; 58 | } 59 | 60 | @Override public String toString() { 61 | 62 | String s = String.format("%30s: %9.4g", coords.toString(), average()); 63 | 64 | if (numberObs() > 1) { 65 | double dvar = Math.sqrt(variance() / numberObs()); 66 | s += String.format(" ± %.2g", dvar); 67 | } 68 | 69 | if (totalVar != null) { 70 | double varFrac = sensitivityIndex(); 71 | if (varFrac >= 0) 72 | s += String.format(" (%.4g %%)", 100 * varFrac); 73 | } 74 | 75 | return s; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/QMCSampler.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import umontreal.ssj.stat.Tally; 4 | import umontreal.ssj.hups.*; 5 | import umontreal.ssj.mcqmctools.*; 6 | 7 | /** 8 | * QMC sampler. 9 | * 10 | * The samples produced by this sampler are deterministic. 11 | * 12 | */ 13 | public class QMCSampler implements Sampler { 14 | 15 | protected PointSet points; 16 | 17 | public QMCSampler (PointSet points) { 18 | this.points = points; 19 | } 20 | 21 | public PointSet getPointSet() { 22 | return points; 23 | } 24 | 25 | /** @copydoc Sampler::getNumSimulationsPerSample() */ 26 | public int getNumSimulationsPerSample() { 27 | return 1; 28 | } 29 | 30 | /** @copydoc Sampler::getNumSamples() */ 31 | public int getNumSamples() { 32 | return points.getNumPoints(); 33 | } 34 | 35 | /** @copydoc Sampler::simulate(MonteCarloModel, ObservationCollector) */ 36 | public void simulateRuns (MonteCarloModel model, ObservationCollector collector) { 37 | 38 | for (PointSetIterator it = points.iterator(); it.hasNextPoint(); it.resetToNextPoint()) { 39 | model.simulate(it); 40 | collector.observe(model.getPerformance()); 41 | } 42 | } 43 | 44 | /** @copydoc Sampler::simulate(MonteCarloModelDouble, ObservationCollector) */ 45 | public void simulateRuns (MonteCarloModelDouble model, Tally collector) { 46 | for (PointSetIterator it = points.iterator(); it.hasNextPoint(); it.resetToNextPoint()) { 47 | model.simulate(it); 48 | collector.add(model.getPerformance()); 49 | } 50 | } 51 | 52 | @Override public String toString() { 53 | return "QMC Sampler [nPoints=" + points.getNumPoints() + "]" 54 | + " [points=" + points.getClass().getSimpleName() + "]"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/RandomIntegrator.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import umontreal.ssj.rng.RandomStream; 4 | 5 | public interface RandomIntegrator extends Integrator { 6 | /** 7 | * Use \c stream as the source of randomness. 8 | * 9 | */ 10 | public void setStream(RandomStream stream); 11 | 12 | /** 13 | * Returns the currently used random stream. May be \c null. 14 | * 15 | */ 16 | public RandomStream getStream(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/RandomSampler.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import umontreal.ssj.rng.RandomStream; 4 | 5 | public interface RandomSampler extends Sampler { 6 | /** 7 | * Use \c stream as the source of randomness. 8 | * 9 | */ 10 | public void setStream(RandomStream stream); 11 | 12 | /** 13 | * Returns the currently used random stream. May be \c null. 14 | * 15 | */ 16 | public RandomStream getStream(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/Sampler.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import umontreal.ssj.mcqmctools.MonteCarloModel; 4 | import umontreal.ssj.mcqmctools.MonteCarloModelDouble; 5 | import umontreal.ssj.stat.*; 6 | 7 | public interface Sampler { 8 | /** 9 | * Returns the number of times the model is simulated each time a sample is produced. 10 | * 11 | */ 12 | public int getNumSimulationsPerSample(); 13 | 14 | /** 15 | * Returns the number of samples produced each time the simulateRuns() method is called. 16 | * 17 | */ 18 | public int getNumSamples(); 19 | 20 | /** 21 | * Simulates the model multiple times. 22 | * 23 | * The samples are added to the observation collector \c collector. 24 | * 25 | */ 26 | public void simulateRuns (MonteCarloModel model, ObservationCollector collector); 27 | 28 | /** 29 | * Simulates the model multiple times. 30 | * 31 | * The samples are added to the collector \c collector. 32 | * 33 | */ 34 | public void simulateRuns (MonteCarloModelDouble model, Tally collector); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/SplitStream.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.mcqmctools.anova; 2 | 3 | import umontreal.ssj.rng.*; 4 | 5 | 6 | /** 7 | * Implements a random stream that mixes two input streams by using a coordinate mask. 8 | * 9 | */ 10 | public class SplitStream extends RandomStreamBase { 11 | 12 | protected int curCoordIndex; 13 | protected CoordinateSet coords; 14 | protected double[] vals; 15 | 16 | /** 17 | * Reads 2 * nCache values from a a stream and stores them for future use. 18 | * 19 | * When nextValue() is called, a value is popped from the 2 * nCache 20 | * cached values at even indices for the coordinates contained in the 21 | * coordinate set \c coords, and at odd indices otherwise. 22 | * 23 | */ 24 | public SplitStream(RandomStream stream, int nCache) { 25 | this.vals = new double[2 * nCache]; 26 | this.curCoordIndex = 0; 27 | this.coords = null; 28 | stream.nextArrayOfDouble(vals, 0, 2 * nCache); 29 | } 30 | 31 | public SplitStream(double[] vals) { 32 | this.curCoordIndex = 0; 33 | this.coords = null; 34 | this.vals = vals; 35 | } 36 | 37 | public SplitStream clone() { 38 | SplitStream s = new SplitStream(vals.clone()); 39 | s.curCoordIndex = curCoordIndex; 40 | s.coords = coords; 41 | return s; 42 | } 43 | 44 | public void setCoordinates(CoordinateSet coords) { 45 | this.coords = coords; 46 | } 47 | 48 | public CoordinateSet getCoordinates() { 49 | return coords; 50 | } 51 | 52 | @Override protected double nextValue() { 53 | int a = (coords != null && coords.contains(curCoordIndex)) ? 0 : 1; 54 | return vals[2*(curCoordIndex++) + a]; 55 | //return vals[a*vals.length/2 + (curCoordIndex++)]; 56 | } 57 | 58 | @Override public void resetNextSubstream() { 59 | throw new UnsupportedOperationException(); 60 | } 61 | 62 | @Override public void resetStartStream() { 63 | throw new UnsupportedOperationException(); 64 | } 65 | 66 | @Override public void resetStartSubstream() { 67 | curCoordIndex = 0; 68 | } 69 | 70 | @Override public String toString() { 71 | return getClass().getSimpleName() + " [nCache=" + (vals.length/2) + "]"; 72 | } 73 | } 74 | 75 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/anova/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.mcqmctools.anova 3 | * 4 | * Tools to estimate ANOVA components for Monte Carlo models. 5 | * 6 | * @anchor REF_mcqmctools.anova_overview_sec_overview 7 | * 8 | * This package offers tools to estimate ANOVA components for Monte Carlo models. 9 | * It is not yet fully integrated with the rest of SSJ, and this is why some SSJ classes 10 | * are duplicated here: these are different (older) versions of these classes. 11 | * 12 | * (To do...) 13 | * 14 | * 15 | * 16 | * # Examples 17 | * 18 | * @anchor REF_mcqmctools.anova_overview_sec_examples 19 | * 20 | * The following examples show how to use this package. (To do... ) 21 | * 22 | * 23 | */ 24 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/mcqmctools/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.mcqmctools 3 | * 4 | * Tools for Simple Monte Carlo and Quasi-Monte Carlo Experiments. 5 | * 6 | * @anchor REF_mcqmctools_overview_sec_overview 7 | * 8 | * This package offers elementary tools to help perform Monte Carlo and 9 | * quasi-Monte Carlo experiments with simple stochastic simulation models. 10 | * To use these tools, the simulation model must be represented in a class that 11 | * implements the @ref MonteCarloModel interface. This interface requires in particular a method 12 | * `simulate` that simulates the model and a method `getPerformance` to recover the performance 13 | * measure(s) (or data) generated by the simulation. This *performance* can be any type of object. 14 | * In the subclass @ref MonteCarloModelDouble, it assumed to be a real number; this is the simplest case. 15 | * In the class @ref MonteCarloModelDoubleArray, the returned performance is assumed to be a 16 | * `double[]` array, so a vector of several measures can be returned for each simulation run. 17 | * In @ref MonteCarloModelCV, it is assumed that the simulation produces a real-valued performance, 18 | * plus a vector of zero-mean control variates. 19 | * 20 | * The class @ref MonteCarloExperiment provides methods to perform a simulation experiment that 21 | * simulates the model for `n` independent runs and recover the data in statistical collectors, 22 | * compute confidence intervals, make histograms, scatter plots, print a report, etc. 23 | * 24 | * The class @ref RQMCExperiment provides tools to perform similar experiments with 25 | * randomized quasi-Monte Carlo (RQMC) instead. In an RQMC experiment, one simulates the system 26 | * `n` times, using an RQMC point set of size `n`, and this is repeated `m` times by 27 | * randomizing the point set independently for each of the `m` replications. 28 | * 29 | * @ref RQMCExperimentSeries offers tools to perform RQMC experiments for a series of several values of `n`, 30 | * for example all powers of 2 in some interval, in order to study the behavior of RQMC estimators 31 | * as a function of `n`. For example, one might be interested in estimating how the variance 32 | * (and in some cases the bias) converges as a function of `n`, and perhaps plot it in log-log scale. 33 | * 34 | * 35 | * 36 | * # Examples 37 | * 38 | * @anchor REF_markovchainrqmc_overview_sec_examples 39 | * 40 | * The following examples show how to use this package. (To do... ) 41 | * 42 | * 43 | */ 44 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/probdist/ConstantIntDist.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: ConstantIntDist 3 | * Description: constant integer distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.probdist; 26 | 27 | /** 28 | * Represents a *constant* discrete distribution taking a single integer 29 | * value with probability 1. Its mass function is 30 | * @anchor REF_probdist_ConstantIntDist_eq_fconsint 31 | * @f[ 32 | * p(x) = \left\{\begin{array}{ll} 33 | * 1, 34 | * & 35 | * \qquad\mbox{for } x = c, 36 | * \\ 37 | * 0, 38 | * & 39 | * \qquad\mbox{elsewhere. } 40 | * \end{array}\right. \tag{fconsint} 41 | * @f] 42 | * Its distribution function is 43 | * @anchor REF_probdist_ConstantIntDist_eq_cdfconsint 44 | * @f[ 45 | * F(x) = \left\{\begin{array}{ll} 46 | * 0, 47 | * & 48 | * \qquad\mbox{ for } x < c 49 | * \\ 50 | * 1, 51 | * & 52 | * \qquad\mbox{ for } x \ge c. 53 | * \end{array}\right. \tag{cdfconsint} 54 | * @f] 55 | *
56 | * 57 | * @ingroup probdist_discrete 58 | */ 59 | public class ConstantIntDist extends UniformIntDist { 60 | 61 | /** 62 | * Constructs a new constant distribution with probability 1 at `c`. 63 | */ 64 | public ConstantIntDist (int c) { 65 | super (c, c); 66 | } 67 | 68 | /** 69 | * Returns a `String` containing information about the current 70 | * distribution. 71 | */ 72 | public String toString () { 73 | return getClass().getSimpleName() + " : c = " + i; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/probdist/ExponentialDistFromMean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: ExponentialDistFromMean 3 | * Description: exponential distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.probdist; 26 | 27 | /** 28 | * Extends the @ref ExponentialDist class with a constructor accepting as 29 | * argument the mean @f$1/\lambda@f$ instead of the rate @f$\lambda@f$. 30 | * 31 | *
32 | * 33 | * @ingroup probdist_continuous 34 | */ 35 | public class ExponentialDistFromMean extends ExponentialDist { 36 | 37 | /** 38 | * Constructs a new exponential distribution with mean `mean`. 39 | * @param mean the required mean. 40 | */ 41 | public ExponentialDistFromMean (double mean) { 42 | super (1.0 / mean); 43 | } 44 | 45 | /** 46 | * Calls umontreal.ssj.probdist.ExponentialDist.setLambda(double) with 47 | * argument `1/mean` to change the mean of this distribution. 48 | * @param mean the new mean. 49 | */ 50 | public void setMean (double mean) { 51 | setLambda (1.0 / mean); 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/probdist/GammaDistFromMoments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: GammaDistFromMoments 3 | * Description: gamma distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.probdist; 26 | 27 | /** 28 | * Extends the @ref GammaDist distribution with constructors accepting the 29 | * mean @f$\mu@f$ and variance @f$\sigma^2@f$ as arguments instead of a 30 | * shape parameter @f$\alpha@f$ and a scale parameter @f$\lambda@f$. Since 31 | * @f$\mu=\alpha/ \lambda@f$, and @f$\sigma^2=\alpha/ \lambda^2@f$, the 32 | * shape and scale parameters are @f$\alpha=\mu^2 / \sigma^2@f$, and 33 | * @f$\lambda=\mu/ \sigma^2@f$, respectively. 34 | * 35 | *
36 | * 37 | * @ingroup probdist_continuous 38 | */ 39 | public class GammaDistFromMoments extends GammaDist { 40 | 41 | /** 42 | * Constructs a gamma distribution with mean `mean`, variance `var`, 43 | * and `d` decimal of precision. 44 | * @param mean the desired mean. 45 | * @param var the desired variance. 46 | * @param d the number of decimals of precision. 47 | */ 48 | public GammaDistFromMoments (double mean, double var, int d) { 49 | super (mean * mean / var, mean / var, d); 50 | } 51 | 52 | /** 53 | * Constructs a gamma distribution with mean `mean`, and variance 54 | * `var`. 55 | * @param mean the desired mean. 56 | * @param var the desired variance. 57 | */ 58 | public GammaDistFromMoments (double mean, double var) { 59 | super (mean * mean / var, mean / var); 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/probdist/LognormalDistFromMoments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: LognormalDistFromMoments 3 | * Description: lognormal distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.probdist; 26 | 27 | /** 28 | * Extends the @ref LognormalDist class with a constructor accepting the 29 | * mean @f$m@f$ and the variance @f$v@f$ of the distribution as arguments. 30 | * The mean and variance of a lognormal random variable with parameters 31 | * @f$\mu@f$ and @f$\sigma@f$ are @f$e^{\mu+\sigma^2/2}@f$ and 32 | * @f$e^{2\mu+ \sigma^2}(e^{\sigma^2} - 1)@f$ respectively, so the 33 | * parameters are given by 34 | * @f$\sigma=\sqrt{\ln(v/m^2+1)}@f$ 35 | * and @f$\mu=\ln(m) - \sigma^2/2@f$. 36 | * 37 | *
38 | * 39 | * @ingroup probdist_continuous 40 | */ 41 | public class LognormalDistFromMoments extends LognormalDist { 42 | public LognormalDistFromMoments (double mean, double var) { 43 | super (getMu (mean, var), Math.sqrt (getSigma2 (mean, var))); 44 | } 45 | 46 | private static double getMu (double mean, double var) { 47 | final double sigma2 = getSigma2 (mean, var); 48 | return Math.log (mean) - sigma2 / 2.0; 49 | } 50 | 51 | private static double getSigma2 (double mean, double var) { 52 | if (mean <= 0) 53 | throw new IllegalArgumentException ("Mean must be positive"); 54 | if (var <= 0) 55 | throw new IllegalArgumentException ("Variance must be positive"); 56 | return Math.log (var / (mean * mean) + 1); 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/randvar/BetaSymmetricalGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: BetaSymmetricalGen 3 | * Description: random variate generators for the symmetrical beta distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Richard Simard 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.randvar; 26 | import umontreal.ssj.rng.*; 27 | import umontreal.ssj.probdist.*; 28 | 29 | /** 30 | * This class implements random variate generators with the *symmetrical 31 | * beta* distribution with shape parameters @f$\alpha= \beta@f$, over the 32 | * interval @f$(0,1)@f$. 33 | * 34 | *
35 | * 36 | * @ingroup randvar_continuous 37 | */ 38 | public class BetaSymmetricalGen extends BetaGen { 39 | 40 | /** 41 | * Creates a new symmetrical beta generator with parameters 42 | * @f$\alpha=@f$ `alpha`, over the interval @f$(0,1)@f$, using stream 43 | * `s`. 44 | */ 45 | public BetaSymmetricalGen (RandomStream s, double alpha) { 46 | this (s, new BetaSymmetricalDist (alpha)); 47 | } 48 | 49 | /** 50 | * Creates a new generator for the distribution `dist`, using stream 51 | * `s`. 52 | */ 53 | public BetaSymmetricalGen (RandomStream s, BetaSymmetricalDist dist) { 54 | super (s, dist); 55 | } 56 | public static double nextDouble (RandomStream s, double alpha) { 57 | return BetaSymmetricalDist.inverseF (alpha, s.nextDouble()); 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/randvar/ConstantGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: ConstantGen 3 | * Description: random variate generator for a constant distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.randvar; 26 | 27 | /** 28 | * This class implements a random variate generator that returns a constant 29 | * value. Its mass function is 30 | * @anchor REF_randvar_ConstantGen_eq_randcons 31 | * @f[ 32 | * p(x) = \left\{\begin{array}{ll} 33 | * 1, 34 | * & 35 | * \qquad\mbox{for } x = c, 36 | * \\ 37 | * 0, 38 | * & 39 | * \qquad\mbox{elsewhere. } 40 | * \end{array}\right. \tag{randcons} 41 | * @f] 42 | *
43 | * 44 | * @ingroup randvar_continuous 45 | */ 46 | public class ConstantGen extends RandomVariateGen { 47 | private double val; 48 | 49 | /** 50 | * Constructs a new constant generator returning the given value `val`. 51 | */ 52 | public ConstantGen (double val) { 53 | this.val = val; 54 | } 55 | 56 | @Override 57 | public double nextDouble() { 58 | return val; 59 | } 60 | 61 | @Override 62 | public void nextArrayOfDouble (double[] v, int start, int n) { 63 | for (int i = 0; i < n; i++) 64 | v[start + i] = val; 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/randvar/JohnsonSBGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: JohnsonSBGen 3 | * Description: random variate generators for the Johnson $S_B$ distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.randvar; 26 | import umontreal.ssj.rng.*; 27 | import umontreal.ssj.probdist.*; 28 | 29 | /** 30 | * This class implements random variate generators for the Johnson 31 | * @f$S_B@f$ distribution. 32 | * 33 | *
34 | * 35 | * @ingroup randvar_continuous 36 | */ 37 | public class JohnsonSBGen extends JohnsonSystemG { 38 | 39 | /** 40 | * Creates a JohnsonSB random variate generator. 41 | */ 42 | public JohnsonSBGen (RandomStream s, double gamma, double delta, 43 | double xi, double lambda) { 44 | super (s, new JohnsonSBDist(gamma, delta, xi, lambda)); 45 | setParams (gamma, delta, xi, lambda); 46 | } 47 | 48 | /** 49 | * Creates a new generator for the JohnsonSB distribution `dist`, using 50 | * stream `s`. 51 | */ 52 | public JohnsonSBGen (RandomStream s, JohnsonSBDist dist) { 53 | super (s, dist); 54 | if (dist != null) 55 | setParams (dist.getGamma(), dist.getDelta(), dist.getXi(), 56 | dist.getLambda()); 57 | } 58 | 59 | /** 60 | * Uses inversion to generate a new JohnsonSB variate, using stream 61 | * `s`. 62 | */ 63 | public static double nextDouble (RandomStream s, double gamma, 64 | double delta, double xi, double lambda) { 65 | return JohnsonSBDist.inverseF (gamma, delta, xi, lambda, 66 | s.nextDouble()); 67 | } 68 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/randvar/JohnsonSLGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: JohnsonSLGen 3 | * Description: random variate generators for the Johnson $S_L$ distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Richard Simard 9 | * @since July 2012 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.randvar; 26 | import umontreal.ssj.rng.*; 27 | import umontreal.ssj.probdist.*; 28 | 29 | /** 30 | * This class implements random variate generators for the Johnson 31 | * @f$S_L@f$ distribution. 32 | * 33 | *
34 | * 35 | * @ingroup randvar_continuous 36 | */ 37 | public class JohnsonSLGen extends JohnsonSystemG { 38 | 39 | /** 40 | * Creates a JohnsonSL random variate generator. 41 | */ 42 | public JohnsonSLGen (RandomStream s, double gamma, double delta, 43 | double xi, double lambda) { 44 | super (s, new JohnsonSLDist(gamma, delta, xi, lambda)); 45 | setParams (gamma, delta, xi, lambda); 46 | } 47 | 48 | /** 49 | * Creates a new generator for the JohnsonSL distribution `dist`, using 50 | * stream `s`. 51 | */ 52 | public JohnsonSLGen (RandomStream s, JohnsonSLDist dist) { 53 | super (s, dist); 54 | if (dist != null) 55 | setParams (dist.getGamma(), dist.getDelta(), dist.getXi(), 56 | dist.getLambda()); 57 | } 58 | 59 | /** 60 | * Uses inversion to generate a new JohnsonSL variate, using stream 61 | * `s`. 62 | */ 63 | public static double nextDouble (RandomStream s, double gamma, 64 | double delta, double xi, double lambda) { 65 | return JohnsonSLDist.inverseF (gamma, delta, xi, lambda, 66 | s.nextDouble()); 67 | } 68 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/randvar/JohnsonSUGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: JohnsonSUGen 3 | * Description: random variate generators for the Johnson $S_U$ distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.randvar; 26 | import umontreal.ssj.rng.*; 27 | import umontreal.ssj.probdist.*; 28 | 29 | /** 30 | * This class implements random variate generators for the Johnson 31 | * @f$S_U@f$ distribution. 32 | * 33 | *
34 | * 35 | * @ingroup randvar_continuous 36 | */ 37 | public class JohnsonSUGen extends JohnsonSystemG { 38 | 39 | /** 40 | * Creates a JohnsonSU random variate generator. 41 | */ 42 | public JohnsonSUGen (RandomStream s, double gamma, double delta, 43 | double xi, double lambda) { 44 | super (s, new JohnsonSUDist(gamma, delta, xi, lambda)); 45 | setParams (gamma, delta, xi, lambda); 46 | } 47 | 48 | /** 49 | * Creates a new generator for the JohnsonSU distribution `dist`, using 50 | * stream `s`. 51 | */ 52 | public JohnsonSUGen (RandomStream s, JohnsonSUDist dist) { 53 | super (s, dist); 54 | if (dist != null) 55 | setParams (dist.getGamma(), dist.getDelta(), dist.getXi(), 56 | dist.getLambda()); 57 | } 58 | 59 | /** 60 | * Uses inversion to generate a new JohnsonSU variate, using stream 61 | * `s`. 62 | */ 63 | public static double nextDouble (RandomStream s, double gamma, 64 | double delta, double xi, double lambda) { 65 | return JohnsonSUDist.inverseF (gamma, delta, xi, lambda, 66 | s.nextDouble()); 67 | } 68 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/randvar/LognormalSpecialGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: LognormalSpecialGen 3 | * Description: random variates from the lognormal distribution 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.randvar; 26 | 27 | /** 28 | * Implements methods for generating random variates from the *lognormal* 29 | * distribution using an arbitrary normal random variate generator. The 30 | * (non-static) `nextDouble` method calls the `nextDouble` method of the 31 | * normal generator and takes the exponential of the result. 32 | * 33 | *
34 | * 35 | * @ingroup randvar_continuous 36 | */ 37 | public class LognormalSpecialGen extends RandomVariateGen { 38 | 39 | NormalGen myGen; 40 | 41 | /** 42 | * Create a lognormal random variate generator using the normal 43 | * generator `g` and with the same parameters. 44 | */ 45 | public LognormalSpecialGen (NormalGen g) { 46 | // Necessary to compile, but we do not want to use stream and dist 47 | super (g.stream, null); 48 | stream = null; 49 | myGen = g; 50 | } 51 | 52 | 53 | public double nextDouble() { 54 | return Math.exp (myGen.nextDouble()); 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/randvarmulti/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.randvarmulti 3 | * 4 | * Generating Random Vectors. 5 | * 6 | * This package provides a collection of classes for non-uniform random 7 | * variate generation, very similar to `randvar`, but for multivariate 8 | * distributions. 9 | */ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/rng/CloneableRandomStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: CloneableRandomStream 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.rng; 26 | 27 | /** 28 | * @ref CloneableRandomStream extends @ref RandomStream and Cloneable. All 29 | * classes that implements this interface are able to produce cloned objects. 30 | * 31 | * The cloned object is entirely independent of the older odject. Moreover 32 | * the cloned object has all the same properties as the older one. All his 33 | * seeds are duplicated, and therefore both generators will produce the same 34 | * random number sequence. 35 | * 36 | *
37 | */ 38 | public interface CloneableRandomStream extends RandomStream, Cloneable { 39 | 40 | /** 41 | * Clones the current object and returns its copy. 42 | * @return A deep copy of the current object 43 | */ 44 | public CloneableRandomStream clone(); 45 | 46 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/rng/RandomStreamFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: RandomStreamFactory 3 | * Description: random stream factory that can construct instances of 4 | a given type of random stream 5 | * Environment: Java 6 | * Software: SSJ 7 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 8 | * Organization: DIRO, Universite de Montreal 9 | * @author 10 | * @since 11 | * 12 | * 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | */ 26 | package umontreal.ssj.rng; 27 | 28 | import umontreal.ssj.rng.RandomStream; 29 | import umontreal.ssj.rng.MRG32k3a; 30 | 31 | /** 32 | * Represents a random stream factory capable of constructing instances of a 33 | * given type of random stream by invoking the #newInstance method each time 34 | * a new random stream is needed, instead of invoking directly the specific 35 | * constructor of the desired type. Hence, if several random streams of a 36 | * given type (class) must be constructed at different places in a large 37 | * simulation program, and if we decide to change the type of stream in the 38 | * future, there is no need to change the code at those different places. 39 | * With the random stream factory, the class-specific code for constructing 40 | * these streams appears at a single place, where the factory is constructed. 41 | * 42 | * The class @ref BasicRandomStreamFactory provides an implementation of 43 | * this interface. 44 | * 45 | *
46 | */ 47 | public interface RandomStreamFactory { 48 | 49 | /** 50 | * Constructs and returns a new random stream. If the instantiation of the 51 | * random stream fails, this method throws a 52 | * @ref RandomStreamInstantiationException. 53 | * @return the newly-constructed random stream. 54 | * 55 | * @exception RandomStreamInstantiationException if the new random stream 56 | * cannot be instantiated. 57 | */ 58 | public RandomStream newInstance(); 59 | 60 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/simevents/eventlist/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.simevents.eventlist 3 | * 4 | * This package provides different kinds of event list implementations. One 5 | * can change the default @ref umontreal.ssj.simevents.eventlist.SplayTree 6 | * event list implemntation via the method 7 | * umontreal.ssj.simevents.Sim.init(umontreal.ssj.simevents.eventlist.EventList). 8 | * 9 | * @remark **Pierre:** Should add the appropriate references for the 10 | * different event list implementations. 11 | */ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/simevents/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.simevents 3 | * 4 | * Simulation Clock and Event List Management. 5 | * 6 | * This package provides the simulation clock and tools to manage the 7 | * future events list. These are the basic tools for discrete-event 8 | * simulation. Several different implementations of the event list are 9 | * offered. Some basic tools for continuous simulation (i.e., solving 10 | * differential equations with respect to time) are also provided. 11 | * 12 | * @anchor REF_simevents_overview_sec_overview 13 | * 14 | * This package provides the simulation clock and tools to manage the future 15 | * events list. These are the basic tools for discrete-event simulation. 16 | * Several different implementations of the event list are offered. Some 17 | * basic tools for continuous simulation (i.e., solving differential 18 | * equations with respect to time) are also provided. 19 | * 20 | * The scheduling part of discrete-event simulations is managed by the 21 | * "chief-executive" class @ref umontreal.ssj.simevents.Simulator, which 22 | * contains the simulation clock and the central monitor. The event list is 23 | * taken from one of the implementations of the interface 24 | * @ref umontreal.ssj.simevents.eventlist.EventList, which provide different 25 | * kinds of event list implementations. One can change the default 26 | * @ref umontreal.ssj.simevents.eventlist.SplayTree event list implementation 27 | * via the method umontreal.ssj.simevents.Sim.init(EventList). The class 28 | * @ref umontreal.ssj.simevents.Event provides the facilities for creating 29 | * and scheduling events in the simulation. Each type of event must be 30 | * defined by extending the class @ref umontreal.ssj.simevents.Event. The 31 | * class @ref umontreal.ssj.simevents.Continuous provides elementary tools 32 | * for continuous simulation, where certain variables vary continuously in 33 | * time according to ordinary differential equations. 34 | * 35 | * The class @ref umontreal.ssj.simevents.LinkedListStat implements *doubly 36 | * linked* lists, with tools for inserting, removing, and viewing objects in 37 | * the list, and automatic statistical collection. These lists can contain 38 | * any kind of Object. 39 | */ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/stat/ObservationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: ObservationListener 3 | * Description: Observation listener 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.stat; 26 | 27 | /** 28 | * Represents an object that can listen to observations broadcast by 29 | * statistical probes. 30 | * 31 | *
32 | */ 33 | public interface ObservationListener { 34 | 35 | /** 36 | * Receives the new observation `x` broadcast by `probe`. 37 | * @param probe the statistical probe broadcasting the observation. 38 | * @param x the observation being broadcast. 39 | */ 40 | public void newObservation (StatProbe probe, double x); 41 | 42 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/stat/density/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.stat.density 3 | * 4 | * Univariate density estimation. 5 | * 6 | * This package provides tools for univariate density estimation from a set of 7 | * real-valued observations \f$x_0,x_1,\dots,x_{n-1}\f$ which may come from 8 | * real-life data or may have been generated by simulation. 9 | * The goal is to construct an estimator \f$\hat{f}_n\f$ of the unknown density \f$f\f$ 10 | * of a random variable \f$X\f$ over a finite interval \f$[a,b]\f$, 11 | * based on \f$n\f$ realizations of \f$X\f$. 12 | * One standard way of measuring the performance of the density estimator (DE) 13 | * is the mean integrated square error (MISE), which can be 14 | * decomposed as the sum of the integrated variance (IV) and the integrated 15 | * square bias (ISB), as follows: 16 | * \f[ 17 | * \textrm{MISE} = \int_a^b\mathbb{E} [\hat{f}(x) - f(x)]^2\mathrm{d}x = 18 | * \int_a^b\textrm{Var}[\hat{f}(x)]\mathrm{d}x + \int_a^b \left( 19 | * \mathbb{E}[\hat{f}(x)] - f(x) \right)^2\mathrm{d}x = \textrm{IV} + \textrm{ISB}. 20 | * \f] 21 | * 22 | * The abstract class @ref umontreal.ssj.stat.density.DensityEstimator represents 23 | * an estimator \f$\hat{f}_n\f$ of an unknown density \f$f\f$. 24 | * The actual density estimators are implemented in subclasses, which must provide 25 | * methods to evaluate \f$\hat{f}_n\f$ either at a single point or at a finite set of evaluation points. 26 | * The abstract class provides generic tools to plot estimated densities, 27 | * compute the empirical integrated variance (IV) when several independent replicates of the estimator 28 | * are available, and investigate its convergence behavior as a function of `n`. 29 | * 30 | * Current implementations of this abstract class include histograms in 31 | * @ref umontreal.ssj.stat.density.DEHistogram and kernel density estimators (KDEs) in 32 | * @ref umontreal.ssj.stat.density.DEKernelDensity. 33 | * Some tools are provided to select the kernel bandwidth for the KDEs. 34 | * 35 | * One further subclass of @ref DensityEstimator is the abstract 36 | * class @ref umontreal.ssj.stat.density.DensityDerivativeEstimator. This class 37 | * allows to estimate the *derivative* of an unknown density from the \f$n\f$ observations. 38 | * Even though it is strictly speaking not a density estimator, it is structured 39 | * very similarly and the class provides the same methods as for common density estimators. 40 | * 41 | */ 42 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/stat/list/ArrayOfObservationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: ArrayOfObservationListener 3 | * Description: Array of observation listener 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 2007 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.stat.list; 26 | import umontreal.ssj.stat.StatProbe; 27 | 28 | /** 29 | * Represents an object that can listen to observations broadcast by lists of 30 | * statistical probes. 31 | * 32 | *
33 | */ 34 | public interface ArrayOfObservationListener { 35 | 36 | /** 37 | * Receives the new array of observations `x` broadcast by the list of 38 | * statistical probes `listOfProbes`. 39 | * @param listOfProbes the list of statistical probes broadcasting the 40 | * observation. 41 | * @param x the array of observations being broadcast. 42 | */ 43 | public void newArrayOfObservations (ListOfStatProbes listOfProbes, 44 | double[] x); 45 | 46 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/stat/list/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.stat.list 3 | * 4 | * @anchor REF_stat_list_overview_over_li_tal Provides support 5 | * for lists of statistical probes. Sometimes, a simulator computes several 6 | * related performance measures such as the quality of service for different 7 | * call types in a phone call center, the waiting times of different types of 8 | * customers, the average number of pieces of different types a machine 9 | * processes, etc. A list of statistical probes, in contrast with an ordinary 10 | * array, can be resized. Since a list of statistical probes implements the 11 | * Java `List` interface, one can iterate over each probe, e.g., to set 12 | * reporting options. In addition to an ordinary list, a list of probes 13 | * provides facilities to get a vector of averages, a vector of sums, and to 14 | * create reports. 15 | * 16 | * In Java, a list is usually constructed empty, and 17 | * filled with items. Lists of statistical probes can be constructed this 18 | * generic way, or created using factory methods that automatically construct 19 | * the probes. 20 | * 21 | * @ref umontreal.ssj.stat.list.ListOfStatProbes is the base class for lists 22 | * of statistical probes. It can hold a list of any 23 | * @ref umontreal.ssj.stat.StatProbe subclass, and provides the basic 24 | * facilities to obtain an array of sums, an array of averages, etc. 25 | * Subclasses provide probe-specific functionalities for adding vectors of 26 | * observations, computing sample covariances, etc. 27 | * @ref umontreal.ssj.stat.list.ListOfTallies is used to contain 28 | * @ref umontreal.ssj.stat.Tally instances. A subclass, 29 | * @ref umontreal.ssj.stat.list.ListOfTalliesWithCovariance, is provided to 30 | * add support for covariance computation without storing observations. The 31 | * @ref umontreal.ssj.stat.list.ListOfFunctionOfMultipleMeansTallies is 32 | * available to regroup @ref umontreal.ssj.stat.FunctionOfMultipleMeansTally 33 | * objects. 34 | * 35 | * All classes in this package representing lists of probes support the 36 | * observer design pattern similarly to the classes in package `stat`. A list 37 | * of statistical probes maintains a list of registered 38 | * @ref umontreal.ssj.stat.list.ArrayOfObservationListener objects, and 39 | * broadcasts information to all its registered observers when it receives a 40 | * new vector of observations. Any object that implements the interface 41 | * @ref umontreal.ssj.stat.list.ArrayOfObservationListener can register as an 42 | * observer. 43 | */ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/stat/matrix/MatrixOfObservationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: MatrixOfObservationListener 3 | * Description: Observation listener 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 2006 10 | 11 | * SSJ is free software: you can redistribute it and/or modify it under 12 | * the terms of the GNU General Public License (GPL) as published by the 13 | * Free Software Foundation, either version 3 of the License, or 14 | * any later version. 15 | 16 | * SSJ is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | 21 | * A copy of the GNU General Public License is available at 22 | GPL licence site. 23 | */ 24 | package umontreal.ssj.stat.matrix; 25 | import umontreal.ssj.stat.StatProbe; 26 | import cern.colt.matrix.DoubleMatrix2D; 27 | 28 | /** 29 | * Represents an object that can listen to observations broadcast by matrices 30 | * of statistical probes. 31 | * 32 | *
33 | */ 34 | public interface MatrixOfObservationListener { 35 | 36 | /** 37 | * Receives the new matrix of observations `x` broadcast by the matrix of 38 | * statistical probes `matrixOfProbes`. 39 | * @param matrixOfProbes the matrix of statistical probes broadcasting the 40 | * observation. 41 | * @param x the matrix of observations being broadcast. 42 | */ 43 | public void newMatrixOfObservations (MatrixOfStatProbes matrixOfProbes, 44 | DoubleMatrix2D x); 45 | 46 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/stochprocess/VarianceGammaProcessAlternate.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.stochprocess; 2 | 3 | import umontreal.ssj.rng.*; 4 | 5 | /** 6 | * This is a @ref VarianceGammaProcess for which the successive random numbers 7 | * are used in a different order to generate the sample path. 8 | * The first one is used for the first generated value of the gamma process, 9 | * the second one for the first generated value of the Brownian process, 10 | * the third one for the second generated value of the gamma process, 11 | * the fourth one for the second value of the Brownian process, and so on. 12 | * Only the order in which the uniform random numbers are used in the method `generatePath` differs. 13 | * These numbers are generated at the beginning and then reordered. 14 | * This can make a difference when we use RQMC methods. 15 | * 16 | *
17 | */ 18 | public class VarianceGammaProcessAlternate extends VarianceGammaProcess { 19 | 20 | 21 | public VarianceGammaProcessAlternate (double s0, double theta, double sigma, 22 | double nu, RandomStream stream) { 23 | super (s0, theta, sigma, nu, stream); 24 | } 25 | 26 | 27 | public VarianceGammaProcessAlternate (double s0, BrownianMotion BM, 28 | GammaProcess Gamma) { 29 | super (s0, BM, Gamma); 30 | } 31 | 32 | /** 33 | * Generates the sample path by using the uniform random numbers in an alternate way, 34 | * and returns the path of the VG process. 35 | */ 36 | public double[] generatePath() { 37 | int d = getNumObservationTimes(); 38 | double[] points = new double[2*d]; 39 | RandomStream stream = getStream(); 40 | for (int j=0; j<2*d; j++) 41 | points[j] = stream.nextDouble(); 42 | return generatePath (points); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/stochprocess/VarianceGammaProcessDiffPCABridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: VarianceGammaProcessDiffPCABridge 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @authors Jean-Sébastien Parent & Maxime Dion 9 | * @since 2008 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.stochprocess; 26 | import umontreal.ssj.rng.*; 27 | 28 | /** 29 | * Same as @ref VarianceGammaProcessDiff, but the two inner 30 | * @ref GammaProcess ’es are of the type PCABridge. Also, 31 | * `generatePath(double[] uniform01)` distributes the lowest coordinates 32 | * uniforms to the inner @ref GammaProcessPCABridge according to their 33 | * eigenvalues. 34 | * 35 | *
36 | */ 37 | public class VarianceGammaProcessDiffPCABridge extends 38 | VarianceGammaProcessDiffPCA { 39 | 40 | /** 41 | * Constructs a new @ref VarianceGammaProcessDiffPCABridge with 42 | * parameters @f$\theta= \mathtt{theta}@f$, @f$\sigma= 43 | * \mathtt{sigma}@f$, @f$\nu= \mathtt{nu}@f$ and initial value 44 | * @f$S(t_0) = \mathtt{s0}@f$. There is only one 45 | * @ref umontreal.ssj.rng.RandomStream here which is used for the two 46 | * inner @ref GammaProcessPCABridge ’s. The other parameters are set 47 | * as in @ref VarianceGammaProcessDiff. 48 | */ 49 | public VarianceGammaProcessDiffPCABridge (double s0, double theta, 50 | double sigma, double nu, 51 | RandomStream stream) { 52 | super(s0, theta, sigma, nu, 53 | new GammaProcessPCABridge (0.0, 1.0, 1.0, stream), 54 | new GammaProcessPCABridge (0.0, 1.0, 1.0, stream)); 55 | // Params mu, nu of the 2 gamma processes are redefined in init() 56 | // which will be called after a call to 'setObservTimes' 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/stochprocess/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.stochprocess 3 | * 4 | * Stochastic Processes. 5 | * 6 | * This package provides classes to define stochastic processes @f$\{X(t), 7 | * t\ge0\}@f$ in the real space, and to simulate their sample paths at a finite number of 8 | * observation times @f$t_0 \le t_1 \le\cdots\le t_d@f$, i.e., *skeletons* of their 9 | * sample paths. 10 | * The generated path skeleton is a vector @f$(X(t_0),X(t_1),\dots,X(t_d)) \in \mathbb{R}@f$. 11 | * 12 | * The observation times @f$t_0, \dots, t_d@f$ can be specified (and can be changed) 13 | * after defining the process, via the method `setObservationTimes`. 14 | * In some cases, the observation times can also be specified one by one 15 | * when generating the value at the next observation time. 16 | * This may be convenient or even necessary 17 | * if the observation times are random, for example. 18 | * The random stream used to generate the sample path can also be set or changed, using 19 | * `setStream`, and it can also be passed each time to the method that generates the paths. 20 | * 21 | * The available processes include the Brownian motion (or Gaussian process), 22 | * Gamma Process, Inverse Gaussian, versions with a random clock (or subordinate process) 23 | * such as the variance-gamma and normal inverse Gaussian processes, 24 | * exponential (or geometric) versions of all of these, and more. 25 | * Many of those processes can be simulated in different ways, such as standard sequential 26 | * generation of the increments (which are independent in the caes of L\'evy processes), 27 | * or using a bridge sampling strategy as in `BrownianMotionBridge`, or by using a 28 | * principal component decomposition as in `BrownianMotionPCA`. 29 | * The choice of simulation strategy can have a significant impact on the variance 30 | * when combined with randomized quasi-Monte Carlo (RQMC). 31 | * 32 | * There are also multivariate versions in which the state is a \f$c\f$-dimensional vector, 33 | * @f$\mathbb{X}(t) \in \mathbb{R}@f$. At each time step, a new state vector is generated. 34 | * 35 | * @remark: In the future, it might be useful to have a common interface implemented 36 | * by `StochasticProcess` and @ref umontreal.ssj.markovchainrqmc.MarkovChainDouble. 37 | * 38 | */ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/util/Chrono.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: Chrono 3 | * Description: computes the CPU time for the current thread only 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.util; 26 | 27 | /** 28 | * The @ref Chrono class extends the @ref umontreal.ssj.util.AbstractChrono 29 | * class and computes the CPU time for the current thread only. It is equivalent to 30 | * @ref ChronoSingleThread. 31 | * The class @ref umontreal.ssj.util.ChronoWall provides another option. 32 | * 33 | *
34 | */ 35 | public class Chrono extends AbstractChrono { 36 | private ChronoSingleThread chrono = new ChronoSingleThread(); 37 | 38 | protected void getTime (long[] tab) { 39 | chrono.getTime(tab); 40 | } 41 | 42 | /** 43 | * Constructs a `Chrono` object and initializes it to zero. 44 | */ 45 | public Chrono() { 46 | chrono.init(); 47 | init(); 48 | } 49 | 50 | /** 51 | * Creates a `Chrono` instance adapted for a program using a single thread. 52 | * It is equivalent to @ref ChronoSingleThread. 53 | * This class should not be used to create a timer for a 54 | * multi-threaded program, because the obtained CPU times will differ 55 | * depending on the used Java version. 56 | * @return the constructed timer. 57 | */ 58 | public static Chrono createForSingleThread () { 59 | return new Chrono(); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/util/ChronoWall.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: ChronoWall 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author Éric Buist 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.util; 26 | 27 | /** 28 | * Extends the @ref AbstractChrono class to compute the wall-clock time 29 | * using Java's builtin `System.nanoTime`. This can be used as a rough 30 | * approximation of the CPU time taken by a program if no other tasks are 31 | * executed on the host while the program is running. 32 | * 33 | *
34 | */ 35 | public class ChronoWall extends AbstractChrono { 36 | 37 | protected void getTime (long[] tab) { 38 | long rawTime = System.nanoTime(); 39 | final long DIV = 1000000000L; 40 | long seconds = rawTime/DIV; 41 | long micros = (rawTime % DIV)/1000L; 42 | tab[0] = seconds; 43 | tab[1] = micros; 44 | } 45 | 46 | /** 47 | * Constructs a new chrono object and initializes it to zero. 48 | */ 49 | public ChronoWall() { 50 | super(); 51 | init(); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/util/io/AbstractDataWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: AbstractDataWriter 3 | * Description: 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author David Munger 9 | * @since August 2009 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.util.io; 26 | import java.io.IOException; 27 | 28 | /** 29 | * This abstract class implements shared functionality for data writers. 30 | * 31 | *
32 | */ 33 | public abstract class AbstractDataWriter implements DataWriter { 34 | 35 | /** 36 | * @name Writing one-dimensional arrays 37 | * @{ 38 | */ 39 | 40 | /** 41 | * Writes a one-dimensional array of strings. If `label` is `null`, 42 | * writes an anonymous field. 43 | */ 44 | public void write (String label, String[] a) throws IOException { 45 | write(label, a, a.length); 46 | } 47 | 48 | /** 49 | * Writes a one-dimensional array of 32-bit integers (big endian). If 50 | * `label` is `null`, writes an anonymous field. 51 | */ 52 | public void write (String label, int[] a) throws IOException { 53 | write(label, a, a.length); 54 | } 55 | 56 | /** 57 | * Writes a one-dimensional array of 32-bit floats (big endian). If 58 | * `label` is `null`, writes an anonymous field. 59 | */ 60 | public void write (String label, float[] a) throws IOException { 61 | write(label, a, a.length); 62 | } 63 | 64 | /** 65 | * Writes a one-dimensional array of 64-bit doubles (big endian). If 66 | * `label` is `null`, writes an anonymous field. 67 | */ 68 | public void write (String label, double[] a) throws IOException { 69 | write(label, a, a.length); 70 | } 71 | 72 | } 73 | 74 | /** 75 | * @} 76 | */ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/util/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.util 3 | * 4 | * This package provides various kinds of general basic utilities 5 | * used in SSJ and also in the *simulation laboratory* at DIRO, 6 | * Université de Montréal. Much of this was originally implemented in 7 | * the Modula-2 language before 1990 and has been translated in C and then in Java, with 8 | * some adaptations along the road. 9 | * 10 | **/ -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/util/sort/DoubleArrayComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: DoubleArrayComparator 3 | * Description: Compares two double's arrays 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | * 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | package umontreal.ssj.util.sort; 26 | import java.util.Comparator; 27 | 28 | /** 29 | * This provides an implementation of Comparator in which arrays of `double` 30 | * in @f$d@f$ dimensions are compared by comparing their coordinate @f$j@f$ 31 | * in the natural order of real numbers, where @f$j \in\{0,…,d-1\}@f$ is 32 | * given in the constructor. The method `compare(d1, d2)` returns @f$-1@f$, 33 | * @f$0@f$, or @f$1@f$ depending on whether `d1[j]` is less than, equal to, 34 | * or greater than `d2[j]`. 35 | * 36 | *
37 | */ 38 | public class DoubleArrayComparator implements Comparator { 39 | private int j; 40 | 41 | /** 42 | * Constructs a comparator, where `j` is the coordinate used for the 43 | * comparisons. 44 | * @param j index used for comparison 45 | */ 46 | public DoubleArrayComparator (int j) { 47 | this.j = j; 48 | } 49 | 50 | /** 51 | * Returns @f$-1@f$, @f$0@f$, or @f$1@f$ depending on whether `d1[j]` 52 | * is less than, equal to, or greater than `d2[j]`. 53 | * @param d1 first array 54 | * @param d2 second array 55 | */ 56 | public int compare (double[] d1, double[] d2) { 57 | if (j >= d1.length || j >= d2.length) 58 | throw new IllegalArgumentException("Comparing in a"+ 59 | "dimension larger than array dimension"); 60 | return (d1[j]< d2[j] ? -1 : (d1[j] > d2[j] ? 1 : 0)); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/util/sort/MultiDim01.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: MultiDim01 3 | * Description: Represents an object which can be compared in many dimensions. 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | 11 | * SSJ is free software: you can redistribute it and/or modify it under 12 | * the terms of the GNU General Public License (GPL) as published by the 13 | * Free Software Foundation, either version 3 of the License, or 14 | * any later version. 15 | 16 | * SSJ is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | 21 | * A copy of the GNU General Public License is available at 22 | GPL licence site. 23 | */ 24 | package umontreal.ssj.util.sort; 25 | 26 | /** 27 | * This interface represents a point or array of @f$d@f$ dimensions in a unit 28 | * hypercube @f$[0, 1)^d@f$. The value of the @f$j@f$th dimension can be 29 | * accessed with the method {@link #getCoordinate() getCoordinate(j)}. 30 | * 31 | *
32 | */ 33 | public interface MultiDim01 { 34 | 35 | /** 36 | * This method returns the number dimensions of this point. 37 | */ 38 | public int dimension(); 39 | 40 | /** 41 | * Returns the @f$d@f$ coordinates of this point. 42 | */ 43 | public double[] getPoint(); 44 | 45 | /** 46 | * Returns the value of @f$j@f$th coordinate (or dimension). This value 47 | * should be in the interval @f$[0, 1)@f$. If @f$j@f$ is outside the 48 | * range @f$\{0,…,d-1\}@f$, this method should throw an 49 | * IllegalArgumentException. 50 | */ 51 | public double getCoordinate (int j); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/util/sort/MultiDimSort01.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: MultiDimSort01 3 | * Description: Represents a sort on multidimensional arrays of MultiDimComparable. 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | 11 | * SSJ is free software: you can redistribute it and/or modify it under 12 | * the terms of the GNU General Public License (GPL) as published by the 13 | * Free Software Foundation, either version 3 of the License, or 14 | * any later version. 15 | 16 | * SSJ is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | 21 | * A copy of the GNU General Public License is available at 22 | GPL licence site. 23 | */ 24 | package umontreal.ssj.util.sort; 25 | import java.util.Comparator; 26 | import java.util.Arrays; 27 | 28 | /** 29 | * This interface extends @ref MultiDimSort to implement multivariate 30 | * sorting algorithms that sort points of @f$d@f$ dimensions in the unit 31 | * hypercube @f$[0, 1)^d@f$. 32 | * 33 | *
34 | */ 35 | public interface MultiDimSort01 extends 36 | MultiDimSort { 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/util/sort/MultiDimSortComparable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Class: MultiDimSortComparable 3 | * Description: Represents a sort on multidimensional arrays of MultiDimComparable. 4 | * Environment: Java 5 | * Software: SSJ 6 | * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal 7 | * Organization: DIRO, Universite de Montreal 8 | * @author 9 | * @since 10 | 11 | * SSJ is free software: you can redistribute it and/or modify it under 12 | * the terms of the GNU General Public License (GPL) as published by the 13 | * Free Software Foundation, either version 3 of the License, or 14 | * any later version. 15 | 16 | * SSJ is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | 21 | * A copy of the GNU General Public License is available at 22 | GPL licence site. 23 | */ 24 | package umontreal.ssj.util.sort; 25 | import java.util.Comparator; 26 | import java.util.Arrays; 27 | 28 | /** 29 | * This interface extends @ref MultiDimSort to implement multivariate 30 | * sorting algorithms that sort objects that are pairwise comparable. These 31 | * objects have @f$d@f$ sorting fields (or coordinates) and must implement 32 | * the interface @ref MultiDimComparable, which is used to sort them on any 33 | * given coordinate, numbered from 0 to @f$d-1@f$. 34 | * 35 | * The ordering is induced by the method 36 | * umontreal.ssj.util.MultiDimComparable.compareTo, and the number of the 37 | * largest coordinate used by the sort must not exceed @f$d-1@f$, where the 38 | * dimension @f$d@f$ refers to the value returned by 39 | * umontreal.ssj.util.MultiDimComparable.dimension. One can sort only a 40 | * subset of the objects, or all of them. 41 | * 42 | *
43 | */ 44 | public interface MultiDimSortComparable > extends 45 | MultiDimSort { 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/umontreal/ssj/util/sort/overview.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @package umontreal.ssj.util.sort 3 | * 4 | * This subpackage contains classes for sorting multi-dimensional points. 5 | * These sorts are useful in particular for the Array-RQMC method for Markov chains. 6 | * 7 | */ 8 | -------------------------------------------------------------------------------- /src/ssjutil/c/Chrono.c: -------------------------------------------------------------------------------- 1 | /* Interface C --> Java pour GlobalCPUTimeChrono.java */ 2 | 3 | #include 4 | #include 5 | #ifdef _WIN32 6 | #include 7 | #endif 8 | #include 9 | #ifdef _linux 10 | #include 11 | #include 12 | #endif 13 | #include "umontreal_ssj_util_GlobalCPUTimeChrono.h" 14 | 15 | #ifdef _WIN32 16 | static HANDLE currentProcess; 17 | 18 | JNIEXPORT jint JNICALL 19 | JNI_OnLoad (JavaVM* vm, void* reserved) { 20 | currentProcess = GetCurrentProcess(); 21 | return JNI_VERSION_1_2; 22 | } 23 | 24 | /* 25 | * A helper function for converting FILETIME to a LONGLONG [safe from memory 26 | * alignment point of view]. 27 | */ 28 | static ULONGLONG 29 | fileTimeToInt64 (const FILETIME * time) 30 | { 31 | ULARGE_INTEGER _time; 32 | 33 | _time.LowPart = time->dwLowDateTime; 34 | _time.HighPart = time->dwHighDateTime; 35 | 36 | return _time.QuadPart; 37 | } 38 | #endif 39 | 40 | JNIEXPORT void JNICALL 41 | Java_umontreal_ssj_util_GlobalCPUTimeChrono_Heure (JNIEnv *env, jclass class, jlongArray array){ 42 | 43 | #ifdef _linux 44 | struct tms us; 45 | #endif 46 | #ifdef _WIN32 47 | FILETIME creationTime, exitTime, kernelTime, userTime; 48 | #endif 49 | jlong *jarray = (*env)->GetLongArrayElements(env, array, 0); 50 | 51 | #if defined(_linux) 52 | long TIC = sysconf(_SC_CLK_TCK); 53 | 54 | times(&us); 55 | 56 | jarray[1] = us.tms_utime + us.tms_stime; 57 | jarray[0] = jarray[1] / TIC; 58 | jarray[1] = (jarray[1] % TIC) * 1000000 / TIC; 59 | #elif defined(_WIN32) 60 | /* Strongly inspired from 61 | * http://www.javaworld.com/javaworld/javaqa/2002-11/01-qa-1108-cpu.html */ 62 | GetProcessTimes (currentProcess, &creationTime, &exitTime, 63 | &kernelTime, &userTime); 64 | ULONGLONG rawTime = (ULONGLONG)(fileTimeToInt64 (&kernelTime) + 65 | fileTimeToInt64 (&userTime)); 66 | /* We have to divide by 10000 to get milliseconds out of 67 | * the computed time. So we divide by 10000*1000 to get seconds. */ 68 | jarray[0] = (unsigned long)(rawTime / 10000000); 69 | /* One raw time unit corresponds to 10 microseconds. 70 | */ 71 | jarray[1] = (unsigned long)((rawTime % 10000000) / 10); 72 | #else 73 | /* This one is bad but portable across Unixes. 74 | * The clock function wraps after approximately 72 minutes. */ 75 | jarray[1] = clock(); 76 | jarray[0] = jarray[1] / CLOCKS_PER_SEC; 77 | jarray[1] = (jarray[1] % CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC; 78 | #endif 79 | 80 | (*env)->ReleaseLongArrayElements(env, array, jarray, 0); 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/ChronoTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.*; 2 | // import static org.junit.jupiter.api.Assertions.*; 3 | import umontreal.ssj.util.GlobalCPUTimeChrono; 4 | 5 | public class ChronoTest { 6 | @Test 7 | public void testChrono() { 8 | GlobalCPUTimeChrono timer = new GlobalCPUTimeChrono(); 9 | System.out.println(timer.format()); 10 | // no assert; just test execution 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/CompareOutputs.java: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.*; 2 | import static org.junit.jupiter.api.Assertions.*; 3 | import org.junit.jupiter.params.*; 4 | // import org.junit.jupiter.api.runners.*; 5 | // import org.junit.runners.Parameterized.*; 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.util.regex.Pattern; 9 | import java.util.Collection; 10 | import java.util.List; 11 | import java.util.Arrays; 12 | 13 | /* Must be updated for the new Junit !!! 14 | * 15 | 16 | @RunWith(Parameterized.class) 17 | public class CompareOutputs { 18 | 19 | final static Pattern ignorePat = Pattern.compile(".*(\\bCPU time|\\bEfficiency ratio).*"); 20 | 21 | @Parameters 22 | public static Collection data() { 23 | return Arrays.asList(new Object[][] { 24 | { "tutorial", Asian.class, null }, 25 | { "tutorial", AsianQMC.class, null }, 26 | { "tutorial", BankEv.class, null }, 27 | { "tutorial", CallCenter.class, new String[]{"tutorial/CallCenter.dat"} }, 28 | { "tutorial", CallEv.class, new String[]{"tutorial/CallEv.dat"} }, 29 | { "tutorial", Collision.class, null }, 30 | { "tutorial", InventoryCRN.class, null }, 31 | { "tutorial", Inventory.class, null }, 32 | { "tutorial", Nonuniform.class, null }, 33 | { "tutorial", PreyPred.class, null }, 34 | { "tutorial", QueueEv.class, null }, 35 | { "tutorial", QueueLindley.class, null }, 36 | { "tutorial", QueueObs.class, null }, 37 | { "probdistmulti/norta", ExampleNortaInitDisc.class, null } 38 | }); 39 | } 40 | 41 | private String prefix; 42 | private Class targetClass; 43 | private String[] args; 44 | 45 | public CompareOutputs(String prefix, Class targetClass, String[] args) { 46 | this.prefix = prefix; 47 | this.targetClass = targetClass; 48 | this.args = args; 49 | } 50 | 51 | @Test 52 | public void runTutorialClass() throws RunClass.RunClassException, IOException { 53 | String expected = RunClass.readFile(new File(prefix, targetClass.getSimpleName() + ".txt")); 54 | String actual = RunClass.run(targetClass, args); 55 | RunClass.compareLineByLine(targetClass.getName(), expected, actual, ignorePat); 56 | } 57 | } 58 | 59 | */ 60 | -------------------------------------------------------------------------------- /src/test/java/ExamplesTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.*; 2 | import static org.junit.jupiter.api.Assertions.*; 3 | // import org.junit.runner.RunWith; 4 | // import org.junit.runners.Parameterized; 5 | // import org.junit.runners.Parameterized.*; 6 | import java.io.IOException; 7 | import java.util.regex.Pattern; 8 | import java.util.Collection; 9 | import java.util.List; 10 | import java.util.Arrays; 11 | 12 | /* Must be updated for the new Junit !!! 13 | * 14 | 15 | @RunWith(Parameterized.class) 16 | public class ExamplesTest { 17 | 18 | @Parameters 19 | public static Collection data() { 20 | return Arrays.asList(new Object[][] { 21 | { BoxTest.class }, 22 | { ChartTest1.class }, 23 | { ChartTest2.class }, 24 | { ContDistPlot.class }, 25 | { DistIntTest.class }, 26 | { EmpiricalChartTest.class }, 27 | { HistogramChartTest.class }, 28 | { HistogramTest1.class }, 29 | { NormalChart.class }, 30 | { normaltest.class } 31 | }); 32 | } 33 | 34 | private Class targetClass; 35 | 36 | public ExamplesTest(Class targetClass) { 37 | this.targetClass = targetClass; 38 | } 39 | 40 | @Test 41 | public void runExampleClass() throws RunClass.RunClassException, IOException { 42 | String output = RunClass.run(targetClass); 43 | } 44 | } 45 | 46 | */ 47 | 48 | -------------------------------------------------------------------------------- /src/test/java/UnuranTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.*; 2 | import static org.junit.jupiter.api.Assertions.*; 3 | import umontreal.ssj.randvar.UnuranContinuous; 4 | import umontreal.ssj.randvar.UnuranDiscreteInt; 5 | import umontreal.ssj.rng.MRG31k3p; 6 | 7 | public class UnuranTest { 8 | 9 | @Test 10 | public void testUnuranContinuous() { 11 | final double[] expected = new double[]{ 12 | 0.6294093864066692, 13 | -1.2277564567077497, 14 | -0.3424878256069986, 15 | 0.08287788846040008, 16 | 1.3744521552951496, 17 | -0.14927140089739152, 18 | -0.7238407550828191, 19 | 0.7421332531396772, 20 | 1.657117449078283, 21 | -0.05304194486402798 22 | }; 23 | UnuranContinuous gen = new UnuranContinuous(new MRG31k3p(), "normal()"); 24 | for (int i = 0; i < expected.length; i++) 25 | assertEquals(expected[i], gen.nextDouble(), 1e-9, "output[" + i + "]"); 26 | } 27 | 28 | @Test 29 | public void testUnuranDiscreteInt() { 30 | final int[] expected = new int[]{ 11, 8, 9, 7, 11, 9, 10, 6, 9, 15 }; 31 | UnuranDiscreteInt gen = new UnuranDiscreteInt(new MRG31k3p(), "poisson(10)"); 32 | for (int i = 0; i < expected.length; i++) 33 | assertEquals(expected[i], gen.nextInt(), "output[" + i + "]"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/umontreal/ssj/randvar/MixtureGenTest.java: -------------------------------------------------------------------------------- 1 | package umontreal.ssj.randvar; 2 | 3 | import org.junit.jupiter.api.*; 4 | import static org.junit.jupiter.api.Assertions.*; 5 | import umontreal.ssj.probdist.*; 6 | import umontreal.ssj.rng.MRG32k3a; 7 | import umontreal.ssj.rng.RandomStream; 8 | import umontreal.ssj.stat.Tally; 9 | 10 | /** 11 | * Test the class {@link umontreal.ssj.randvar.MixtureGen}. 12 | */ 13 | public class MixtureGenTest { 14 | 15 | @Test 16 | public void testMixtureMean() { 17 | // define the distributions 18 | Distribution[] dists = new Distribution[2]; 19 | dists[0] = new NormalDist(10, 5); 20 | dists[1] = new ExponentialDist(0.2); 21 | 22 | double[] weights = new double[]{0.5, 0.5}; 23 | 24 | RandomStream rs = new MRG32k3a(); 25 | 26 | MixtureGen mg = new MixtureGen(rs, dists, weights); 27 | 28 | int n = 100000; 29 | 30 | // compute mean 31 | Tally t = new Tally("Mixture stats"); 32 | for (int i = 0; i < n; i++) { 33 | t.add(mg.nextDouble()); 34 | } 35 | 36 | double trueMean = 7.5; 37 | double eps = 0.1; 38 | System.out.println("Real mean: " + trueMean + " , average found: " + t.average()); 39 | assertTrue(t.average() > (trueMean - eps) && t.average() < (trueMean + eps)); 40 | } 41 | 42 | @Test 43 | public void testMixtureMean2() { 44 | // define the distributions 45 | Distribution[] dists = new Distribution[3]; 46 | dists[0] = new NormalDist(10, 5); 47 | dists[1] = new ExponentialDist(0.2); 48 | dists[2] = new NormalDist(20,5); 49 | 50 | double[] weights = new double[]{0.3, 0.3, 0.4}; 51 | 52 | RandomStream rs = new MRG32k3a(); 53 | 54 | MixtureGen mg = new MixtureGen(rs, dists, weights); 55 | 56 | int n = 100000; 57 | 58 | // compute mean 59 | Tally t = new Tally("Mixture stats"); 60 | for (int i = 0; i < n; i++) { 61 | t.add(mg.nextDouble()); 62 | } 63 | 64 | double trueMean = 12.5; 65 | double eps = 0.1; 66 | System.out.println("Real mean: " + trueMean + " , average found: " + t.average()); 67 | assertTrue(t.average() > (trueMean - eps) && t.average() < (trueMean + eps)); 68 | } 69 | 70 | } 71 | --------------------------------------------------------------------------------