python 蒙特卡洛模拟_蒙特卡洛模拟(Python)深入教程

本文深入探讨了使用Python进行蒙特卡洛模拟的教程,详细解释了如何利用这种强大的统计方法解决复杂问题,适用于人工智能领域的概率计算。
摘要由CSDN通过智能技术生成

python 蒙特卡洛模拟

机器学习数学程序设计教程 (Machine Learning, Mathematics, Programming, Tutorial)

Author(s): Pratik Shukla, Roberto Iriondo

作者:Pratik Shukla,Roberto Iriondo

什么是蒙特卡洛模拟? (What is the Monte Carlo Simulation?)

A Monte Carlo method is a technique that uses random numbers and probability to solve complex problems. The Monte Carlo simulation, or probability simulation, is a technique used to understand the impact of risk and uncertainty in financial sectors, project management, costs, and other forecasting machine learning models.

蒙特卡洛方法是一种使用随机数和概率来解决复杂问题的技术。 蒙特卡洛模拟或概率模拟是一种用于了解风险和不确定性对金融部门,项目管理,成本和其他预测的影响的技术 机器学习 楷模。

Risk analysis is part of almost every decision we make, as we constantly face uncertainty, ambiguity, and variability in our lives. Moreover, even though we have unprecedented access to information, we cannot accurately predict the future.

风险分析几乎是我们所做每个决策的一部分,因为我们不断面临生活中的不确定性,歧义和多变性。 此外,即使我们拥有前所未有的信息访问渠道,也无法准确预测未来。

The Monte Carlo simulation allows us to see all the possible outcomes of our decisions and assess risk impact, in consequence allowing better decision making under uncertainty.

蒙特卡洛模拟使我们能够看到决策的所有可能结果并评估风险影响,从而可以在不确定性下做出更好的决策。

In this article, we will go through five different examples to understand the Monte Carlo Simulation method.

在本文中,我们将通过五个不同的示例来理解蒙特卡洛模拟方法。

📚 Resources: Google Colab Implementation | GitHub Repository 📚

📚资源: Google Colab实施 | GitHub存储库 📚

应用范围: (Applications:)

  • Finance.

    金融。
  • Project Management.

    项目管理。
  • Energy.

    能源。
  • Manufacturing.

    制造业。
  • Engineering.

    工程。
  • Research and Development.

    研究与开发。
  • Insurance.

    保险。
  • Oil and Gas.

    油和气。
  • Transportation.

    运输。
  • Environment.

    环境。
  • And others.

    和别的。

例子: (Examples:)

  1. Coin Flip Example.

    硬币翻转的例子

  2. Estimating PI Using Circle and Square.

    使用圆形和正方形估算PI。

  3. Monty Hall Problem.

    蒙蒂·霍尔问题。

  4. Buffon’s Needle Problem.

    布冯的针问题。

  5. Why Does the House Always Win?

    为什么房子总是赢?

一个。 硬币翻转示例: (a. Coin Flip Example:)

The probability of head for a fair coin is 1/2. However, is there any way we can prove it experimentally? In this example, we are going to use the Monte-Carlo method to simulate the coin-flipping iteratively 5000 times to find out why the probability of a head or tail is always 1/2. If we repeat this coin flipping many, many more times, then we can achieve higher accuracy on an exact answer for our probability value.

买到一枚公平硬币的概率为1/2。 但是,有什么方法可以通过实验证明吗? 在此示例中,我们将使用蒙特卡洛方法来反复模拟抛硬币5000次,以找出为什么头或尾的概率始终为1/2的原因。 如果我们重复多次抛硬币,那么我们可以在对概率值的准确答案上获得更高的准确性。

Figure 2: Heads and tails, mathematical representation.
Figure 2: Heads and tails, mathematical representation.
图2:正面和反面,数学表示。

While flipping a coin:

掷硬币时:

Figure 3: Formula for heads and tails coin example.
Figure 3: Formula for heads and tails coin example.
图3:正面和反面硬币示例的公式。

Next, we are going to prove this formula experimentally using the Monte Carlo Method.

接下来,我们将使用蒙特卡洛方法通过实验证明该公式。

Python实现: (Python Implementation:)

  1. Import required libraries:

    导入所需的库:

Figure 4: Import the required libraries for our coin flipping example, the Monte Carlo Simulation
Figure 4: Import the required libraries for our coin flipping example.
图4:导入硬币翻转示例所需的库。

2. Coin flip function:

2.投币功能:

Figure 5: A simple function randomizing the results between 0 and 1, 0 for heads and 1 for tails.
Figure 5: A simple function randomizing the results between 0 and 1, 0 for heads, and 1 for tails.
图5:一个简单的函数将结果随机分配在0和1之间,头部为0,尾部为1。

3. Checking the output of the function:

3.检查功能的输出:

Figure 6: Running the function of coin_flip()
Figure 6: Running the function of coin_flip()
图6:运行coin_flip()函数

4. Main function:

4.主要功能:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值