In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the counting method of Java probability theory". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the counting method of Java probability theory"?
Probability
Probability theory studies random events. It comes from the study of gamblers. There are many random events, such as throwing one, is it just luck?
Gamblers gradually discover the pattern of random events. Throwing two is a common game. If repeated many times, the number of times the total is 2 will be less than the number of times the total is 7. This is the rule that gamblers grasp: although I cannot predict the specific outcome of the event, I can understand the possibility of each outcome. This is the core of probability theory.
What exactly is "probability"? This is still controversial in mathematics. "Frequency School" believes that probability is the proportion of repeated attempts and the number of times a result occurs to the total number of attempts. "Bayesian School" believes that probability is the strength of subjective beliefs. Fortunately, these disputes do not affect our use of "probability" philosophy in our daily life. When the probability of rain forecast is 80%, many people will bring umbrellas as a result. The newspaper will analyze the probability of a team winning a game, and fans will be surprised if the team with a 10% chance of winning in the end wins. After all, this is a small probability event.
It is not easy to know the probability of a result. The above analysis of the team's winning probability, there are many factors to be considered. If you vote for one, there are six possible outcomes. Many reasons can affect the results, such as whether the seed is uniform, such as whether the person who throws the seed has a skill bias. The probability of each result is the same only when it is absolutely uniform and there is no cheating. Otherwise, it is impossible to give a definite probability value to the result. Therefore, in order to assign a probability to the result mathematically, we often add some assumptions to random events. These conditions are idealized, but they do not deviate from reality. For example, we say that throwing seeds, throwing seeds evenly, throwing people do not have any special means, and it is inferred that each result may be the same. Then, the probability of the occurrence of any one of these results is 1Universe 6.
Basic counting principle
Above we talked about the hypothesis of "equal probability". If the probability of each result is the same, the task of assigning probability to the result becomes easier. In calculating this probability, we only need the total number of results with equal probability to know the probability of each result. For example, throwing a seed will have six results, and if the probability is equal, then the probability of each result is 1 prime 6. For some complex situations, counting techniques need to be used.
The basic principles of counting are described as follows:
If an experiment can be divided into m steps, each step has the possibility of n _ 1, n _ 2, and n _ 2, respectively.
N1 × N2 ×... × nmn1 × N2 ×... × nm
A possible outcome.
The core of the basic technical principle is "step by step". For a simple one-step thing, we can tell the total number of results more directly. Such as the gender of giving birth to a child, such as the pros and cons of a coin, such as the result of a son. When a random event is composed of multiple steps, and each step is random, then the distribution can simplify the complexity of the problem. Imagine a restaurant with three windows selling three drinks, five dishes and two staples. Each student is limited to one choice in each window, then the student's food and beverage package will have a total of 30 possible results of 3x5x2. If the master of each window is very bossy and gives the students something at will, then we can even assume equal probability conditions, and the probability of each kind of food and beverage cover occurrence is 1 stroke 30.
Of course, as a student, will you protest against such a "random" canteen?
The application of basic counting principle is not limited to the theory of probability. When programmers do algorithm analysis, they virtually use counting. For example, if a nested loop requires M steps for the outer loop and N steps for the inner loop, then the total number of operations is MxN. It can be said that counting is a very important part of "discrete mathematics", and discrete mathematics is the core mathematics course of computer major.
The basic counting principle is the starting point of thinking. In reality, the situation tends to change more. Especially when our "distributed" actions are all acting on the same group, it will be relatively complicated. We classify the following situations:
Ordered repeated sampling
Consider the following two questions:
How many possible results are there when one is thrown twice in a row?
An optional 6 numbers, each number can be 0 to 9, how many possible results are there?
We can see that the sampling results of this kind are made up of multiple samples. The sample of each sample may also appear next time. For example, it may be 1 for the first time and 1 for the second time. This is called repetitive sampling (or sampling with replacement). In our example, there are six possible results for each sample.
The order in which the samples appear affects the results. For example, (1) (1) (1) and (2) (2) (2) are two different results.
Mathematically, there are n possibilities for each sampling if m times of sampling with return are carried out. If the end result is orderly, then there will be
Nmnm
It's possible.
Here is an example of our simulation:
Import itertoolsa = [1,2,3,4,5,6] outcomes = list (itertools.product (a, a)) print (outcomes) print (len (outcomes))
A total of 36 possible results are returned:
[(1,1), (1,2), (1,3), (1,4), (1,5), (1,6), (2,1), (2,2), (2,6), (2,4), (2,5), (2,6), (3,1), (3,2), (3, 3), (3, 4), (3, 5), (3, 6), (4) 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6), (5, 1), (5, 2), (5, 3), (5, 4), (5, 5), (5, 6), (6, 1), (6, 2), (6, 3), (6, 4), (6, 5), (6, 6)] 36
If the probability of each result is the same, then for one of the specific results, the probability of its occurrence is P=1/36P=1/36.
Ordered non-repetitive sampling
Consider the following two questions:
How many possibilities are there to pick two out of the four people as captain and vice-captain respectively?
From 10 classes, choose 3 courses and put them in the schedule of Monday, Wednesday and Friday respectively. How many possibilities are there?
It can be seen that there is no repetition of such sampling. The sample of a certain sampling will not appear after that, and the action of the previous step reduces the choice of the later step, which is called non-repetitive sampling. Under the premise of non-repetition, the number of possible results of each sampling decreases progressively, for example, if one of the four people is chosen as the captain, then the lieutenant can only choose from three people.
Again, the results are orderly. A serves as captain, B serves as vice captain, and A serves as vice captain and B serves as captain, which are two different results.
Ordered non-repetitive sampling is also called permutation. Mathematically, if you select m from n samples and put them in m positions, there will be
N × (n − 1) ×... × (n − mole 1) n × (n − 1) ×... × (n − mu 1)
It's possible. If we use the factorial (factorial) operator, the result can be represented as
N! (n − m)! n! (n − m)!
Among them, 1 × 2 ×... × (n − 1) × n − 1 × 2 × n.
We use the following program to simulate the situation of the team leader:
Import itertoolsa = ["Tom", "Lee", "King", "James"] outcomes = list (itertools.permutations (a, 2) print (outcomes) print (len (outcomes))
The result is
[('Tom',' Lee'), ('Tom',' King'), ('Tom',' James'), ('Lee',' Tom'), ('Lee',' King'), ('Lee',' James'), ('King',' Tom'), ('King',' Lee'), ('King',' James'), ('James',' Tom'), ('James',' Lee') ('James',' King')]
There are 12 possible outcomes.
Disordered non-repetitive sampling
Consider the following questions:
How many possibilities are there to draw two out of four people?
How many possibilities are there to draw three cards from a deck?
In the above questions, each sampling is also non-repetitive. But here, the sampling results are disordered. For example, pulling out "Lee" and "Tom" as well as "Tom" and "Lee" is the same result. This sampling method is called combination.
M samples have munim! A kind of arrangement. If m is taken from n samples as a combination, all the masks! A sort of sort should be seen as a. Therefore, there are
N! (n − m)! MSN! (n − m)! M!
A possible outcome. We can record combinations in the following ways:
(nm) = n! (n − m)! M! (nm) = n! (n − m)! M!
Let's simulate the first question:
Import itertoolsa = ["Tom", "Lee", "King", "James"] outcomes = list (itertools.combinations (a, 2) print (outcomes) print (len (outcomes))
The results are as follows
[('Tom',' Lee'), ('Tom',' King'), ('Tom',' James'), ('Lee',' King'), ('Lee',' James'), ('King',' James')]
As you can see, there are 6 possible combinations of 2 out of 4. This is half of the arrangement.
The problem of combination can be further extended. For example, how many ways are there to divide nine balls into three piles of one, three, and five? This is equivalent to taking one out of nine balls, then three out of the remaining eight balls, and the last five into a pile. It can be proved that the result is
9!1!3!5!9!1!3!5!
Similarly, n balls are divided into n _ 1, N _ 2, and N _ 1, N _ 2, and n=n1+n2+...+nmn=n1+n2+...+nm. There will be
N!n1!n2!...nm!n!n1!n2!...nm!
It's possible.
Disordered repeated sampling
Consider the following questions:
There are four kinds of prizes for scratch awards. If you buy 3 tickets, how many kinds of chances are there to win?
In each of the above sampling, it is repeated sampling, that is, after extraction, it is put back. For example, in the scratch prize, you can scrape the same prize many times. We record the results in a table:
Lamp, watch, computer, car may be 13000, may be 22010, may be 30111.
As we can see, we are actually dividing three sheets into four parts, and the number of each copy varies (≥ 0) (≥ 0).
This is similar to the problem of putting five identical items in three different containers:
We use two black separators to divide five identical items into three piles. Here, for example, the result of dividing the item into (0,2,3).
Two of the seven locations are selected as the locations of the partitions, with a total of
(72) (72)
It's possible.
Generally speaking, from n samples, disordered repeated sampling m times, there are
(n / m − 1m − 1) (n / m − 1m − 1)
It's possible.
Factorial and combination
We have used factorial several times above, and in Python, it can be implemented using math.factorial:
Import mathprint (math.factorial (5))
In addition, combinations can be approximated using scipy.misc.comb, such as:
Import scipy.miscprint (scipy.misc.comb (4, 2)) so far, I believe you have a deeper understanding of "what is the counting method of Java probability theory". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.