In [2]:
from autograd import grad
import autograd.numpy as np

In [2]:
from numpy.linalg import det
def BC(X,Y):
    return det(np.dot(X.T,Y)) / np.sqrt(det(np.dot(X.T,X)) * det(np.dot(Y.T,Y)))

In [23]:
np.random.seed(0)
X = np.random.rand(1000)*10
Y = 2*X + np.random.randn(1000)+5

In [ ]:


In [3]:
import matplotlib.pyplot as plt

In [4]:
%matplotlib inline

In [26]:
plt.scatter(X,Y)


Out[26]:
<matplotlib.collections.PathCollection at 0x108debd10>

In [104]:
def loss(theta):
    return -np.sum((Y-(theta[0]*X+theta[1]))**2)

In [105]:
loss((2,5))


Out[105]:
-934.32577445239758

In [106]:
gradient = grad(loss)

In [107]:
gradient(np.zeros(2))


Out[107]:
array([ 181870.67601732,   29894.94974059])

In [111]:
n=1000
x = np.zeros((n,2))
for i in range(1,n):
    x[i] = x[i-1] + gradient(x[i-1])*0.000001

In [112]:
x[-1]


Out[112]:
array([ 2.41886504,  2.24361507])

In [113]:
plt.plot(x[:,0],x[:,1])
plt.scatter(x[:,0],x[:,1])


Out[113]:
<matplotlib.collections.PathCollection at 0x1093baad0>

In [446]:
def autocorrelation(X,k=1):
    mu = X.mean(0)
    denom=(len(X)-k)*np.std(X,0)**2
    s = np.sum((X[:-k]-mu)*(X[k:]-mu),0)
    return np.sum(s/denom)
    #return np.sum(s/denom)

In [531]:
def time_lag_corr_cov(X,tau=1):
    #mu = (X[:-tau].mean(0) + X[tau:].mean(0)) / 2
    mu = X.mean(0)
    X_ = X-mu
    M = len(X) - tau
    dim = len(X.T)
    corr = np.zeros((dim,dim))
    cov = np.zeros((dim,dim))
    for i in range(M):
        corr += np.outer(X_[i],X_[i+tau]) + np.outer(X_[i+tau],X_[i])
        cov += np.outer(X_[i],X_[i]) + np.outer(X_[i+tau],X_[i+tau])
    return corr / (2.0*M),cov / (2.0*M)

In [536]:
def autocorr(X,tau=1):
    mu = X.mean(0)
    X_ = X-mu
    M = len(X) - tau
    dim = len(X.T)
    corr = np.zeros((dim,dim))
    for i in range(M):
        corr += np.outer(X_[i],X_[i+tau]) + np.outer(X_[i+tau],X_[i])
    return corr / (2.0*M)

c = autocorr(X_dihedral[:10000])
plt.imshow(c,interpolation='none')


Out[536]:
<matplotlib.image.AxesImage at 0x16daabb10>

In [549]:
plt.hist(c.reshape(np.prod(c.shape)),bins=50);



In [553]:
for i in range(10):
    print(np.sum(np.abs(autocorr(np.random.randn(1000,84)))))


126.870378741
127.352984372
125.744061127
125.41081678
127.146192582
127.114146144
125.251621406
125.642977222
126.265956242
130.183072033

In [552]:
np.sum(np.abs(autocorr(X_dihedral[:10000])))


Out[552]:
200.2648099577363

In [532]:
time_lag_corr_cov(X_dihedral)


Out[532]:
(array([[  5.34731614e-02,   1.02479150e-02,   1.09036138e-02, ...,
           8.11111667e-03,   4.65396996e-03,  -5.14005893e-04],
        [  1.02479150e-02,   7.50955461e-02,   1.99509757e-02, ...,
           2.96661861e-03,   1.44088783e-02,   2.91962291e-03],
        [  1.09036138e-02,   1.99509757e-02,   5.60410698e-02, ...,
          -8.87908554e-03,   4.11025273e-03,   5.34145917e-03],
        ..., 
        [  8.11111667e-03,   2.96661861e-03,  -8.87908554e-03, ...,
           2.45416456e-01,   1.27587891e-01,   6.56333443e-02],
        [  4.65396996e-03,   1.44088783e-02,   4.11025273e-03, ...,
           1.27587891e-01,   6.32641612e-01,   2.46835418e-01],
        [ -5.14005893e-04,   2.91962291e-03,   5.34145917e-03, ...,
           6.56333443e-02,   2.46835418e-01,   6.62830222e-01]]),
 array([[  7.21106966e-02,   1.03182610e-02,   1.07774718e-02, ...,
           8.15109420e-03,   4.66923198e-03,  -5.94737988e-04],
        [  1.03182610e-02,   8.68528782e-02,   1.99040486e-02, ...,
           2.90775315e-03,   1.43930782e-02,   2.91953291e-03],
        [  1.07774718e-02,   1.99040486e-02,   6.66072636e-02, ...,
          -8.84939350e-03,   4.10271659e-03,   5.35302946e-03],
        ..., 
        [  8.15109420e-03,   2.90775315e-03,  -8.84939350e-03, ...,
           2.60291605e-01,   1.27267887e-01,   6.46718922e-02],
        [  4.66923198e-03,   1.43930782e-02,   4.10271659e-03, ...,
           1.27267887e-01,   6.52734235e-01,   2.46570003e-01],
        [ -5.94737988e-04,   2.91953291e-03,   5.35302946e-03, ...,
           6.46718922e-02,   2.46570003e-01,   7.41956445e-01]]))

In [447]:
np.std(X_dihedral,0).shape


Out[447]:
(84,)

In [448]:
X_dihedral.mean(0).shape


Out[448]:
(84,)

In [5]:
from msmbuilder.example_datasets import AlanineDipeptide,FsPeptide
dataset = FsPeptide().get()
fs_trajectories = dataset.trajectories
from msmbuilder import featurizer
dhf = featurizer.DihedralFeaturizer()
dhft = dhf.fit_transform(fs_trajectories)
X_dihedral = np.vstack(dhft)#[0]


loading trajectory_1.xtc...
loading trajectory_10.xtc...
loading trajectory_11.xtc...
loading trajectory_12.xtc...
loading trajectory_13.xtc...
loading trajectory_14.xtc...
loading trajectory_15.xtc...
loading trajectory_16.xtc...
loading trajectory_17.xtc...
loading trajectory_18.xtc...
loading trajectory_19.xtc...
loading trajectory_2.xtc...
loading trajectory_20.xtc...
loading trajectory_21.xtc...
loading trajectory_22.xtc...
loading trajectory_23.xtc...
loading trajectory_24.xtc...
loading trajectory_25.xtc...
loading trajectory_26.xtc...
loading trajectory_27.xtc...
loading trajectory_28.xtc...
loading trajectory_3.xtc...
loading trajectory_4.xtc...
loading trajectory_5.xtc...
loading trajectory_6.xtc...
loading trajectory_7.xtc...
loading trajectory_8.xtc...
loading trajectory_9.xtc...

In [508]:
X_dihedral.mean(0).shape


Out[508]:
(84,)

In [509]:
X_dihedral.shape


Out[509]:
(280000, 84)

In [510]:
autocorrelation(X_dihedral)


Out[510]:
68.898237813741176

In [511]:
from sklearn.decomposition import PCA
pca = PCA(2)
autocorrelation(pca.fit_transform(X_dihedral))


Out[511]:
1.9735162402530837

In [513]:
X_ = pca.fit_transform(X_dihedral)
plt.scatter(X_[:,0],X_[:,1],linewidths=0,s=1,
            c=np.arange(len(X_)),alpha=0.5)


Out[513]:
<matplotlib.collections.PathCollection at 0x12de8c850>

In [514]:
A_init = pca.components_.T
A_init.shape


Out[514]:
(84, 2)

In [515]:
np.dot(X_dihedral,A_init)


Out[515]:
array([[-2.33946753, -0.89564353],
       [-2.60062861, -1.45025086],
       [-2.26692963, -1.53225303],
       ..., 
       [-2.75940418,  1.27710533],
       [-2.97198439,  1.17977309],
       [-3.00106859,  1.19465375]], dtype=float32)

In [8]:
from msmbuilder.decomposition import tICA
tica = tICA(2,10)
X_tica = tica.fit_transform([X_dihedral])[0]
#autocorrelation(X_tica)

In [519]:
plt.scatter(X_tica[:,0],X_tica[:,1],linewidths=0,s=4,
            c=np.arange(len(X_)),alpha=0.5)


Out[519]:
<matplotlib.collections.PathCollection at 0x1106c8490>

In [520]:
A_init_tica=tica.components_.T

In [521]:
def autocorr_loss(A_vec):
    A = np.reshape(A_vec,A_init.shape)
    X_ = np.dot(X_dihedral,A)
    X_ /= (np.max(X_) - np.min(X_))
    return autocorrelation(X_)

In [522]:
autocorr_loss(A_init_tica.reshape(84*2))


Out[522]:
1.9894663016784198

In [523]:
autocorr_grad = grad(autocorr_loss)

In [524]:
plt.hist(autocorr_grad(A_init_tica.reshape(84*2)));



In [525]:
plt.hist(A_init_tica.reshape(84*2),bins=50);



In [411]:
%timeit autocorr_loss(A_init_tica.reshape(84*2))


100 loops, best of 3: 3.34 ms per loop

In [412]:
%timeit autocorr_grad(A_init_tica.reshape(84*2))


100 loops, best of 3: 8.91 ms per loop

In [528]:
n=100
x = np.zeros((n,84*2))
x[0] = A_init_tica.reshape(84*2)
from time import time
t = time()
for i in range(1,n):
    x[i] = x[i-1] + autocorr_grad(x[i-1])*10
    print(i,time()-t)


