当前位置: 首页>>代码示例>>Python>>正文


Python Population.compute_log_p方法代码示例

本文整理汇总了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
开发者ID:chris-stock,项目名称:pyglm,代码行数:52,代码来源:synth_harness.py

示例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
开发者ID:memming,项目名称:pyglm,代码行数:45,代码来源:synth_harness.py


注:本文中的population.Population.compute_log_p方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。