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


Python Network.generate方法代码示例

本文整理汇总了Python中Network.Network.generate方法的典型用法代码示例。如果您正苦于以下问题:Python Network.generate方法的具体用法?Python Network.generate怎么用?Python Network.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Network.Network的用法示例。


在下文中一共展示了Network.generate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Network

# 需要导入模块: from Network import Network [as 别名]
# 或者: from Network.Network import generate [as 别名]
N = 300
net = Network(N)
alpha_unif(net, 0.5)

# Initialize the data model; generate covariates and associated coefficients
data_model = NonstationaryLogistic()
data_model.kappa = -7.0
covariates = ['x_%d' % i for i in range(5)]
for covariate in covariates:
    data_model.beta[covariate] = normal(0, 1.0)

    x_node = normal(0, 1.0, N)
    def f_x(i_1, i_2):
        return abs(x_node[i_1] - x_node[i_2]) < 0.3
    net.new_edge_covariate(covariate).from_binary_function_ind(f_x)
net.generate(data_model)
net.offset_extremes()
net.show()
print 'True theta_0: %.2f' % data_model.beta['x_0']

# Initialize the fit model; specify which covariates it should have terms for
fit_model = NonstationaryLogistic()
for covariate in covariates:
    fit_model.beta[covariate] = None

# Set up random subnetwork generator, and run fitting experiments
gen = RandomSubnetworks(net, (200, 200))
for rep in range(5):
    subnet = gen.sample()

    fit_model.fit(subnet)
开发者ID:wang-xinhong,项目名称:StochasticBlockmodel,代码行数:33,代码来源:test_minimal.py

示例2: Network

# 需要导入模块: from Network import Network [as 别名]
# 或者: from Network.Network import generate [as 别名]
#!/usr/bin/env python

from Models import Stationary, Blockmodel, FixedMargins
from Network import Network

net = Network(100)
net.new_node_covariate_int('r')[:] = 20
net.new_node_covariate_int('c')[:] = 20
net.new_node_covariate_int('z')[:] = ([0] * 50) + ([1] * 50)

base_model = Blockmodel(Stationary(),2)
base_model.Theta[0,0] = 3.0
base_model.Theta[0,1] = -1.0
base_model.Theta[1,0] = -2.0
base_model.Theta[1,1] = 0.0
model = FixedMargins(base_model)

net.generate(base_model)
net.show_heatmap('z')

net.generate(model)
net.show_heatmap('z')

开发者ID:othercriteria,项目名称:StochasticBlockmodel,代码行数:24,代码来源:minitest.py

示例3: FixedMargins

# 需要导入模块: from Network import Network [as 别名]
# 或者: from Network.Network import generate [as 别名]
        print 'Unrecognized covariate structure.'
        import sys; sys.exit()
        
    net.new_edge_covariate(name).from_binary_function_ind(f_x)

# Specify data model as generation permuation networks
net.new_node_covariate_int('r')[:] = 1
net.new_node_covariate_int('c')[:] = 1
data_model = FixedMargins(data_model, 'r', 'c')

coverage_levels = np.append(0.0, np.cumsum(params['coverage_increments']))
traces = { 'wall_time': [],
           'nll': [] }

for rep in range(params['num_reps']):
    net.generate(data_model, arbitrary_init = params['arb_init'])

    wall_time_trace = [net.gen_info['wall_time']]
    nll_trace = [data_model.nll(net)]

    for coverage_inc in params['coverage_increments']:
        data_model.gibbs_improve_perm(net, net.adjacency_matrix(), coverage_inc)

        wall_time_trace.append(net.gen_info['wall_time'])
        nll_trace.append(data_model.nll(net))

    traces['wall_time'].append(wall_time_trace)
    traces['nll'].append(nll_trace)

plt.figure()
plt.title('Computation time')
开发者ID:wang-xinhong,项目名称:StochasticBlockmodel,代码行数:33,代码来源:test_gibbs.py

示例4: do_experiment