(1, 1.2756741046905518)
(2, 2.4555060863494873)
(3, 3.682971954345703)
(4, 4.900946140289307)
(5, 6.144735097885132)
(6, 7.42544412612915)
(7, 8.672209978103638)
(8, 9.887005090713501)
(9, 11.1405611038208)
(10, 12.347078084945679)
(11, 13.682538986206055)
(12, 14.987375020980835)
(13, 16.176119089126587)
(14, 17.352954149246216)
(15, 18.535717964172363)
(16, 19.724857091903687)
(17, 20.996942043304443)
(18, 22.221500158309937)
(19, 23.408400058746338)
(20, 24.601027011871338)
(21, 25.814558029174805)
(22, 27.053038120269775)
(23, 28.427603006362915)
(24, 29.96596908569336)
(25, 31.183199167251587)
(26, 32.408610105514526)
(27, 33.67013216018677)
(28, 34.930222034454346)
(29, 36.242202043533325)
(30, 37.65337610244751)
(31, 39.01504707336426)
(32, 40.237180948257446)
(33, 41.50289797782898)
(34, 42.82864999771118)
(35, 44.210366010665894)
(36, 45.44645094871521)
(37, 46.644782066345215)
(38, 47.85747694969177)
(39, 49.06873416900635)
(40, 50.29502606391907)
(41, 51.56689405441284)
(42, 52.7984139919281)
(43, 53.98324108123779)
(44, 55.20710301399231)
(45, 56.54530906677246)
(46, 58.49988508224487)
(47, 60.305763959884644)
(48, 61.60413098335266)
(49, 62.86765193939209)
(50, 64.15945506095886)
(51, 65.3730411529541)
(52, 66.6182451248169)
(53, 67.92451000213623)
(54, 69.16255307197571)
(55, 70.37182211875916)
(56, 71.55093216896057)
(57, 72.7451159954071)
(58, 73.93846297264099)
(59, 75.22172904014587)
(60, 76.46791315078735)
(61, 77.67371416091919)
(62, 78.89929604530334)
(63, 80.11202001571655)
(64, 81.319020986557)
(65, 82.62489295005798)
(66, 83.89004611968994)
(67, 85.1257209777832)
(68, 86.35105395317078)
(69, 87.57233715057373)
(70, 88.84649205207825)
(71, 90.35525798797607)
(72, 91.60165214538574)
(73, 92.83305311203003)
(74, 94.06678414344788)
(75, 95.25879406929016)
(76, 96.48914408683777)
(77, 97.7921850681305)
(78, 99.04098510742188)
(79, 100.23077607154846)
(80, 101.40849804878235)
(81, 102.58998107910156)
(82, 103.77699899673462)
(83, 105.06083106994629)
(84, 106.30316114425659)
(85, 107.48813700675964)
(86, 108.69099593162537)
(87, 109.88321805000305)
(88, 111.06356310844421)
(89, 112.3293571472168)
(90, 113.55351614952087)
(91, 114.75269412994385)
(92, 115.93436002731323)
(93, 117.11670303344727)
(94, 117.65999102592468)
(95, 118.08764505386353)
(96, 118.45428895950317)
(97, 118.83310294151306)
(98, 119.2075309753418)
(99, 119.59555196762085)

In [560]:
plt.plot(x);



In [530]:
X_ = np.dot(X_dihedral,x[-1].reshape(84,2))
plt.scatter(X_[:,0],X_[:,1],linewidths=0,s=4,
            c=np.arange(len(X_)),alpha=0.5)


Out[530]:
<matplotlib.collections.PathCollection at 0x165acb850>

In [561]:
X_dihedral.shape


Out[561]:
(280000, 84)

In [ ]:


In [468]:
for i in range(len(x))[::50]:
    X_ = np.dot(X_dihedral,x[i].reshape(84,2))
    plt.scatter(X_[:,0],X_[:,1],linewidths=0,s=4,
                c=np.arange(len(X_)),alpha=0.5)
    plt.savefig('{0}.jpg'.format(i))
    plt.close()

In [469]:
autocorr_loss(x[-1]),autocorr_loss(A_init_tica),autocorr_loss(A_init)


Out[469]:
(1.9957626524900636, 1.9947409358638186, 1.9879298)

In [478]:
def autocorr_loss_mult(A_vec):
    A = np.reshape(A_vec,A_init.shape)
    X_ = np.dot(X_dihedral,A)
    return autocorrelation(X_,1) + autocorrelation(X_,10)
    #s = 0
    #for i in range(10):
    #    s += autocorrelation(X_,1+2*i)
    return autocorrelation(X_)

In [479]:
autocorrelation(X_dihedral,10)


Out[479]:
41.089905

In [480]:
autocorr_grad_mult = grad(autocorr_loss_mult)

In [482]:
autocorr_loss_mult(np.ones(84*2))


Out[482]:
3.699189352176437

In [481]:
autocorr_grad_mult(np.ones(84*2)).shape


Out[481]:
(168,)

In [486]:
n=1000
x = np.zeros((n,84*2))
x[0] = A_init_tica.reshape(84*2)
for i in range(1,n):
    x[i] = x[i-1] + autocorr_grad_mult(x[i-1])

In [487]:
plt.plot(x);



In [495]:
X_ = np.dot(X_dihedral,x[100].reshape(84,2))
plt.scatter(X_[:,0],X_[:,1],linewidths=0,s=4,
            c=np.arange(len(X_)),alpha=0.5)


Out[495]:
<matplotlib.collections.PathCollection at 0x10d3b64d0>

In [490]:
l = [autocorr_loss_mult(x_) for x_ in x]

In [492]:
l


