<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from kameleon_mcmc . distribution . Distribution import Distribution , Sample <EOL> class Discrete ( Distribution ) : <EOL> def __init__ ( self , omega , support = None ) : <EOL> Distribution . __init__ ( self , dimension = None ) <EOL> assert ( abs ( sum ( omega ) - <NUM_LIT:1> ) < <NUM_LIT> ) <EOL> if support == None : <EOL> support = range ( len ( omega ) ) <EOL> else : <EOL> assert ( len ( omega ) == len ( support ) ) <EOL> self . num_objects = len ( omega ) <EOL> self . omega = omega <EOL> self . cdf = np . cumsum ( omega ) <EOL> self . support = support <EOL> def __str__ ( self ) : <EOL> s = self . __class__ . __name__ + "<STR_LIT>" <EOL> s += "<STR_LIT>" + str ( self . num_objects ) <EOL> s += "<STR_LIT>" + str ( self . omega ) <EOL> s += "<STR_LIT>" + str ( self . cdf ) <EOL> s += "<STR_LIT>" + str ( self . support ) <EOL> s += "<STR_LIT:U+002CU+0020>" + Distribution . __str__ ( self ) <EOL> s += "<STR_LIT:]>" <EOL> return s <EOL> def sample ( self , n = <NUM_LIT:1> ) : <EOL> u = np . random . rand ( n ) <EOL> rez = np . zeros ( [ n ] ) <EOL> for ii in range ( <NUM_LIT:0> , n ) : <EOL> jj = <NUM_LIT:0> <EOL> while u [ ii ] > self . cdf [ jj ] : <EOL> jj += <NUM_LIT:1> <EOL> rez [ ii ] = self . support [ jj ] <EOL> return Sample ( rez . astype ( np . int32 ) ) <EOL> def log_pdf ( self , X ) : <EOL> return None </s>
