SlideShare uma empresa Scribd logo
1 de 33
Baixar para ler offline
Dominando Modelos Ocultos de
Markov com Python e GHMM
Daker Fernandes Pinheiro

Setembro/2011, Python Brasil
Sobre mim...



   from Petrolina-PE import Daker
   Ciência da Computação CIn-UFPE
   Developer Instituto Nokia de Tecnologia (IDNT)
   Software Livre
   KDE, Qt, Plasma, QML-Box2D, MeeGo Components, dia2code,
   QMLFB, ...
   GSoC: Plasma Components
   PUG-PE
   Nerd Power
   Camisetas Brancas :-)
Senta que lá vem história




Processamento de Sequências Biológicas e Metodos e Algoritmos em
Biologia Computacional - 2011.1
    Prof. Ivan Gesteira
    DNA, RNA
    Proteínas
    Modelos Ocultos de Markov
Problemas em Biologia Computacional




  Identicação de regiões de interesse no DNA
  Classicação de DNA e Proteínas
  Clusterização de DNA e Proteínas
  Proling de DNA e Proteínas
  Identicação de Anomalias
  Ilhas CpG
  ...
Modelos Ocultos de Markov




  Ou Hidden Markov Models (HMMs)
  Modelo Matemático
  Probabilístico
  Análise de Séries e Sequências
  Estados internos vs. Comportamento
Problemas diversos




   Classicação
   Clusterização
   Reconhecimento
   Análise de Séries Temporais
   Análise de Sequências
   Geração segundo o modelo
Problemas Diversos




   Linguagem Natural
   Sinais
   Música
   Mineração de Dados
   Aprendizagem de Máquina
   Extração de Informação
Fair-Bet Casino


Existe um casino onde existe um jogo de apostas com moedas e um
funcionário que as lança moedas.
Fair-Bet Casino




Cada moeda pode assumir dois valores:
   Cara (H)
   Coroa (T)
Fair-Bet Casino




O funcionário tem duas moedas:
    Uma moeda Justa: que pode dar como resultado (emite símbolos)
    com a seguinte distribuição
        Cara com probabilidade 50%
        Coroa com probabilidade 50%
    Uma moeda Viciada:
        Cara com probabilidade 75%
        Coroa com probabilidade 25%
Fair-Bet Casino



Grafo de emissões:
Fair-Bet Casino




Esse funcionário sempre usa uma das duas moedas. Mas pode
trocá-las com 10% das vezes que vai fazer um novo sorteio.
     Estados
     Transições
Fair-Bet Casino




Grafo de transições de estados:
Fair-Bet Casino




O funcionário começa com qualquer uma das moedas com igual
probabilidade.
Fair-Bet Casino



Transições do estado inicial:
Fair-Bet Casino


Modelo completo:
Problema



Imagine que você é um apostador
Problema




Dada uma sequência de lançamentos:
T, T, T, H, T, H, H, T, T, H, H, T, H, T, H, H, H, H, T, T, H, T, H,
    T, H, H, H, T, H, H, H, H, H, T, H, H, T, H, H, H, T, H, T
Quais moedas o lançador estava utilizando em cada momento?
Solução




          Não existe solução extata! Mas...
Solução




                 Probabilidades a posteriori

Dado uma sequência, quais as probabilidades de estar em cada modelo

                            +Viterbi
Biblioteca:

         General Hidden Markov Model (GHMM)

+ Biopython (Cenas de um próximo capítulo)
GHMM




 Biblioteca C++
 HMMs + Algoritmos
 Binding Python
GHMM




import ghmm

# Criando a l f a b e t o para r e p r e s e n t a r os
#     s i m b o l o s e m i t i d o s p e l o me modelo .

emission_alphabet = ghmm. Alphabet ( [ 'H ' , 'T ' ] )
GHMM




# Matriz de t r a n s i c o e s :
#       l i n h a s representam e s t a d o s de origem
#       c o l u n a s representam e s t a d o s de d e s t i n o
#       v a l o r e s da matriz representam a
#               p r o b a b i l i d a d e da t r a n s i c a o de e s t a d o s
#
transitions_probabilities = [
    [ 0 . 9 , 0 . 1 ] , # 0 : e s t a d o de j u s t o
    [ 0 . 1 , 0 . 9 ] , # 1: estado viciado
]
GHMM