Out[492]:
[3.983951859123092,
 3.9848932702859257,
 3.985466113536182,
 3.9858801974996774,
 3.9862011907840609,
 3.9864601126246266,
 3.9866738546013094,
 3.9868528480077798,
 3.987004245465696,
 3.9871333201369783,
 3.9872441386594453,
 3.9873399223710315,
 3.9874232638548541,
 3.987496269852536,
 3.9875606629225597,
 3.9876178576971721,
 3.9876690200880787,
 3.9877151142009217,
 3.9877569399218502,
 3.9877951631895989,
 3.9878303404315019,
 3.9878629383059478,
 3.9878933496632669,
 3.9879219064618665,
 3.9879488902367859,
 3.9879745406029885,
 3.9879990621826877,
 3.9880226302667166,
 3.9880453954587263,
 3.9880674874991642,
 3.9880890184260385,
 3.9881100851973712,
 3.9881307718747068,
 3.9881511514472718,
 3.9881712873608368,
 3.9881912348026916,
 3.9882110417847478,
 3.9882307500587504,
 3.988250395891777,
 3.988270010724805,
 3.9882896217337058,
 3.9883092523082113,
 3.9883289224622871,
 3.9883486491867677,
 3.9883684467537952,
 3.9883883269803859,
 3.988408299457975,
 3.9884283717536224,
 3.9884485495869502,
 3.9884688369872663,
 3.9884892364339382,
 3.9885097489828611,
 3.9885303743812308,
 3.9885511111725691,
 3.9885719567939013,
 3.988592907666165,
 3.9886139592788874,
 3.9886351062703334,
 3.9886563425034449,
 3.9886776611387766,
 3.9886990547040728,
 3.9887205151613658,
 3.9887420339717936,
 3.9887636021581656,
 3.988785210365279,
 3.9888068489184607,
 3.9888285078797843,
 3.9888501771024876,
 3.9888718462830859,
 3.9888935050113528,
 3.9889151428183043,
 3.9889367492214118,
 3.9889583137679727,
 3.9889798260755693,
 3.9890012758702658,
 3.9890226530221575,
 3.9890439475783448,
 3.9890651497932659,
 3.9890862501562925,
 3.98910723941697,
 3.989128108607261,
 3.9891488490615474,
 3.9891694524339081,
 3.9891899107129372,
 3.9892102162343899,
 3.9892303616912468,
 3.989250340141715,
 3.9892701450152437,
 3.9892897701163212,
 3.9893092096265454,
 3.989328458105037,
 3.989347510487133,
 3.9893663620815181,
 3.9893850085662512,
 3.9894034459832484,
 3.9894216707319101,
 3.9894396795616447,
 3.9894574695635505,
 3.9894750381612782,
 3.9894923831013767,
 3.989509502442933,
 3.9895263945469281,
 3.9895430580650277,
 3.989559491928321,
 3.9895756953357298,
 3.9895916677422991,
 3.9896074088474625,
 3.9896229185833114,
 3.9896381971028521,
 3.9896532447685913,
 3.989668062140816,
 3.9896826499666833,
 3.9896970091689452,
 3.9897111408352544,
 3.9897250462076936,
 3.9897387266725843,
 3.98975218375042,
 3.9897654190865679,
 3.9897784344417908,
 3.9897912316834487,
 3.9898038127769833,
 3.989816179777594,
 3.9898283348224837,
 3.9898402801234751,
 3.9898520179595045,
 3.989863550670151,
 3.9898748806489452,
 3.9898860103373819,
 3.9898969422188912,
 3.9899076788135277,
 3.9899182226726255,
 3.9899285763738304,
 3.9899387425167694,
 3.9899487237183213,
 3.9899585226087386,
 3.9899681418277924,
 3.9899775840211591,
 3.9899868518370436,
 3.9899959479231191,
 3.9900048749236414,
 3.990013635476485,
 3.9900222322110737,
 3.990030667745641,
 3.9900389446852977,
 3.9900470656200326,
 3.9900550331227871,
 3.990062849747904,
 3.9900705180294977,
 3.9900780404801854,
 3.9900854195896835,
 3.9900926578236304,
 3.9900997576227413,
 3.9901067214016712,
 3.9901135515483364,
 3.9901202504230855,
 3.9901268203580256,
 3.9901332636565039,
 3.9901395825925929,
 3.9901457794107476,
 3.9901518563252183,
 3.9901578155200479,
 3.990163659148676,
 3.9901693893337353,
 3.9901750081669802,
 3.9901805177091942,
 3.9901859199901999,
 3.9901912170086353,
 3.9901964107323478,
 3.9902015030981044,
 3.9902064960120507,
 3.9902113913493968,
 3.9902161909550307,
 3.990220896643411,
 3.9902255101988464,
 3.9902300333757097,
 3.9902344678987762,
 3.9902388154633308,
 3.9902430777355296,
 3.9902472563526987,
 3.9902513529235435,
 3.9902553690285902,
 3.9902593062204077,
 3.9902631660239365,
 3.9902669499369514,
 3.9902706594301982,
 3.9902742959479043,
 3.9902778609081553,
 3.9902813557029715,
 3.9902847816991129,
 3.9902881402380945,
 3.9902914326366004,
 3.9902946601870237,
 3.9902978241576244,
 3.9903009257930591,
 3.9903039663146642,
 3.9903069469208035,
 3.9903098687872722,
 3.9903127330676438,
 3.9903155408936888,
 3.9903182933756574,
 3.9903209916026467,
 3.9903236366429864,
 3.9903262295446149,
 3.9903287713352826,
 3.9903312630231458,
 3.9903337055968637,
 3.9903361000260364,
 3.990338447261605,
 3.9903407482360818,
 3.9903430038639178,
 3.9903452150418395,
 3.9903473826491416,
 3.9903495075479896,
 3.9903515905837805,
 3.9903536325854247,
 3.9903556343656015,
 3.990357596721132,
 3.9903595204332896,
 3.9903614062679669,
 3.9903632549759793,
 3.9903650672935558,
 3.9903668439424038,
 3.9903685856298838,
 3.9903702930497094,
 3.9903719668816944,
 3.9903736077923182,
 3.9903752164349688,
 3.9903767934500394,
 3.9903783394653618,
 3.9903798550962852,
 3.9903813409460467,
 3.9903827976058883,
 3.9903842256553648,
 3.9903856256625541,
 3.9903869981842695,
 3.9903883437662353,
 3.9903896629434463,
 3.9903909562402387,
 3.9903922241704444,
 3.990393467237765,
 3.9903946859359358,
 3.9903958807487818,
 3.9903970521505867,
 3.9903982006061476,
 3.9903993265709929,
 3.9904004304915972,
 3.9904015128056649,
 3.9904025739419664,
 3.9904036143209001,
 3.9904046343544373,
 3.9904056344462924,
 3.9904066149922128,
 3.9904075763799547,
 3.9904085189896703,
 3.990409443193816,
 3.9904103493574388,
 3.9904112378384089,
 3.9904121089872695,
 3.9904129631477159,
 3.9904138006565884,
 3.9904146218438905,
 3.9904154270331378,
 3.9904162165413015,
 3.9904169906791269,
 3.9904177497510269,
 3.990418494055517,
 3.9904192238849827,
 3.9904199395260438,
 3.9904206412595813,
 3.9904213293608644,
 3.9904220040996936,
 3.9904226657404473,
 3.9904233145422308,
 3.9904239507590011,
 3.9904245746395839,
 3.990425186427883,
 3.9904257863629526,
 3.9904263746790063,
 3.9904269516056576,
 3.9904275173678383,
 3.9904280721861043,
 3.990428616276501,
 3.9904291498508111,
 3.9904296731166222,
 3.9904301862772766,
 3.9904306895321944,
 3.9904311830767183,
 3.9904316671022944,
 3.9904321417965365,
 3.99043260734343,
 3.9904330639231764,
 3.9904335117124341,
 3.9904339508842606,
 3.9904343816083312,
 3.9904348040509383,
 3.9904352183750587,
 3.99043562474038,
 3.9904360233034337,
 3.9904364142176392,
 3.9904367976332851,
 3.9904371736978277,
 3.9904375425556213,
 3.9904379043481684,
 3.990438259214244,
 3.9904386072898239,
 3.9904389487080874,
 3.9904392835996823,
 3.9904396120925951,
 3.9904399343123025,
 3.9904402503816749,
 3.9904405604212623,
 3.9904408645491767,
 3.9904411628811403,
 3.9904414555306817,
 3.9904417426089585,
 3.9904420242249259,
 3.9904423004854497,
 3.9904425714952132,
 3.9904428373568388,
 3.9904430981709078,
 3.9904433540360067,
 3.9904436050487835,
 3.9904438513038603,
 3.9904440928941352,
 3.9904443299105958,
 3.9904445624423683,
 3.9904447905769556,
 3.9904450143999126,
 3.990445233995338,
 3.9904454494454535,
 3.9904456608309768,
 3.9904458682309976,
 3.9904460717230243,
 3.9904462713830302,
 3.9904464672854876,
 3.9904466595034433,
 3.9904468481083999,
 3.9904470331704731,
 3.9904472147585603,
 3.9904473929398971,
 3.9904475677805973,
 3.9904477393454414,
 3.9904479076979076,
 3.9904480729001799,
 3.9904482350132566,
 3.9904483940969673,
 3.9904485502098836,
 3.9904487034094522,
 3.9904488537520306,
 3.9904490012927356,
 3.9904491460857905,
 3.9904492881842208,
 3.9904494276399873,
 3.9904495645040772,
 3.9904496988265326,
 3.9904498306562743,
 3.990449960041305,
 3.9904500870288162,
 3.9904502116648706,
 3.9904503339947608,
 3.9904504540628198,
 3.9904505719125321,
 3.9904506875865211,
 3.9904508011266175,
 3.9904509125737544,
 3.9904510219681173,
 3.9904511293490605,
 3.9904512347552368,
 3.9904513382244371,
 3.9904514397938082,
 3.99045153949973,
 3.9904516373778343,
 3.9904517334631406,
 3.990451827789852,
 3.9904519203916271,
 3.9904520113014348,
 3.9904521005515052,
 3.9904521881736015,
 3.9904522741987423,
 3.9904523586573251,
 3.9904524415792917,
 3.990452522993873,
 3.9904526029297323,
 3.9904526814150536,
 3.9904527584773959,
 3.9904528341438112,
 3.99045290844085,
 3.9904529813944722,
 3.9904530530302025,
 3.990453123373042,
 3.9904531924474456,
 3.9904532602775395,
 3.9904533268868367,
 3.9904533922984498,
 3.990453456535084,
 3.9904535196188515,
 3.9904535815716327,
 3.9904536424147699,
 3.9904537021692015,
 3.99045376085544,
 3.9904538184936738,
 3.990453875103618,
 3.9904539307046716,
 3.9904539853158569,
 3.99045403895569,
 3.9904540916425084,
 3.9904541433942335,
 3.9904541942283509,
 3.9904542441621444,
 3.9904542932125175,
 3.9904543413959894,
 3.99045438872884,
 3.9904544352269409,
 3.9904544809059446,
 3.9904545257811703,
 3.9904545698676515,
 3.9904546131801353,
 3.990454655732973,
 3.990454697540454,
 3.9904547386164078,
 3.9904547789744989,
 3.9904548186280469,
 3.9904548575901897,
 3.9904548958737718,
 3.9904549334914092,
 3.9904549704554761,
 3.9904550067780775,
 3.9904550424711203,
 3.9904550775462995,
 3.990455112014978,
 3.9904551458885065,
 3.9904551791777543,
 3.9904552118936159,
 3.9904552440466192,
 3.9904552756471761,
 3.9904553067054875,
 3.9904553372315203,
 3.9904553672351128,
 3.99045539672586,
 3.9904554257131335,
 3.9904554542063111,
 3.9904554822143483,
 3.9904555097461838,
 3.9904555368105656,
 3.9904555634160421,
 3.9904555895709919,
 3.9904556152836963,
 3.9904556405622116,
 3.9904556654144359,
 3.9904556898482255,
 3.9904557138711718,
 3.990455737490739,
 3.990455760714287,
 3.990455783549038,
 3.9904558060019921,
 3.9904558280801568,
 3.9904558497903304,
 3.9904558711391438,
 3.9904558921331432,
 3.9904559127787569,
 3.9904559330822855,
 3.9904559530499202,
 3.9904559726877373,
 3.9904559920016247,
 3.9904560109974883,
 3.9904560296810252,
 3.9904560480578404,
 3.9904560661334956,
 3.9904560839133025,
 3.9904561014026876,
 3.9904561186067466,
 3.9904561355306618,
 3.9904561521794166,
 3.9904561685579152,
 3.9904561846710189,
 3.9904562005234352,
 3.9904562161198234,
 3.9904562314647212,
 3.9904562465626077,
 3.9904562614178962,
 3.9904562760348754,
 3.9904562904177974,
 3.9904563045707131,
 3.9904563184978192,
 3.9904563322030548,
 3.9904563456903048,
 3.9904563589634483,
 3.9904563720262782,
 3.9904563848824814,
 3.9904563975356804,
 3.9904564099894273,
 3.9904564222472585,
 3.9904564343126143,
 3.9904564461888072,
 3.9904564578792203,
 3.9904564693870572,
 3.9904564807155007,
 3.9904564918676844,
 3.9904565028466958,
 3.9904565136555403,
 3.990456524297179,
 3.9904565347744616,
 3.9904565450902769,
 3.9904565552474773,
 3.9904565652487305,
 3.9904565750967524,
 3.9904565847941829,
 3.9904565943436512,
 3.9904566037476363,
 3.9904566130087127,
 3.9904566221292681,
 3.9904566311117806,
 3.990456639958555,
 3.9904566486719624,
 3.9904566572542404,
 3.9904566657076472,
 3.9904566740343754,
 3.9904566822365872,
 3.9904566903163783,
 3.9904566982758642,
 3.9904567061170337,
 3.9904567138419536,
 3.9904567214525342,
 3.9904567289507256,
 3.9904567363384755,
 3.9904567436175102,
 3.9904567507898401,
 3.99045675785709,
 3.9904567648211353,
 3.990456771683661,
 3.9904567784463314,
 3.9904567851108865,
 3.9904567916788944,
 3.9904567981520311,
 3.9904568045318212,
 3.9904568108198397,
 3.9904568170175656,
 3.9904568231265758,
 3.9904568291483034,
 3.9904568350841378,
 3.9904568409355421,
 3.9904568467039132,
 3.9904568523906234,
 3.9904568579969535,
 3.9904568635242983,
 3.9904568689738991,
 3.9904568743470259,
 3.9904568796449604,
 3.9904568848688702,
 3.9904568900200306,
 3.9904568950996051,
 3.9904569001086978,
 3.9904569050485064,
 3.9904569099201144,
 3.9904569147246658,
 3.9904569194631749,
 3.9904569241367889,
 3.9904569287464757,
 3.9904569332933071,
 3.990456937778279,
 3.9904569422023717,
 3.9904569465665349,
 3.990456950871732,
 3.9904569551189364,
 3.9904569593090202,
 3.9904569634429579,
 3.9904569675215722,
 3.9904569715457487,
 3.9904569755163379,
 3.9904569794342137,
 3.9904569833001542,
 3.9904569871150359,
 3.9904569908796019,
 3.9904569945947226,
 3.9904569982610458,
 3.9904570018794443,
 3.9904570054505974,
 3.9904570089752207,
 3.9904570124540966,
 3.9904570158879116,
 3.9904570192773203,
 3.9904570226230387,
 3.9904570259257732,
 3.9904570291860999,
 3.9904570324047142,
 3.9904570355823128,
 3.9904570387193949,
 3.9904570418166694,
 3.9904570448746872,
 3.9904570478940879,
 3.9904570508754684,
 3.990457053819358,
 3.9904570567263091,
 3.990457059596924,
 3.9904570624317288,
 3.9904570652312596,
 3.990457067996025,
 3.990457070726567,
 3.9904570734234159,
 3.9904570760870017,
 3.9904570787178906,
 3.9904570813165652,
 3.990457083883451,
 3.9904570864190143,
 3.9904570889237814,
 3.9904570913981336,
 3.9904570938425827,
 3.990457096257459,
 3.9904570986433292,
 3.9904571010005361,
 3.9904571033295011,
 3.9904571056306679,
 3.9904571079043833,
 3.9904571101510773,
 3.9904571123711783,
 3.990457114564987,
 3.9904571167329292,
 3.990457118875351,
 3.9904571209926472,
 3.9904571230851547,
 3.990457125153231,
 3.9904571271972094,
 3.9904571292174698,
 3.9904571312142783,
 3.9904571331880465,
 3.9904571351390477,
 3.9904571370676072,
 3.9904571389740533,
 3.990457140858684,
 3.9904571427218007,
 3.9904571445637407,
 3.9904571463847169,
 3.9904571481850635,
 3.990457149965088,
 3.9904571517250629,
 3.9904571534652509,
 3.9904571551859322,
 3.9904571568873473,
 3.990457158569789,
 3.99045716023348,
 3.9904571618787115,
 3.9904571635057504,
 3.9904571651147727,
 3.9904571667060904,
 3.9904571682799359,
 3.9904571698364362,
 3.9904571713759798,
 3.9904571728987261,
 3.9904571744048605,
 3.9904571758946608,
 3.9904571773683215,
 3.9904571788260661,
 3.9904571802680593,
 3.9904571816945564,
 3.9904571831057964,
 3.9904571845018815,
 3.9904571858830997,
 3.9904571872495826,
 3.9904571886015487,
 3.990457189939153,
 3.9904571912626712,
 3.9904571925722205,
 3.9904571938679609,
 3.9904571951501122,
 3.9904571964188142,
 3.990457197674286,
 3.9904571989166593,
 3.9904572001460838,
 3.9904572013627719,
 3.9904572025668683,
 3.9904572037585151,
 3.9904572049379219,
 3.9904572061051482,
 3.9904572072604205,
 3.9904572084038934,
 3.9904572095356574,
 3.9904572106558875,
 3.9904572117647659,
 3.990457212862399,
 3.9904572139489036,
 3.9904572150244522,
 3.990457216089184,
 3.9904572171431729,
 3.9904572181866134,
 3.9904572192196346,
 3.990457220242309,
 3.9904572212548155,
 3.9904572222572803,
 3.9904572232497442,
 3.9904572242324208,
 3.9904572252053874,
 3.9904572261687932,
 3.9904572271226906,
 3.9904572280672395,
 3.9904572290025575,
 3.9904572299286882,
 3.9904572308458639,
 3.9904572317541129,
 3.9904572326534904,
 3.9904572335441859,
 3.9904572344262355,
 3.990457235299814,
 3.9904572361649722,
 3.9904572370218325,
 3.9904572378704568,
 3.9904572387110067,
 3.9904572395434856,
 3.9904572403680545,
 3.9904572411847452,
 3.9904572419937159,
 3.9904572427950207,
 3.9904572435887697,
 3.9904572443749942,
 3.9904572451538556,
 3.9904572459253722,
 3.9904572466896657,
 3.9904572474467823,
 3.9904572481968517,
 3.9904572489399039,
 3.990457249676103,
 3.9904572504053979,
 3.9904572511279524,
 3.9904572518438446,
 3.9904572525530995,
 3.9904572532558187,
 3.9904572539520893,
 3.9904572546419459,
 3.9904572553255142,
 3.9904572560027809,
 3.9904572566739085,
 3.9904572573388775,
 3.9904572579978002,
 3.9904572586508076,
 3.9904572592977869,
 3.9904572599389834,
 3.9904572605743525,
 3.990457261204003,
 3.9904572618280207,
 3.9904572624463777,
 3.9904572630591977,
 3.9904572636665572,
 3.9904572642684437,
 3.9904572648649923,
 3.9904572654562385,
 3.9904572660421915,
 3.9904572666229763,
 3.9904572671986172,
 3.9904572677691235,
 3.9904572683345991,
 3.9904572688950783,
 3.990457269450649,
 3.9904572700013388,
 3.9904572705471986,
 3.9904572710882418,
 3.9904572716245856,
 3.9904572721562412,
 3.9904572726832375,
 3.9904572732056831,
 3.9904572737235426,
 3.9904572742369386,
 3.9904572747458844,
 3.9904572752504013,
 3.9904572757506043,
 3.9904572762464179,
 3.9904572767380446,
 3.9904572772254183,
 3.9904572777085852,
 3.9904572781876553,
 3.9904572786625443,
 3.9904572791334276,
 3.9904572796003119,
 3.9904572800631888,
 3.9904572805221266,
 3.9904572809771675,
 3.9904572814283563,
 3.9904572818756909,
 3.9904572823192899,
 3.9904572827590932,
 3.9904572831951994,
 3.9904572836276548,
 3.9904572840564456,
 3.9904572844816522,
 3.9904572849032842,
 3.9904572853213658,
 3.9904572857359586,
 3.9904572861471026,
 3.9904572865548182,
 3.990457286959106,
 3.9904572873600577,
 3.9904572877576516,
 3.9904572881519558,
 3.9904572885429896,
 3.990457288930819,
 3.9904572893153807,
 3.9904572896968284,
 3.9904572900750859,
 3.9904572904502507,
 3.9904572908223317,
 3.9904572911913454,
 3.990457291557318,
 3.9904572919203196,
 3.9904572922803259,
 3.99045729263741,
 3.9904572929915467,
 3.9904572933427982,
 3.9904572936912066,
 3.9904572940367715,
 3.990457294379524,
 3.9904572947194947,
 3.9904572950567361,
 3.9904572953912596,
 3.9904572957230222,
 3.9904572960521127,
 3.99045729637858,
 3.9904572967023784,
 3.9904572970236112,
 3.990457297342231,
 3.9904572976583368,
 3.9904572979718407,
 3.9904572982828506,
 3.9904572985913815,
 3.9904572988974452,
 3.9904572992010516,
 3.9904572995022187,
 3.9904572998010295,
 3.9904573000974355,
 3.9904573003914967,
 3.9904573006832105,
 3.990457300972611,
 3.9904573012596849,
 3.9904573015445512,
 3.9904573018271186,
 3.9904573021074494,
 3.9904573023855763,
 3.9904573026615147,
 3.9904573029352575,
 3.9904573032068966,
 3.990457303476326,
 3.9904573037436655,
 3.9904573040089328,
 3.9904573042721161,
 3.9904573045331837,
 3.9904573047922476,
 3.9904573050492886,
 3.9904573053043446,
 3.990457305557344,
 3.9904573058084285,
 3.9904573060575448,
 3.9904573063047057,
 3.9904573065499207,
 3.9904573067932914,
 3.9904573070347373,
 3.9904573072742942,
 3.990457307512028,
 3.990457307747922,
 3.9904573079819512,
 3.9904573082142023,
 3.9904573084446682,
 3.9904573086733315,
 3.9904573089002877,
 3.990457309125425,
 3.9904573093488538,
 3.9904573095705986,
 3.9904573097906049,
 3.9904573100089298,
 3.9904573102255778,
 3.9904573104405969,
 3.9904573106538943,
 3.9904573108656223,
 3.9904573110757227,
 3.9904573112842074,
 3.9904573114911148,
 3.9904573116964066,
 3.9904573119001885,
 3.9904573121024076,
 3.9904573123030627,
 3.9904573125021994,
 3.9904573126998546,
 3.9904573128959724,
 3.9904573130906411,
 3.9904573132837857,
 3.9904573134754884,
 3.990457313665738,
 3.9904573138545776,
 3.9904573140419801,
 3.9904573142279642,
 3.990457314412529,
 3.990457314595738,
 3.9904573147775313,
 3.9904573149579519,
 3.9904573151370379,
 3.9904573153147744,
 3.9904573154911813,
 3.9904573156662488,
 3.9904573158400405,
 3.9904573160124817,
 3.9904573161836261,
 3.9904573163535364,
 3.9904573165221557,
 3.9904573166895538,
 3.990457316855629,
 3.9904573170205158,
 3.9904573171841546,
 3.9904573173465763,
 3.9904573175077882,
 3.9904573176678015,
 3.9904573178266323,
 3.9904573179842586,
 3.9904573181407361,
 3.9904573182960736,
 3.9904573184501948,
 3.9904573186032293,
 3.9904573187551144,
 3.9904573189058725,
 3.9904573190555244,
 3.9904573192040478,
 3.9904573193514752,
 3.990457319497847,
 3.9904573196431112,
 3.9904573197873194,
 3.9904573199304663,
 3.9904573200725277,
 3.9904573202135731,
 3.9904573203535803,
 3.9904573204925406,
 3.9904573206304859,
 3.990457320767427,
 3.9904573209033636,
 3.9904573210383036,
 3.9904573211722392,
 3.9904573213051986,
 3.9904573214372041,
 3.9904573215682309,
 3.990457321698337,
 3.9904573218274315,
 3.9904573219555983,
 3.990457322082833,
 3.9904573222091271,
 3.9904573223345237,
 3.9904573224590063,
 3.990457322582563,
 3.9904573227052333,
 3.9904573228270248,
 3.9904573229479281,
 3.9904573230679303,
 3.9904573231870768,
 3.9904573233053435,
 3.9904573234227882,
 3.9904573235393404,
 3.9904573236550593,
 3.9904573237699674,
 3.9904573238839922,
 3.9904573239972203,
 3.9904573241096433,
 3.9904573242212562,
 3.9904573243320374,
 3.9904573244420072,
 3.990457324551218,
 3.9904573246596566,
 3.9904573247672586,
 3.9904573248740909,
 3.9904573249801909,
 3.9904573250855071,
 3.9904573251900564,
 3.9904573252938738,
 3.9904573253969549,
 3.990457325499249,
 3.99045732560085,
 3.9904573257016893,
 3.9904573258018501,
 3.9904573259012368,
 3.9904573259999507,
 3.9904573260979359,
 3.9904573261952434,
 3.9904573262918572,
 3.9904573263877534,
 3.9904573264829803,
 3.9904573265775451,
 3.9904573266713812,
 3.9904573267645844,
 3.9904573268571175,
 3.9904573269490005,
 3.9904573270402328,
 3.9904573271307466,
 3.990457327220704,
 3.9904573273099948,
 3.9904573273986235,
 3.9904573274866459,
 3.9904573275740374,
 3.9904573276608222,
 3.9904573277469582,
 3.9904573278324942,
 3.9904573279174276,
 3.990457328001745,
 3.9904573280854931,
 3.9904573281686502,
 3.9904573282511882,
 3.9904573283331315,
 3.9904573284145428,
 3.9904573284953564]

