SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
KernelDensityVarCorrectGen.java
1/*
2 * Class: KernelDensityVarCorrectGen
3 * Description: random variate generators for distributions obtained via
4 kernel density estimation methods
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 */
26package umontreal.ssj.randvar;
27
28import umontreal.ssj.probdist.*;
29import umontreal.ssj.rng.RandomStream;
30
52
53 protected double sigmak2; // Value of sigma_k^2.
54 protected double mean; // Sample mean of the observations.
55 protected double invSigmae; // 1 / sigma_e.
56
65 double sigmak2) {
66 super(s, dist, kGen, h);
67 this.sigmak2 = sigmak2;
68 mean = dist.getSampleMean();
69 double var = dist.getSampleVariance();
70 invSigmae = 1.0 / Math.sqrt(1.0 + h * h * sigmak2 / var);
71 }
72
79 this(s, dist, kGen, 0.77639 * getBaseBandwidth(dist), 1.0);
80 }
81
82 public void setBandwidth(double h) {
83 if (h < 0)
84 throw new IllegalArgumentException("h < 0");
85 bandwidth = h;
86 double var = ((EmpiricalDist) dist).getSampleVariance();
87 invSigmae = 1.0 / Math.sqrt(1.0 + h * h * sigmak2 / var);
88 }
89
90 public double nextDouble() {
91 double x = mean + invSigmae * (dist.inverseF(stream.nextDouble()) - mean + bandwidth * kernelGen.nextDouble());
92 if (positive)
93 return Math.abs(x);
94 else
95 return x;
96 }
97}
Extends DiscreteDistribution to an empirical distribution function, based on the observations (sorte...
static double getBaseBandwidth(EmpiricalDist dist)
Computes and returns the value of in ( bandwidth0 ).
KernelDensityGen(RandomStream s, EmpiricalDist dist, RandomVariateGen kGen, double h)
Creates a new generator for a kernel density estimated from the observations given by the empirical d...
KernelDensityVarCorrectGen(RandomStream s, EmpiricalDist dist, NormalGen kGen)
This constructor uses a gaussian kernel and the default bandwidth suggested in Table&#160; kernels for th...
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
KernelDensityVarCorrectGen(RandomStream s, EmpiricalDist dist, RandomVariateGen kGen, double h, double sigmak2)
Creates a new generator for a kernel density estimated from the observations given by the empirical d...
This class implements methods for generating random variates from the normal distribution .
This is the base class for all random variate generators over the real line.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...