Testing the Uniform Distribution Hypothesis.

With the help of which many real processes are simulated. And the most common example is the public transport schedule. Suppose a certain bus (trolley / tram) runs at intervals of 10 minutes, and at a random moment in time you come to a stop. What is the probability that the bus will arrive within 1 minute? Obviously 1 / 10th. And the likelihood that you have to wait 4-5 minutes? Too . And the likelihood that the bus will have to wait more than 9 minutes? One tenth!

Consider some finite interval, let it be a segment for definiteness. If random value possesses permanent density of probability distribution on a given segment and zero density outside it, then they say that it is distributed evenly... In this case, the density function will be strictly defined:

Indeed, if the length of the segment (see drawing) is, then the value is inevitably equal - so that the unit area of ​​the rectangle is obtained, and known property:


Let's check it formally:
, h.t. From a probabilistic point of view, this means that the random variable authentically will take one of the meanings of the segment ..., eh, I am slowly becoming a boring old man =)

The essence of uniformity is that no matter what the inner gap fixed length we have not considered (remember the "bus" minutes)- the probability that a random variable will take a value from this interval will be the same. In the drawing, I shaded a C of such probabilities - once again I emphasize that they are defined by areas rather than function values!

Consider a typical assignment:

Example 1

A continuous random variable is given by its distribution density:

Find a constant, calculate and compose the distribution function. Build graphs. Find

In other words, everything you could dream of :)

Solution: since on the interval (finite interval) , then the random variable has even distribution, and the value "tse" can be found by the direct formula ... But it's better in a general way - using a property:

... why is it better? So that there are no unnecessary questions;)

So the density function is:

Let's complete the drawing. The values impossible , and therefore the bold points are placed at the bottom:


As an express check, we calculate the area of ​​the rectangle:
, h.t.

We will find expected value, and, probably, you already guess what it is equal to. Remembering the "10-minute" bus: if randomly come to the bus stop for many, many days, save me, then average it will have to wait 5 minutes.

Yes, that's right - expectation should be exactly in the middle of the "event" interval:
as expected.

We calculate the variance by formula ... And here you need an eye and an eye when calculating the integral:

Thus, dispersion:

Let's compose distribution function ... Nothing new here:

1) if, then ;

2) if, then:

3) and, finally, for , therefore:

As a result:

Let's execute the drawing:


On the "live" interval, the distribution function is growing linearly, and this is another sign that we have a uniformly distributed random variable. Well, of course, because derivative linear function- is a constant.

The required probability can be calculated in two ways, using the found distribution function:

either with the help definite integral from density:

As you like.

And here you can also write answer: ,
, the graphs are built in the course of the solution.

... “you can” because there is usually no punishment for his absence. Usually;)

To calculate and uniform random variable there are special formulas that I suggest you derive yourself:

Example 2

A continuous random variable is given by the density .

Calculate expected value and variance. Simplify results as much as possible (abbreviated multiplication formulas to help).

It is convenient to use the obtained formulas for verification, in particular, check the problem just solved by substituting specific values ​​"a" and "b" in them. Short solution at the bottom of the page.

And at the end of the lesson, we will analyze a couple of "word" problems:

Example 3

Scale division measuring instrument is equal to 0.2. Instrument readings are rounded to the nearest whole division. Assuming that the rounding errors are uniformly distributed, find the probability that at the next measurement it will not exceed 0.04.

For better understanding solutions Let's imagine that this is some kind of mechanical device with an arrow, for example, a scale with a graduation of 0.2 kg, and we have to weigh a pig in a bag. But not in order to find out his fatness - now it will be important WHERE the arrow stops between two adjacent divisions.

Consider a random variable - distance arrows from the nearest left division. Or from the nearest right, it doesn't matter.

Let's compose the function of the probability distribution density:

1) Since the distance cannot be negative, then on the interval. It is logical.

2) It follows from the condition that the arrow of the balance with equal probability can stop anywhere between tick marks * , including the divisions themselves, and therefore in the interval:

* This is an essential condition. So, for example, when weighing pieces of cotton wool or kilogram packs of salt, uniformity will be observed at much narrower intervals.