In [491]:
plt.plot(l)


Out[491]:
[<matplotlib.lines.Line2D at 0x1658eb810>]

In [ ]:
# idea: tICA requires the specification of 
# a single autocorrelation time-- can we consider multiple?

In [563]:
# we want to find an embedding of the dihedral angles that puts kinetically-nearby points near each other in the embedding

In [564]:
X_dihedral.shape


Out[564]:
(280000, 84)

In [653]:
pca_w = PCA(whiten=True)
X_dihedral_whitened = pca_w.fit_transform(X_dihedral)

In [654]:
pca = PCA(n_components=2)
X_pca = pca.fit_transform(X_dihedral_whitened)

In [655]:
sum(pca.explained_variance_ratio_)


Out[655]:
0.023809560189405953

In [656]:
from scipy.spatial.distance import euclidean

In [906]:
def d(x,y):
    return np.sqrt(np.dot(x-y,x-y))

def scalar_penalize(close_distance,far_distance):
    return close_distance-far_distance

def mult_penalize(close_distance,far_distance):
    return close_distance/far_distance

def exp_penalize(close_distance,far_distance,scale=10):
    return np.exp(scale*(close_distance-far_distance))

def zero_one_penalize(close_distance,far_distance):
    return 1.0*(close_distance > far_distance)

