Exemple #1
0
def problem_case():
    exptree = ExpTree()
    exptree.apply_binary_op(exptree.root, ops.add)
    l1, l2 = exptree.leaves[0], exptree.leaves[1]
    exptree.apply_unary_op(l1, ops.sin)
    exptree.apply_unary_op(l2, ops.tan)

    x, y = gen_data.get_data(exptree, [])

    print exptree.root.collapse()
    print
    astar = AStar(x, y, False)



    err = np.array([x for x in astar.best_err if not math.isnan(x) and not math.isinf(x)])
    print err
    plt.plot(range(len(err)), err)
    plt.axis([-.1, len(err)+1, -1, max(err)+1])
    plt.show()
Exemple #2
0
# %%
from pathlib import Path
from gen_data import get_data
import matplotlib.pyplot as plt

# %%
d = get_data(25)

# %%
fig, ax = plt.subplots()
m = d[6]
ax.plot(m.time, m)

# %%
out = Path("../../slides/figs") / Path(__file__).with_suffix(".pdf").name
fig.savefig(out)
Exemple #3
0
import matplotlib.pyplot as plt
import logging
from mpl_toolkits.mplot3d import Axes3D
from diff_map import DiffusionMap
from gen_data import get_data
from pars_rep_dm import compute_res

import numpy as np
# Demo to check parsimonious representation of eigenvectors/values

sample = 'c_curve'  #'punc_sphere'
A, color = get_data(sample, 1000)

# target dimension
# For plotting reasons, ndim should be bigger than 5
ndim = 6

# Diff. Map computation and plot
diff_map = DiffusionMap()
diff_map.set_params(A)
w, x = diff_map.dim_reduction(ndim=ndim)

# Plot original 3D data
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(231, projection='3d')
ax.set_title("Original 3D data")
ax.scatter(A[:, 0], A[:, 1], A[:, 2], c=color, cmap=plt.cm.Spectral)

ax = fig.add_subplot(232)
ax.set_title("Diffusion Maps")
plt.scatter(x[:, 0], x[:, 1], c=color, cmap=plt.cm.Spectral)
# Test for projection of outlier(new) points with diffusion maps
# Given an outlier point, compute its projection into the reduced dimension space

import numpy as np
from gen_data import get_data
from diff_map import DiffusionMap
import matplotlib.pyplot as plt
from interpolation import *
from mpl_toolkits.mplot3d import Axes3D

samples = 'gaussian_test'
num_samples = 3000
test, color_2 = get_data(samples, num_samples)

# Simple script to test diff. maps dimension reduction
samples = 'gaussian'
num_samples = 1000
A, color = get_data(samples, num_samples)

# target dimension
ndim = 10
# parameters for diff. maps
step = 1
eps = 0

# params for k nearest neighbourhood
# params for eps nearest neighbourhood(epsilon param depends highly on the dataset)
#nbhd_param = {'k': 50}
#nbhd_param = None
# nbhd_param = {'eps': 1.75}
Exemple #5
0
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from diff_map import DiffusionMap
from gen_data import get_data


# Simple script to test diff. maps dimension reduction
samples = 'curve_3d'
num_samples = 1500
A, color = get_data(samples, num_samples)
fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(121, projection='3d')
ax.scatter(A[:,0], A[:,1], A[:,2], c = color, cmap = plt.cm.Spectral)
plt.title('Original data')
# target dimension
ndim = 2
# parameters for diff. maps
step = 2
eps = 0 # if eps = 0, then eps is computed as the median

# params for k nearest neighbourhood
# params for eps nearest neighbourhood(epsilon param depends highly on the dataset)
nbhd_param = None
#nbhd_param = {'k': 10}
nbhd_param = {'eps': 0.05}

diff_map = DiffusionMap(step, eps)
diff_map.set_params(A, nbhd_param)
w, x = diff_map.dim_reduction(ndim)
import matplotlib

matplotlib.use('Agg')
import matplotlib.pyplot as plt

os.environ['CUDA_VISIBLE_DEVICES'] = '0'
# second to last argument False for nclt True for others
#weight_path = 'success_models/ShopFacade_weights/model_epoch_3.ckpt'
#image_path = '.ShopFacade/'
#fig_name = 'ShopFacade Trajectory.png'

weight_path = 'success_models/KingsCollege/model_epoch_90.ckpt'
image_path = './KingsCollege/'
fig_name = 'KingsCollege Trajectory.png'
trainer = train.trainer(weight_path, image_path, True, True, True)
datasource = gen_data.get_data()

# initialize plot tool
fig = plt.figure(1)

error = np.zeros([len(datasource.images), 3])

for i in range(len(datasource.images)):
    np_image = datasource.images[i]
    feed = {
        tf.get_default_graph().get_tensor_by_name('Placeholder:0'):
        np.expand_dims(np_image, axis=0)
    }

    # ground truth x y z
    pose_x = np.asarray(datasource.poses[i][0:3])
Exemple #7
0
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from gen_data import get_data
import numpy as np
from diff_map import DiffusionMap
from pars_rep_dm import compute_res

# Plot range of "good" epsilons as in
#   "Detecting the slow manifold by anisotropic diffusion maps"-
#   Amit Singer, Radek Erban, I. Kevrekidis, R.R. Coifman

sample = 'torus_curve'
data, color = get_data(sample, 2000)

ndim = 5
step = 1
eps = 0.2

# DM constructor and main parameters
diff_map = DiffusionMap(step, eps)
diff_map.set_params(data)

m_dist = diff_map.sq_distance
#coeffs = np.random.uniform(-14, 14, size=100)

# \epsilon in interval [2^-14, 2^14]
# L(\epsilon) = \sum_i \sum_j W_{ij}(\epsilon)
coeffs = np.arange(-14, 14, 28.0 / 100.0)
powers = np.power(2, 2 * coeffs)

pow_sum = []