#NEWLINE# def initialize( self , corpus ) : #NEWLINE# #INDENT# '\n        Initialize the random projection matrix.\n        ' #NEWLINE# if ( randmat . id2word is None ) : #NEWLINE# #INDENT# logger . info ( 'no word id mapping provided; initializing from corpus, assuming identity' ) #NEWLINE# self . id2word = utils . dict_from_corpus ( corpus ) #NEWLINE# self . num_terms = len ( self . id2word ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . num_terms = ( 1 + max ( ( [ ( - 1 ) ] + self . id2word . keys ( ) ) ) ) #NEWLINE# #UNINDENT# shape = ( self . num_topics , self . num_terms ) #NEWLINE# logger . info ( ( 'constructing %s random matrix' % str ( shape ) ) ) #NEWLINE# randmat = ( 1 - ( 2 * numpy . random . binomial ( 1 , 0.5 , shape ) ) ) #NEWLINE# self . projection = numpy . asfortranarray ( randmat , dtype = numpy . float32 )