def triplet_batch_objective_simple(embedding_points,tau_1=1,tau_2=10,penalize=scalar_penalize):
    loss = 0.0
    n_triplets = len(embedding_points) - tau_2
    assert(n_triplets>0)
    for i in range(n_triplets):
        close = d(embedding_points[i],embedding_points[i+tau_1])
        far = d(embedding_points[i],embedding_points[i+tau_2])
        loss += penalize(close,far)
        #print(close,far)
        #print(contribution)
    return loss / n_triplets

In [836]:
triplet_batch_objective_simple(X_dihedral,penalize=zero_one_penalize)


Out[836]:
0.24513018322082933

In [837]:
triplet_batch_objective_simple(X_dihedral,tau_1=5,tau_2=10,penalize=zero_one_penalize)


Out[837]:
0.40134647665988071

In [839]:
triplet_batch_objective_simple(X_dihedral,tau_1=1,tau_2=100,penalize=zero_one_penalize)


Out[839]:
0.095787781350482312

In [840]:
sample = X_dihedral[:10000]

In [842]:
%timeit triplet_batch_objective_simple(sample,tau_1=1,tau_2=100,penalize=zero_one_penalize)


10 loops, best of 3: 155 ms per loop

In [861]:
taus = np.array([1,2,3,4,5,10,20,30,40,50,100,200,300,400,500])
results = np.zeros((len(taus),len(taus)))

for i,tau_1 in enumerate(taus):
    for j,tau_2 in enumerate(taus):
        if tau_2 > tau_1:
            results[i,j] = triplet_batch_objective_simple(sample,tau_1=tau_1,tau_2=tau_2,penalize=zero_one_penalize)

In [864]:
plt.imshow(results,interpolation='none',cmap='Blues')
plt.colorbar()


Out[864]:
<matplotlib.colorbar.Colorbar instance at 0x14e0e6d88>

In [718]:
# alternate flow: select random center points along the trajectory....

In [907]:
def stoch_triplet_objective(transform,full_set,tau_1=1,tau_2=10,batch_size=50,penalize=scalar_penalize):
    
    '''to-do: make this work with a list of trajectories'''
    
    if type(full_set)==list:
        # it's a list of trajectories, each a numpy array
        list_ind = np.random.randint(0,len(full_set),batch_size)
        centers = np.random.randint(0,len(full_set[0])-tau_2,batch_size)
        triplets = [(full_set[l][c],full_set[l][c+tau_1],full_set[l][c+tau_2]) for l,c in zip(list_ind,centers)]
    else:
        # it's just one trajectory in a numpy array
        centers = np.random.randint(0,len(full_set)-tau_2,batch_size)
        triplets = [(full_set[c],full_set[c+tau_1],full_set[c+tau_2]) for c in centers]
    
    triplets = [(transform(a),transform(b),transform(c)) for (a,b,c) in triplets]
    loss = 0
    for i in range(batch_size):
        close = d(triplets[i][0],triplets[i][1])
        far = d(triplets[i][0],triplets[i][2])
        loss += penalize(close,far)
    return loss / batch_size

In [775]:
%timeit stoch_triplet_objective(lambda i:i,dhft,batch_size=100)


1000 loops, best of 3: 1.51 ms per loop

In [787]:
loss(pca.components_.T)


Out[787]:
-0.055016825001686809

In [900]:
A.shape,A.sum(0).shape
sum(np.abs(A)),sum(np.abs(A/np.abs(A).sum(0)))


Out[900]:
(array([ 0.00068699,  0.00070484]), array([ 1.,  1.]))

In [910]:
def loss(weights,batch_size=1000):
    transform = lambda x:np.dot(x,weights)
    return stoch_triplet_objective(transform,dhft,batch_size=batch_size)

def loss_vec(weights,target_dim=2,batch_size=100,penalize=mult_penalize):
    A = np.reshape(weights,(weights.shape[0]/target_dim,target_dim))
    #A /= np.sum(A,0)
    #A /= np.abs(A).sum(0)
    #A = A/np.reshape(np.sum(A**2,1),(weights.shape[0]/target_dim,1))
    transform = lambda x:np.dot(x,A)
    return stoch_triplet_objective(transform,dhft,batch_size=batch_size,penalize=penalize)

grad_loss = grad(loss)
plt.scatter(grad_loss(np.ones(84)),grad_loss(np.ones(84)))
plt.hlines(0,-0.1,0.1,linestyles='--')
plt.vlines(0,-0.1,0.1,linestyles='--')

print(spearmanr(grad_loss(np.ones(84)),grad_loss(np.ones(84))))

plt.figure()

grad_loss = grad(loss_vec)
plt.scatter(grad_loss(np.ones(84*2)),grad_loss(np.ones(84*2)))
plt.hlines(0,-0.1,0.1,linestyles='--')
plt.vlines(0,-0.1,0.1,linestyles='--')
spearmanr(grad_loss(np.ones(84*2)),grad_loss(np.ones(84*2)))


