Exemplo n.º 1
0
def test_score_3():
    ds = MullerPotential(random_state=0).get_cached().trajectories
    cluster = NDGrid(n_bins_per_feature=6,
                     min=[PARAMS['MIN_X'], PARAMS['MIN_Y']],
                     max=[PARAMS['MAX_X'], PARAMS['MAX_Y']])

    assignments = cluster.fit_transform(ds)

    train_indices = [9, 4, 3, 6, 2]
    test_indices = [8, 0, 5, 7, 1]
    temp = '1.0929e-02  5.4147e-02  9.8362e-02  0.1000e+00  6.0455e-02  2.8775e-02\
  6.6456e-02  3.3957e-02  4.1484e-03  0.1000e+00  5.0847e-02  1.1516e-02\
  3.5266e-02  1.2830e-02  0.1000e+00  2.1801e-02  1.6639e-02  9.4932e-03\
  0.1000e+00  0.1000e+00  1.1050e-01  4.0076e-03  0.1000e+00  0.1000e+00\
  1.8930e-02 -7.1060e+00 -4.5787e+00 -2.4950e+00 -4.0964e+00 -7.4127e+00\
 -6.7574e+00 -4.7137e+00 -3.9530e+00 -4.5781e+00 -7.4585e+00 -6.4634e+00\
 -5.8060e+00 -5.4783e+00 -5.3519e+00 -7.4653e+00 -6.5113e+00 -2.1477e+00\
 -4.8138e+00 -9.7187e+00 -9.0358e+00 -1.4599e+00 -8.8985e-01 -8.3461e+00\
 -7.0930e+00 -2.7618e+00 -6.7421e+00'

    model = PESContinuousTimeMSM(lag_time=3, n_timescales=1, sliding_window=False,
                              ergodic_cutoff=1)
    model.theta_ = list(map(np.float64, temp.split()))
    train_data = [assignments[i] for i in train_indices]
    test_data = [assignments[i] for i in test_indices]

    model.fit(train_data)
    print(model.summarize())
    train = model.score_
    test = model.score(test_data)
    print(train, test)
Exemplo n.º 2
0
def test_score_3():
    import warnings
    warnings.simplefilter('ignore')
    from msmbuilder.example_datasets.muller import MULLER_PARAMETERS as PARAMS

    cluster = NDGrid(n_bins_per_feature=6,
                     min=[PARAMS['MIN_X'], PARAMS['MIN_Y']],
                     max=[PARAMS['MAX_X'], PARAMS['MAX_Y']])

    ds = MullerPotential(random_state=0).get()['trajectories']
    assignments = cluster.fit_transform(ds)

    train_indices = [9, 4, 3, 6, 2]
    test_indices = [8, 0, 5, 7, 1]

    model = ContinuousTimeMSM(lag_time=3,
                              n_timescales=1,
                              sliding_window=False,
                              ergodic_cutoff=1)
    train_data = [assignments[i] for i in train_indices]
    test_data = [assignments[i] for i in test_indices]

    model.fit(train_data)
    train = model.score_
    test = model.score(test_data)
    print(train, test)
Exemplo n.º 3
0
def test_score_2():
    ds = MullerPotential(random_state=0).get_cached().trajectories
    cluster = NDGrid(n_bins_per_feature=6,
                     min=[PARAMS['MIN_X'], PARAMS['MIN_Y']],
                     max=[PARAMS['MAX_X'], PARAMS['MAX_Y']])
    assignments = cluster.fit_transform(ds)
    test_indices = [5, 0, 4, 1, 2]
    train_indices = [3, 6, 7, 8, 9]

    model = PESContinuousTimeMSM(lag_time=3, n_timescales=1)
    temp='3.13268076e-02  1.45678356e-01  3.12558665e-01  0.10000000e+00\
  2.72951862e-02  9.64773504e-02  1.26398091e-01  1.27775726e-01\
  2.74208403e-03  9.57265955e-04  1.89498433e-01  0.10010000e+00\
  9.73644477e-02  4.16877008e-02  0.10010000e+00  1.73803374e-01\
  4.31281724e-02  0.10001000e+00  0.10010000e+00  4.03763450e-01\
  0.10001000e+00  0.10001000e+00  0.10010000e+00  2.78156537e-01\
 -7.75852152e+00 -4.77716045e+00 -2.67428479e+00 -4.33901900e+00\
 -9.23925293e+00 -6.65216281e+00 -4.88309143e+00 -4.04247463e+00\
 -4.67140081e+00 -7.95471679e+00 -6.26342874e+00 -6.02515423e+00\
 -5.64532492e+00 -5.56770596e+00 -7.66164067e+00 -6.22050765e+00\
 -2.12577068e+00 -4.84152585e+00 -9.21360166e+00 -1.43207874e+00\
 -8.55459835e-01 -9.21329384e+00 -6.99418825e+00 -2.73060233e+00\
 -6.60364249e+00'
    model.theta_= list(map(np.float64, temp.split()))

    model.fit([assignments[i] for i in train_indices])
    print('Initial theta: \n')
    print(model._initial_guess(model.countsmat_))
    test = model.score([assignments[i] for i in test_indices])
    train = model.score_
    print('train', train, 'test', test)
    print(model.optimizer_state_)
    # print(model.summarize())
    assert 1 <= test < 2
    assert 1 <= train < 2
