Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Defining Bayesian Networks | Bayesian Networks: Directed Models
Probabilistic Graphical Models Essentials

bookDefining Bayesian Networks

A Bayesian network is a type of probabilistic graphical model that represents a set of random variables and their conditional dependencies using a directed acyclic graph (DAG). In this graph, each node corresponds to a random variable, and each directed edge encodes a direct probabilistic influence from one variable to another. The strength and nature of these dependencies are captured by conditional probability tables (CPTs), with each node's CPT specifying the probability of that variable given its parent variables in the graph.

12345678910111213141516171819202122232425262728293031323334
# Define the structure of the Bayesian network # Variables: Rain, Sprinkler, WetGrass # Parents for each variable parents = { "Rain": [], "Sprinkler": ["Rain"], "WetGrass": ["Rain", "Sprinkler"] } # Conditional probability tables (CPTs) CPT = { # P(Rain) "Rain": { True: 0.2, False: 0.8 }, # P(Sprinkler | Rain) "Sprinkler": { (True,): {True: 0.01, False: 0.99}, # Rain = True (False,): {True: 0.4, False: 0.6} # Rain = False }, # P(WetGrass | Rain, Sprinkler) "WetGrass": { (True, True): {True: 0.99, False: 0.01}, (True, False): {True: 0.8, False: 0.2}, (False, True): {True: 0.9, False: 0.1}, (False, False): {True: 0.0, False: 1.0} } } # Example: how to access the probability that WetGrass is True given Rain=True and Sprinkler=False prob = CPT["WetGrass"][(True, False)][True] print(f"P(WetGrass=True | Rain=True, Sprinkler=False) = {prob}")
copy

In the code above, the parents dictionary encodes the structure of the Bayesian network as a directed acyclic graph: Rain has no parents, Sprinkler depends on Rain, and WetGrass depends on both Rain and Sprinkler. The CPT dictionary specifies the conditional probability tables for each variable. For instance, CPT["Rain"] gives the prior probability of rain, while CPT["Sprinkler"] defines the probability that the sprinkler is on, conditioned on whether it is raining. CPT["WetGrass"] lists the probability that the grass is wet for each possible combination of rain and sprinkler states. Each CPT entry maps a tuple of parent values to a dictionary of probabilities for the variable's possible states, allowing you to quickly look up the relevant probability for any configuration in the network.

question mark

Which of the following statements about Bayesian networks are correct?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 1

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookDefining Bayesian Networks

Deslize para mostrar o menu

A Bayesian network is a type of probabilistic graphical model that represents a set of random variables and their conditional dependencies using a directed acyclic graph (DAG). In this graph, each node corresponds to a random variable, and each directed edge encodes a direct probabilistic influence from one variable to another. The strength and nature of these dependencies are captured by conditional probability tables (CPTs), with each node's CPT specifying the probability of that variable given its parent variables in the graph.

12345678910111213141516171819202122232425262728293031323334
# Define the structure of the Bayesian network # Variables: Rain, Sprinkler, WetGrass # Parents for each variable parents = { "Rain": [], "Sprinkler": ["Rain"], "WetGrass": ["Rain", "Sprinkler"] } # Conditional probability tables (CPTs) CPT = { # P(Rain) "Rain": { True: 0.2, False: 0.8 }, # P(Sprinkler | Rain) "Sprinkler": { (True,): {True: 0.01, False: 0.99}, # Rain = True (False,): {True: 0.4, False: 0.6} # Rain = False }, # P(WetGrass | Rain, Sprinkler) "WetGrass": { (True, True): {True: 0.99, False: 0.01}, (True, False): {True: 0.8, False: 0.2}, (False, True): {True: 0.9, False: 0.1}, (False, False): {True: 0.0, False: 1.0} } } # Example: how to access the probability that WetGrass is True given Rain=True and Sprinkler=False prob = CPT["WetGrass"][(True, False)][True] print(f"P(WetGrass=True | Rain=True, Sprinkler=False) = {prob}")
copy

In the code above, the parents dictionary encodes the structure of the Bayesian network as a directed acyclic graph: Rain has no parents, Sprinkler depends on Rain, and WetGrass depends on both Rain and Sprinkler. The CPT dictionary specifies the conditional probability tables for each variable. For instance, CPT["Rain"] gives the prior probability of rain, while CPT["Sprinkler"] defines the probability that the sprinkler is on, conditioned on whether it is raining. CPT["WetGrass"] lists the probability that the grass is wet for each possible combination of rain and sprinkler states. Each CPT entry maps a tuple of parent values to a dictionary of probabilities for the variable's possible states, allowing you to quickly look up the relevant probability for any configuration in the network.

question mark

Which of the following statements about Bayesian networks are correct?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 1
some-alt