(0.23359319631467043, 0.032474691723584637)
Out[910]:
(0.11728257568087475, 0.13001659995487677)

In [829]:
from scipy.optimize import minimize
from autograd.convenience_wrappers import hessian_vector_product as hvp
results = minimize(lambda w:loss_vec(w,batch_size=1000),pca.components_.T.flatten(),jac=grad(loss_vec),hessp=hvp(loss_vec,84*2))


/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/autograd/core.py:107: RuntimeWarning: invalid value encountered in divide
  result = self.fun(*argvals, **kwargs)
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/IPython/kernel/__main__.py:7: RuntimeWarning: invalid value encountered in divide

In [825]:
results


Out[825]:
   status: 2
  success: False
     njev: 27
     nfev: 39
 hess_inv: array([[ -2.21817050e+04,   2.65480841e+02,   9.18386187e+02, ...,
          2.21434940e+04,  -2.01959794e+05,   2.34673139e+03],
       [  2.65480841e+02,  -2.17723157e+00,  -1.09911514e+01, ...,
         -2.65011565e+02,   2.41703806e+03,  -2.80853657e+01],
       [  9.18386187e+02,  -1.09911514e+01,  -3.70220869e+01, ...,
         -9.16762811e+02,   8.36133699e+03,  -9.71569047e+01],
       ..., 
       [  2.21434940e+04,  -2.65011565e+02,  -9.16762811e+02, ...,
         -2.21033523e+04,   2.01602802e+05,  -2.34258321e+03],
       [ -2.01959794e+05,   2.41703806e+03,   8.36133699e+03, ...,
          2.01602802e+05,  -1.83871785e+06,   2.13655326e+04],
       [  2.34673139e+03,  -2.80853657e+01,  -9.71569047e+01, ...,
         -2.34258321e+03,   2.13655326e+04,  -2.47262401e+02]])
      fun: -623081.39430930861
        x: array([  1.53409553e+05,  -1.83599060e+03,  -6.35145357e+03,
         9.25355340e+04,   4.86300675e+03,  -4.19874940e+04,
         4.28260499e+04,  -4.86986400e+04,   7.47097283e+02,
         4.47033863e+04,   7.43781431e+04,   3.88579358e+04,
        -4.68411428e+04,   2.01346486e+03,  -8.23291284e+04,
        -2.40380362e+04,   6.40701823e+04,  -5.04104613e+03,
        -1.16687953e+04,  -1.41957754e+04,   1.39347311e+04,
        -9.04298348e+03,   2.01670466e+04,  -2.59065596e+04,
        -6.41744148e+04,  -3.44357700e+04,   5.94513824e+04,
        -1.52341736e+03,   4.51714411e+04,  -7.05421766e+04,
         2.22613344e+03,  -5.82775439e+04,  -4.82129670e+04,
         8.91693089e+04,  -2.90099487e+04,   2.36732736e+04,
         2.10120938e+04,   2.65477512e+04,  -9.88928966e+04,
         1.16904918e+05,  -5.46497678e+04,  -1.46952509e+04,
         2.40083322e+04,   2.95579536e+05,   3.16674194e+05,
         3.23421013e+05,   1.33972764e+05,   1.16573291e+05,
        -3.39023730e+05,  -2.09942459e+04,  -2.05343600e+04,
         7.65859630e+04,   9.98509743e+03,  -2.82086719e+04,
        -1.97370586e+05,   1.59294459e+05,   2.06165262e+04,
         7.25615977e+04,  -5.77387972e+04,  -8.71778361e+04,
        -4.68337049e+04,  -2.13632949e+04,   1.44378377e+05,
        -2.38517215e+05,   1.85975525e+04,  -7.38072168e+04,
         1.52580953e+05,   1.58530204e+05,  -1.15241946e+04,
        -2.54228900e+04,   1.02692420e+05,   9.40680777e+04,
        -5.47669905e+04,  -3.59737658e+04,  -8.52556456e+03,
        -3.14414162e+05,   2.97203800e+05,  -2.46703067e+05,
         1.10591842e+05,  -7.35443662e+03,   2.56462928e+05,
         8.63007419e+04,   2.26023465e+05,  -8.44260019e+04,
         5.07877155e+05,  -4.16658964e+05,  -4.75426861e+04,
        -2.08245610e+05,   2.77736088e+05,   2.44118682e+04,
         5.40982340e+04,  -5.05916114e+04,   8.84881298e+04,
         1.18736592e+05,   3.13954547e+04,  -1.48237953e+04,
         2.21315029e+05,  -1.47748607e+04,  -4.33409249e+04,
        -1.36779340e+03,   3.68778288e+03,   1.26692231e+05,
        -1.61129939e+04,  -1.38363352e+05,  -1.54900825e+05,
         1.15049692e+05,  -2.52412864e+04,  -1.94784724e+04,
        -8.07059517e+04,  -2.10555195e+04,   6.38754675e+04,
         8.51565763e+04,   7.98375164e+04,   7.23611201e+04,
         1.04572813e+05,   1.96367703e+05,  -2.52451333e+05,
         2.43040680e+05,  -1.27937311e+05,  -4.36698204e+04,
         1.78644006e+05,   1.09655932e+05,   1.46074810e+05,
         2.02578216e+05,  -7.41387759e+05,   5.06390012e+05,
        -9.36140103e+05,   4.15497308e+04,   7.04044523e+04,
         6.36151137e+04,   9.99225388e+04,   3.33254369e+04,
         4.30011011e+04,   6.86544679e+03,   3.11569252e+04,
         1.56923902e+04,   3.59710804e+04,  -1.41325002e+05,
         1.39878643e+05,  -2.18166025e+04,   4.07743742e+04,
         3.09176662e+04,   8.11761059e+04,   7.15662791e+04,
        -4.68789102e+02,  -1.36606095e+05,  -8.01442619e+04,
         6.96432718e+04,  -6.63329017e+04,   6.58753241e+04,
        -4.62053991e+03,   8.99578514e+04,   1.23430466e+04,
         1.54185710e+05,   3.96465115e+03,   2.32523586e+04,
        -2.87899604e+04,   1.95074165e+05,  -7.66749385e+04,
         1.29730005e+05,  -1.55486417e+04,   4.03712305e+04,
         8.25331502e+04,   2.70896784e+04,   5.21194855e+03,
        -1.53138232e+05,   1.39669856e+06,  -1.62292872e+04])
  message: 'Desired error not necessarily achieved due to precision loss.'
      jac: array([ -3.11921908e-03,   1.79295321e-03,   2.50077288e-03,
         1.31229954e-03,   1.31811865e-03,  -1.82592903e-03,
        -2.06133929e-03,  -3.37820886e-03,   1.64817861e-03,
         1.65735178e-05,  -3.72237011e-03,   2.05770134e-03,
        -3.48852208e-03,  -3.26156238e-04,   1.92561970e-03,
         3.63407933e-04,  -5.93748686e-03,   3.56834840e-03,
        -4.11023112e-04,   7.56166042e-04,  -3.42319534e-03,
        -1.01819631e-03,   4.35061535e-03,  -6.63365770e-03,
         2.85010671e-03,  -7.68950632e-04,   3.63232937e-03,
         2.25814677e-03,   9.63874885e-05,   5.04973551e-03,
         9.39586090e-04,   7.07304428e-04,   4.10916104e-03,
        -1.97708773e-03,   4.06931145e-03,   3.62787653e-03,
        -8.88672915e-04,  -8.92443064e-05,   1.26336666e-02,
        -5.23822642e-03,   1.79863077e-02,   5.61661769e-03,
         2.47268559e-02,  -1.37829182e-03,  -8.83567144e-04,
         1.40316215e-02,  -6.81625624e-03,   1.11520225e-02,
         1.02568566e-02,  -3.99815357e-03,  -8.13254070e-03,
         7.04383806e-03,  -9.90552281e-03,  -5.62630917e-03,
         5.37509536e-03,  -2.30399878e-03,  -1.38230467e-02,
         9.49052800e-03,   9.35443360e-03,   1.31277081e-02,
        -2.62994095e-03,  -4.86420084e-03,  -2.08296286e-03,
        -2.74649445e-03,   8.97801567e-04,  -1.21944252e-02,
         7.47714439e-03,  -3.03711866e-03,  -2.37592040e-02,
         2.19681056e-03,  -4.88549505e-03,  -3.13416391e-03,
        -7.63960863e-03,   8.79938921e-03,  -3.64451951e-03,
         2.12609489e-03,   3.73573645e-03,   1.00902670e-02,
        -1.66229097e-02,   1.17410985e-02,  -7.31432241e-02,
         2.94092987e-02,  -2.58046976e-02,  -3.10319808e-02,
        -3.01251579e-02,  -7.61864788e-03,  -1.92394592e-02,
         5.32536226e-03,   2.07045220e-02,  -2.96976789e-03,
        -4.96968345e-03,  -9.05389805e-03,  -5.99779303e-03,
         8.02361087e-03,   6.38061407e-03,  -4.50284452e-03,
         2.06231090e-03,  -1.08372337e-02,   1.05038544e-02,
        -3.64888757e-03,   1.00358048e-02,   4.79966092e-03,
         6.56007316e-03,  -3.10217225e-03,   5.66368243e-05,
         7.16559153e-04,  -4.91786092e-03,   2.71469940e-03,
         3.59872663e-03,  -5.59393871e-03,   7.32133561e-03,
         1.60535881e-02,   3.21873329e-03,  -8.94744971e-04,
         5.38252026e-03,  -3.41849387e-03,  -2.37225443e-03,
        -8.19352663e-03,   1.41810944e-02,  -2.25199417e-02,
         3.17134106e-02,  -2.12818482e-02,   2.47085853e-02,
        -7.25649131e-03,   6.28671506e-02,   2.42752110e-02,
         3.40782096e-02,  -1.28429932e-02,  -1.23041956e-02,
        -8.00216029e-03,   5.07235460e-03,   1.73667058e-03,
         7.13711280e-04,  -5.32669626e-03,  -6.58308660e-03,
         2.03073705e-03,   8.07224295e-03,  -6.06802588e-03,
         5.12651479e-03,  -2.20261306e-03,   8.93502025e-03,
        -4.90577507e-03,   1.61211946e-03,   4.37676963e-03,
         3.06027595e-03,  -2.63543434e-03,  -5.33808863e-03,
         6.51518219e-03,  -1.63561067e-03,  -4.13813090e-03,
        -2.16578614e-03,  -7.04747145e-03,  -2.31572189e-04,
         2.98635372e-03,   6.64409599e-04,  -2.09657903e-03,
        -1.41219293e-03,  -7.81675049e-03,  -1.36225630e-03,
         1.33312751e-03,   5.65090966e-03,  -4.48183060e-03,
         1.62468680e-02,  -8.72451052e-03,   1.34026598e-03,
         3.22621013e-04,  -3.34235737e-01,   4.96566700e-02])

