SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
DEDerivativeGaussian.java
1package umontreal.ssj.stat.density;
2
3import umontreal.ssj.probdist.NormalDist;
4
22
24
30 public DEDerivativeGaussian(int order) {
31 setOrder(order);
32 }
33
41 public DEDerivativeGaussian(int order, double[] data) {
42 this(order);
43 this.data = data;
44 }
45
51 public DEDerivativeGaussian(double h) {
52 setH(h);
53 }
54
62 public DEDerivativeGaussian(double h, double[] data) {
63 this(h);
64 this.data = data;
65 }
66
74
75 public DEDerivativeGaussian(int order, double h) {
76 this(order);
77 setH(h);
78 }
79
88 public DEDerivativeGaussian(int order, double h, double[] data) {
89 this(order, h);
90 this.data = data;
91
92 }
93
101 @Override
102 public double evalDensity(double x) {
103 double z;
104 double sign = getOrder() % 2 == 0 ? 1.0 : -1.0;
105 double density = 0.0;
106 int n = data.length;
107 double nInv = 1.0 / (double) n;
108 double hInv = 1.0 / getH();
109
110 double norma = sign * nInv * Math.pow(hInv, getOrder() + 1.0);
111
112 for (int i = 0; i < n; i++) {
113 z = (x - data[i]) * hInv;
114
116 }
117 density *= norma;
118 return density;
119 }
120
128 @Override
129 public double[] evalDensity(double[] evalPoints) {
130 double z = 0.0;
131 double sign = getOrder() % 2 == 0 ? 1.0 : -1.0;
132 int k = evalPoints.length;
133 double[] density = new double[k];
134 int n = data.length;
135 double nInv = 1.0 / (double) n;
136 double hInv = 1.0 / getH();
137
138 double norma = sign * nInv * Math.pow(hInv, getOrder() + 1.0);
139
140 for (int j = 0; j < k; j++) { // evalPoints indexed by j
141 for (int i = 0; i < n; i++) { // data points indexed by i
142 z = (evalPoints[j] - data[i]) * hInv;
144 }
145
146 density[j] *= norma;
147 }
148
149 return density;
150 }
151
155 @Override
156 public String toString() {
157 return "DDE [Gaussian kernel with h = " + getH() + "]";
158 }
159
160 // STATIC METHODS
171 public static double evalDensity(double x, int order, double h, double[] data) {
172 double z;
173 double sign = order % 2 == 0 ? 1.0 : -1.0;
174 double density = 0.0;
175 int n = data.length;
176 double nInv = 1.0 / (double) n;
177 double hInv = 1.0 / h;
178
179 double norma = sign * nInv * Math.pow(hInv, order + 1.0);
180
181 for (int i = 0; i < n; i++) {
182 z = (x - data[i]) * hInv;
183
184 density += NormalDist.density01(z) * hermitePoly(order, z);
185 }
186 density *= norma;
187 return density;
188 }
189
201 public static double[] evalDensity(double[] evalPoints, int order, double h, double[] data) {
202 double z = 0.0;
203 double sign = order == 0 ? 1.0 : -1.0;
204 int k = evalPoints.length;
205 double[] density = new double[k];
206 int n = data.length;
207 double nInv = 1.0 / (double) n;
208 double hInv = 1.0 / h;
209
210 double norma = sign * nInv * Math.pow(hInv, order + 1.0);
211
212 for (int j = 0; j < k; j++) { // evalPoints indexed by j
213 for (int i = 0; i < n; i++) { // data points indexed by i
214 z = (evalPoints[j] - data[i]) * hInv;
215 density[j] += NormalDist.density01(z) * hermitePoly(order, z);
216 }
217
218 density[j] *= norma;
219 }
220
221 return density;
222 }
223
244 public static double[][] evalDensity(double[] evalPoints, int order, double h, double[][] data) {
245 int m = data.length;
246 double[][] density = new double[m][];
247 for (int r = 0; r < m; r++)
248 density[r] = evalDensity(evalPoints, order, h, data[r]);
249 return density;
250 }
251
263 public static double hermitePoly(int r, double x) {
264 if (r == 0)
265 return 1.0;
266 else if (r == 1)
267 return x;
268 else
269 return hermitePoly(r - 1, x) * x - ((double) r - 1.0) * hermitePoly(r - 2, x);
270 }
271
272}
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a  (page 80)).
static double density01(double x)
Same as density(0, 1, x).
String toString()
Gives a short description of the estimator.a short description.
DEDerivativeGaussian(double h, double[] data)
Constructs a DDE with a Gaussian kernel function with bandwidth h based on the observations data.
DEDerivativeGaussian(int order, double h)
Constructs a DDE with a Gaussian kernel function of order order and bandwidth h.
static double[] evalDensity(double[] evalPoints, int order, double h, double[] data)
Evaluates the DDE of order order with bandwidth h which is defined by the observations data at each o...
static double evalDensity(double x, int order, double h, double[] data)
Evaluates the DDE of order order with bandwidth h which is defined by the observations data at the ev...
static double[][] evalDensity(double[] evalPoints, int order, double h, double[][] data)
Assume that we have independent realizations of the underlying model.
double evalDensity(double x)
Evaluates the DDE at the point x.
DEDerivativeGaussian(double h)
Constructs a DDE with a Gaussian kernel function with bandwidth h.
static double hermitePoly(int r, double x)
Computes the probabilist's Hermite polynomial of order r at x, which is defined by the recursion.
DEDerivativeGaussian(int order)
Constructs a DDE with a Gaussian kernel function of order order.
double[] evalDensity(double[] evalPoints)
Evaluates the DDE at all the points in evalPoints and the resulting values are returned in an array.
DEDerivativeGaussian(int order, double[] data)
Constructs a DDE with a Gaussian kernel function of order order based on the observations data.
DEDerivativeGaussian(int order, double h, double[] data)
Constructs a DDE with a Gaussian kernel function of order order and bandwidth h based on the observat...
This class implements a density derivative estimator (DDE) based on a kernel density estimator (KDE) ...
void setOrder(int order)
Sets the order of the DDE to order.
double[] data
The data associated with this DensityEstimator object, if any.
Tools for univariate density estimation.