예제 #1
0
    # Create graph

    G, colors = build_regular_structure(width_basis=15,
                                        basis_type="star",
                                        nb_shapes=5,
                                        shape=["house"],
                                        start=0,
                                        add_random_edges=0)

    W = nx.adjacency_matrix(G)
    W.eliminate_zeros()
    taus = [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1]

    # Apply kernel at every node
    signal = np.eye(W.shape[0])
    heat_kernel = heat.Heat(W=W, taus=taus)
    feats = heat_kernel.featurize(signal)

    print('simple-example.py: saving feats to %s.npy' % args.outpath)
    np.save(args.outpath, feats)

    # --
    # Cluster resulting features

    # Normalize features
    nfeats = feats - feats.mean(axis=0, keepdims=True)
    nfeats /= (1e-10 + nfeats.std(axis=0, keepdims=True))
    nfeats[np.isnan(nfeats)] = 0

    # Reduce dimension
    pca_feats = PCA(n_components=10).fit_transform(nfeats)
예제 #2
0
 
 np.random.seed(args.seed)
 taus = map(float, args.taus.split(','))
 
 print("main.py: loading %s" % args.inpath, file=sys.stderr)
 
 edgelist = np.array(pd.read_csv(args.inpath, sep='\t', header=None, dtype=int))
 W = sparse.csr_matrix((np.arange(edgelist.shape[0]), (edgelist[:,0], edgelist[:,1])))
 W = ((W + W.T) > 0).astype(int)
 
 if not (np.sum(W, axis=0) > 0).all():
     print("main.py: dropping isolated nodes", file=sys.stderr)
     keep = np.asarray(W.sum(axis=0) > 0).squeeze()
     W = W[keep]
     W = W[:,keep]
 
 print("main.py: running on graph w/ %d edges" % W.nnz, file=sys.stderr)
 
 t = time()
 hk = heat.Heat(W=W, taus=taus)
 
 if args.n_queries < 0:
     args.n_queries = hk.num_nodes
 
 print("main.py: running %d queries" % args.n_queries, file=sys.stderr)
 pfeats = par_graphwave(hk, n_queries=args.n_queries, n_chunks=args.n_chunks, n_jobs=args.n_jobs, verbose=10)
 
 run_time = time() - t
 print("main.py: took %f seconds -- saving %s.npy" % (run_time, args.outpath), file=sys.stderr)
 
 np.save(args.outpath, pfeats)
예제 #3
0
# Program that solve the heat equation using finite differences

import heat
import test_function
# Factors
r = 0.3

dx = 0.1
dt = r*dx*dx
x_end = 3.
t_end = 6.
b = [0., 0.]
coef = 1.

# Creating and solving the problem
H = heat.Heat(dx, dt, x_end, t_end, coef, b, test_function.sinx)

H.heat_solve()

# Ploting the result using matplotlui
H.heat_plot()

예제 #4
0
# from heat import Heat
# from plot import Plot

# read data
df = pd.read_csv(
    '/Users/lukasgehrke/Documents/temp/chatham/crd_gaze_phys-LOW_work-HIGH_equip-Bike_all_good_s.csv'
)
# select a subject
s1 = df[df['pID'] == 40]
s1[['X', 'Y']]

# read background image for heatmap
img = mpimg.imread('/Users/lukasgehrke/Documents/temp/matb.png')

h = heat.Heat('workhigh', s1, None, img)

# specify resolution
x_edges = np.linspace(0, 1280, 100)
y_edges = np.linspace(0, 720, 100)
bins = [x_edges, y_edges]

h.heatmap = h.histogram2d(bins)
h.heatmap = h.zscore(h.heatmap)
h.heatmap = h.gaussian(h.heatmap, 1)

p = plot.Plot(h)
p.cm = p.make_cm_transparent(p.cm)
p.heat_xy()

# # create plot and add plot data