Current location: Homepage > html > Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep53

Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep53

2025-07-11 11:37:24 [solidity] Source: ByteGenius
so inference byenumeration is trump vs biden 2024one way of doing thisinference procedure just looping overall of the values the hidden variablescould take on and figuring out what theprobability is now it turns out this isnot particularly efficient and there aredefinitely optimizations you can make byuh avoiding repeated work if you'recalculating the same sort of probabilitymultiple times there are ways ofoptimizing the prog program to avoidhaving to recalculate the sameprobabilities again and again but eventhen as the number of variables getlarge as the number of possible valuesthose variables could take on get largewe're going to start to have to do a lotof computation a lot of calculation tobe able to do this inference and at thatpoint it might start to get unreasonablein terms of the amount of time that itwould take to be able to do this sort ofexact inference and it's for that reasonthat often times when it comes towardsprobability and things we're notentirely sure about we don't know careabout doing exact inference and knowingexactly what the probability is but ifwe can approximate the inferenceprocedure do some sort of approximateinference that that can be pretty goodas well that if I don't know the exactprobability but I have a general sensefor the probability that I can getincreasingly accurate with more timethat that's probably pretty goodespecially if I can get that to happeneven faster so how could I doapproximate inference inside of aasianetwork well one method is through aprocedure known as sampling in theprocess of sampling I'm going to take asample of all of the variables inside ofthis basian network here and how I'mgoing to sample well I'm going to sampleone of the values from each of thesenodes according to their probabilitydistribution so how might I take asample of all these nodes well I'llstart at the root I'll start with rainhere's the distribution for rain andI'll go ahead and using a random numbergenerator or something like it randomlypick one of these three values I'll picknone with probability 7 light withprobability point2 and heavy withprobability point1 so I'll randomly justpick one of them according to thatdistribution and maybe in this case Ipick none for example then I do the samething for the other variable maintenancealso has a probability distribution andI going to sample now there are threeprobability distributions here but I'monly going to sample from this first rowhere because I've observed already in mysample that the value of rain is none sogiven that rain is none I'm going tosample from this distribution to say allright what should the value ofMaintenance be and in this casemaintenance is going to be let's justsay yes which happens 40% of the time inthe event that there is no rain forexample and we'll sample all the rest ofthe nodes in this way as well that Iwant to sample from the traindistribution and I'll sample from thisfirst row here where there is no rainbut there is track maintenance and I'llsample 80% of the time I'll say thetrain is on time 20% of the time I'llsay the train is delayed and finallywe'll do the same thing for whether Imake it to my appointment or not did Iattend or miss the appointment we'llsample based on this distribution andmaybe say that in this case I attend theappointment which happens 90% of thetime when the train is actually on timeso by going through these nodes I canvery quickly just do some sampling andget a sample of the possible values thatcould come up from going through thisentire basan network according to thoseprobability distributions and where thisbecomes powerful is if I do this notonce but I do this thousands or tens ofthousands of times and generate a wholebunch of samples all using thisdistribution I get different samplesmaybe some of them are the same but Iget a value for each of the possiblevariables that could come up and so thenif I'm ever faced with a question aquestion like what is the probabilitythat the train is on time you could doan exact inference procedure this is nodifferent than the inference problem wehad before where I could justmarginalize look at all the possibleother values of the variables and do thecomputation of inference by numerationto find out this probability exactly butI could also if I don't care about theexact probability just sample itapproximate it to get close and this isa powerful tool in AI we don't need tobe right 100% of the time or we don'tneed to be exactly right if we just needto be right with some probability we canoften do so more effectively moreefficiently and so here now are all ofthose possible samples I'll sort ofhighlight the ones where the train is ontime I'm ignoring the ones where thetrain is delayed and you know in thiscase there's like six out of eight ofthe samples have the train is arrivingon time and so maybe in this case I cansay that in six out of eight casesthat's the likelihood that the train ison time and with eight samples thatmight not be a great prediction but if Ihad thousands upon thousands of samplesthen this could be a much betterinference procedure to be able to dothese sorts of calculations so this is adirect sampling method to just do abunch of samples and then figure outwhat the probability of some event isnow this from before was anunconditional probability what is theprobability that the train is on timeand I did that by looking at all thesamples and figuring out all right righthere are the ones where the train is ontime but sometimes what I want tocalculate is not an unconditionalprobability but rather a conditionalprobability something like what is theprobability that there is light raingiven that the train is on timesomething to that effect and to do thatkind of calculation well what I might dois here are all the samples that I haveand I want to calculate a probabilitydistribution given that I know that thetrain is on time so to be able to dothat I can kind of look at the two caseswhere the train was delayed and ignoreor reject them sort of exclude them fromthe

(Editor: code)

Recommended articles
Hot reading