ó
æÊMc           @   s  d  Z  d Z d d l m Z m Z d d d d d g Z d d d d d d d  g Z e e g  e D] \ Z	 Z
 e
 ^ q_ ƒ ƒ Z d „  Z d „  Z d „  Z e e e g Z e e ƒ Z e e ƒ Z e g  e e ƒ D] \ Z Z	 e	 e f ^ qÏ ƒ Z e g  e e ƒ D] \ Z Z
 e
 e f ^ q ƒ Z e j e e ƒ e e f ƒ Z xu e e ƒ D]g \ Z Z xX e e ƒ D]J \ Z
 Z x; e e ƒ D]- \ Z	 Z e e e ƒ e e e
 e e	 f <qWqfWqMWe j d e e e ƒ f ƒ Z x: e D]2 \ Z	 Z
 e d e e
 e e e	 f c d 7<qÞWe j e e e ƒ Z e  e _! e j" ƒ  d e# e j$ ƒ GHe j% ƒ  Z& d GHe j' d
 ƒ Z
 e& e
 e e
 d e !GHd GHd! Gx e D] Z( d e( Gq–WxS e e ƒ D]E \ Z
 Z d e Gx. e e ƒ D]  \ Z	 Z( d e& e
 e e	 GqÖWqµWHd S("   s¥   Example use of the maximum entropy package for a classification task.

    An extension of the machine translation example from the paper 'A maximum
    entropy approach to natural language processing' by Berger et al., 1996.

    Consider the translation of the English word 'in' into French.  Suppose we
    notice the following facts in a corpus of parallel texts:

        (1)    p(dans) + p(en) + p(Ã ) + p(au cours de) + p(pendant) = 1
        (2)    p(dans | next English word = 'a' or 'the') = 8/10
        (3)    p(dans | c) + p(Ã  | c)  = 1/2   for all other c

    This code finds the probability distribution with maximal entropy
    subject to these constraints.
s   Ed Schofieldiÿÿÿÿ(   t
   maxentropyt   sparset   danst   ens   Ã s   au cours det   pendantt   at   thet   happyt   healthyc         C   s
   |  t  k S(   N(   t   samplespace(   t   xt   c(    (    sN   C:\Python27\Lib\site-packages\scipy\maxentropy\examples\conditionalexample2.pyt   f0   s    c         C   s$   |  d k r | d k r t  St Sd  S(   NR   R   R   (   R   R   (   t   Truet   False(   R
   R   (    (    sN   C:\Python27\Lib\site-packages\scipy\maxentropy\examples\conditionalexample2.pyt   f1!   s    c         C   s"   |  d k s |  d k o! | d k S(   NR   s   Ã R   R   (   R   s   the(    (   R
   R   (    (    sN   C:\Python27\Lib\site-packages\scipy\maxentropy\examples\conditionalexample2.pyt   f2'   s    i   i    s   
Fitted model parameters are:
s2   
pmf table p(x | c), where c is the context 'the':s   
Fitted distribution is:s   %12ss   c \ xs   
%12ss   %12.3fN(   s   dansR   (   s   dansR   (   s   dansR   (   s   danss   the(   R   R   (   s   dansR   (   s   au cours deR   s          c \ x()   t   __doc__t
   __author__t   scipyR    R   R	   t   corpust   listt   setR
   R   t   contextsR   R   R   t   ft   lent   numcontextst   numsamplepointst   dictt	   enumeratet   it   samplespace_indext   context_indext
   lil_matrixt   Ft   f_it   contextt   samplepointt   Nt   conditionalmodelt   modelR   t   verboset   fitt   strt   paramst   probdistt   pt   indext   label(    (    (    sN   C:\Python27\Lib\site-packages\scipy\maxentropy\examples\conditionalexample2.pyt   <module>   sN   +			11-	*	
