1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. 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 */
17 package org.apache.commons.math4.legacy.distribution;
18
19 import org.apache.commons.rng.UniformRandomProvider;
20
21 /**
22 * Base interface for multivariate distributions on the reals.
23 *
24 * This is based largely on the {@code ContinuousDistribution} interface,
25 * but cumulative distribution functions are not required because they
26 * are often quite difficult to compute for multivariate distributions.
27 *
28 * @since 3.1
29 */
30 public interface MultivariateRealDistribution {
31 /**
32 * Returns the probability density function (PDF) of this distribution
33 * evaluated at the specified point {@code x}. In general, the PDF is the
34 * derivative of the cumulative distribution function. If the derivative
35 * does not exist at {@code x}, then an appropriate replacement should be
36 * returned, e.g. {@code Double.POSITIVE_INFINITY}, {@code Double.NaN}, or
37 * the limit inferior or limit superior of the difference quotient.
38 *
39 * @param x Point at which the PDF is evaluated.
40 * @return the value of the probability density function at point {@code x}.
41 */
42 double density(double[] x);
43
44 /**
45 * Gets the number of random variables of the distribution.
46 * It is the size of the array returned by the {@link Sampler#sample() sample}
47 * method.
48 *
49 * @return the number of variables.
50 */
51 int getDimension();
52
53 /**
54 * Creates a sampler.
55 *
56 * @param rng Generator of uniformly distributed numbers.
57 * @return a sampler that produces random numbers according this
58 * distribution.
59 *
60 * @since 4.0
61 */
62 Sampler createSampler(UniformRandomProvider rng);
63
64 /**
65 * Sampling functionality.
66 *
67 * @since 4.0
68 */
69 interface Sampler {
70 /**
71 * Generates a random value vector sampled from this distribution.
72 *
73 * @return a random value vector.
74 */
75 double[] sample();
76 }
77 }