本文整理汇总了Python中population.Population.compute_log_p方法的典型用法代码示例。如果您正苦于以下问题:Python Population.compute_log_p方法的具体用法?Python Population.compute_log_p怎么用?Python Population.compute_log_p使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类population.Population
的用法示例。
在下文中一共展示了Population.compute_log_p方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize_test_harness
# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import compute_log_p [as 别名]
def initialize_test_harness():
""" Initialize a model with N neurons. Use the data if specified on the
command line, otherwise sample new data from the model.
Return a population object, the data, and a set of true parameters
which is expected for synthetic tests
"""
# Parse command line args
(options, args) = parse_cmd_line_args()
# Load data from file or create synthetic test dataset
data = load_data(options)
print "Creating master population object"
model = make_model(options.model, N=data['N'])
stabilize_sparsity(model)
popn = Population(model)
popn.set_data(data)
# Initialize the GLM with the data
popn_true = None
x_true = None
if 'vars' in data:
x_true = data['vars']
# Load the true model
model_true = None
data_dir = os.path.dirname(options.dataFile)
model_file = os.path.join(data_dir, 'model.pkl')
print "Loading true model from %s" % model_file
with open(model_file) as f:
model_true = cPickle.load(f)
# HACK FOR EXISTING DATA!
if 'N_dims' not in model_true['network']['graph']:
model_true['network']['graph']['N_dims'] = 1
if 'location_prior' not in model_true['network']['graph']:
model_true['network']['graph']['location_prior'] = \
{
'type' : 'gaussian',
'mu' : 0.0,
'sigma' : 1.0
}
if 'L' in x_true['net']['graph']:
x_true['net']['graph']['L'] = x_true['net']['graph']['L'].ravel()
# END HACK
popn_true = Population(model_true)
popn_true.set_data(data)
ll_true = popn_true.compute_log_p(x_true)
print "true LL: %f" % ll_true
return options, popn, data, popn_true, x_true
示例2: initialize_test_harness
# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import compute_log_p [as 别名]
def initialize_test_harness(N=2):
""" Initialize a model with N neurons. Use the data if specified on the
command line, otherwise sample new data from the model.
Return a population object, the data, and a set of true parameters
which is expected for synthetic tests
"""
# Parse command line args
(options, args) = parse_cmd_line_args()
# Initialize a model with N neurons
print "Initializing GLM"
model = make_model('spatiotemporal_glm', N=N)
# model = make_model('standard_glm', N=N)
population = Population(model)
# Load data
if not options.dataFile is None:
if options.dataFile.endswith('.mat'):
print "Loading data from %s" % options.dataFile
#data = scipy.io.loadmat(options.dataFile)
# Scipy's IO is weird -- we can save dicts as structs but its hard to reload them
raise Exception('Loading from .mat file is not implemented!')
elif options.dataFile.endswith('.pkl'):
print "Loading data from %s" % options.dataFile
with open(options.dataFile,'r') as f:
data = cPickle.load(f)
else:
raise Exception("Unrecognized file type: %s" % options.dataFile)
else:
print "Generating synthetic data"
data = generate_synth_data(population,
options.resultsDir,
T_stop=60)
# Initialize the GLM with the data
x_true = data['vars']
population.set_data(data)
ll_true = population.compute_log_p(x_true)
print "true LL: %f" % ll_true
return population, data, x_true