<s> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import FromScratchMult <EOL> def init_global_params ( hmodel , Data , initname = None , seed = <NUM_LIT:0> , nRepeatTrue = <NUM_LIT:2> , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> PRNG = np . random . RandomState ( seed ) <EOL> if initname . count ( '<STR_LIT>' ) > <NUM_LIT:0> : <EOL> if hasattr ( Data , '<STR_LIT>' ) : <EOL> resp = calc_resp_from_true_labels ( Data ) <EOL> elif hasattr ( Data , '<STR_LIT>' ) : <EOL> if '<STR_LIT>' in Data . TrueParams : <EOL> resp = Data . TrueParams [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in Data . TrueParams : <EOL> resp = Data . TrueParams [ '<STR_LIT>' ] <EOL> if initname == '<STR_LIT>' : <EOL> pass <EOL> elif initname == '<STR_LIT>' : <EOL> Ktrue = resp . shape [ <NUM_LIT:1> ] <EOL> rowIDs = PRNG . permutation ( Data . nObs ) <EOL> L = len ( rowIDs ) / nRepeatTrue <EOL> bigResp = np . zeros ( ( Data . nObs , Ktrue * nRepeatTrue ) ) <EOL> curLoc = <NUM_LIT:0> <EOL> for r in range ( nRepeatTrue ) : <EOL> targetIDs = rowIDs [ curLoc : curLoc + L ] <EOL> bigResp [ targetIDs , r * Ktrue : ( r + <NUM_LIT:1> ) * Ktrue ] = resp [ targetIDs , : ] <EOL> curLoc += L <EOL> resp = bigResp <EOL> elif initname == '<STR_LIT>' : <EOL> hmodel . set_global_params ( ** Data . TrueParams ) <EOL> return <EOL> else : <EOL> raise NotImplementedError ( '<STR_LIT>' % ( initname ) ) <EOL> if hmodel . obsModel . __class__ . __name__ . count ( '<STR_LIT>' ) > <NUM_LIT:0> : <EOL> LP = dict ( resp = resp ) <EOL> else : <EOL> LP = FromScratchMult . getLPfromResp ( resp , Data ) <EOL> SS = hmodel . get_global_suff_stats ( Data , LP ) <EOL> hmodel . update_global_params ( SS ) <EOL> def calc_resp_from_true_labels ( Data ) : <EOL> TrueLabels = Data . TrueLabels <EOL> uniqueLabels = np . unique ( TrueLabels ) <EOL> Ktrue = len ( uniqueLabels ) <EOL> resp = np . zeros ( ( Data . nObs , Ktrue ) ) <EOL> for k in range ( Ktrue ) : <EOL> mask = TrueLabels == uniqueLabels [ k ] <EOL> resp [ mask , k ] = <NUM_LIT:1.0> <EOL> return resp </s>
