def train_unsupervised_hierarchy(X1, X2, n_epochs=30): g1 = gwr_h_unimodal(n_layers=2, window_size=[3, 3], gwr_pars=pars) g2 = gwr_h_unimodal(n_layers=2, window_size=[3, 3], gwr_pars=pars) g3 = gwr(**pars) X1_ = g1.train(X1, n_epochs=n_epochs) X2_ = g2.train(X2, n_epochs=n_epochs) X = np.hstack((X1_, X2_)) g3.train(X, n_epochs=n_epochs) return g1, g2, g3
def test_activation_trajectories(self): X = np.array([[1], [2], [3], [4], [5], [6]]) ossh = gwr_h_unimodal(window_size=[1, 2, 3], lab_ratio=2 / 3) ossh.H[0].G.add_node(0, attr_dict={'pos': np.array([1]), 'lab': 1}) ossh.H[0].G.add_node(1, attr_dict={'pos': np.array([4]), 'lab': 2}) ossh.H[0].G.add_node(2, attr_dict={'pos': np.array([7]), 'lab': 3}) ossh.H[1].G.add_node(0, attr_dict={'pos': np.array([1, 1]), 'lab': 1}) ossh.H[1].G.add_node(1, attr_dict={'pos': np.array([5, 7]), 'lab': 2}) tr0_fp = ossh._get_trajectories_from_previous(X,0) tr0 = ossh._get_activation_trajectories_old(X, 0) tr0_test = X np.testing.assert_array_equal(tr0_fp, tr0) np.testing.assert_array_equal(tr0, tr0_test) tr1_fp = ossh._get_trajectories_from_previous(tr0,1) tr1 = ossh._get_activation_trajectories_old(X, 1) tr1_test = np.array([[1, 1], [1, 4], [4, 4], [4, 4], [4, 7]]) np.testing.assert_array_equal(tr1_fp, tr1) np.testing.assert_array_equal(tr1, tr1_test) tr2_fp = ossh._get_trajectories_from_previous(tr1, 2) tr2 = ossh._get_activation_trajectories_old(X, 2) tr2_test = np.array([[1, 1, 1, 1, 5, 7], [1, 1, 5, 7, 5, 7], [5, 7, 5, 7, 5, 7]]) np.testing.assert_array_equal(tr2_fp,tr2) np.testing.assert_array_equal(tr2,tr2_test)
a1_raw = pd.read_csv(dir + 'a1_raw.csv') a1_va3 = np.genfromtxt(dir + 'a1_va3.csv', delimiter=',') y = np.array(a1_raw['phase'].astype('category').cat.codes) pos = np.array(a1_raw.iloc[:, :18]) dif = a1_raw.shape[0] - a1_va3.shape[0] pos = pos[dif // 2:-dif // 2, :18] y = y[dif // 2:-dif // 2] vel = a1_va3[:, :32] pars = {'act_thr': 0.75, 'max_size': 200} g1 = gwr_h_unimodal(n_layers=2, window_size=[3, 3], gwr_pars=pars) g2 = gwr_h_unimodal(n_layers=2, window_size=[3, 3], gwr_pars=pars) pos_ = g1.train(pos, n_epochs=40) vel_ = g2.train(vel, n_epochs=40) #posc = g1._get_activation_trajectories(pos) X_ = np.hstack((pos_, vel_)) # TODO add an extra unsupervised layer here y_ = -np.ones(X_.shape[0]) for i in range(5, y.shape[0]): c = collections.Counter(y[i - 5:i]) lab = c.most_common()[0][0]
import matplotlib.pyplot as plt from neuralgas.oss_gwr import gwr from neuralgas.oss_gwr_h import gwr_h_unimodal from neuralgas.oss_gwr_h import _propagate_trajectories iris = sklearn.datasets.load_iris() X = iris.data X1 = X[:, :2] X2 = X[:, 2:] y = iris.target g1 = gwr_h_unimodal(n_layers=2, window_size=[1, 2], gwr_pars=[{ 'act_thr': 0.7 }, { 'act_thr': 0.7 }]) g2 = gwr_h_unimodal(n_layers=2, window_size=[1, 2], gwr_pars=[{ 'act_thr': 0.7 }, { 'act_thr': 0.7 }]) g3 = gwr() XX1 = g1.train(X1)