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:)
一个。 硬币翻转示例: (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的原因。 如果我们重复多次抛硬币,那么我们可以在对概率值的准确答案上获得更高的准确性。
While flipping a coin:
掷硬币时:
Next, we are going to prove this formula experimentally using the Monte Carlo Method.
接下来,我们将使用蒙特卡洛方法通过实验证明该公式。
Python实现: (Python Implementation:)
Import required libraries:
导入所需的库:
2. Coin flip function:
2.投币功能:
3. Checking the output of the function:
3.检查功能的输出:
4. Main function:
4.主要功能: