#NEWLINE# def initialize_models( self , bdb , generator_id , modelnos , model_config ) : #NEWLINE# #INDENT# cc_cache = self . _crosscat_cache ( bdb ) #NEWLINE# if ( ( cc_cache is not None ) and ( generator_id in cc_cache . thetas ) ) : #NEWLINE# #INDENT# assert ( not any ( ( ( modelno in cc_cache . thetas [ generator_id ] ) for modelno in modelnos ) ) ) #NEWLINE# #UNINDENT# if ( model_config is None ) : #NEWLINE# #INDENT# model_config = { #NEWLINE# #INDENT# 'kernel_list' : [ ] , #NEWLINE# 'initialization' : 'from_the_prior' , #NEWLINE# 'row_initialization' : 'from_the_prior' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# M_c = self . _crosscat_metadata ( bdb , generator_id ) #NEWLINE# ( X_L_list , X_D_list ) = self . _crosscat . initialize ( seed = crosscat_seed ( bdb ) , M_c = M_c , M_r = None , T = self . _crosscat_data ( bdb , generator_id , M_c ) , n_chains = len ( modelnos ) , initialization = model_config [ 'initialization' ] , row_initialization = model_config [ 'row_initialization' ] ) #NEWLINE# if ( len ( modelnos ) == 1 ) : #NEWLINE# #INDENT# X_L_list = [ X_L_list ] #NEWLINE# X_D_list = [ X_D_list ] #NEWLINE# #UNINDENT# dep_constraints = [ ( crosscat_cc_colno ( bdb , generator_id , colno1 ) , crosscat_cc_colno ( bdb , generator_id , colno2 ) , dep ) for ( colno1 , colno2 , dep ) in crosscat_gen_column_dependencies ( bdb , generator_id ) ] #NEWLINE# if ( 0 < len ( dep_constraints ) ) : #NEWLINE# #INDENT# ( X_L_list , X_D_list ) = self . _crosscat . ensure_col_dep_constraints ( seed = crosscat_seed ( bdb ) , M_c = M_c , M_r = None , T = self . _crosscat_data ( bdb , generator_id , M_c ) , X_L = X_L_list , X_D = X_D_list , dep_constraints = dep_constraints ) #NEWLINE# #UNINDENT# insert_theta_sql = '\n            INSERT INTO bayesdb_crosscat_theta\n                (generator_id, modelno, theta_json)\n                VALUES (:generator_id, :modelno, :theta_json)\n        ' #NEWLINE# for ( modelno , ( X_L , X_D ) ) in zip ( modelnos , zip ( X_L_list , X_D_list ) ) : #NEWLINE# #INDENT# theta = { #NEWLINE# #INDENT# 'X_L' : X_L , #NEWLINE# 'X_D' : X_D , #NEWLINE# 'iterations' : 0 , #NEWLINE# 'model_config' : model_config , #NEWLINE# #UNINDENT# } #NEWLINE# self . _theta_validator . validate ( theta ) #NEWLINE# bdb . sql_execute ( insert_theta_sql , { #NEWLINE# #INDENT# 'generator_id' : generator_id , #NEWLINE# 'modelno' : modelno , #NEWLINE# 'theta_json' : json . dumps ( theta ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( cc_cache is not None ) : #NEWLINE# #INDENT# if ( generator_id in cc_cache . thetas ) : #NEWLINE# #INDENT# assert ( modelno not in cc_cache . thetas [ generator_id ] ) #NEWLINE# cc_cache . thetas [ generator_id ] [ modelno ] = theta #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cc_cache . thetas [ generator_id ] = { #NEWLINE# #INDENT# modelno : theta , #NEWLINE# #UNINDENT# }