SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
LatinHypercube.java
1/*
2 * Class: LatinHypercube
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 * 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 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
23 */
24package umontreal.ssj.hups;
25
26import umontreal.ssj.rng.RandomStream;
27import umontreal.ssj.rng.*;
28
47public class LatinHypercube extends CachedPointSet {
48
49 protected double delta; // Size of divisions in each dimension, = 1/n
50
58 public LatinHypercube(int n, int dim) {
59 this.dim = dim;
60 delta = 1.0 / n;
61 numPoints = n;
62 x = new double[numPoints][dim];
63 }
64
73 public void randomize(RandomStream stream) {
74 int[] permutation = new int[numPoints];
75 // RandomPermutation.init (permutation, numPoints);
76 // Generate one random number uniformly in each interval for first coord.
77 for (int i = 0; i < numPoints; i++) {
78 permutation[i] = i;
79 x[i][0] = (i + stream.nextDouble()) * delta;
80 }
81 for (int j = 1; j < dim; j++) {
82 RandomPermutation.shuffle(permutation, stream);
83 // Generate one random number uniformly in each interval for coord. j.
84 for (int i = 0; i < numPoints; i++)
85 x[permutation[i]][j] = (i + stream.nextDouble()) * delta;
86 }
87 }
88
94 public void addRandomShift(int fromDim, int toDim, RandomStream stream) {
95 randomize(stream);
96 }
97
103 randomize(rand.getStream());
104 }
105
106 public String toString() {
107 return "LatinHypercube: LHS over the unit cube in " + dim + "dimensions.";
108 }
109}
void randomize(RandomStream stream)
This randomization generates a random LHS point set.
LatinHypercube(int n, int dim)
Constructs the structure for a Latin hypercube with n points in dim dimensions.
String toString()
Formats a string that contains information about the point set.
void randomize(PointSetRandomization rand)
Randomizes the points using LHS, regardless of what rand is.
void addRandomShift(int fromDim, int toDim, RandomStream stream)
Random shifts and partial randomizations are irrelevant here, so this method is redefined to be equiv...
int numPoints
Number of points.
int dim
Dimension of the points.
Provides methods to randomly shuffle arrays or lists using a random stream.
static void shuffle(List<?> list, RandomStream stream)
Same as java.util.Collections.shuffle(List<?
This interface is for a randomization that can be used to randomize a umontreal.ssj....
RandomStream getStream()
Returns the internal umontreal.ssj.rng.RandomStream.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...