Rejection Sampling - VISUALLY EXPLAINED with EXAMPLES!

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ธ.ค. 2024

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

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

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

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

      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.

  • @chriskindler10
    @chriskindler10 ปีที่แล้ว +7

    that's actually a terrific explanation

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

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

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

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

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

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

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

    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 . ❤❤❤

  • @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!

  • @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 !

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

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

  • @YogeshYewale-i3m
    @YogeshYewale-i3m ปีที่แล้ว +1

    Excellent explanation ever on rejection sampling

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

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

  • @domeknight
    @domeknight 5 วันที่ผ่านมา

    Absolutely excellent. Thank you very much!

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

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

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

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

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

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

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

    Thank you for your explanation, nice presentation!

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

    Thank you so much! Your video really helped me understand the method and remember it, which is equally important. 🙂

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

    Kudos for explaining very well. I wish to comment on just one thing. @12:08 I could not see the two colors (red and blue) clearly in the video. Maybe the picture can be made to have white background to make the colors more obvious.

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

    Legendary video man thank you!!!

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

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

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

    What a wonderful explanation

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

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

    • @KapilSachdeva
      @KapilSachdeva  2 ปีที่แล้ว +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 2 ปีที่แล้ว

      @@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  2 ปีที่แล้ว

      @@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 2 ปีที่แล้ว

      @@KapilSachdeva thx good work!

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

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

  • @MeesumQazalbash
    @MeesumQazalbash ปีที่แล้ว +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  11 หลายเดือนก่อน +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.

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

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

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

      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.

  • @pcaltd.1824
    @pcaltd.1824 3 ปีที่แล้ว +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  3 ปีที่แล้ว +3

      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 3 ปีที่แล้ว +1

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

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

      🙏

  • @leilanifrost771
    @leilanifrost771 ปีที่แล้ว +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  ปีที่แล้ว +1

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

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

    Thank you, I understood clearly.

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

    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?

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

    thank you so much , very well explained !

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

    thank you, very well explained!

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

    Thank you very much for your video. But I have a question: when g(x) is a function U(a,b), the probability of choosing Y which obeys g(x) is the same for all Y in (a,b). But when the bounding function is Gaussian or something else (i.e. when simulating g(x) we cannot guarantee the probability of selecting each point is the same), does it affects the probability of selecting X which obeys f( x) ?
    ( Because if the simulation of Y is not equivalent then even if the next steps are effective, we cannot guarantee that we give equal chances to all points X when starting before "reject or accept")

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

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

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

    Best explanation

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

    Hi Sir. Amazing tutorial!

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

    Excellent video

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

    Lovely sir!

  • @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.

  • @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.

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

    Thank you, I understand now😊

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

    Thank you so much

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

    great tutorial thanks a lot

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

    Thank you so much!

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

    Amazing, thx a lot.

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

    May god bless you

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

    Excellent

  • @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 2 ปีที่แล้ว +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  2 ปีที่แล้ว

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

    • @chronicillnessrevolution5079
      @chronicillnessrevolution5079 2 ปีที่แล้ว +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  2 ปีที่แล้ว +3

      Thank you for catching it 🙏

  • @BilalTaskin-om6il
    @BilalTaskin-om6il ปีที่แล้ว +1

    magnificent...

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

    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 ปีที่แล้ว

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

    • @prateekcaire4193
      @prateekcaire4193 ปีที่แล้ว +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.

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

    then why not just use f(x), let c*g be a straight line equal to the maximum of f(x)