Rejection Sampling - VISUALLY EXPLAINED with EXAMPLES!

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ม.ค. 2021
  • This tutorial explains the Rejection Sampling algorithm using a difficult to sample univariate distribution function.
    #sampling
    #montecarlo
    #statistics
    If you prefer to read, I have written an article on this algorithm here -
    towardsdatascience.com/what-i...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 103

  • @rfhp1710
    @rfhp1710 2 ปีที่แล้ว +32

    Rotating the plots is a stroke of genius, things clicked instinctively. You are a gifted content maker. Keep making videos.

    • @KapilSachdeva
      @KapilSachdeva  2 ปีที่แล้ว +5

      Thanks 🙏… finally someone saw the rotated plot and understood its significance … I am happy now :)

    • @partha95123
      @partha95123 ปีที่แล้ว +2

      Indeed Kapil ji is an artist! I'm writing my thesis with his videos as inspiration.

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว +1

      You guys are so kind. Many thanks for the encouragement. @adithyanssathish5485 would love to read your thesis when it is ready.

    • @partha95123
      @partha95123 ปีที่แล้ว +2

      Yes Kapil ji. I will send an invite to public part of my thesis defence for a duration of 30 minutes.

  • @yli6050
    @yli6050 28 วันที่ผ่านมา

    Watching your videos keeps reminding me of the phrase “a picture is worth a thousand words”, to which I want to add “ a great picture is worth thousands in gold”. Many times I had to freeze the video to let a particular moment sink in, because I couldn’t believe the insight that picture brings out . ❤❤❤

  • @chriskindler10
    @chriskindler10 10 หลายเดือนก่อน +6

    that's actually a terrific explanation

  • @prajwalchauhan6440
    @prajwalchauhan6440 6 หลายเดือนก่อน +2

    Best explanation for this topic on TH-cam. I wonder how you even came up with this. Genius

  • @Kn1ghtCh4ser
    @Kn1ghtCh4ser หลายเดือนก่อน +1

    You just saved a college student living in South Korea! Thanks for amazing visualization and explanations!

  • @dhimanbhowmick9558
    @dhimanbhowmick9558 6 วันที่ผ่านมา

    Thank you for your hard work, which enables us to understand crystal clear. Thanks a lot ❤❤❤

  • @julialikesscience
    @julialikesscience 8 หลายเดือนก่อน +2

    this brilliant change of viewpoint helps to explain the method in a much simpler way!

  • @drewburns7805
    @drewburns7805 ปีที่แล้ว +2

    Fantastic explanation! Best video on this subject I've seen so far. Saved me lots of time searching for clarification. Thank you!

  • @haihoangthanh8949
    @haihoangthanh8949 2 หลายเดือนก่อน +1

    thank you for your detail and understandable explanation. The video animations are great and impressive.

  • @alonsomadronal2919
    @alonsomadronal2919 ปีที่แล้ว +2

    Such a Masterpiece of a video, thanks for the explanation!

  • @sudhagarraghavan9696
    @sudhagarraghavan9696 3 ปีที่แล้ว +6

    Excellent video and clearly explained ! Hope you can also do tutorials on other MCMC sampling methods such Gibbs Sampling, Metropolis-Hasting and Hamiltonian !

  • @hiiiqwq5833
    @hiiiqwq5833 4 หลายเดือนก่อน +1

    This is sooo helpful! Totally addressed my concern!! Thank you!

  • @ilke3395
    @ilke3395 2 หลายเดือนก่อน +1

    Thank you so much sir for the amazing explanation and visualization.

  • @cjhhong
    @cjhhong 2 ปีที่แล้ว +1

    Thank you so much. I now understand the concept better.

  • @olivier306
    @olivier306 ปีที่แล้ว +2

    Legendary video man thank you!!!

  • @korntantiwanit
    @korntantiwanit ปีที่แล้ว +1

    Thank you for your explanation, nice presentation!

  • @user-hv9ze2qd8f
    @user-hv9ze2qd8f 8 หลายเดือนก่อน +1

    Excellent explanation ever on rejection sampling

  • @ankushkothiyal5372
    @ankushkothiyal5372 2 ปีที่แล้ว +1

    Thank you, I understood clearly.

  • @cello9834
    @cello9834 ปีที่แล้ว +1

    thank you so much , very well explained !

  • @jahanvi9429
    @jahanvi9429 2 ปีที่แล้ว +1

    thank you, very well explained!

  • @corradoforza
    @corradoforza 2 ปีที่แล้ว +1

    Thank you so much for this video, it is very clear and makes rejection sampling easy to understand

  • @lawrencege6942
    @lawrencege6942 2 ปีที่แล้ว +1

    Thank you so much!

  • @Nier914
    @Nier914 2 ปีที่แล้ว +1

    Thank you, I understand now😊

  • @sujatharamakrishnan
    @sujatharamakrishnan 7 หลายเดือนก่อน

    Thank you for the very clear explanation of the rejection samling method?.I want to compute the acceptance rate for a specifice probem. Could you define what is the acceptance rate?

  • @minma02262
    @minma02262 2 ปีที่แล้ว +1

    Hi Sir. Amazing tutorial!

  • @janhavisoni1559
    @janhavisoni1559 7 หลายเดือนก่อน +1

    Thank you so much

  • @lone_Traveller_101
    @lone_Traveller_101 7 หลายเดือนก่อน +1

    Lovely sir!

  • @fatihboyar9697
    @fatihboyar9697 ปีที่แล้ว +1

    great tutorial thanks a lot

  • @Anteater23
    @Anteater23 2 ปีที่แล้ว +1

    Excellent video

  • @leilanifrost771
    @leilanifrost771 9 หลายเดือนก่อน +1

    That was a great video! Just wanted to ask how you would approach scaling the proposal distribution if you don't know the parameters of the target distribution?

    • @KapilSachdeva
      @KapilSachdeva  9 หลายเดือนก่อน +1

      In that case you would not use Rejection sampling. You would want to use an algo like metropolis Hastings, HMC etc

  • @MuhammadAbdullah-iv2gu
    @MuhammadAbdullah-iv2gu ปีที่แล้ว +1

    Best explanation

  • @BilalTaskin-om6il
    @BilalTaskin-om6il 9 หลายเดือนก่อน +1

    magnificent...

  • @ahnafsamin3777
    @ahnafsamin3777 2 ปีที่แล้ว +1

    Excellent

  • @ZoeZhou-yk9sd
    @ZoeZhou-yk9sd ปีที่แล้ว +1

    Thank you for the video! Whats is the software you used to create this video plz?

  • @MeesumQazalbash
    @MeesumQazalbash 6 หลายเดือนก่อน +1

    Wonderful tutorial no doubt Indian teachers are best. I am new to sampling and my work often involves multivariate pdfs to sample from. Is there any beginner's tutorial on it?

    • @KapilSachdeva
      @KapilSachdeva  5 หลายเดือนก่อน +1

      May be see the metropolis Hastings tutorial on my channel. I would suggest to learn pymc3 library as these sampling algos are part of it with a nice framework and api.

  • @lerneninverschiedenenforme7513
    @lerneninverschiedenenforme7513 3 ปีที่แล้ว +2

    Do I understand correctly, that you need two random values?
    1st: Random value used as the actual "random variable"
    2nd: Random value to evaluate, wheather the random value from (1) is used or not.

    • @KapilSachdeva
      @KapilSachdeva  3 ปีที่แล้ว

      Your understanding is correct.

  • @pcaltd.1824
    @pcaltd.1824 2 ปีที่แล้ว +3

    Lovely video. If you do not know what the target function is, how can you obtain C and how can you ensure the envelope function is not exceeded by the value of the target?

    • @KapilSachdeva
      @KapilSachdeva  2 ปีที่แล้ว +2

      Sorry for the late reply. My understanding is that for Rejection sampling you need to know the function as this is how you will evaluate f(x) (f is the target distribution).
      Finding the good envelop - This is the challenge with this algorithm and it becomes worse as you go in higher dimensions. One remedy that is generally suggested is to use - "adaptive rejection sampling" .
      See section 11.1.3 of PRML (www.microsoft.com/en-us/research/uploads/prod/2006/01/Bishop-Pattern-Recognition-and-Machine-Learning-2006.pdf), it is quite well explained there.

    • @pcaltd.1824
      @pcaltd.1824 2 ปีที่แล้ว +1

      @@KapilSachdeva Thanks for clarifying. The reference looks very useful.

    • @KapilSachdeva
      @KapilSachdeva  2 ปีที่แล้ว

      🙏

  • @gwirvanmenez3470
    @gwirvanmenez3470 ปีที่แล้ว

    Hello after computation I find that the integral of f(x) is ~5.73 on [-3;3]. Wich mean that f(x) is not a density fonction. Is the exemple still corect if the integral of f(x) is not equal to 1 on [-3;3] ?

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว +1

      Yes. Think of the function as unnormalized density function.

  • @ananyapamde4514
    @ananyapamde4514 2 ปีที่แล้ว +2

    May god bless you

  • @marcogelsomini7655
    @marcogelsomini7655 ปีที่แล้ว +2

    nice vid, what is the point of sampling if you know the analytical form of the function?

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว +2

      Good question.
      Three points to note -
      * Knowing the analytical form of the function does not mean that one can sample from it.
      * In a more sophisticated setup you do not even know the analytical form a function. A typical example is the posterior in Bayesian Statistics.
      *Sampling is necessary to use Law of large numbers to approximate a function (where its analytical form is available or not!)

    • @marcogelsomini7655
      @marcogelsomini7655 ปีที่แล้ว

      @@KapilSachdeva ok thanks. But this algorithm required to know the real function as you need to compute C the intersection of the random sample and confront with uniform random sample in order to accept o reject right?

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว

      @@marcogelsomini7655 This is the correct understanding. This is also why it is a limited and inefficient algorithm.
      Look at the metropolis-hasting algorithm that does not have this requirement. I have a tutorial on that as well.

    • @marcogelsomini7655
      @marcogelsomini7655 ปีที่แล้ว

      @@KapilSachdeva thx good work!

  • @arpansrivastava6405
    @arpansrivastava6405 2 หลายเดือนก่อน

    1:31 how do we not know how to sample as the distribution function is already given and you also plotted it ?

    • @KapilSachdeva
      @KapilSachdeva  หลายเดือนก่อน

      Somehow it is a common confusion for many.
      Knowing a distribution function can only help you find the probability of a sample. Sampling from a function is a different task. Sampling means asking your computer to generate a sample.
      Sampling makes use of random number generator. Now your random number generator (algorithm) is to behave in such a way that the samples (random numbers) are generated in accordance with their prob distribution. Some samples are supposed to be more (the one with high prob) and some less.
      This is why various sampling algos/techniques are created. Your computer by default can give uniform random numbers. Most of the algorithms directly or indirectly manipulate the result of uniform random number generator.

  • @pzakala
    @pzakala ปีที่แล้ว

    Sorry for stupid question. I`m now in static algorithms. Why we can`t sample for target function in this case. For example, we can just divide over function for 4.5. The resulting function will looks like distribution function 😅.

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว

      Most likely I am not following your suggestion - "divide over function for 4.5". If possible elaborate on this.

  • @chronicillnessrevolution5079
    @chronicillnessrevolution5079 ปีที่แล้ว +1

    Heads up: I plotted the target function according to its expression shown in the video, but the graph that results from this expression is different from the one you show.

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว

      Have uploaded my (very old notebook) on colab. See if it helps
      colab.research.google.com/drive/1olDMLkwPk16YBmfPdq1zXmvtIVG8kF8R?usp=sharing

    • @chronicillnessrevolution5079
      @chronicillnessrevolution5079 ปีที่แล้ว +3

      @@KapilSachdeva Found your typo. In the video it says sin^2(6+x) but in your code it is sin^2(6*x). Using the latter gives the correct plot

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว +3

      Thank you for catching it 🙏

  • @prateekcaire4193
    @prateekcaire4193 6 หลายเดือนก่อน

    Assuming the proposal function is the same as the target function, then the rejection region would be 0. However, this would result in accepting everything, which could lead to incorrect acceptance if there is nothing above the pink blinker point.

    • @prateekcaire4193
      @prateekcaire4193 6 หลายเดือนก่อน

      It was helpful to build some intuition around though. Thanks!

    • @prateekcaire4193
      @prateekcaire4193 6 หลายเดือนก่อน +1

      ok i got it now. proposal function sampling will also follow probabilistic sampling and sampling from proposal (guassian or uniform) is quite easy

  • @JoseVinicius-fe3vk
    @JoseVinicius-fe3vk ปีที่แล้ว

    why Y axis goes beyond 1? there is no way something has over 100% chance of happening

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว

      This is an example function that does not represent pdf but you still want to obtain samples in accordance with this function. Or, think of it as unnormalized PDF.

  • @ddiq47
    @ddiq47 ปีที่แล้ว

    How do you get the values of f to determine rejection or acceptance?
    It’s confusing to me as the reason for using this method was based on being unable to sample from the original distribution f. What am I missing here

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว

      In many situations you have an analytical form of the distribution function available but this does not mean you can sample from that function. This is where this technique is used.

    • @ddiq47
      @ddiq47 ปีที่แล้ว

      @@KapilSachdeva when you say an analytical form of the distribution, what does that mean? Would it be a function like in the video, or a dataset of known function values?

    • @KapilSachdeva
      @KapilSachdeva  ปีที่แล้ว

      A function. Using this function for a give sample you can compute it’s prob/score/value.