In [826]:
A = results['x'].reshape((84,2))
A = A/np.reshape(np.sum(A**2,1),(84,1))
projected = np.dot(X_dihedral,A)
projected /= np.sum(projected,0)
plt.scatter(projected[:,0],projected[:,1],linewidths=0,s=4,
            c=np.arange(len(projected)),alpha=0.5)


Out[826]:
<matplotlib.collections.PathCollection at 0x1585d69d0>

In [809]:
np.sum(A,0).shape


Out[809]:
(2,)

In [802]:
triplet_batch_objective_simple(projected),triplet_batch_objective_simple(X_pca),triplet_batch_objective_simple(X_tica)


Out[802]:
(-237709.37021398873, -0.13081254662521502, -0.02914822703015163)

In [877]:
def adagrad(grad, x, num_iters=100, step_size=0.1, gamma=0.9, eps = 10**-8):
    """Root mean squared prop: See Adagrad paper for details.
    
    Stolen from autograd examples: https://github.com/HIPS/autograd/blob/master/examples/optimizers.py#L21"""
    avg_sq_grad = np.ones(len(x))
    history = np.zeros((num_iters+1,len(x)))
    history[0] = x
    for i in xrange(num_iters):
        g = grad(x)
        avg_sq_grad = avg_sq_grad * gamma + g**2 * (1 - gamma)
        x -= step_size * g/(np.sqrt(avg_sq_grad) + eps)
        history[i+1] = x
    return history

In [920]:
loss_func = lambda weights:loss_vec(weights,batch_size=1000,penalize=scalar_penalize)
history = adagrad(grad(loss_func),pca.components_.T.flatten(),num_iters=100)

In [929]:
pca = PCA(n_components=2)
X_pca = pca.fit_transform(X_dihedral)

In [921]:
normed_history = norm_history(history)
plt.plot(normed_history[:,:10]);



In [932]:
def rotation_matrix(theta=np.pi/2):
    r = np.zeros((2,2))
    r[0,0] = r[1,1] = np.cos(theta)
    r[0,1] = np.sin(theta)
    r[1,0] = -np.sin(theta)
    return r

np.dot(projected,rotation_matrix())


Out[932]:
array([[ 0.12059438,  0.32942242],
       [ 0.06334414,  0.43453591],
       [-0.13716879,  0.49586   ],
       ..., 
       [-0.03424259,  0.82814035],
       [ 0.07694437,  0.7218961 ],
       [ 0.02018024,  0.70227231]])

In [935]:
proj_mat = np.reshape(normed_history[-1],(84,2))
projected = np.dot(X_dihedral,proj_mat)
#projected /= np.sum(projected,0)
projected = np.dot(projected,rotation_matrix(np.pi/4))
plt.scatter(projected[:,0],projected[:,1],linewidths=0,s=1,
            c=np.arange(len(projected)),alpha=0.5,cmap='rainbow')
plt.title('Triplet-based linear embedding')
plt.figure()

plt.scatter(X_pca[:,0],X_pca[:,1],linewidths=0,s=1,
            c=np.arange(len(projected)),alpha=0.5,cmap='rainbow')
plt.title('PCA')
plt.figure()

plt.scatter(X_tica[:,0],X_tica[:,1],linewidths=0,s=1,
            c=np.arange(len(projected)),alpha=0.5,cmap='rainbow')
plt.title('tICA')


Out[935]:
<matplotlib.text.Text at 0x110a4b390>

In [973]:
from mdp.nodes import XSFANode
xsfa = XSFANode(output_dim=2)
pca = PCA()
X_dihedral_ = pca.fit_transform(X_dihedral)[:,:20]
X_xsfa = xsfa.execute(X_dihedral_)


/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/utils/covariance.py:17: MDPWarning: You have summed 2.800000e+05 entries in the covariance matrix.
As you are using dtype 'float32', you are probably getting severe round off
errors. See CovarianceMatrix docstring for more information.
  warnings.warn(wr, mdp.MDPWarning)
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/utils/covariance.py:17: MDPWarning: You have summed 2.799990e+05 entries in the covariance matrix.
As you are using dtype 'float32', you are probably getting severe round off
errors. See CovarianceMatrix docstring for more information.
  warnings.warn(wr, mdp.MDPWarning)
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]
/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/mdp/nodes/expansion_nodes.py:85: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  factor = prec[lens[j]:, :]

In [975]:
len(projected),len(X_xsfa)


Out[975]:
(280000, 280000)

In [963]:
plt.plot(pca.explained_variance_ratio_)


Out[963]:
[<matplotlib.lines.Line2D at 0x12b528690>]

In [976]:
plt.scatter(X_xsfa[:,0],X_xsfa[:,1],linewidths=0,s=1,
            c=np.arange(len(X_xsfa)),alpha=0.5,cmap='rainbow')


Out[976]:
<matplotlib.collections.PathCollection at 0x155998fd0>

In [ ]:
# now let's test which embedding is best for constructing MSMs...

from msmbuilder.cluster import MiniBatchKMeans
from msmbuilder.msm import MarkovStateModel
from sklearn.pipeline import Pipeline

results = dict()
embeddings = [('tICA',X_tica),('PCA',X_pca),('Triplet',projected),('xSFA',X_xsfa)]
for (name,dataset) in embeddings:
    pipeline = Pipeline([
        ('cluster', MiniBatchKMeans(n_clusters=100)),
        ('msm', MarkovStateModel(lag_time=10))
    ])
    pipeline.fit([dataset[:100000]])
    results[name] = pipeline
    print(name,pipeline.score([dataset[100000:]]))


MSM contains 1 strongly connected component above weight=0.10. Component 0 selected, with population 100.000000%
MSM contains 1 strongly connected component above weight=0.10. Component 0 selected, with population 100.000000%
('tICA', 9.7099445473289929)
MSM contains 1 strongly connected component above weight=0.10. Component 0 selected, with population 100.000000%
MSM contains 1 strongly connected component above weight=0.10. Component 0 selected, with population 100.000000%
('PCA', 8.5677762821306302)
MSM contains 1 strongly connected component above weight=0.10. Component 0 selected, with population 100.000000%
MSM contains 1 strongly connected component above weight=0.10. Component 0 selected, with population 100.000000%

In [951]:
msm = MarkovStateModel()
msm.fit(np.random.randint(0,10,100000))
print(msm.summarize())


MSM contains 1 strongly connected component above weight=1.00. Component 0 selected, with population 100.000000%
Markov state model
------------------
Lag time         : 1
Reversible type  : mle
Ergodic cutoff   : 1.0
Prior counts     : 0

Number of states : 10
Number of nonzero entries in counts matrix : 100 (100.0%)
Nonzero counts matrix entries:
    Min.   : 928.0
    1st Qu.: 982.0
    Median : 1004.5
    Mean   : 1000.0
    3rd Qu.: 1019.5
    Max.   : 1082.0

Total transition counts :
    99999.0 counts
Total transition counts / lag_time:
    99999.0 units
Timescales:
    [0.23, 0.20, 0.19, 0.17, 0.15, nan, nan, nan, nan]  units


In [916]:
from time import time
t = time()
grad(loss_vec)(pca.components_.T.flatten())
print(time()-t)


0.0778019428253

In [873]:
pca.components_.T.flatten().shape


Out[873]:
(168,)

In [786]:
from scipy.stats import spearmanr
spearmanr(grad_loss(np.ones(84)),grad_loss(np.ones(84)))


Out[786]:
(0.43426141540953733, 3.6727068404420694e-05)

In [ ]:


In [749]:
objective_evaluations = np.array([stoch_triplet_objective(dhft,tau_1=1,tau_2=100,batch_size=100) for _ in range(1000)])

In [750]:
objective_evaluations.std(),objective_evaluations.mean()


Out[750]:
(0.078510417209893948, -1.0240131136143207)

In [743]:
fs_trajectories


Out[743]:
[<mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x16fdf79d0>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x16fdf72d0>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x16f9d3ad0>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1701c66d0>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1701c6dd0>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1701c6510>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1701c67d0>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1701c6710>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1702cb310>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1702cbc50>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1702cb850>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x12ca7bc50>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x12ca7bb10>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x12ca7b810>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x12ca7b710>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x12ca7bc10>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x10d2b7750>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1700c4410>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x1701bd550>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x10d2b7290>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x10d2b7f90>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x10d2b7b50>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x10d2b7490>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x10d2b72d0>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x10d2b74d0>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x13624be10>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x10d409610>,
 <mdtraj.Trajectory with 10000 frames, 264 atoms, 23 residues, without unitcells at 0x12d3a7c50>]

