<s> '''<STR_LIT>''' <EOL> import scipy . linalg <EOL> import numpy as np <EOL> from bnpy . util . RandUtil import rotateCovMat <EOL> from bnpy . data import XData , MinibatchIterator <EOL> K = <NUM_LIT:5> <EOL> D = <NUM_LIT:2> <EOL> w = np . asarray ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ] ) <EOL> w = w / w . sum ( ) <EOL> Mu = np . zeros ( ( K , D ) ) <EOL> V = <NUM_LIT:1.0> / <NUM_LIT> <EOL> SigmaBase = np . asarray ( [ [ V , <NUM_LIT:0> ] , [ <NUM_LIT:0> , V / <NUM_LIT> ] ] ) <EOL> Sigma = np . zeros ( ( <NUM_LIT:5> , D , D ) ) <EOL> for k in xrange ( <NUM_LIT:4> ) : <EOL> Sigma [ k ] = rotateCovMat ( SigmaBase , k * np . pi / <NUM_LIT> ) <EOL> Sigma [ <NUM_LIT:4> ] = <NUM_LIT:4> * V * np . eye ( D ) <EOL> cholSigma = np . zeros ( Sigma . shape ) <EOL> for k in xrange ( K ) : <EOL> cholSigma [ k ] = scipy . linalg . cholesky ( Sigma [ k ] ) <EOL> def sample_data_from_comp ( k , Nk , PRNG ) : <EOL> return Mu [ k , : ] + np . dot ( cholSigma [ k ] . T , PRNG . randn ( D , Nk ) ) . T <EOL> def get_short_name ( ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' <EOL> def get_data_info ( ) : <EOL> return '<STR_LIT>' % ( K , D ) <EOL> def get_X ( seed , nObsTotal ) : <EOL> PRNG = np . random . RandomState ( seed ) <EOL> trueList = list ( ) <EOL> Npercomp = PRNG . multinomial ( nObsTotal , w ) <EOL> X = list ( ) <EOL> for k in range ( K ) : <EOL> X . append ( sample_data_from_comp ( k , Npercomp [ k ] , PRNG ) ) <EOL> trueList . append ( k * np . ones ( Npercomp [ k ] ) ) <EOL> X = np . vstack ( X ) <EOL> TrueZ = np . hstack ( trueList ) <EOL> permIDs = PRNG . permutation ( X . shape [ <NUM_LIT:0> ] ) <EOL> X = X [ permIDs ] <EOL> TrueZ = TrueZ [ permIDs ] <EOL> return X , TrueZ <EOL> def get_data ( seed = <NUM_LIT> , nObsTotal = <NUM_LIT> , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> X , TrueZ = get_X ( seed , nObsTotal ) <EOL> Data = XData ( X = X ) <EOL> Data . summary = get_data_info ( ) <EOL> return Data <EOL> def get_minibatch_iterator ( seed = <NUM_LIT> , dataorderseed = <NUM_LIT:0> , nBatch = <NUM_LIT:10> , nObsBatch = None , nObsTotal = <NUM_LIT> , nLap = <NUM_LIT:1> , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> X , TrueZ = get_X ( seed , nObsTotal ) <EOL> Data = XData ( X = X ) <EOL> DataIterator = MinibatchIterator ( Data , nBatch = nBatch , nObsBatch = nObsBatch , nLap = nLap , dataseed = seed ) <EOL> DataIterator . summary = get_data_info ( ) <EOL> return DataIterator </s>
