Пример #1
0
        #INative = np.array(mInfo.ContactStateIndices)==mInfo.NativeContactStateIndex
        #stability = np.real( EigAns[1][INative,0]/EigAns[1][:,0].sum() )
        stability = 0.0  # for testing

        # print stability and timescale info 
        print '%d\t%8.3f\t%16.8f\t%16.8f'%(TotalCounts, stability, result[0,1], result[1,1]),
    else:
        print '%d\tnot enough counts yet...'%(TotalCounts),


    # revise our estimates of how many samples to take from each state
    if Adaptive:
        lagTime = 1
        TotalSamples = sum(NumSamplesPerState) # this is the number of new samples we want to make each time'
        #print 'TotalSamples', TotalSamples
        s = ssaCalculator(lagTime, C.todense(), nNewSamples=TotalSamples, evalList=[1,2], recommendationScheme = 'Nina')
        #print 's.varianceContributions', s.varianceContributions
        for EigInd in range(len(s.evalList)):
            #print s.uncertainty_variance(EigInd),
            if EigInd == 0:
                RecommendedSamplesPerState = list(s.resamplingDistribution(EigInd))
                NumSamplesPerState = RecommendedSamplesPerState
        if (0):
            print 
            print 's.weights', np.array(s.weights)
            print 's.qlists[EigInd=0]', s.qlists[0]
            print 's.resamplingDistribution', 'for eigenvalue index', s.evalList[0], repr(RecommendedSamplesPerState).replace(' ','').strip()

    print '----------'

sys.exit(1)
Пример #2
0
    # Find all the non-ergodic states and sample only these in the next round 
    I_nonergodic = (Mapping == -1)
    MacroNumSamplesPerState = np.where(I_nonergodic, nsamples_uniform, 0) 
    NumSamplesPerState = [MacroNumSamplesPerState[mInfo.ContactStateIndices[i]] for i in range(NumStates)]

    if C_trimmed.shape == C_macro.shape:
        ErgodicMacro = True   


print 'C_macro', C_macro

# Next, use Nina's adaptive sampling algorithm to determine which macrostate should be sampled at each round 
for trial in range(NumTrials):

    lagTime = 1.
    s = ssaCalculator(lagTime, C_macro.todense(), evalList=[1,2], recommendationScheme = 'Nina', nNewSamples=nsamples_adaptive)
    EigInd = 0 
    MacroNumSamplesPerState = np.array(s.resamplingDistribution(EigInd))  # Recommended Samples
    print 'Adaptive sampling macrostate indices', MacroNumSamplesPerState.nonzero()[0]

    NumSamplesPerState = [MacroNumSamplesPerState[mInfo.ContactStateIndices[i]] for i in range(NumStates)]

    # sample microstates corresonding to the recommended macrostate
    for i in np.array(NumSamplesPerState).nonzero()[0]:
        if i%1000 == 0:
            print 'Sampling', NumSamplesPerState[i], 'transitions from state', i, 'of', NumStates, '...'
        # look for possible transitions
        possible_j = jumps[i][0]
        jprobs = jumps[i][1]
        # sample counts from state i
        picks = draw_index(jprobs, n_picks=NumSamplesPerState[i])
Пример #3
0
        # print stability and timescale info
        print '%d\t%8.3f\t%16.8f\t%16.8f' % (TotalCounts, stability,
                                             result[0, 1], result[1, 1])
    else:
        print '%d\tnot enough counts yet...' % (TotalCounts)

    # revise our estimates of how many samples to take from each state
    if Adaptive:
        lagTime = 1
        TotalSamples = sum(
            NumSamplesPerState
        )  # this is the number of new samples we want to make each time'
        # print 'TotalSamples', TotalSamples
        s = ssaCalculator(lagTime,
                          C,
                          nNewSamples=TotalSamples,
                          evalList=[1, 2],
                          recommendationScheme='Nina')
        #print 's.qlist', s.qlist
        #print 's.varianceContributions', s.varianceContributions
        for EigInd in range(len(s.evalList)):
            print s.uncertainty_variance(EigInd),
            #print 's.resamplingDistribution', 'for eigenvalue index', s.evalList[EigInd]
            RecommendedSamplesPerState = list(s.resamplingDistribution(EigInd))
            print np.argmax(RecommendedSamplesPerState)
            if EigInd == 0:
                NumSamplesPerState = RecommendedSamplesPerState

sys.exit(1)