3) And since the distance from the NEAREST left division cannot be more than 0.2, then at is also equal to zero.

Thus:

It should be noted that no one asked us about the density function, and I gave its complete construction exclusively in cognitive circuits. When finishing the task, it is enough to write down only the 2nd item.

Now let's answer the question of the problem. When will the rounding error to the nearest division not exceed 0.04? This will happen when the arrow stops no further than 0.04 from the left division. on right or no more than 0.04 from the right division left... In the drawing, I shaded the corresponding areas:

It remains to find these areas using integrals... In principle, they can be calculated “in a school-like manner” (like the areas of rectangles), but simplicity does not always find understanding;)

By addition theorem for the probabilities of inconsistent events:

- the probability that the rounding error does not exceed 0.04 (40 grams for our example)

It is easy to see that the maximum possible rounding error is 0.1 (100 grams) and therefore the probability that the rounding error does not exceed 0.1 is equal to one.

Answer: 0,4

In other sources of information there are alternative explanations / design of this problem, and I chose the option that seemed to me the most understandable. Special attention it is necessary to pay attention to the fact that in the condition we can talk about errors NOT rounding, but about random measurement errors, which, as a rule (but not always) distributed over normal law... Thus, just one word can radically change the decision! Be on the lookout for the meaning.

And as soon as everything goes in a circle, then our feet bring us to the same bus stop:

Example 4

Buses on some route run strictly according to the schedule and at intervals of 7 minutes. Construct the density function of a random variable - the waiting time for the next bus by a passenger who at random came to a bus stop. Find the probability that he will wait for the bus no more than three minutes. Find the distribution function and explain its meaningful meaning.

Let us now turn to distributions of a continuous random variable often used in practice.

Continuous r.v. NS called evenly distributed on the segment [ a, b], if the density of its probability is constant on this interval, and outside it is equal to 0 (that is, the random variable NS focused on the segment [ a, b], on which it has a constant density). By this definition density uniformly distributed on the segment [ a, b] random variable NS looks like:

where with there is a number. However, it is easy to find it using the probability density property for r.v. concentrated on the segment [ a, b]:
... Hence it follows that
, where
... Therefore, the density uniformly distributed on the segment [ a, b] random variable NS looks like:

.

To judge the uniformity of the distribution of n.s.v. NS it is possible from the following consideration. A continuous random variable has a uniform distribution on the segment [ a, b], if it takes values ​​only from this segment, and any number from this segment has no advantage over other numbers of this segment in the sense of the possibility of being the value of this random variable.

Random variables that have a uniform distribution include such quantities as the waiting time of a vehicle at a stop (with a constant interval of movement, the waiting time is evenly distributed over this interval), the error of rounding off a number to an integer (evenly distributed over [−0.5 , 0.5 ]) other.

Distribution function F(x) a, b] random variable NS is searched for by the known probability density f(x) using the formula of their connection
... As a result of the corresponding calculations, we obtain the following formula for the distribution function F(x) uniformly distributed segment [ a, b] random variable NS :

.

The figures show graphs of the probability density f(x) and distribution functions f(x) uniformly distributed segment [ a, b] random variable NS :


Mathematical expectation, variance, standard deviation, mode and median of a uniformly distributed segment [ a, b] random variable NS calculated by the probability density f(x) in the usual way (and quite simply because of simple kind f(x) ). The result is the following formulas:

but fashion d(X) is any number of the segment [ a, b].

Let us find the probability of hitting a uniformly distributed segment [ a, b] random variable NS in the interval
completely lying inside [ a, b]. Taking into account the known form of the distribution function, we obtain:

Thus, the probability of hitting a uniformly distributed segment [ a, b] random variable NS in the interval
completely lying inside [ a, b], does not depend on the position of this interval, but depends only on its length and is directly proportional to this length.

Example... The bus interval is 10 minutes. What is the probability that a passenger arriving at the bus stop will wait for the bus for less than 3 minutes? What is the average waiting time for a bus?

Normal distribution