# p r o b a b i l i d a d e s de comecar em H e T
initial_states_distribution = [0.5 , 0.5]
GHMM



# Matriz de emissao de s i m b o l o s

# 0 : p r o b a b i l i d a d e s de emissao da moeda j u s t a
emissions_fair = [0.5 , 0.5]
# 1 : p r o b a b i l i d a d e s de emissao da moeda v i c i a d a
emissions_biased = [ 0 . 5 , 0 . 5 ]

emissions_probabilities = [
    emissions_fair ,
    emissions_biased
]
GHMM




# Criando Modelo Oculto de Markov
hmm = ghmm. HMMFromMatrices (
    # Alfabeto
    emission_alphabet ,
    # Tipo de d i s t r i b u i c a o ( d i s c r e t a , gau ss ia na , . . . )
    ghmm. D i s c r e t e D i s t r i b u t i o n ( emission_alphabet ) ,
     transitions_probabilities ,
    emissions_probabilities ,
     initial_states_distribution
)
GHMM




Resolvendo o problema do Casino

t o s s e s = [ T, T, T, H, . . . , H, T]

# XXX
sequence = ghmm. EmissionSequence ( emission_alphabet ,
                                        tosses )

v i t er b i _ p a t h , states_prob = hmm. v i t e r b i ( sequence )
GHMM




Resolvendo o problema do Casino

 p r i n t ( v i t e r b i _ p a t h )
[0 , 0 , 0 , 0 , . . . , 1 , 1 , 1 , 1 , 1]

 p r i n t states_prob
[[0.8407944139086141 , 0.1592055860913865] ,
 [0.860787703168127 , 0.13921229683187356] , . . . ]
Fair-Bet Casino




Probabilidades a posteriori:
Algoritmos




  Geração de sequências
  Emissão com distribuições Gaussianas
  Baum Welch
Agradecimentos




  INDT
  CIn - UFPE
  Prof. Ivan Gesteira
  Python Brasil
  Vocês!
