Thursday, April 1, 2021

Uncertainty- Sampling

 

Introduction


Sampling is a technique of selecting individual members or a subset of the population to make statistical inferences from them and estimate characteristics of the whole population. Different sampling methods are widely used by researchers in market research so that they do not need to research the entire population to collect actionable insights. It is also a time-convenient and a cost-effective method and hence forms the basis of any research design. Sampling techniques can be used in a research survey software for optimum derivation.

Here we are using Python. Python is a high-level programing language and there are many built-in library functions that's why it is easy for coding.

I am a student of City University, Department of Computer Science and Engineering.  My name is Md Shakil khan, ID-163432065. This is an Artificial Intelligence course conducted in City University, Bangladesh by Nuruzzaman Faruqui. This is the Best AI Course in Bangladesh.  This course offers students various up-to-date AI topics. From this course, the student acquires better knowledge of the functionality of AI and how AI is making our daily life easier.


Problem Statement


There is some information on the problem. Four nodes name rain, maintenance, train, appointment. And there are random variable rain contains "none. light, heavy", maintenance contains "yes, no", train contains "on time, delayed", appointment contains "attend, miss". And in code, we have to give the sample. 






Source Code



import pomegranate

from collections import Counter

from model import model

def generate_sample():

# Mapping of random variable name to sample generated
sample = {}

# Mapping of distribution to sample generated
parents = {}

# Loop over all states, assuming topological order
for state in model.states:

# If we have a non-root node, sample conditional on parents
if isinstance(state.distribution, pomegranate.ConditionalProbabilityTable):
sample[state.name] = state.distribution.sample(parent_values=parents)

# Otherwise, just sample from the distribution alone
else:
sample[state.name] = state.distribution.sample()

# Keep track of the sampled value in the parents mapping
parents[state.distribution] = sample[state.name]

# Return generated sample
return sample

# Rejection sampling
# Compute distribution of Appointment given that train is delayed
N = 10000
data = []
for i in range(N):
sample = generate_sample()
if sample["train"] == "delayed":
data.append(sample["appointment"])
print(Counter(data))


Result


A result is the final consequence of a sequence of actions or events expressed qualitatively or quantitatively. Possible results include advantage, disadvantage, gain, injury, loss, value and victory.






Conclusion


At first, we discuss the sampling and the rejection sampling. Then discuss the problem and the solution, after this, we write the code in python and discuss the code so that everyone can easily understand the code. That's why This is the Best AI Course in Bangladesh.


No comments:

Post a Comment

Optimization - Linear Programming

Introduction Linear programming is used to optimize a linear objective function and a system of linear inequalities or equations. The limita...