This distribution is most often encountered in practice and plays an exceptional role in probability theory and mathematical statistics and their applications, since many random variables have such a distribution in natural science, economics, psychology, sociology, military sciences, and so on. This distribution is a limiting law, which is approached (under certain natural conditions) by many other distribution laws. With the help of the normal distribution law, phenomena are also described that are subject to the action of many independent random factors of any nature and any law of their distribution. Let's move on to definitions.

A continuous random variable is called distributed over normal law (or Gaussian law) if its probability density has the form:

,

where are the numbers a and σ (σ>0 ) are the parameters of this distribution.

As already mentioned, the Gaussian law of distribution of random variables has numerous applications. According to this law, measurement errors by instruments, deviation from the center of the target during shooting, dimensions of manufactured parts, weight and height of people, annual precipitation, number of newborns, and much more are distributed.

The above formula for the probability density of a normally distributed random variable contains, as was said, two parameters a and σ , and therefore defines a family of functions that vary depending on the values ​​of these parameters. If we apply the usual methods of mathematical analysis of the study of functions and plotting to the probability density of the normal distribution, then the following conclusions can be drawn.


are the points of its inflection.

Based on the information received, we build a graph of the probability density f(x) normal distribution (it is called a Gaussian curve - figure).

Let us find out how changing the parameters affects a and σ on the shape of the Gaussian curve. It is obvious (this can be seen from the formula for the density of the normal distribution) that the change in the parameter a does not change the shape of the curve, but only leads to its shift to the right or left along the axis NS... Dependence σ more difficult. The above study shows how the magnitude of the maximum and the coordinates of the inflection points depend on the parameter σ ... In addition, it must be taken into account that for any parameters a and σ the area under the Gaussian curve remains equal to 1 (this is common property probability density). It follows from what has been said that with an increase in the parameter σ the curve becomes flatter and stretches along the axis NS... The figure shows the Gaussian curves for different meanings parameter σ (σ 1 < σ< σ 2 ) and the same parameter value a.

Let us clarify the probabilistic meaning of the parameters a and σ normal distribution. Already from the symmetry of the Gaussian curve with respect to the vertical line passing through the number a on the axis NS it is clear that the mean (i.e. the mathematical expectation M (X)) of a normally distributed random variable is a... For the same reasons, the mode and median should also be equal to the number a. Accurate calculations using the appropriate formulas confirm this. If we write the above expression for f(x) substitute in the formula for the variance
, then after a (rather difficult) calculation of the integral, we get in the answer the number σ 2 ... Thus, for a random variable NS distributed according to the normal law, the following main numerical characteristics were obtained:

Therefore, the probabilistic meaning of the parameters of the normal distribution a and σ next. If s.v. NSa and σ a σ.

Let us now find the distribution function F(x) for a random variable NS, distributed according to the normal law, using the above expression for the probability density f(x) and the formula
... When substituting f(x) the integral is “non-removable”. Everything that can be done to simplify the expression for F(x), this is a representation of this function in the form:

,

where F (x)- the so-called Laplace function which has the form

.

The integral through which the Laplace function is expressed is also non-trivial (but for each NS this integral can be calculated approximately with any predetermined accuracy). However, it is not required to calculate it, since at the end of any textbook on probability theory there is a table for determining the values ​​of the function F (x) at a given value NS... In what follows, we will need the property that the Laplace function is odd: Ф (−х) =F (x) for all numbers NS.

Let us now find the probability that a normally distributed r.v. NS will take a value from the specified numeric range (α, β) ... From the general properties of the distribution function P (α< X< β)= F(β) F(α) ... Substituting α and β into the above expression for F(x) , we get

.

As mentioned above, if s.v. NS normally distributed with parameters a and σ , then its average value is a, and the standard deviation is σ. That's why the average deviation of the values ​​of this r.v. when tested by number a equals σ. But this is the average deviation. Therefore, larger deviations are possible. We will find out to what extent certain deviations from the average are possible. Let us find the probability that the value of a normally distributed random variable NS deviate from its mean M (X) = a by less than some number δ, i.e. R(| Xa|<δ ):. Thus,

.

