<s> from nose . tools import assert_raises <EOL> from numpy . testing import assert_array_equal , assert_array_almost_equal <EOL> import numpy as np <EOL> from seqlearn . hmm import MultinomialHMM <EOL> text = [ w . split ( ) for w in [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] ] <EOL> words , y = zip ( * text ) <EOL> lengths = [ len ( text ) ] <EOL> vocab , identities = np . unique ( words , return_inverse = True ) <EOL> X = ( identities . reshape ( - <NUM_LIT:1> , <NUM_LIT:1> ) == np . arange ( len ( vocab ) ) ) . astype ( int ) <EOL> def test_hmm ( ) : <EOL> n_features = X . shape [ <NUM_LIT:1> ] <EOL> clf = MultinomialHMM ( ) <EOL> clf . fit ( X , y , lengths ) <EOL> assert_array_equal ( clf . classes_ , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:N>" , "<STR_LIT>" ] ) <EOL> assert_array_equal ( clf . predict ( X ) , y ) <EOL> clf . set_params ( decode = "<STR_LIT>" ) <EOL> assert_array_equal ( clf . predict ( X ) , y ) <EOL> n_classes = len ( clf . classes_ ) <EOL> assert_array_almost_equal ( np . ones ( n_features ) , <EOL> np . exp ( clf . coef_ ) . sum ( axis = <NUM_LIT:0> ) ) <EOL> assert_array_almost_equal ( np . ones ( n_classes ) , <EOL> np . exp ( clf . intercept_trans_ ) . sum ( axis = <NUM_LIT:0> ) ) <EOL> assert_array_almost_equal ( <NUM_LIT:1.> , np . exp ( clf . intercept_final_ ) . sum ( ) ) <EOL> assert_array_almost_equal ( <NUM_LIT:1.> , np . exp ( clf . intercept_init_ ) . sum ( ) ) <EOL> def test_hmm_validation ( ) : <EOL> assert_raises ( ValueError , MultinomialHMM ( alpha = <NUM_LIT:0> ) . fit , X , y , lengths ) <EOL> assert_raises ( ValueError , MultinomialHMM ( alpha = - <NUM_LIT:1> ) . fit , X , y , lengths ) </s>