Exemplo n.º 4
0
def test_guess():
    ds = MullerPotential(random_state=0).get_cached().trajectories
    cluster = NDGrid(n_bins_per_feature=5,
                     min=[PARAMS['MIN_X'], PARAMS['MIN_Y']],
                     max=[PARAMS['MAX_X'], PARAMS['MAX_Y']])
    assignments = cluster.fit_transform(ds)

    model1 = ContinuousTimeMSM(guess='log')
    model1.fit(assignments)

    model2 = ContinuousTimeMSM(guess='pseudo')
    model2.fit(assignments)

    diff = model1.loglikelihoods_[-1] - model2.loglikelihoods_[-1]
    assert np.abs(diff) < 1e-3
    assert np.max(np.abs(model1.ratemat_ - model2.ratemat_)) < 1e-1
Exemplo n.º 5
0
def test_score_2():
    ds = MullerPotential(random_state=0).get_cached().trajectories
    cluster = NDGrid(n_bins_per_feature=6,
                     min=[PARAMS['MIN_X'], PARAMS['MIN_Y']],
                     max=[PARAMS['MAX_X'], PARAMS['MAX_Y']])
    assignments = cluster.fit_transform(ds)
    test_indices = [5, 0, 4, 1, 2]
    train_indices = [3, 6, 7, 8, 9]

    model = ContinuousTimeMSM(lag_time=3, n_timescales=1)
    model.fit([assignments[i] for i in train_indices])
    test = model.score([assignments[i] for i in test_indices])
    train = model.score_
    print('train', train, 'test', test)
    assert 1 <= test < 2
    assert 1 <= train < 2
Exemplo n.º 6
0
def test_score_2():
    from msmbuilder.example_datasets.muller import MULLER_PARAMETERS as PARAMS
    ds = MullerPotential(random_state=0).get()['trajectories']
    cluster = NDGrid(n_bins_per_feature=6,
                     min=[PARAMS['MIN_X'], PARAMS['MIN_Y']],
                     max=[PARAMS['MAX_X'], PARAMS['MAX_Y']])
    assignments = cluster.fit_transform(ds)
    test_indices = [5, 0, 4, 1, 2]
    train_indices = [3, 6, 7, 8, 9]

    model = ContinuousTimeMSM(lag_time=3, n_timescales=1)
    model.fit([assignments[i] for i in train_indices])
    test = model.score([assignments[i] for i in test_indices])
    train = model.score_
    print('train', train, 'test', test)
    assert 1 <= test < 2
    assert 1 <= train < 2
Exemplo n.º 7
0
def test_guess():
    from msmbuilder.example_datasets.muller import MULLER_PARAMETERS as PARAMS

    cluster = NDGrid(n_bins_per_feature=5,
                     min=[PARAMS['MIN_X'], PARAMS['MIN_Y']],
                     max=[PARAMS['MAX_X'], PARAMS['MAX_Y']])

    ds = MullerPotential(random_state=0).get()['trajectories']
    assignments = cluster.fit_transform(ds)

    model1 = ContinuousTimeMSM(guess='log')
    model1.fit(assignments)

    model2 = ContinuousTimeMSM(guess='pseudo')
    model2.fit(assignments)

    diff = model1.loglikelihoods_[-1] - model2.loglikelihoods_[-1]
    assert np.abs(diff) < 1e-3
    assert np.max(np.abs(model1.ratemat_ - model2.ratemat_)) < 1e-1
Exemplo n.º 8
0
def test_score_3():
    ds = MullerPotential(random_state=0).get_cached().trajectories
    cluster = NDGrid(n_bins_per_feature=6,
                     min=[PARAMS['MIN_X'], PARAMS['MIN_Y']],
                     max=[PARAMS['MAX_X'], PARAMS['MAX_Y']])

    assignments = cluster.fit_transform(ds)

    train_indices = [9, 4, 3, 6, 2]
    test_indices = [8, 0, 5, 7, 1]

    model = ContinuousTimeMSM(lag_time=3, n_timescales=1, sliding_window=False,
                              ergodic_cutoff=1)
    train_data = [assignments[i] for i in train_indices]
    test_data = [assignments[i] for i in test_indices]

    model.fit(train_data)
    train = model.score_
    test = model.score(test_data)
    print(train, test)
Exemplo n.º 9
0
def test_class():
    xx = MullerPotential(random_state=123122).get()['trajectories']
    assert len(xx) == 10
    assert xx[0].ndim == 2
    assert xx[0].shape[1] == 2
    array2d(xx)
Exemplo n.º 10
0
2-D Decomposition Grid Plot
============================
"""
from msmbuilder.example_datasets import MullerPotential
from msmbuilder.decomposition import tICA
from msmbuilder.cluster import MiniBatchKMeans
from msmbuilder.msm import MarkovStateModel

import numpy as np

import msmexplorer as msme

rs = np.random.RandomState(42)

# Load Fs Peptide Data
trajs = MullerPotential().get().trajectories

# Perform Dimensionality Reduction
tica_model = tICA(lag_time=2, n_components=2)
tica_trajs = tica_model.fit_transform(trajs)

# Perform Clustering
clusterer = MiniBatchKMeans(n_clusters=12, random_state=rs)
clustered_trajs = clusterer.fit_transform(tica_trajs)

# Construct MSM
msm = MarkovStateModel(lag_time=2)
assignments = msm.fit_transform(clustered_trajs)

# Plot Free Energy
data = np.concatenate(trajs, axis=0)