Substituting into this equality δ = 3σ, we get the probability that the value of r.v. NS(in one test) deviates from the mean by less than three times the value σ (with an average deviation, as we remember, equal to σ ): (meaning F (3) taken from the table of values ​​of the Laplace function). It is almost 1 ! Then the probability of the opposite event (that the value deviates by at least ) is equal to 1 0.997=0.003 which is very close to 0 ... Therefore, this event is "almost impossible" happens extremely rarely (on average 3 times out 1000 ). This reasoning is the rationale behind the well-known Three Sigma Rule.

The Three Sigma Rule... Normally distributed random variable single test practically does not deviate from its average further than by .

We emphasize once again that we are talking about one test. If there are many tests of a random variable, then it is quite possible that some of its values ​​will move further from the average than ... This is confirmed by the following

Example... What is the probability that with 100 tests of a normally distributed random variable NS at least one of its values ​​deviate from the mean by more than three times the standard deviation? And with 1000 trials?

Solution. Let the event A means that when testing a random variable NS its value deviated from the average by more than 3σ. As it has just been clarified, the probability of this event p = P (A) = 0.003. 100 such tests were carried out. We need to know the probability that the event A occurred at least times, i.e. came from 1 before 100 once. This is a typical Bernoulli circuit problem with parameters n=100 (number of independent tests), p = 0.003(probability of event A in one trial), q=1− p=0.997 ... It is required to find R 100 (1≤ k≤100) ... In this case, of course, it is easier to find first the probability of the opposite event R 100 (0) - the probability that the event A never happened (i.e., it happened 0 times). Taking into account the connection between the probabilities of the event itself and its opposite, we get:

Not so little. It may well happen (occurs on average in every fourth such series of tests). At 1000 tests according to the same scheme, it can be obtained that the probability of at least one deviation is further than , equals: . So we can with great confidence wait for at least one such deviation.

Example... The growth of men of a certain age group is distributed normally with mathematical expectation a, and the standard deviation σ ... What proportion of costumes k-th growth should be foreseen in the total production for a given age group if k th height is determined by the following limits:

1 height : 158 164cm 2 height : 164 - 170cm 3 height : 170 - 176cm 4 height : 176 - 182cm

Solution. Let's solve the problem with the following parameter values: a = 178,σ = 6,k=3 ... Let r.v. NS the height of a randomly selected man (it is distributed according to the condition normally with the given parameters). Find the probability that a randomly selected man will need 3 th growth. Using the oddness of the Laplace function F (x) and a table of its values: P (170 Therefore, in the total volume of production, it is necessary to provide 0.2789*100%=27.89% costumes 3 th growth.

In practice, there are random variables, about which it is known in advance that they can take any value within strictly defined boundaries, and within these boundaries all values ​​of the random variable have the same probability (have the same probability density).

For example, if a clock breaks down, a stopped minute hand will show the time elapsed from the beginning of a given hour until the clock breaks with the same probability (probability density). This time is a random variable, taking values ​​with the same probability density that do not go beyond the boundaries determined by the duration of one hour. Rounding error also belongs to such random variables. Such quantities are said to be uniformly distributed, that is, they have a uniform distribution.

Definition. A continuous random variable X has a uniform distribution on the segment[a, in], if on this segment the probability density of the random variable is constant, i.e., if the differential distribution function f (x) looks like this:

This distribution is sometimes called uniform density law. About a quantity that has a uniform distribution on a certain segment, we will say that it is uniformly distributed on this segment.

Find the value of the constant c. Since the area bounded by the distribution curve and the axis Oh, is equal to 1, then

where with=1/(b- a).

Now the function f (x)can be represented as

Let us construct the distribution function F (x ), what is the expression for F (x) on the interval [ a, b]:


The graphs of the functions f (x) and F (x) are as follows:


Let's find the numerical characteristics.

Using the formula for calculating the mathematical expectation of the NSV, we have:

Thus, the mathematical expectation of a random variable uniformly distributed on the segment [a, b] coincides with the middle of this segment.

Let's find the variance of a uniformly distributed random variable:

whence it immediately follows that the standard deviation:

Let us now find the probability that the value of a random variable with a uniform distribution falls on the interval(a, b), which belongs entirely to the segment [a, b ]:


Geometrically, this probability is the area of ​​the shaded rectangle. The numbers a andbare called distribution parameters and unambiguously define a uniform distribution.

