#!/usr/bin/env python # coding: utf-8 # In[1]: import networkx import math import scipy.optimize import numpy from lib.time_graph import * from lib.vis import * from lib.syn import * from lib.io import * from lib.datasets import * from lib.time_graph import * from lib.experiments import * from IPython.display import Image # # Synthetic data # In[51]: algos = [TemporalCuts("FSTC-16", "fast-sparse", eps=1e-5, k=16), TemporalCuts("FSTC-64", "fast-sparse", eps=1e-5, k=64), TemporalCuts("STC", "diff-sparse"), TemporalCuts("LAP", "laplacian-sparse"), TemporalCuts("UNION", "union-sparse"), TemporalCuts("SINGLE", "indep-sparse")] grid = slide_diagonal_grids(10, 5, 10.) grid = add_gaussian_noise(grid, 2.8) G, values = time_graph_from_grid(grid, 2) swap_costs = numpy.array([0., .5, 1., 1.5, 2.]) #swap_costs = numpy.array([0.]) * math.exp(2.) res = sparsity_experiments(G, algos, swap_costs, 10) # In[52]: output_file_name = "figs/syn_sparsity.png" plot_sparsity_experiments(res, algos, swap_costs, output_file_name, 0, 600, 1e-4, 1e-1) Image(filename=output_file_name) # In[50]: algos = [TemporalCuts("FSTC-16", "fast-norm", eps=1e-5, k=16), TemporalCuts("FSTC-64", "fast-norm", eps=1e-5, k=64), TemporalCuts("STC", "diff-norm"), TemporalCuts("LAP", "laplacian-norm"), TemporalCuts("UNION", "union-norm"), TemporalCuts("SINGLE", "indep-norm")] grid = grow_diagonal_grids(10, 5, 10.) grid = add_gaussian_noise(grid, 2.8) G, values = time_graph_from_grid(grid, 2) swap_costs = numpy.array([0., .5, 1., 1.5, 2.0]) #swap_costs = numpy.array([0.]) * math.exp(2.) res = sparsity_experiments(G, algos, swap_costs, 10) # In[51]: output_file_name = "figs/syn_norm_sparsity.png" plot_sparsity_experiments(res, algos, swap_costs, output_file_name, 0, 600, 1e-5, 1e-2) Image(filename=output_file_name) # In[2]: algos = [TemporalCuts("FSTC-16", "fast-sparse", eps=1e-5, k=16), TemporalCuts("FSTC-64", "fast-sparse", eps=1e-5, k=64), TemporalCuts("STC", "diff-sparse", eps=0.), TemporalCuts("LAP", "laplacian-sparse"), TemporalCuts("UNION", "union-sparse"), TemporalCuts("SINGLE", "indep-sparse")] swap_costs = numpy.array([0., 0.01, .02, 0.03, .04]) #swap_costs = numpy.array([0.]) * math.exp(2.) G = read_time_graph(primary_school["graph"], .1) res = sparsity_experiments(G, algos, swap_costs, 10) # In[24]: output_file_name = "figs/school_sparsity.png" plot_sparsity_experiments(res, algos, swap_costs, output_file_name, 0, 600, 1e-6, 1e-3) Image(filename=output_file_name) # In[56]: algos = [TemporalCuts("FSTC-16", "fast-norm", eps=1e-5, k=16), TemporalCuts("FSTC-64", "fast-norm", eps=1e-5, k=64), TemporalCuts("STC", "diff-norm", eps=0.), TemporalCuts("LAP", "laplacian-norm"), TemporalCuts("UNION", "union-norm"), TemporalCuts("SINGLE", "indep-norm")] swap_costs = numpy.array([0., 0.01, .02, 0.03, .04]) #swap_costs = numpy.array([0.]) * math.exp(2.) G = read_time_graph(primary_school["graph"], .1) res2 = sparsity_experiments(G, algos, swap_costs, 10) # In[30]: output_file_name = "figs/school_norm_sparsity.png" plot_sparsity_experiments(res, algos, swap_costs, output_file_name, 0, 600, 1e-4, 2e-1) Image(filename=output_file_name) # In[36]: res # In[35]: algos = [TemporalCuts("FSTC-16", "fast-sparse", eps=1e-5, k=16), TemporalCuts("FSTC-64", "fast-sparse", eps=1e-5, k=64), TemporalCuts("STC", "diff-sparse", eps=2e-5), TemporalCuts("LAP", "laplacian-sparse"), TemporalCuts("UNION", "union-sparse"), TemporalCuts("SINGLE", "indep-sparse")] swap_costs = numpy.array([0., 0.1, 0.2, 0.3, 0.4]) G = read_time_graph(stock["graph"], .1) res = sparsity_experiments(G, algos, swap_costs, 10) # In[28]: output_file_name = "figs/stock_sparsity.png" plot_sparsity_experiments(res, algos, [0., 0.1, 0.2, 0.3, 0.4], output_file_name, 0, 600, 1e-6,6e-3) Image(filename=output_file_name) # In[5]: res # In[37]: algos = [TemporalCuts("FSTC-16", "fast-norm", eps=1e-5, k=16), TemporalCuts("FSTC-64", "fast-norm", eps=1e-5, k=64), TemporalCuts("STC", "diff-norm", eps=2e-5), TemporalCuts("LAP", "laplacian-norm"), TemporalCuts("UNION", "union-norm"), TemporalCuts("SINGLE", "indep-norm")] swap_costs = numpy.array([0., 0.1, 0.2, 0.3, 0.4]) #swap_costs = numpy.array([0.]) * math.exp(2.) G = read_time_graph(stock["graph"], .1) res2 = sparsity_experiments(G, algos, swap_costs, 10) # In[49]: output_file_name = "figs/stock_norm_sparsity.png" plot_sparsity_experiments(res2, algos, [0., 0.1, 0.2, 0.3, 0.4], output_file_name, 0, 600, 1e-4, 2) Image(filename=output_file_name) # In[10]: algos = [TemporalCuts("FSTC-16", "fast-sparse", eps=1e-5, k=16), TemporalCuts("FSTC-64", "fast-sparse", eps=1e-5, k=64), TemporalCuts("UNION", "union-sparse"), TemporalCuts("SINGLE", "indep-sparse")] #algos = [TemporalCuts("FSTC-10", "fast-sparse", eps=1e-5, k=10)] swap_costs = numpy.array([0., .002, .004, .006, .008]) G = read_time_graph(dblp["graph"], .1) res = sparsity_experiments(G, algos, swap_costs, 10) # In[ ]: res # In[13]: output_file_name = "figs/dblp_sparsity.png" plot_sparsity_experiments(res, algos, [0., .02, .04, .06, .08], output_file_name, 0, 600, 1e-7, 1e-4) Image(filename=output_file_name)