コード例 #1
0
 def test_fit(self):
     """ Make sure updates occur in the Tikhanov Factors"""
     rcomp = ResComp(**RES)
     t, U = make_data()
     rcomp.update_tikhanov_factors(t, U)
     assert not np.all(rcomp.Rhat == 0.0)
     assert not np.all(rcomp.Yhat == 0.0)
コード例 #2
0
 def test_predict_unseen(self):
     """ Predict on unseen data """
     rcomp = ResComp(**RES)
     tr, ts, Utr, Uts = make_train_test_data()
     rcomp.train(tr, Utr, window=10, overlap=0.9)
     pre = rcomp.predict(ts, Uts[0, :])
     error = np.mean(np.linalg.norm(pre - Uts, ord=2, axis=0)**2)**(1/2)
     assert error < 1.0
コード例 #3
0
 def test_predict(self):
     """ Test that the reservoir can learn a simple signal"""
     rcomp = ResComp(**RES)
     t, U = make_data()
     rcomp.train(t, U)
     pre = rcomp.predict(t[500:], U[500, :])
     error = np.max(np.linalg.norm(pre - U[500:, :], ord=np.inf, axis=0))
     assert error < 0.5
コード例 #4
0
 def test_drive(self):
     """ Drive the internal ode """
     t, U = make_data()
     rcomp = ResComp(**RES)
     r0 = rcomp.W_in @ U[0, :]
     out = rcomp.internal_state_response(t, U, r0)
     m, n = out.shape
     assert m == len(t) and n == rcomp.res_sz
コード例 #5
0
 def test_window(self):
     """ Make sure each partition is smaller than the given time window """
     rcomp = ResComp(**RES)
     for window in [.5, 3, 1001]:
         for timef in [random_time_array, uniform_time_array]:
             times = timef(1000)
             idxs = rcomp._partition(times, window, 0)
             for i,j in idxs:
                 sub = times[i:j]
                 assert sub[-1] - sub[0] <= window + 1e-12
コード例 #6
0
 def test_init_args(self):
     combos = itertools.product(*ADJCOMBOS.values())
     keys = list(PARAMCOMBOS.keys())
     for args in combos:
         I, prms = identity_adj(*args)
         rcomp = ResComp(I)
         assert params_match(rcomp, keys, prms)
         A, prms = nonuniform_adj(*args)
         rcomp = ResComp(A)
         assert params_match(rcomp, keys, prms)
コード例 #7
0
 def test_overlap(self):
     """ Ensure that overlap is correct on average """
     rcomp = ResComp(**RES)
     for window in [30, 100]:
         for overlap in [.1, .9,]:
             T = 1000
             for times in [random_time_array(T), uniform_time_array(T)]:
                 idxs = rcomp._partition(times, window, overlap)
                 prev = None
                 over = 0.0
                 for i,j in idxs:
                     sub = times[i:j]
                     if prev is not None:
                         inters = set(sub).intersection(set(prev))
                         over += len(inters) / len(sub)
                     prev = sub
                 assert np.abs(over/len(idxs) - overlap) < .05
コード例 #8
0
 def test_init_noargs(self):
     kwargs = dict()
     combos = itertools.product(*PARAMCOMBOS.values())
     keys = list(PARAMCOMBOS.keys())
     for c in combos:
         # For each combination of parameters, make a dictionary of kwargs
         for k, v in zip(keys, c):
             kwargs[k] = v
         # Initialize a reservoir computer
         rcomp = ResComp(**kwargs)
         # Check that the initialized rcomp has the right internal data
         assert params_match(rcomp, keys, c)
コード例 #9
0
 def test_jacobian(self):
     kwargs = dict()
     combos = itertools.product(*PARAMCOMBOS.values())
     keys = list(PARAMCOMBOS.keys())
     for c in combos:
         # For each combination of parameters, make a dictionary of kwargs
         for k, v in zip(keys, c):
             kwargs[k] = v
         # Initialize a reservoir computer
         kwargs["res_sz"] = 10
         rcomp = ResComp(**kwargs)
         # Check that the initialized rcomp has the correct jacobian
         err = jacobian_err(rcomp)
         assert  err < 1e-8 , print("\n", kwargs, "Jacobian err:", err)