In [742]:
a = []
type(a)==list


Out[742]:
True

In [738]:
objective_evaluations = np.array([stoch_triplet_objective(X_pca,tau_1=1,tau_2=100,batch_size=100) for _ in range(1000)])

In [739]:
objective_evaluations.std(),objective_evaluations.mean()


Out[739]:
(0.089872599257035876, -0.30047579470220953)

In [658]:
pca.components_.shape


Out[658]:
(2, 84)

In [659]:
triplet_batch_objective_simple(X_pca[:11])


Out[659]:
-1.1056914329528809

In [660]:
np.dot(X_dihedral,pca.components_.T).shape


Out[660]:
(280000, 2)

In [661]:
def sgd(objective,dataset,init_point,batch_size=20,n_iter=100,step_size=0.01,seed=0,stoch_select=False):
    ''' objective takes in a parameter vector and an array of data'''
    np.random.seed(seed)
    testpoints = np.zeros((n_iter,len(init_point)))
    testpoints[0] = init_point
    ind=0
    for i in range(1,n_iter):
        if stoch_select:
            
        else:
            max_ind = ind+batch_size
            if max_ind>=len(dataset):
                ind = max_ind % len(dataset)
                max_ind = ind+batch_size
            subset = dataset[ind:max_ind]
            ind = (ind + batch_size)
        obj_grad = grad(lambda p:objective(p,subset))
        raw_grad = obj_grad(testpoints[i-1])
        gradient = np.nan_to_num(raw_grad)
        #print(gradient,raw_grad)
        testpoints[i] = testpoints[i-1] - gradient*step_size
    return np.array(testpoints)

In [662]:
def projection_obj(proj_vec,subset):
    # WARNING: CURRENTLY HARD-CODED PROJECTION MATRIX DIMENSIONS...
    A = np.reshape(proj_vec,(84,2))
    A /= (A**2).sum(0)
    projected = np.dot(subset,A)
    return triplet_batch_objective_simple(projected)

In [663]:
(A**2).sum(0)


Out[663]:
array([ 1.88739624,  2.22063617])

In [ ]:


In [712]:
raw_points = sgd(projection_obj,X_dihedral_whitened,pca.components_.T.flatten(),step_size=0.01,
                 n_iter=1000,batch_size=20)

In [881]:
def norm(s):
    return s / np.sqrt(np.sum(s**2))

plt.plot(raw_points[:,:10]);
plt.figure()
def norm_history(raw_points):
    return np.array([norm(s) for s in raw_points])
normed_points = norm_history(raw_points)
plt.plot(normed_points);



In [707]:
(pca.components_).flatten().shape


Out[707]:
(168,)

In [708]:
A = np.reshape(raw_points[-1],(84,2))
projected = np.dot(X_dihedral,A)

In [709]:
plt.scatter(projected[:,0],projected[:,1],linewidths=0,s=4,
            c=np.arange(len(projected)),alpha=0.5)


Out[709]:
<matplotlib.collections.PathCollection at 0x136d16d90>

In [681]:
plt.plot(np.linalg.eigh(A.dot(A.T))[0][-5:])


Out[681]:
[<matplotlib.lines.Line2D at 0x1370c4890>]

In [672]:
tica = tICA(n_components=2)
X_tica = tica.fit_transform([X_dihedral_whitened])[0]

In [673]:
plt.scatter(X_tica[:,0],X_tica[:,1],linewidths=0,s=4,
            c=np.arange(len(projected)),alpha=0.5)


Out[673]:
<matplotlib.collections.PathCollection at 0x15f2b0d90>

In [674]:
triplet_batch_objective_simple(X_pca),triplet_batch_objective_simple(X_tica),triplet_batch_objective_simple(projected)


Out[674]:
(-0.13081254662521502, -0.02914822703015163, -0.14260115647680227)

In [9]:
tica = tICA(n_components=2)

In [76]:
from sklearn.preprocessing import PolynomialFeatures
from time import time
t = time()
dhft_poly = []
poly = PolynomialFeatures()
for i in range(len(dhft)):
    dhft_poly.append(poly.fit_transform(dhft[i]))
    print(i,time()-t)


(0, 84.66518688201904)
(1, 161.0204620361328)
(2, 240.11624598503113)
(3, 317.0012698173523)
(4, 397.1793420314789)
(5, 474.335736989975)
(6, 552.1299040317535)
(7, 635.0311679840088)
(8, 717.210186958313)
(9, 796.154079914093)
(10, 878.5384159088135)
(11, 955.2957499027252)
(12, 1032.4457259178162)
(13, 1107.6033058166504)
(14, 1184.548509836197)
(15, 1269.8127160072327)
(16, 1346.871994972229)
(17, 1423.8246500492096)
(18, 1499.0381050109863)
(19, 1574.085198879242)
(20, 1652.7890248298645)
(21, 1730.4122698307037)
(22, 1804.9645309448242)
(23, 1886.4396579265594)
(24, 1966.4261648654938)
(25, 2053.0985310077667)
(26, 2135.7139258384705)
(27, 2214.5209908485413)

In [ ]:


In [15]:
dhft[0].shape


Out[15]:
(10000, 84)

In [19]:
%timeit poly.fit_transform(dhft[0][:1000])


1 loops, best of 3: 5.05 s per loop

In [24]:
dhft_poly_0 = poly.fit_transform(dhft[0])

In [25]:
dhft_poly_0.shape


Out[25]:
(10000, 3655)

In [48]:
tica=tICA(n_components=2,lag_time=10)

In [80]:
X_tica_poly = tica.fit_transform(dhft_poly)

In [81]:
X_tica_poly_vstack = np.vstack(X_tica_poly)

In [84]:
plt.scatter(X_tica_poly_vstack[:,0],X_tica_poly_vstack[:,1],linewidths=0,s=1,
            #c=np.arange(len(X_tica_poly_vstack)),
            c=np.vstack([i*np.ones(len(X_tica_poly[0])) for i in range(len(X_tica_poly))]),
            alpha=0.5,cmap='rainbow')
plt.title('Nonlinear tICA')


Out[84]:
<matplotlib.text.Text at 0x12e4e0a90>

In [78]:
tica = tICA(n_components=2,lag_time=10)
X_tica = tica.fit_transform(dhft)

In [79]:
X_tica_vstack = np.vstack(X_tica)
plt.scatter(X_tica_vstack[:,0],X_tica_vstack[:,1],linewidths=0,s=1,
            c=np.arange(len(X_tica_vstack)),alpha=0.5,cmap='rainbow')
plt.title('tICA')


Out[79]:
<matplotlib.text.Text at 0x12d772790>

In [87]:
from msmbuilder.cluster import MiniBatchKMeans
from msmbuilder.msm import MarkovStateModel
from sklearn.pipeline import Pipeline



results = dict()
embeddings = [('tICA',X_tica),('Nonlinear tICA',X_tica_poly)]
for (name,dataset) in embeddings:
    pipeline = Pipeline([
        ('cluster', MiniBatchKMeans(n_clusters=100)),
        ('msm', MarkovStateModel(lag_time=1))
    ])
    #pipeline.fit([dataset[:5000]])
    #pipeline.fit(dataset)
    
    pipeline.fit(dataset[:14])
    
    results[name] = pipeline
    #print(pipeline.steps[1][1].score_)
    
    print(pipeline.score(dataset[14:]))
    
    #print(name,pipeline.score([dataset[5000:]]))


MSM contains 1 strongly connected component above weight=1.00. Component 0 selected, with population 100.000000%
MSM contains 1 strongly connected component above weight=1.00. Component 0 selected, with population 100.000000%
8.98677190708
MSM contains 1 strongly connected component above weight=1.00. Component 0 selected, with population 100.000000%
MSM contains 1 strongly connected component above weight=1.00. Component 0 selected, with population 100.000000%
9.18017108578

In [67]:
msm = MarkovStateModel()
msm.score_


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-67-872134b361b6> in <module>()
      1 msm = MarkovStateModel()
----> 2 msm.score_

/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/msmbuilder/msm/msm.pyc in score_(self)
    410         Rayleigh quotient, the sum of the first `n_components` eigenvalues
    411         """
--> 412         return self.eigenvalues_.sum()
    413 
    414 

/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/msmbuilder/msm/msm.pyc in eigenvalues_(self)
    505         """Eigenvalues of the transition matrix.
    506         """
--> 507         u, lv, rv = self._get_eigensystem()
    508         return u
    509 

/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/msmbuilder/msm/msm.pyc in _get_eigensystem(self)
    346 
    347         k = n_timescales + 1
--> 348         u, lv, rv = _solve_msm_eigensystem(self.transmat_, k)
    349         self._eigenvalues = u
    350         self._left_eigenvectors = lv

/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/msmbuilder/msm/core.pyc in _solve_msm_eigensystem(transmat, k)
    282         The normalized right eigenvectors (:math:`\psi`) of ``transmat``
    283     """
--> 284     u, lv, rv = scipy.linalg.eig(transmat, left=True, right=True)
    285     order = np.argsort(-np.real(u))
    286     u = np.real_if_close(u[order[:k]])

/Users/joshuafass/anaconda/envs/py27/lib/python2.7/site-packages/scipy/linalg/decomp.pyc in eig(a, b, left, right, overwrite_a, overwrite_b, check_finite)
    148         a1 = asarray(a)
    149     if len(a1.shape) != 2 or a1.shape[0] != a1.shape[1]:
--> 150         raise ValueError('expected square matrix')
    151     overwrite_a = overwrite_a or (_datacopied(a1, a))
    152     if b is not None:

ValueError: expected square matrix

In [56]:
X_tica_poly.shape


Out[56]:
(10000, 2)

In [ ]: