Ejemplo n.º 1
0
def plot_2d(Z, y, name, model_dir):
    plot_dir = os.path.join(model_dir, "figures", "2dscatter")
    colors = np.array(
        ['forestgreen', 'red', 'royalblue', 'purple', 'darkblue', 'orange'])
    os.makedirs(plot_dir, exist_ok=True)
    #    plt.rc('text', usetex=True)
    plt.rcParams['font.family'] = 'serif'
    plt.rcParams['font.serif'] = ['Times New Roman']
    # colors = np.array(['royalblue', 'forestgreen', 'red'])
    fig, ax = plt.subplots(figsize=(6, 5), dpi=200)
    ax.scatter(Z[:, 0], Z[:, 1], c=colors[y], alpha=0.5)
    ax.scatter(0.0, 0.0, c='black', alpha=0.8, marker='s')
    # ax.arrow(0.0, 0.0, Z[:, 0], Z[:, 1])
    ax.set_ylim(-1.2, 1.2)
    ax.set_xlim(-1.2, 1.2)
    ax.set_xticks([-1.0, -0.5, 0.0, 0.5, 1.0])
    ax.set_yticks([-1.0, -0.5, 0.0, 0.5, 1.0])
    ax.grid(linestyle=':')
    Z, _ = F.get_n_each(Z, y, 1)
    for c in np.unique(y):
        ax.arrow(0,
                 0,
                 Z[c, 0],
                 Z[c, 1],
                 head_width=0.03,
                 head_length=0.05,
                 fc='k',
                 ec='k',
                 length_includes_head=True)
    [tick.label.set_fontsize(24) for tick in ax.xaxis.get_major_ticks()]
    [tick.label.set_fontsize(24) for tick in ax.yaxis.get_major_ticks()]
    plt.savefig(os.path.join(plot_dir, "scatter2d-" + name + ".pdf"), dpi=200)
    plt.close()
Ejemplo n.º 2
0
def plot_3d(Z, y, name, model_dir):
    colors = np.array(['green', 'blue', 'red'])
    savedir = os.path.join(model_dir, 'figures', '3d')
    os.makedirs(savedir, exist_ok=True)
    #    plt.rc('text', usetex=True)
    plt.rcParams['font.family'] = 'serif'
    plt.rcParams['font.serif'] = ['Times New Roman']
    colors = np.array(['forestgreen', 'royalblue', 'brown'])
    fig = plt.figure(figsize=(10, 10))
    ax = fig.add_subplot(111, projection='3d')
    ax.scatter(Z[:, 0],
               Z[:, 1],
               Z[:, 2],
               c=colors[y],
               cmap=plt.cm.Spectral,
               s=200.0)
    Z, _ = F.get_n_each(Z, y, 1)
    for c in np.unique(y):
        ax.quiver(0.0,
                  0.0,
                  0.0,
                  Z[c, 0],
                  Z[c, 1],
                  Z[c, 2],
                  length=1.0,
                  normalize=True,
                  arrow_length_ratio=0.05,
                  color='black')
    u, v = np.mgrid[0:2 * np.pi:20j, 0:np.pi:10j]
    x = np.cos(u) * np.sin(v)
    y = np.sin(u) * np.sin(v)
    z = np.cos(v)
    ax.plot_wireframe(x, y, z, color="gray", alpha=0.5)
    ax.xaxis._axinfo["grid"]['color'] = (0, 0, 0, 0.1)
    ax.yaxis._axinfo["grid"]['color'] = (0, 0, 0, 0.1)
    ax.zaxis._axinfo["grid"]['color'] = (0, 0, 0, 0.1)
    [tick.label.set_fontsize(24) for tick in ax.xaxis.get_major_ticks()]
    [tick.label.set_fontsize(24) for tick in ax.yaxis.get_major_ticks()]
    [tick.label.set_fontsize(24) for tick in ax.zaxis.get_major_ticks()]
    ax.view_init(20, 15)
    plt.tight_layout()
    fig.savefig(os.path.join(savedir, f"scatter3d-{name}.jpg"), dpi=200)
    plt.close()
Ejemplo n.º 3
0
    f"_eta{args.eta}"
    f"{args.tail}")
os.makedirs(model_dir, exist_ok=True)
utils.save_params(model_dir, vars(args))
print(model_dir)

# data loading
X_train, y_train, num_classes = dataset.generate_wave(args.time,
                                                      args.samples,
                                                      args.data,
                                                      shuffle=True)
X_test, y_test, _ = dataset.generate_wave(args.time,
                                          args.samples,
                                          args.data,
                                          shuffle=False)
X_translate_train, y_translate_train = F.translate1d(*F.get_n_each(
    X_train, y_train, 10),
                                                     n=2,
                                                     stride=4)
X_translate_test, y_translate_test = F.translate1d(*F.get_n_each(
    X_test, y_test, 10),
                                                   n=2,
                                                   stride=4)

# setup architecture
kernels = F.generate_kernel('gaussian', (args.outchannels, 1, args.ksize))
layers = [Lift1D(kernels)
          ] + [Fourier1D(args.layers, eta=args.eta, eps=args.eps)]
model = Architecture(layers, model_dir, num_classes)

# train/test pass
print("Forward pass - train features")
Ejemplo n.º 4
0
    f"_layers{args.layers}"
    f"_outchannels{args.outchannels}"
    f"_ksize{args.ksize}"
    f"_eps{args.eps}"
    f"_eta{args.eta}"
    f"{args.tail}")
os.makedirs(model_dir, exist_ok=True)
utils.save_params(model_dir, vars(args))
print(model_dir)

# data loading
X_train, y_train, X_test, y_test = dataset.load_MNIST(args.data_dir)
X_train, y_train = F.filter_class(X_train, y_train, args.classes, args.samples)
X_train, y_train = F.shuffle(X_train, y_train)
X_test, y_test = F.filter_class(X_test, y_test, args.classes, args.samples)
X_translate_train, y_translate_train = F.translate2d(*F.get_n_each(
    X_train, y_train, 2),
                                                     n=2,
                                                     stride=4)
X_translate_test, y_translate_test = F.translate2d(*F.get_n_each(
    X_test, y_test, 2),
                                                   n=2,
                                                   stride=4)
utils.save_features(model_dir, "X_train", X_train, y_train)
utils.save_features(model_dir, "X_test", X_test, y_test)
utils.save_features(model_dir, "X_translate_train", X_translate_train,
                    y_translate_train)
utils.save_features(model_dir, "X_translate_test", X_translate_test,
                    y_translate_test)

# setup architecture
kernels = F.generate_kernel('gaussian',