# 需要导入模块: from Network import Network [as 别名]
# 或者: from Network.Network import generate [as 别名]
def do_experiment(params):
    if params['dump_fits'] and params['load_fits']:
        print 'Warning: simultaneously dumping and loading is a bad idea.'
        
    if params['dump_fits']:
        fits = []

    if params['load_fits']:
        with open(params['load_fits'], 'r') as fits_file:
            loaded_params_pick, loaded_fits = json.load(fits_file)

        loaded_params = dict([(k,unpick(v)) for (k,v) in loaded_params_pick])

        # Compare on parameters that control data generation and inference
        run_params = ['N', 'B', 'theta_sd', 'theta_fixed',
                      'alpha_unif_sd', 'alpha_norm_sd', 'alpha_gamma_sd',
                      'cov_unif_sd', 'cov_norm_sd', 'cov_disc_sd',
                      'kappa_target', 'pre_offset', 'post_fit',
                      'fit_nonstationary', 'fit_method', 'num_reps',
                      'is_T', 'sampling', 'sub_sizes_r', 'sub_sizes_c',
                      'random_seed']

        for p in run_params:
            if not np.all(loaded_params[p] == params[p]):
                print 'Warning: load mismatch on', p
    
    # Set random seed for reproducible output
    seed = Seed(params['random_seed'])

    # Initialize full network
    arr = Network(params['N'])

    # Generate node-level propensities to extend and receive edges
    if params['alpha_norm_sd'] > 0.0:
        alpha_norm(arr, params['alpha_norm_sd'])
    elif params['alpha_unif_sd'] > 0.0:
        alpha_unif(arr, params['alpha_unif_sd'])
    elif params['alpha_gamma_sd'] > 0.0:
        # Choosing location somewhat arbitrarily to give unit skewness
        alpha_gamma(arr, 4.0, params['alpha_gamma_sd'])
    else:
        alpha_zero(arr)

    # Generate covariates and associated coefficients
    data_model = NonstationaryLogistic()
    covariates = []
    for b in range(params['B']):
        name = 'x_%d' % b
        covariates.append(name)

        if name in params['theta_fixed']:
            data_model.beta[name] = params['theta_fixed'][name]
        else:
            data_model.beta[name] = np.random.normal(0, params['theta_sd'])

        if params['cov_unif_sd'] > 0.0:
            c = np.sqrt(12) / 2
            def f_x(i_1, i_2):
                return np.random.uniform(-c * params['cov_unif_sd'],
                                         c * params['cov_unif_sd'])
        elif params['cov_norm_sd'] > 0.0:
            def f_x(i_1, i_2):
                return np.random.normal(0, params['cov_norm_sd'])
        elif params['cov_disc_sd'] > 0.0:
            def f_x(i_1, i_2):
                return (params['cov_disc_sd'] *
                        (np.sign(np.random.random() - 0.5)))
        else:
            print 'Error: no covariate distribution specified.'
            sys.exit()

        arr.new_edge_covariate(name).from_binary_function_ind(f_x)

    # Generate large network, if necessary
    if not params['sampling'] == 'new':
        data_model.match_kappa(arr, params['kappa_target'])
        arr.generate(data_model)

    if params['fit_nonstationary']:
        fit_model = NonstationaryLogistic()
    else:
        fit_model = StationaryLogistic()
    for c in covariates:
        fit_model.beta[c] = None

    # Set up recording of results from experiment
    results = Results(params['sub_sizes_r'], params['sub_sizes_c'],
                      params['num_reps'], interactive = params['interactive'])
    add_array_stats(results)
    if params['plot_sig']:
        from scipy.stats import chi2
        crit = lambda dof: -0.5 * chi2.ppf(0.95, dof)

        umle_f = lambda n, f: f.nll(n, ignore_offset = True)
        umle_d = lambda n, d: d.nll(n, ignore_offset = True)
        umle_n = lambda n: NonstationaryLogistic().nll(n, ignore_offset = True)
        results.new('UMLE F-N', 'nm',
                    lambda n, d, f: umle_f(n, f) - umle_n(n))
        results.new('UMLE F-D', 'nm',
                    lambda n, d, f: umle_f(n, f) - umle_d(n, d))
#.........这里部分代码省略.........
开发者ID:othercriteria,项目名称:StochasticBlockmodel,代码行数:103,代码来源:test.py


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