The Monte Carlo Method

Sdílet
Vložit
  • čas přidán 13. 08. 2017
  • RandomMathsInc is back after a long break, and today we talk about approximations using the Monte Carlo Method. Featuring random numbers and coding with Python.
    Footnotes:
    1 - If you want to know more about Monaco, wait until Geography Now makes a video about them (they're a great channel, you should check them out if you haven't already).
    2 - Most of the time, rather than using truly random numbers, computers will use pseudorandom numbers (see en.wikipedia.org/wiki/Pseudor.... They aren't actually random, but looks random enough to us and is random enough for the Monte Carlo Method.
    3 - Have you seen our Pi Day video this year? That problem was solved with the Monte Carlo Method: • Calculating Pi Experim...
    Some pictures I used:
    upload.wikimedia.org/wikipedi...
    upload.wikimedia.org/wikipedi...
    upload.wikimedia.org/wikipedi...
    upload.wikimedia.org/wikipedi...
    upload.wikimedia.org/wikipedi...

Komentáře • 93

  • @malharjajoo7393
    @malharjajoo7393 Před 4 lety +60

    Damn, this was the clearest explanation I've seen on this stuff. Well done !

  • @mateuszkujda3544
    @mateuszkujda3544 Před 4 lety +11

    I never write comments on yt, but I would like to thank the universe for bringing me to your channel and enjoying listening about the math and solving the problem.
    Good job man!

  • @francissydnor7891
    @francissydnor7891 Před 4 lety +7

    Absolutely incredible explanation. The world needs more people who can teach material like you can. Cheers!

  • @Softdattel
    @Softdattel Před 8 měsíci +1

    Very good introduction to monte carlo. You are doing a great job, clear concise, spiced with a little humor, no unrelated story telling! Keep it up. Thanks.

  • @TrueTalenta
    @TrueTalenta Před 2 lety +2

    Has anyone told you that you are just phenomenal and exceptional in your explanations!
    Great job!

  • @bigh8438
    @bigh8438 Před 3 lety +6

    This came up on my timeline. I use a representation of the Monto Carlo method for nuclear simulations at uni

  • @ear4funk814
    @ear4funk814 Před 3 lety +4

    Yep ... definitely clearest example of Monte Carlo Integration I've seen .... great job, and most appreciated!!!!

  • @pythonanimalia
    @pythonanimalia Před 4 lety +5

    new to python. I like that the syntax suggestions pop up while you type. What are you using?

  • @jeshurunjohnson13
    @jeshurunjohnson13 Před 2 lety

    Thank you so much! I was stuck on a piece of code involving Monte Carlo simulations for days!

  • @anandrai492
    @anandrai492 Před 2 lety +1

    Brilliant! So clear and concise, thank you so much.

  • @johnburns9696
    @johnburns9696 Před 2 měsíci

    I really enjoyed your explanation of using Monte Carlo simulation to solve an area under the curve problem. Cheers!

  • @Narutoshippuden2055
    @Narutoshippuden2055 Před 4 lety

    A very clear and concise video, thanks a lot for the explanation.

  • @sergiovazquez2662
    @sergiovazquez2662 Před 4 lety

    Cheers man!! Great explanation for MC Method, and nice RP speaking!

  • @jursamaj
    @jursamaj Před 6 měsíci +1

    6:40 A better method: only generate your x samples. For each x, calculate the y (you're already doing this to decide if an x,y sample is inside or not, so this is the same efficiency). Add all of your y values to a floating point accumulator. At the end, divide the accumulated value by the number of samples to get an average height, and multiply by the width of the domain (10-1=9). You don't even need to know the maximum height this way. In practice, you wouldn't even use random x values, but equally spaced ones.
    In fact, I whipped this up in Python, and got the answer correct to about 1 part in 10^12, compared to yours at 1 part in 1^4.

    • @hansisbrucker813
      @hansisbrucker813 Před 2 měsíci

      Do you happen to have the code somewhere. You made me really curious 🤓👍

  • @jagarali
    @jagarali Před 5 lety +1

    This is a quite exhaustive explanation.. Thanks.

  • @marcusseidowski3320
    @marcusseidowski3320 Před 4 lety

    Well Done and well explaned!!Amen!Can you do something concerning subset simulation or importance sampling?

  • @adinathdesai6880
    @adinathdesai6880 Před rokem

    Thanks a lot, it really helps me to understand the concept and method of Monte Carlo method

  • @emrulhasan5646
    @emrulhasan5646 Před 2 lety

    Awesome explanation. Loved it. Thanks a lot!

  • @KeesJansma7689
    @KeesJansma7689 Před 4 lety +3

    Thanks for this clear explanation! You're a funny cool dude as well.

  • @PintuBhattacharya-mp4mw

    Nicely explained. Requeting for an another video on integration of a 3-variable function.

  • @peterchindove7146
    @peterchindove7146 Před 2 lety

    Totally enjoyed your presentation, kudos!

  • @totimariageraci
    @totimariageraci Před rokem

    Great clear explanation, thank you so much

  • @p.s.srinivas7696
    @p.s.srinivas7696 Před 4 lety

    Well explained. Concept became very clear.

  • @renanlarrieu
    @renanlarrieu Před 2 lety

    Clear and well done explanation. Thank you

  • @rezakhalili5362
    @rezakhalili5362 Před 2 lety

    You're the best. It was so clear to me. unfortunately it wasn't what I wanted. But that made a good vision of this method

  • @Pradeepvlogs101
    @Pradeepvlogs101 Před 3 lety

    So clear explanation! Thanks

  • @seandroid88
    @seandroid88 Před 3 lety

    Thanks this really helped understand the monte carlo question on my final

  • @chdfnh
    @chdfnh Před 4 lety

    Very good explanation. Thanks!

  • @gutzimmumdo4910
    @gutzimmumdo4910 Před rokem

    very clear explanation

  • @stonecastle858
    @stonecastle858 Před 11 měsíci

    Very well explained. Brilliant

  • @user-if2fk2sw8n
    @user-if2fk2sw8n Před rokem

    Thanks for the video...I want to change the co so I can have several experiments and try them on a graph. How do I do so?

  • @dr.md.mehboobalam93
    @dr.md.mehboobalam93 Před 2 lety

    very nice video. I was thinking if we don't know the maximum value of the function then how do you call the random number for y?

  • @jonavuka
    @jonavuka Před 4 lety

    so what if you randomly generated a point twice or more than once for your simulation? Is that not considered or is that attributed to the error

  • @vishalsk8337
    @vishalsk8337 Před 3 lety

    Amazing work!

  • @rockandrolldevil665
    @rockandrolldevil665 Před 3 lety

    Thanks, that was an awesome class!

  • @Danny-ts7sc
    @Danny-ts7sc Před 4 lety

    thank you, your explanation is way better than my teacher

  • @natalie1997927
    @natalie1997927 Před 2 lety

    Hi! can you make a matlab video of how to use Monte Carlo method to calculate the volume of a cone inscribed in the unit cube(L=1)?

  • @spyhunter0066
    @spyhunter0066 Před 11 měsíci

    excellent job, well done!

  • @IbnuNurHamzah
    @IbnuNurHamzah Před 3 lety

    thanks for your explanation dude

  • @marceloescobar6389
    @marceloescobar6389 Před 3 lety

    Brilliant, absolutely brilliant

  • @rafshantik
    @rafshantik Před 3 lety +1

    Such clear pronunciation of scientific terms. How do I talk like you? I always forget what I am going to say whenever giving presentation.

  • @michelebenedetti1335
    @michelebenedetti1335 Před 3 lety

    Hi, I want to apply the Montecarlo method to solve a double integral over a polygonal domain, is it possible?

  • @izzyt2286
    @izzyt2286 Před 2 lety

    THIS WAS AMAZING THANK YOU

  • @iidtxbc
    @iidtxbc Před 2 lety

    Can you do "Quasi Monte Carlo"?

  • @henryadolfo
    @henryadolfo Před 3 lety

    Well done !

  • @plastiqueman
    @plastiqueman Před 3 lety

    Thanks for the video, very helpful. I wrote the codes down exactly the same as you did but I'm getting an error "unsupported operand type(s) for *: 'NoneType' and 'float' "

  • @skilz8098
    @skilz8098 Před 4 lety

    Very nice and simple explanation and demonstration through the use of python. Your algorithm worked quite nicely, however, the source code itself was written in a manner that was designed specifically for this problem... In other words, it's not exactly reusable. I've just written an integrator class in C++ that will calculate the integral of a function using Riemann Sums approximation. I was looking to extend my class to use other methods as well, Monte Carlo being one of them. I'm looking for a generic way to design the Monte Carlo method where the only information the integrator will have is the function of integration (its integrand), the limits of integration, and the step_size! The step_size within the context of Riemann Sums is the "width" of dx where that is defined by (upper - lower)/step_size where upper and lower are the bounds or limits of integration. Your video has given me some insights and it is still useful because I can always apply this technique to some Python source, but as for generating a generic reusable algorithm in C++... I still need to do some more research... Keep up the good work. Also, your video was a bit entertaining too!

    • @darcash1738
      @darcash1738 Před 6 měsíci +1

      I just generalized it in Python. Wasn't bad at all:
      import numpy as np
      def func1(x):
      return np.log(x) / x
      def integrating_carlo(runs: int, function, x_bounds: tuple, y_bounds: tuple):
      in_area = 0
      box_area = np.abs((x_bounds[1] - x_bounds[0]) *
      (y_bounds[1] - y_bounds[0]))
      for i in range(runs):
      x_cord = np.random.uniform(x_bounds[0], x_bounds[1])
      y_cord = np.random.uniform(y_bounds[0], y_bounds[1])
      if y_cord < function(x_cord):
      in_area += 1
      return (in_area/runs) * box_area
      xb1 = (1, 10)
      yb1 = (0, 1/np.e)
      print(integrating_carlo(1000000, func1, xb1, yb1))
      Ok, so the x bounds are simply the bounds of integration, I'm gonna have to come up with another function so I can find the min and max for the function tho so you don't have to manually put in the y-bounds.
      I know how the math works, idk how to code it at this point tho. Find all f'(x) = 0 and f''(x) and that point to see if min or max. Not sure how to code out derivatives ngl.
      In the end, I just checked min and max the normal way, tho it does compromise on some degree of accuracy

  • @Marco-mt8kw
    @Marco-mt8kw Před 4 lety

    Great video, it was helpful

  • @naturfagstoff
    @naturfagstoff Před rokem

    Very very good exl of monte carlo compared area method. You are very talkative and exited when explaining, thats great, bit like me when I've had to much coffe?. Keep up your great work, man!
    Maybe a more generalized method in the programming could be introduced, using numpy, sympy.

  • @sirknightartorias68
    @sirknightartorias68 Před rokem

    Bro, u are AMAZING ⭐

  • @rafaelrodrigues4867
    @rafaelrodrigues4867 Před 4 lety

    Great video great explanation

  • @pacersgo
    @pacersgo Před 2 lety

    In this example you don’t need to use MC. If you simply sample grids in very fine resolution, you can get the same results

  • @thehimalayan7041
    @thehimalayan7041 Před 5 lety +1

    very good, continue for next viedeo on mente carlo method .............I am waiting

  • @PAA-ne3pc
    @PAA-ne3pc Před 2 lety

    But how we are sure that the x_coord belong to the same point of y_coord that we are comparing e.g what if we compared a point on the function to another point under the function but with different x_coord

  • @chrischoir3594
    @chrischoir3594 Před 3 lety

    very nice, thanks

  • @FernandoRodriguez-ge2tg

    I know very basic java and I’m trying to tone out the python because it might confuse me. This video is fun

  • @SathanaST
    @SathanaST Před 3 lety

    Thanks 🙏 you are really cool!

  • @oneJL
    @oneJL Před 3 lety

    could you plz explain more in details that why you come up with the hight of 1/e? Thanks in advance

    • @pacersgo
      @pacersgo Před 2 lety

      It is the max y value

  • @sakibhasan7857
    @sakibhasan7857 Před 2 lety

    pretty cool man❤

  • @____kklw7148
    @____kklw7148 Před 3 lety

    very clear

  • @darcash1738
    @darcash1738 Před 6 měsíci

    in python you should use a for loop, oh yeah plus for loops are faster

  • @Throwingness
    @Throwingness Před 2 lety

    Magnificent explanation and demo.
    Did you know you can write 1000000 as 1_000_000 in python?

  • @vishalsaini5021
    @vishalsaini5021 Před 2 lety

    Greetings of the day sir...... Could you please make a video on how to consider uncertainty in big data such as solar radiation of 8760 hours with the help of Monte Carlo simulation

  • @boomsaway3
    @boomsaway3 Před 6 lety +4

    yoo thank you for this video, helped me so much. i dont get why university lectures always over complicate things so annoying haha

    • @donharrold1375
      @donharrold1375 Před 3 lety +2

      It’s pathetic, but they’d rather seem smart than educate you.

  • @ncirisaif9162
    @ncirisaif9162 Před 4 lety

    thank you

  • @austinjohn8713
    @austinjohn8713 Před 3 lety +1

    Thank you very much for making me understand what monte carlo methods are. The use of repeated random number generation combined with probability to provide numerical solutions to problems.
    Please you are calling the random generator twice in each loop iteration and therefore 2 million times by the time the loop is over . That is expensive. rather generate two sets of 1 million random numbers for x and y then traverse them in the loop. that way the random generator is called just twice

  • @sirisaksirisak6981
    @sirisaksirisak6981 Před 3 lety

    In what situation MC doesn't work?How to reprove?

    • @pacersgo
      @pacersgo Před 2 lety

      MC can be too slow for some applications. For example in radiotherapy, people try to calculate the distribution of the radiation dose to the patient body in real time. And until now it is still not possible with MC because of the long computational time.

  • @entoris476
    @entoris476 Před 6 lety +2

    This method is obviously quite bad to use when the region probability is quite small, then you'd need to make the 'box' a bit more of an exotic shape to increase the probability...

    • @RandomMathsInc
      @RandomMathsInc  Před 6 lety +2

      Making the box more exotic-shaped, however, would mean it wouldn't be so simple to calculate the area of the box anymore.

    • @brendamartinez6955
      @brendamartinez6955 Před 4 lety

      Guernsey island

  • @donharrold1375
    @donharrold1375 Před 3 lety

    Seems like a massive amount of effort when a more straightforward numerical integration would be a lot quicker, i.e. divide the X axis into intervals (strips) between the limits of interest, calculate the Y value at the mid point of each interval and calculate the area of each rectangular strip under the curve. Sum the area of all the rectangles under the curve and hey presto you have solved the integral.

    • @1972hattrick
      @1972hattrick Před 3 lety

      Simpsons rule is much better than your method

    • @alanwatchesstuff
      @alanwatchesstuff Před 3 lety

      It's mostly used for higher dimensions because it is much faster. Imagine integrating an equation with multiple inputs, it will take forever to divide them into calculate the area for each inteval (you need (number of intevals)^(number of inputs) steps). For 10 variables, each one divide by say 10000, then you need (10000^10 steps). That's a lot of steps. Sure the error for monte carlos are higher than the midpoint method (O converges slower), but it is a very fast method that gives relatively decent accuracy.

    • @bishbash111gb
      @bishbash111gb Před 3 lety

      This is the slowest of monte carlo integration techniques. You can use techniques such as importance sampling to increase the rate at which it converges

  • @theirishpizzaguy6663
    @theirishpizzaguy6663 Před 2 lety

    This might be a perfect explanation/tutorial.

  • @matteofalduto766
    @matteofalduto766 Před 3 lety

    The initial dart example is, in general, correct for a multivariable function. But the example of the logx/x is misleading, as you turn a single variable function with a single variable domain, into a 2 variable scenario. The correct way of explaining a Monte Carlo integration in 1D would be showing how the average of f(x) over a wide set of random x (in other words the average value of the graph) is equal to the area divided by the width of the domain... Said differently: the area of the graph over a given domain is the same as the area of a rectangle that is as wide as the domain, and as high as the average value of your function.

    • @peterchindove7146
      @peterchindove7146 Před 2 lety

      There are two variables x and y =f((x).

    • @matteofalduto766
      @matteofalduto766 Před 2 lety

      @@peterchindove7146 Well, y is a dependent variable, it doesn't count in this sense. You have only one independent variable over which you integrate, that's x. For example, a multivariable function would be something like z = f(x,y).

    • @peterchindove7146
      @peterchindove7146 Před 2 lety

      @@matteofalduto766 So ..the generated random number (r) is the other independent variable at x (let's call it r_x), within the domain...which you compare to lnx/x ( ie r_x >? lnx /x ). Am l helping?

  • @hsinghal1
    @hsinghal1 Před 2 lety

    ok

  • @tongxie7078
    @tongxie7078 Před rokem

    This is the worst explanation I have seen on this stuff. Thank you so much!

  • @maxdefire
    @maxdefire Před 3 lety

    Time solution obtain solution time time solution time obtain solution.

  • @michaelblankenau3129
    @michaelblankenau3129 Před rokem

    I just keep hearing the same words over and over again

  • @_tube7362
    @_tube7362 Před rokem

    Dame good explanation, Can I get your email/Linkedin account?

  • @staynjohnson4221
    @staynjohnson4221 Před 3 lety

    Unfortunately, there is no double-like button.