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


Python MSMLib.renumber_states方法代码示例

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


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

示例1: test_renumber_states_1

# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import renumber_states [as 别名]
def test_renumber_states_1():
    a = np.random.randint(3, size=(2,10))
    a[np.where(a==0)] = 1
    a[0,0] = -1
    
    # since its inplace
    new_a = a.copy()
    mapping = MSMLib.renumber_states(new_a)
    
    assert new_a[0,0] == -1
    npt.assert_array_equal(np.where(a==2), np.where(new_a==1))
    npt.assert_array_equal(mapping, [1,2])
    npt.assert_array_equal(mapping[new_a][np.where(a!= -1)], a[np.where(a!= -1)])
开发者ID:jimsnyderjr,项目名称:msmbuilder,代码行数:15,代码来源:test_msmlib.py

示例2: test_renumber_states_1

# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import renumber_states [as 别名]
def test_renumber_states_1():
    a = np.random.randint(3, size=(2, 10))
    a[np.where(a == 0)] = 1
    a[0, 0] = -1

    # since its inplace
    new_a = a.copy()
    mapping = MSMLib.renumber_states(new_a)

    eq(int(new_a[0, 0]), -1)
    eq(np.where(a == 2)[0], np.where(new_a == 1)[0])
    eq(np.where(a == 2)[1], np.where(new_a == 1)[1])
    eq(mapping, np.array([1, 2]))
    eq(mapping[new_a][np.where(a != -1)], a[np.where(a != -1)])
开发者ID:msmbuilder,项目名称:msmbuilder-legacy,代码行数:16,代码来源:test_msmlib.py

示例3: _run_trial

# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import renumber_states [as 别名]
def _run_trial(arg_dict):

    # inject the arg_dict into the local namespace - may be a bad idea...
    for key in arg_dict.keys():
        exec(key + " = arg_dict['" + key + "']")

    # initialize data structures to hold output
    distance_to_target = np.zeros(rounds_of_sampling)
    obs_distance = np.zeros(rounds_of_sampling)

    # the assignments array will hold all of the output of all simulations
    assignments = -1.0 * np.ones((rounds_of_sampling * simultaneous_samplers + 1,
                                      max(size_of_intial_data, length_of_sampling_trajs+1) ))

    # initialize the "true" transition matrix
    if not transition_matrix:
        assert num_states > 0
        C_rand = np.random.randint( 0, 100, (num_states, num_states) )
        C_rand += C_rand.T
        T = MSMLib.estimate_transition_matrix( C_rand )
    else:
        T = transition_matrix
        num_states = T.shape[0]
    T = sparse.csr_matrix(T)
    msm_analysis.check_transition(T)
        
    if observable_function:
        try:
            obs_goal = observable_function(T)
        except Exception as e:
            print >> sys.stderr, e
            raise Exception("Error evaluating function: %s" % observable_function.__name__)
            
    assignments[0,:size_of_intial_data] = msm_analysis.sample(T, None, size_of_intial_data)

    # iterate, adding simulation time
    for sampling_round in range(rounds_of_sampling):
        
        # apply the adaptive sampling method - we need to be true to what a
        # real simulation would actually see for the counts matrix
        mod_assignments = assignments.copy()
        mapping = MSMLib.renumber_states( mod_assignments )
        C_mod = MSMLib.get_count_matrix_from_assignments( mod_assignments )
        T_mod = MSMLib.estimate_transition_matrix(C_mod)
        adaptive_sampling_multivariate = SamplerObject.sample(C_mod)

        # choose the states to sample from (in the original indexing)
        state_inds = np.arange(len(adaptive_sampling_multivariate))
        sampler = stats.rv_discrete(name='sampler', 
                                    values=[state_inds, adaptive_sampling_multivariate])
        starting_states = sampler.rvs( size=simultaneous_samplers )
        starting_states = mapping[starting_states]

        # start new 'simulations' in each of those states
        for i,init_state in enumerate(starting_states):
            a_ind = sampling_round * simultaneous_samplers + i + 1
            s_ind = length_of_sampling_trajs + 1
            assignments[a_ind,:s_ind] = msm_analysis.sample(T, init_state, s_ind)

        # build a new MSM from all the simulation so far
        C_raw = MSMLib.get_count_matrix_from_assignments( assignments, n_states=num_states )
        C_raw = C_raw + C_raw.T # might want to add trimming, etc.
        T_pred = MSMLib.estimate_transition_matrix(C_raw) 

        # calculate the error between the real transition matrix and our best prediction
        assert T.shape == T_pred.shape
        distance_to_target[sampling_round] = np.sqrt( ((T_pred - T).data ** 2).sum() ) \
                                             / float(num_states)

        if observable_function:
            obs_distance[sampling_round] = np.abs(observable_function(T_mod) - obs_goal)

    return distance_to_target, obs_distance
开发者ID:pandegroup,项目名称:msmaccelerator,代码行数:75,代码来源:test_adaptive.py


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