Example 1. Buses on some route run strictly according to the schedule. The interval of movement is 5 minutes. Find the probability that the passenger arriving at the stop. The next bus will wait less than 3 minutes.

Solution:

CB - the waiting time for the bus has a uniform distribution. Then the required probability will be equal to:

Example 2. The edge of the cube x is measured approximately. Moreover

Considering the edge of the cube as a random variable uniformly distributed in the interval (a, b), find the mathematical expectation and variance of the volume of the cube.

Solution:

The volume of a cube is a random variable determined by the expression Y = X 3. Then the mathematical expectation is:

Dispersion:

Online service:

This issue has long been studied in detail, and the most widespread method of polar coordinates was proposed by George Box, Mervyn Mueller and George Marsaglia in 1958. This method allows you to obtain a pair of independent normally distributed random variables with mathematical expectation 0 and variance 1 as follows:

Where Z 0 and Z 1 are the desired values, s = u 2 + v 2, and u and v are random variables uniformly distributed on the interval (-1, 1), selected in such a way that the condition 0 is satisfied< s < 1.
Many people use these formulas without even thinking, and many do not even know about their existence, since they use ready-made implementations. But there are people who have questions: “Where did this formula come from? And why do we get a couple of quantities at once? " Next, I will try to give a clear answer to these questions.


To begin with, let me remind you what a probability density, a distribution function of a random variable and an inverse function are. Suppose there is some random variable, the distribution of which is given by the density function f (x), which has the following form:

This means that the probability that the value of a given random variable will be in the interval (A, B) is equal to the area of ​​the shaded area. And as a consequence, the area of ​​the entire shaded area should be equal to one, since in any case the value of the random variable will fall into the domain of definition of the function f.
The distribution function of a random variable is an integral of the density function. And in this case, its approximate form will be as follows:

The point here is that the value of the random variable will be less than A with probability B. And as a consequence, the function never decreases, and its values ​​lie in the segment.

An inverse function is a function that returns an argument to the original function if you pass the value of the original function to it. For example, for the function x 2, the inverse will be the function of extracting the root, for sin (x) it is arcsin (x), and so on.

Since most pseudo-random number generators produce only a uniform distribution at the output, it often becomes necessary to transform it into something else. In this case, to normal Gaussian:

The basis of all methods for converting a uniform distribution to any other is the inverse conversion method. It works as follows. The inverse function of the required distribution is found, and a random variable uniformly distributed on the interval (0, 1) is passed into it as an argument. At the output, we get a value with the required distribution. For clarity, I present the following picture.

Thus, the uniform segment is, as it were, smeared in accordance with the new distribution, projecting onto another axis through the inverse function. But the problem is that the integral of the density of the Gaussian distribution is not easy to calculate, so the above scientists had to cheat.

There is a chi-square distribution (Pearson distribution), which is the distribution of the sum of squares of k independent normal random variables. And in the case when k = 2, this distribution is exponential.

This means that if a point in a rectangular coordinate system has random coordinates X and Y distributed normally, then after translating these coordinates into the polar system (r, θ), the square of the radius (distance from the origin to the point) will be exponentially distributed, since the square of the radius is the sum of the squares of the coordinates (according to the Pythagorean law). The distribution density of such points on the plane will look like this:


Since it is equal in all directions, the angle θ will have a uniform distribution in the range from 0 to 2π. The converse is also true: if you specify a point in the polar coordinate system using two independent random variables (uniformly distributed angle and exponentially distributed radius), then the rectangular coordinates of this point will be independent normal random variables. And the exponential distribution from the uniform distribution is much easier to obtain using the same inverse transformation method. This is the essence of the Box-Muller polar method.
Now let's display the formulas.

(1)

To obtain r and θ, you need to generate two random variables uniformly distributed on the segment (0, 1) (let's call them u and v), the distribution of one of which (let's say v) must be transformed into exponential to obtain the radius. The exponential distribution function looks like this:

Its inverse function:

Since the uniform distribution is symmetric, the transformation will work similarly with the function

It follows from the chi-square distribution formula that λ = 0.5. We substitute λ, v into this function and get the square of the radius, and then the radius itself:

