The Monte Carlo Method

Поділитися
Вставка
  • Опубліковано 13 сер 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...

КОМЕНТАРІ • 93

  • @malharjajoo7393
    @malharjajoo7393 4 роки тому +60

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

  • @mateuszkujda3544
    @mateuszkujda3544 4 роки тому +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 3 роки тому +7

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

  • @jursamaj
    @jursamaj 5 місяців тому +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 Місяць тому

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

  • @bigh8438
    @bigh8438 3 роки тому +6

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

  • @Softdattel
    @Softdattel 7 місяців тому +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 2 роки тому +2

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

  • @johnburns9696
    @johnburns9696 2 місяці тому

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

  • @ear4funk814
    @ear4funk814 3 роки тому +4

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

  • @pythonanimalia
    @pythonanimalia 4 роки тому +5

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

  • @anandrai492
    @anandrai492 2 роки тому +1

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

  • @Narutoshippuden2055
    @Narutoshippuden2055 4 роки тому

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

  • @jeshurunjohnson13
    @jeshurunjohnson13 2 роки тому

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

  • @marcusseidowski3320
    @marcusseidowski3320 4 роки тому

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

  • @sergiovazquez2662
    @sergiovazquez2662 3 роки тому

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

  • @jagarali
    @jagarali 5 років тому +1

    This is a quite exhaustive explanation.. Thanks.

  • @adinathdesai6880
    @adinathdesai6880 Рік тому

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

  • @emrulhasan5646
    @emrulhasan5646 2 роки тому

    Awesome explanation. Loved it. Thanks a lot!

  • @KeesJansma7689
    @KeesJansma7689 4 роки тому +3

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

  • @dr.md.mehboobalam93
    @dr.md.mehboobalam93 2 роки тому

    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?

  • @seandroid88
    @seandroid88 3 роки тому

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

  • @rezakhalili5362
    @rezakhalili5362 2 роки тому

    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

  • @totimariageraci
    @totimariageraci Рік тому

    Great clear explanation, thank you so much

  • @jonavuka
    @jonavuka 4 роки тому

    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

  • @PintuBhattacharya-mp4mw
    @PintuBhattacharya-mp4mw 3 роки тому

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

  • @natalie1997927
    @natalie1997927 2 роки тому

    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)?

  • @renanlarrieu
    @renanlarrieu 2 роки тому

    Clear and well done explanation. Thank you

  • @p.s.srinivas7696
    @p.s.srinivas7696 4 роки тому

    Well explained. Concept became very clear.

  • @peterchindove7146
    @peterchindove7146 2 роки тому

    Totally enjoyed your presentation, kudos!

  • @user-if2fk2sw8n
    @user-if2fk2sw8n Рік тому

    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?

  • @plastiqueman
    @plastiqueman 3 роки тому

    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' "

  • @chdfnh
    @chdfnh 4 роки тому

    Very good explanation. Thanks!

  • @Pradeepvlogs101
    @Pradeepvlogs101 3 роки тому

    So clear explanation! Thanks

  • @michelebenedetti1335
    @michelebenedetti1335 3 роки тому

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

  • @rockandrolldevil665
    @rockandrolldevil665 3 роки тому

    Thanks, that was an awesome class!

  • @Danny-ts7sc
    @Danny-ts7sc 4 роки тому

    thank you, your explanation is way better than my teacher

  • @rafshantik
    @rafshantik 3 роки тому +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.

  • @stonecastle858
    @stonecastle858 10 місяців тому

    Very well explained. Brilliant

  • @gutzimmumdo4910
    @gutzimmumdo4910 Рік тому

    very clear explanation

  • @marceloescobar6389
    @marceloescobar6389 3 роки тому

    Brilliant, absolutely brilliant

  • @vishalsk8337
    @vishalsk8337 3 роки тому

    Amazing work!

  • @oneJL
    @oneJL 3 роки тому

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

    • @pacersgo
      @pacersgo 2 роки тому

      It is the max y value

  • @izzyt2286
    @izzyt2286 2 роки тому

    THIS WAS AMAZING THANK YOU

  • @IbnuNurHamzah
    @IbnuNurHamzah 3 роки тому

    thanks for your explanation dude

  • @skilz8098
    @skilz8098 4 роки тому

    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 5 місяців тому +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

  • @spyhunter0066
    @spyhunter0066 10 місяців тому

    excellent job, well done!

  • @PAA-ne3pc
    @PAA-ne3pc 2 роки тому

    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

  • @Marco-mt8kw
    @Marco-mt8kw 4 роки тому

    Great video, it was helpful

  • @naturfagstoff
    @naturfagstoff Рік тому

    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.

  • @pacersgo
    @pacersgo 2 роки тому

    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 5 років тому +1

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

  • @FernandoRodriguez-ge2tg
    @FernandoRodriguez-ge2tg 6 років тому

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

  • @rafaelrodrigues4867
    @rafaelrodrigues4867 3 роки тому

    Great video great explanation

  • @iidtxbc
    @iidtxbc 2 роки тому

    Can you do "Quasi Monte Carlo"?

  • @henryadolfo
    @henryadolfo 3 роки тому

    Well done !

  • @chrischoir3594
    @chrischoir3594 3 роки тому

    very nice, thanks

  • @sirknightartorias68
    @sirknightartorias68 Рік тому

    Bro, u are AMAZING ⭐

  • @SathanaST
    @SathanaST 3 роки тому

    Thanks 🙏 you are really cool!

  • @ncirisaif9162
    @ncirisaif9162 4 роки тому

    thank you

  • @vishalsaini5021
    @vishalsaini5021 2 роки тому

    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

  • @____kklw7148
    @____kklw7148 3 роки тому

    very clear

  • @boomsaway3
    @boomsaway3 6 років тому +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 3 роки тому +2

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

  • @austinjohn8713
    @austinjohn8713 3 роки тому +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 3 роки тому

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

    • @pacersgo
      @pacersgo 2 роки тому

      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.

  • @Throwingness
    @Throwingness 2 роки тому

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

  • @sakibhasan7857
    @sakibhasan7857 2 роки тому

    pretty cool man❤

  • @entoris476
    @entoris476 6 років тому +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  6 років тому +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 4 роки тому

      Guernsey island

  • @darcash1738
    @darcash1738 5 місяців тому

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

  • @donharrold1375
    @donharrold1375 3 роки тому

    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 3 роки тому

      Simpsons rule is much better than your method

    • @alanwatchesstuff
      @alanwatchesstuff 3 роки тому

      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 3 роки тому

      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

  • @matteofalduto766
    @matteofalduto766 3 роки тому

    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 2 роки тому

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

    • @matteofalduto766
      @matteofalduto766 2 роки тому

      @@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 2 роки тому

      @@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?

  • @theirishpizzaguy6663
    @theirishpizzaguy6663 2 роки тому

    This might be a perfect explanation/tutorial.

  • @hsinghal1
    @hsinghal1 2 роки тому

    ok

  • @tongxie7078
    @tongxie7078 Рік тому

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

  • @maxdefire
    @maxdefire 3 роки тому

    Time solution obtain solution time time solution time obtain solution.

  • @michaelblankenau3129
    @michaelblankenau3129 Рік тому

    I just keep hearing the same words over and over again

  • @_tube7362
    @_tube7362 Рік тому

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

  • @staynjohnson4221
    @staynjohnson4221 3 роки тому

    Unfortunately, there is no double-like button.