Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Defining Markov Random Fields | Markov Random Fields: Undirected Models
Probabilistic Graphical Models Essentials

bookDefining Markov Random Fields

Markov random fields (MRFs) are a type of probabilistic graphical model that use undirected graphs to represent relationships between random variables. In an MRF, each node corresponds to a random variable, and edges indicate direct probabilistic dependencies without specifying direction. The joint distribution over all variables is defined by a product of factors, also called potentials, which are non-negative functions defined over cliques (fully connected subsets) of the graph. These factors capture the local interactions between variables and together encode the global structure of the model.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
# Define the undirected graph structure as an adjacency list graph = { 'A': ['B'], 'B': ['A', 'C'], 'C': ['B'] } # Define binary variables: each can be 0 or 1 variables = ['A', 'B', 'C'] variable_states = [0, 1] # Define factor tables (potentials) for each clique # Here, we have pairwise factors for edges (A,B) and (B,C), and single-variable factors for each node # Factor for edge (A, B) phi_AB = { (0, 0): 1.0, (0, 1): 0.5, (1, 0): 0.5, (1, 1): 1.5 } # Factor for edge (B, C) phi_BC = { (0, 0): 1.0, (0, 1): 0.7, (1, 0): 0.7, (1, 1): 1.2 } # Singleton factors (optional, can be all ones for simplicity) phi_A = {0: 1.0, 1: 1.0} phi_B = {0: 1.0, 1: 1.0} phi_C = {0: 1.0, 1: 1.0} # Collect all factors in a dictionary factors = { ('A',): phi_A, ('B',): phi_B, ('C',): phi_C, ('A', 'B'): phi_AB, ('B', 'C'): phi_BC } print("Graph structure:") print(graph) print("\nVariables:") print(variables) print("\nFactors:") for key, value in factors.items(): print(f"{key}: {value}")
copy

In the code above, the undirected structure of the MRF is captured by the graph dictionary, where each variable lists its neighbors, reflecting the edges of the graph. The factors are represented as Python dictionaries: for each clique (in this case, the pairs (A, B) and (B, C)), a factor table assigns a non-negative value (potential) to every possible assignment of the variables in that clique. Singleton factors for A, B, and C are included for completeness but set to 1.0, so they do not affect the distribution. The joint probability for a configuration of all variables is proportional to the product of all these factor values for the corresponding assignments. This representation allows you to encode complex dependencies in an undirected way, with the semantics of the model determined by the structure of the graph and the values in the factor tables.

question mark

Which of the following statements about Markov random fields (MRFs) are correct?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. 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 Markov Random Fields

Deslize para mostrar o menu

Markov random fields (MRFs) are a type of probabilistic graphical model that use undirected graphs to represent relationships between random variables. In an MRF, each node corresponds to a random variable, and edges indicate direct probabilistic dependencies without specifying direction. The joint distribution over all variables is defined by a product of factors, also called potentials, which are non-negative functions defined over cliques (fully connected subsets) of the graph. These factors capture the local interactions between variables and together encode the global structure of the model.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
# Define the undirected graph structure as an adjacency list graph = { 'A': ['B'], 'B': ['A', 'C'], 'C': ['B'] } # Define binary variables: each can be 0 or 1 variables = ['A', 'B', 'C'] variable_states = [0, 1] # Define factor tables (potentials) for each clique # Here, we have pairwise factors for edges (A,B) and (B,C), and single-variable factors for each node # Factor for edge (A, B) phi_AB = { (0, 0): 1.0, (0, 1): 0.5, (1, 0): 0.5, (1, 1): 1.5 } # Factor for edge (B, C) phi_BC = { (0, 0): 1.0, (0, 1): 0.7, (1, 0): 0.7, (1, 1): 1.2 } # Singleton factors (optional, can be all ones for simplicity) phi_A = {0: 1.0, 1: 1.0} phi_B = {0: 1.0, 1: 1.0} phi_C = {0: 1.0, 1: 1.0} # Collect all factors in a dictionary factors = { ('A',): phi_A, ('B',): phi_B, ('C',): phi_C, ('A', 'B'): phi_AB, ('B', 'C'): phi_BC } print("Graph structure:") print(graph) print("\nVariables:") print(variables) print("\nFactors:") for key, value in factors.items(): print(f"{key}: {value}")
copy

In the code above, the undirected structure of the MRF is captured by the graph dictionary, where each variable lists its neighbors, reflecting the edges of the graph. The factors are represented as Python dictionaries: for each clique (in this case, the pairs (A, B) and (B, C)), a factor table assigns a non-negative value (potential) to every possible assignment of the variables in that clique. Singleton factors for A, B, and C are included for completeness but set to 1.0, so they do not affect the distribution. The joint probability for a configuration of all variables is proportional to the product of all these factor values for the corresponding assignments. This representation allows you to encode complex dependencies in an undirected way, with the semantics of the model determined by the structure of the graph and the values in the factor tables.

question mark

Which of the following statements about Markov random fields (MRFs) are correct?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

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