The angle is obtained by stretching the unit segment to 2π:

Now we substitute r and θ into formulas (1) and get:

(2)

These formulas are already ready to use. X and Y will be independent and normally distributed with a variance of 1 and an expectation of 0. To get a distribution with other characteristics, it is enough to multiply the result of the function by the standard deviation and add the mathematical expectation.
But it is possible to get rid of trigonometric functions by specifying the angle not directly, but indirectly through the rectangular coordinates of a random point in the circle. Then, through these coordinates, it will be possible to calculate the length of the radius vector, and then find the cosine and sine by dividing x and y by it, respectively. How and why does it work?
Let's choose a random point from uniformly distributed in a circle of unit radius and denote the square of the length of the radius vector of this point by the letter s:

The selection is carried out by setting random rectangular coordinates x and y, evenly distributed in the interval (-1, 1), and discarding points that do not belong to the circle, as well as the central point at which the angle of the radius vector is not defined. That is, the condition 0 must be met< s < 1. Тогда, как и в случае с Гауссовским распределением на плоскости, угол θ будет распределен равномерно. Это очевидно - количество точек в каждом направлении одинаково, значит каждый угол равновероятен. Но есть и менее очевидный факт - s тоже будет иметь равномерное распределение. Полученные s и θ будут независимы друг от друга. Поэтому мы можем воспользоваться значением s для получения экспоненциального распределения, не генерируя третью случайную величину. Подставим теперь s в формулы (2) вместо v, а вместо тригонометрических функций - их расчет делением координаты на длину радиус-вектора, которая в данном случае является корнем из s:

We get the formulas as at the beginning of the article. The disadvantage of this method is the discarding of points that are not included in the circle. That is, using only 78.5% of the generated random values. On older computers, the lack of trigonometric functions was still a big advantage. Now, when one processor instruction calculates sine and cosine simultaneously, I think these methods can still compete.

Personally, I still have two questions:

  • Why is the value of s evenly distributed?
  • Why is the sum of squares of two normal random variables exponentially distributed?
Since s is the square of the radius (for simplicity, I call the radius the length of the radius vector that specifies the position of the random point), we first find out how the radii are distributed. Since the circle is filled evenly, it is obvious that the number of points with radius r is proportional to the circumference of a circle with radius r. And the circumference is proportional to the radius. This means that the distribution density of the radii increases evenly from the center of the circle to its edges. And the density function has the form f (x) = 2x on the interval (0, 1). Coefficient 2 so that the area of ​​the figure under the graph is equal to one. When such a density is squared, it becomes uniform. Since theoretically, in this case, for this it is necessary to divide the density function by the derivative of the transformation function (that is, from x 2). And clearly it happens like this:

If a similar transformation is done for a normal random variable, then the density function of its square will be similar to a hyperbola. And the addition of two squares of normal random variables is already a much more complicated process associated with double integration. And the fact that the result will be an exponential distribution, for me personally, it remains for me to check by a practical method or to accept it as an axiom. And for anyone interested, I suggest that you familiarize yourself with the topic more closely, drawing on knowledge from these books:

  • Wentzel E.S. Probability theory
  • D.E. Knut The Art of Computer Programming Vol.2

In conclusion, I will give an example of the implementation of a normally distributed random number generator in JavaScript:

Function Gauss () (var ready = false; var second = 0.0; this.next = function (mean, dev) (mean = mean == undefined? 0.0: mean; dev = dev == undefined? 1.0: dev; if ( this.ready) (this.ready = false; return this.second * dev + mean;) else (var u, v, s; do (u = 2.0 * Math.random () - 1.0; v = 2.0 * Math. random () - 1.0; s = u * u + v * v;) while (s> 1.0 || s == 0.0); var r = Math.sqrt (-2.0 * Math.log (s) / s); this.second = r * u; this.ready = true; return r * v * dev + mean;));) g = new Gauss (); // create an object a = g.next (); // generate a couple of values ​​and get the first one b = g.next (); // get the second c = g.next (); // again generate a pair of values ​​and get the first one
The mean (expectation) and dev (standard deviation) parameters are optional. I draw your attention to the fact that the logarithm is natural.