Dúvidas?
Twitter: @dakerfp
E-mail: daker.pinheiro@openbossa.org
Freenode: dakerfp
Blog: http://codecereal.blogspot.com
Blog: http://blog.qtlabs.org.br
Blog: http://aimotion.blogspot.com
Gitorious: http://gitorious.org/ dakerfp
Github: http://github.com/dakerfp
GHMM: http://ghmm.org

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Modelos Ocultos de Markov com Python e GHMM

  • 1. Dominando Modelos Ocultos de Markov com Python e GHMM Daker Fernandes Pinheiro Setembro/2011, Python Brasil
  • 2. Sobre mim... from Petrolina-PE import Daker Ciência da Computação CIn-UFPE Developer Instituto Nokia de Tecnologia (IDNT) Software Livre KDE, Qt, Plasma, QML-Box2D, MeeGo Components, dia2code, QMLFB, ... GSoC: Plasma Components PUG-PE Nerd Power Camisetas Brancas :-)
  • 3. Senta que lá vem história Processamento de Sequências Biológicas e Metodos e Algoritmos em Biologia Computacional - 2011.1 Prof. Ivan Gesteira DNA, RNA Proteínas Modelos Ocultos de Markov
  • 4. Problemas em Biologia Computacional Identicação de regiões de interesse no DNA Classicação de DNA e Proteínas Clusterização de DNA e Proteínas Proling de DNA e Proteínas Identicação de Anomalias Ilhas CpG ...
  • 5. Modelos Ocultos de Markov Ou Hidden Markov Models (HMMs) Modelo Matemático Probabilístico Análise de Séries e Sequências Estados internos vs. Comportamento
  • 6. Problemas diversos Classicação Clusterização Reconhecimento Análise de Séries Temporais Análise de Sequências Geração segundo o modelo
  • 7. Problemas Diversos Linguagem Natural Sinais Música Mineração de Dados Aprendizagem de Máquina Extração de Informação
  • 8. Fair-Bet Casino Existe um casino onde existe um jogo de apostas com moedas e um funcionário que as lança moedas.
  • 9. Fair-Bet Casino Cada moeda pode assumir dois valores: Cara (H) Coroa (T)
  • 10. Fair-Bet Casino O funcionário tem duas moedas: Uma moeda Justa: que pode dar como resultado (emite símbolos) com a seguinte distribuição Cara com probabilidade 50% Coroa com probabilidade 50% Uma moeda Viciada: Cara com probabilidade 75% Coroa com probabilidade 25%
  • 12. Fair-Bet Casino Esse funcionário sempre usa uma das duas moedas. Mas pode trocá-las com 10% das vezes que vai fazer um novo sorteio. Estados Transições
  • 13. Fair-Bet Casino Grafo de transições de estados:
  • 14. Fair-Bet Casino O funcionário começa com qualquer uma das moedas com igual probabilidade.
  • 17. Problema Imagine que você é um apostador
  • 18. Problema Dada uma sequência de lançamentos: T, T, T, H, T, H, H, T, T, H, H, T, H, T, H, H, H, H, T, T, H, T, H, T, H, H, H, T, H, H, H, H, H, T, H, H, T, H, H, H, T, H, T Quais moedas o lançador estava utilizando em cada momento?
  • 19. Solução Não existe solução extata! Mas...
  • 20. Solução Probabilidades a posteriori Dado uma sequência, quais as probabilidades de estar em cada modelo +Viterbi
  • 21. Biblioteca: General Hidden Markov Model (GHMM) + Biopython (Cenas de um próximo capítulo)
  • 22. GHMM Biblioteca C++ HMMs + Algoritmos Binding Python
  • 23. GHMM import ghmm # Criando a l f a b e t o para r e p r e s e n t a r os # s i m b o l o s e m i t i d o s p e l o me modelo . emission_alphabet = ghmm. Alphabet ( [ 'H ' , 'T ' ] )
  • 24. GHMM # Matriz de t r a n s i c o e s : # l i n h a s representam e s t a d o s de origem # c o l u n a s representam e s t a d o s de d e s t i n o # v a l o r e s da matriz representam a # p r o b a b i l i d a d e da t r a n s i c a o de e s t a d o s # transitions_probabilities = [ [ 0 . 9 , 0 . 1 ] , # 0 : e s t a d o de j u s t o [ 0 . 1 , 0 . 9 ] , # 1: estado viciado ]
  • 25. GHMM # p r o b a b i l i d a d e s de comecar em H e T initial_states_distribution = [0.5 , 0.5]
  • 26. GHMM # Matriz de emissao de s i m b o l o s # 0 : p r o b a b i l i d a d e s de emissao da moeda j u s t a emissions_fair = [0.5 , 0.5] # 1 : p r o b a b i l i d a d e s de emissao da moeda v i c i a d a emissions_biased = [ 0 . 5 , 0 . 5 ] emissions_probabilities = [ emissions_fair , emissions_biased ]
  • 27. GHMM # Criando Modelo Oculto de Markov hmm = ghmm. HMMFromMatrices ( # Alfabeto emission_alphabet , # Tipo de d i s t r i b u i c a o ( d i s c r e t a , gau ss ia na , . . . ) ghmm. D i s c r e t e D i s t r i b u t i o n ( emission_alphabet ) , transitions_probabilities , emissions_probabilities , initial_states_distribution )
  • 28. GHMM Resolvendo o problema do Casino t o s s e s = [ T, T, T, H, . . . , H, T] # XXX sequence = ghmm. EmissionSequence ( emission_alphabet , tosses ) v i t er b i _ p a t h , states_prob = hmm. v i t e r b i ( sequence )
  • 29. GHMM Resolvendo o problema do Casino p r i n t ( v i t e r b i _ p a t h ) [0 , 0 , 0 , 0 , . . . , 1 , 1 , 1 , 1 , 1] p r i n t states_prob [[0.8407944139086141 , 0.1592055860913865] , [0.860787703168127 , 0.13921229683187356] , . . . ]
  • 31. Algoritmos Geração de sequências Emissão com distribuições Gaussianas Baum Welch
  • 32. Agradecimentos INDT CIn - UFPE Prof. Ivan Gesteira Python Brasil Vocês!
  • 33. Dúvidas? Twitter: @dakerfp E-mail: daker.pinheiro@openbossa.org Freenode: dakerfp Blog: http://codecereal.blogspot.com Blog: http://blog.qtlabs.org.br Blog: http://aimotion.blogspot.com Gitorious: http://gitorious.org/ dakerfp Github: http://github.com/dakerfp GHMM: http://ghmm.org