<s> import os <EOL> import cPickle <EOL> import numpy as np <EOL> np . seterr ( over = "<STR_LIT>" ) <EOL> from scipy . io import loadmat <EOL> from scipy . misc import logsumexp <EOL> import seaborn as sns <EOL> sns . set ( style = "<STR_LIT>" ) <EOL> import matplotlib . pyplot as plt <EOL> from matplotlib . patches import Circle <EOL> import matplotlib <EOL> matplotlib . rcParams . update ( { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:9> , <EOL> '<STR_LIT>' : <NUM_LIT:7> , <EOL> '<STR_LIT>' : <NUM_LIT:7> , <EOL> '<STR_LIT>' : <NUM_LIT:9> } ) <EOL> from hips . plotting . layout import create_axis_at_location , create_figure , remove_plot_labels <EOL> from hips . plotting . colormaps import harvard_colors , gradient_cmap <EOL> colors = harvard_colors ( ) <EOL> from graphistician . internals . utils import compute_optimal_rotation <EOL> from pybasicbayes . util . text import progprint_xrange <EOL> import pyhawkes . models <EOL> reload ( pyhawkes . models ) <EOL> from pyhawkes . models import ContinuousTimeNetworkHawkesModel <EOL> from pyhawkes . internals . network import LatentDistanceAdjacencyModel , ErdosRenyiFixedSparsity , ErdosRenyiModel <EOL> with open ( "<STR_LIT>" , "<STR_LIT:r>" ) as f : <EOL> matdata = loadmat ( f ) <EOL> S = matdata [ '<STR_LIT:data>' ] [ '<STR_LIT:S>' ] [ <NUM_LIT:0> , <NUM_LIT:0> ] . ravel ( ) . astype ( np . float ) <EOL> C = matdata [ '<STR_LIT:data>' ] [ '<STR_LIT:C>' ] [ <NUM_LIT:0> , <NUM_LIT:0> ] . ravel ( ) . astype ( np . int ) <EOL> X = matdata [ '<STR_LIT:data>' ] [ '<STR_LIT:X>' ] [ <NUM_LIT:0> , <NUM_LIT:0> ] . astype ( np . float ) <EOL> M = S . shape [ <NUM_LIT:0> ] <EOL> perm = np . argsort ( S ) <EOL> S = S [ perm ] <EOL> C = C [ perm ] <EOL> X = X [ perm ] <EOL> S -= S . min ( ) <EOL> T = np . ceil ( S . max ( ) ) <EOL> C -= <NUM_LIT:1> <EOL> K = C . max ( ) + <NUM_LIT:1> <EOL> X -= X . mean ( <NUM_LIT:0> ) <EOL> rad = <NUM_LIT> <EOL> pfs = np . zeros ( ( K , <NUM_LIT:2> ) ) <EOL> pfs_cov = np . zeros ( ( K , <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> for k in range ( K ) : <EOL> pfs [ k ] = X [ C == k ] . mean ( <NUM_LIT:0> ) <EOL> pfs_cov [ k ] = np . cov ( X [ C == k ] . T ) <EOL> pf_size = np . array ( [ np . linalg . eigvalsh ( cc ) . max ( ) for cc in pfs_cov ] ) <EOL> pf_size -= pf_size . min ( ) <EOL> pf_size /= pf_size . max ( ) <EOL> pfs_rad = np . sqrt ( np . sum ( pfs ** <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> pfs_th = np . arctan2 ( pfs [ : , <NUM_LIT:1> ] , pfs [ : , <NUM_LIT:0> ] ) <EOL> node_perm = np . lexsort ( ( pfs_rad , pfs_th ) ) <EOL> B = <NUM_LIT:1> <EOL> dt_max = <NUM_LIT:1.> <EOL> train_frac = <NUM_LIT> <EOL> T_train = train_frac * T <EOL> T_test = T - T_train <EOL> train_inds = S < T_train <EOL> S_train , C_train , X_train = S [ train_inds ] , C [ train_inds ] , X [ train_inds ] <EOL> S_test , C_test , X_test = S [ ~ train_inds ] , C [ ~ train_inds ] , X [ ~ train_inds ] <EOL> S_test -= T_train <EOL> dense_network = ErdosRenyiFixedSparsity ( K = K , p = <NUM_LIT:1.0> , kappa = <NUM_LIT:1> , alpha = <NUM_LIT:1.0> , beta = <NUM_LIT:1.0> ) <EOL> er_network = ErdosRenyiModel ( K = K , kappa = <NUM_LIT:1> , alpha = <NUM_LIT:1.0> , beta = <NUM_LIT:1.0> ) <EOL> dist_network = LatentDistanceAdjacencyModel ( K = K , kappa = <NUM_LIT:1> , dim = <NUM_LIT:2> , alpha = <NUM_LIT:1.0> , beta = <NUM_LIT:1.0> ) <EOL> networks = [ dense_network , er_network , dist_network ] <EOL> names = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> N_samples = <NUM_LIT:1000> <EOL> results = [ ] <EOL> results_dir = os . path . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> for network , name in zip ( networks , names ) : <EOL> results_file = os . path . join ( results_dir , "<STR_LIT>" % name ) <EOL> if os . path . exists ( results_file ) : <EOL> with open ( results_file , "<STR_LIT:r>" ) as f : <EOL> result = cPickle . load ( f ) <EOL> results . append ( result ) <EOL> continue <EOL> print "<STR_LIT>" , name , "<STR_LIT>" <EOL> model = ContinuousTimeNetworkHawkesModel ( <EOL> K , dt_max = <NUM_LIT:1.> , <EOL> network = network ) <EOL> model . add_data ( S_train , C_train , T_train ) <EOL> model . resample_model ( ) <EOL> model . add_data ( S_test , C_test , T - T_train ) <EOL> test_data = model . data_list . pop ( ) <EOL> lls = [ model . log_likelihood ( ) ] <EOL> plls = [ model . log_likelihood ( test_data ) ] <EOL> Weffs = [ ] <EOL> Ps = [ ] <EOL> Ls = [ ] <EOL> for iter in progprint_xrange ( N_samples , perline = <NUM_LIT> ) : <EOL> model . resample_model ( ) <EOL> lls . append ( model . log_likelihood ( ) ) <EOL> plls . append ( model . log_likelihood ( test_data ) ) <EOL> Weffs . append ( model . W_effective ) <EOL> Ps . append ( model . network . P ) <EOL> if isinstance ( network , LatentDistanceAdjacencyModel ) : <EOL> Ls . append ( model . network . L ) <EOL> result = ( lls , plls , Weffs , Ps , Ls ) <EOL> results . append ( result ) <EOL> with open ( results_file , "<STR_LIT:w>" ) as f : <EOL> cPickle . dump ( result , f , protocol = - <NUM_LIT:1> ) <EOL> def plot_results ( result ) : <EOL> lls , plls , Weffs , Ps , Ls = result <EOL> wheel_cmap = gradient_cmap ( [ colors [ <NUM_LIT:0> ] , colors [ <NUM_LIT:3> ] , colors [ <NUM_LIT:2> ] , colors [ <NUM_LIT:1> ] , colors [ <NUM_LIT:0> ] ] ) <EOL> fig = create_figure ( figsize = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> ax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> color = wheel_cmap ( ( np . pi + pfs_th [ k ] ) / ( <NUM_LIT:2> * np . pi ) ) <EOL> alpha = <NUM_LIT> <EOL> ax . add_patch ( Circle ( ( pfs [ k , <NUM_LIT:0> ] , pfs [ k , <NUM_LIT:1> ] ) , <EOL> radius = <NUM_LIT:3> + <NUM_LIT:4> * pf_size [ k ] , <EOL> color = color , ec = "<STR_LIT:none>" , <EOL> alpha = alpha ) <EOL> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] ) <EOL> plt . xlabel ( "<STR_LIT>" ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . yticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plt . savefig ( os . path . join ( results_dir , "<STR_LIT>" ) ) <EOL> fig = create_figure ( figsize = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> ax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> Weff = np . array ( Weffs [ N_samples // <NUM_LIT:2> : ] ) . mean ( <NUM_LIT:0> ) <EOL> Weff = Weff [ np . ix_ ( node_perm , node_perm ) ] <EOL> lim = Weff [ ( <NUM_LIT:1> - np . eye ( K ) ) . astype ( np . bool ) ] . max ( ) <EOL> im = ax . imshow ( np . kron ( Weff , np . ones ( ( <NUM_LIT:20> , <NUM_LIT:20> ) ) ) , <EOL> interpolation = "<STR_LIT:none>" , cmap = "<STR_LIT>" , vmax = lim ) <EOL> ax . set_xticks ( [ ] ) <EOL> ax . set_yticks ( [ ] ) <EOL> node_values = ( ( np . pi + pfs_th [ node_perm ] ) / ( <NUM_LIT:2> * np . pi ) ) [ : , None ] * np . ones ( ( K , <NUM_LIT:2> ) ) <EOL> yax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> remove_plot_labels ( yax ) <EOL> yax . imshow ( node_values , interpolation = "<STR_LIT:none>" , <EOL> cmap = wheel_cmap ) <EOL> yax . set_xticks ( [ ] ) <EOL> yax . set_yticks ( [ ] ) <EOL> yax . set_ylabel ( "<STR_LIT>" ) <EOL> xax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> remove_plot_labels ( xax ) <EOL> xax . imshow ( node_values . T , interpolation = "<STR_LIT:none>" , <EOL> cmap = wheel_cmap ) <EOL> xax . set_xticks ( [ ] ) <EOL> xax . set_yticks ( [ ] ) <EOL> xax . set_xlabel ( "<STR_LIT>" ) <EOL> cbax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> plt . colorbar ( im , cax = cbax , ticks = [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> cbax . tick_params ( labelsize = <NUM_LIT:8> , pad = <NUM_LIT:1> ) <EOL> cbax . set_ticklabels = [ "<STR_LIT:0>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> ax . set_title ( "<STR_LIT>" ) <EOL> plt . savefig ( os . path . join ( results_dir , "<STR_LIT>" ) ) <EOL> fig = create_figure ( figsize = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> ax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> P = np . array ( Ps [ N_samples // <NUM_LIT:2> : ] ) . mean ( <NUM_LIT:0> ) <EOL> P = P [ np . ix_ ( node_perm , node_perm ) ] <EOL> im = ax . imshow ( np . kron ( P , np . ones ( ( <NUM_LIT:20> , <NUM_LIT:20> ) ) ) , <EOL> interpolation = "<STR_LIT:none>" , cmap = "<STR_LIT>" , vmin = <NUM_LIT:0> , vmax = <NUM_LIT:1> ) <EOL> ax . set_xticks ( [ ] ) <EOL> ax . set_yticks ( [ ] ) <EOL> node_values = ( ( np . pi + pfs_th [ node_perm ] ) / ( <NUM_LIT:2> * np . pi ) ) [ : , None ] * np . ones ( ( K , <NUM_LIT:2> ) ) <EOL> yax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> remove_plot_labels ( yax ) <EOL> yax . imshow ( node_values , interpolation = "<STR_LIT:none>" , <EOL> cmap = wheel_cmap ) <EOL> yax . set_xticks ( [ ] ) <EOL> yax . set_yticks ( [ ] ) <EOL> yax . set_ylabel ( "<STR_LIT>" ) <EOL> xax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> remove_plot_labels ( xax ) <EOL> xax . imshow ( node_values . T , interpolation = "<STR_LIT:none>" , <EOL> cmap = wheel_cmap ) <EOL> xax . set_xticks ( [ ] ) <EOL> xax . set_yticks ( [ ] ) <EOL> xax . set_xlabel ( "<STR_LIT>" ) <EOL> cbax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> plt . colorbar ( im , cax = cbax , ticks = [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ] ) <EOL> cbax . tick_params ( labelsize = <NUM_LIT:8> , pad = <NUM_LIT:1> ) <EOL> cbax . set_ticklabels = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:1.0>" ] <EOL> ax . set_title ( "<STR_LIT>" ) <EOL> plt . savefig ( os . path . join ( results_dir , "<STR_LIT>" ) ) <EOL> plt . show ( ) <EOL> def plot_pred_lls ( results ) : <EOL> homog_rates = np . zeros ( K ) <EOL> for k in range ( K ) : <EOL> homog_rates [ k ] = ( C_train == k ) . sum ( ) / T_train <EOL> homog_pll = <NUM_LIT:0> <EOL> for k in range ( K ) : <EOL> homog_pll += - T_test * homog_rates [ k ] <EOL> homog_pll += ( C_test == k ) . sum ( ) * np . log ( homog_rates [ k ] ) <EOL> plt . figure ( ) <EOL> for i , result in enumerate ( results ) : <EOL> lls , plls , Weffs , Ps , Ls = result <EOL> plls = plls [ N_samples // <NUM_LIT:2> : ] <EOL> J = len ( plls ) <EOL> avg_pll = - np . log ( J ) + logsumexp ( plls ) <EOL> avg_pll = ( avg_pll - homog_pll ) / len ( S_test ) <EOL> samples = np . random . choice ( plls , size = ( <NUM_LIT:100> , J ) , replace = True ) <EOL> pll_samples = logsumexp ( ( samples - homog_pll ) / len ( S_test ) , axis = <NUM_LIT:1> ) - np . log ( J ) <EOL> std_hll = pll_samples . std ( ) <EOL> print "<STR_LIT>" , avg_pll , "<STR_LIT>" , std_hll <EOL> plt . bar ( i , avg_pll ) <EOL> plt . show ( ) <EOL> def plot_locations ( result , offset = <NUM_LIT:0> ) : <EOL> _ , _ , _ , _ , Ls = result <EOL> Ls_rot = [ ] <EOL> for L in Ls : <EOL> R = compute_optimal_rotation ( L , pfs , scale = False ) <EOL> Ls_rot . append ( L . dot ( R ) ) <EOL> Ls_rot = np . array ( Ls_rot ) <EOL> fig = create_figure ( figsize = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> ax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> toplot = np . linspace ( offset , K + offset , <NUM_LIT:4> , endpoint = False ) . astype ( np . int ) <EOL> print toplot <EOL> wheel_cmap = gradient_cmap ( [ colors [ <NUM_LIT:0> ] , colors [ <NUM_LIT:3> ] , colors [ <NUM_LIT:2> ] , colors [ <NUM_LIT:1> ] , colors [ <NUM_LIT:0> ] ] ) <EOL> plot_colors = [ wheel_cmap ( ( np . pi + pfs_th [ node_perm [ j ] ] ) / ( <NUM_LIT:2> * np . pi ) ) for j in toplot ] <EOL> for i , k in enumerate ( node_perm ) : <EOL> if i not in toplot : <EOL> color = <NUM_LIT> * np . ones ( <NUM_LIT:3> ) <EOL> plt . plot ( pfs [ k , <NUM_LIT:0> ] , pfs [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] , <EOL> alpha = <NUM_LIT:1.0> ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> if i in toplot : <EOL> j = np . where ( toplot == i ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> color = plot_colors [ j ] <EOL> plt . plot ( pfs [ k , <NUM_LIT:0> ] , pfs [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . yticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] ) <EOL> ax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> for L in Ls_rot [ : : <NUM_LIT:2> ] : <EOL> for j in np . random . permutation ( len ( toplot ) ) : <EOL> k = node_perm [ toplot ] [ j ] <EOL> color = plot_colors [ j ] <EOL> plt . plot ( L [ k , <NUM_LIT:0> ] , L [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = "<STR_LIT:none>" , <EOL> markersize = <NUM_LIT:4> , alpha = <NUM_LIT> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> plt . xticks ( [ - <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:2> ] ) <EOL> plt . ylim ( - <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> plt . yticks ( [ - <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:2> ] ) <EOL> plt . savefig ( os . path . join ( results_dir , "<STR_LIT>" % offset ) ) <EOL> def plot_mean_locations ( ) : <EOL> _ , _ , _ , _ , Ls = result <EOL> Ls_rot = [ ] <EOL> for L in Ls : <EOL> R = compute_optimal_rotation ( L , pfs ) <EOL> Ls_rot . append ( L . dot ( R ) ) <EOL> Ls_rot = np . array ( Ls_rot ) <EOL> Ls_mean = np . mean ( Ls_rot , <NUM_LIT:0> ) <EOL> fig = create_figure ( figsize = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> plt . subplot ( <NUM_LIT> , aspect = '<STR_LIT>' ) <EOL> wheel_cmap = gradient_cmap ( [ colors [ <NUM_LIT:0> ] , colors [ <NUM_LIT:3> ] , colors [ <NUM_LIT:2> ] , colors [ <NUM_LIT:1> ] , colors [ <NUM_LIT:0> ] ] ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> color = wheel_cmap ( ( np . pi + pfs_th [ k ] ) / ( <NUM_LIT:2> * np . pi ) ) <EOL> plt . plot ( pfs [ k , <NUM_LIT:0> ] , pfs [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] , <EOL> alpha = <NUM_LIT> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] , [ ] ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . yticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] , [ ] ) <EOL> plt . subplot ( <NUM_LIT> , aspect = '<STR_LIT>' ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> color = wheel_cmap ( ( np . pi + pfs_th [ k ] ) / ( <NUM_LIT:2> * np . pi ) ) <EOL> plt . plot ( Ls_mean [ k , <NUM_LIT:0> ] , Ls_mean [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] , <EOL> alpha = <NUM_LIT> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT:30> , <NUM_LIT:30> ) <EOL> plt . xticks ( [ ] ) <EOL> plt . ylim ( - <NUM_LIT:30> , <NUM_LIT:30> ) <EOL> plt . yticks ( [ ] ) <EOL> plt . tight_layout ( ) <EOL> plt . savefig ( os . path . join ( results_dir , "<STR_LIT>" ) ) <EOL> plt . show ( ) <EOL> def plot_pca_locations ( ) : <EOL> from pyhawkes . utils . utils import convert_continuous_to_discrete <EOL> S_dt = convert_continuous_to_discrete ( S , C , <NUM_LIT> , <NUM_LIT:0> , T ) <EOL> from scipy . ndimage . filters import gaussian_filter1d <EOL> S_smooth = np . array ( [ gaussian_filter1d ( s , <NUM_LIT:4> ) for s in S_dt . T ] ) . T <EOL> from sklearn . decomposition import PCA <EOL> pca = PCA ( n_components = <NUM_LIT:2> ) <EOL> pca . fit ( S_smooth ) <EOL> Z = pca . components_ . T <EOL> R = compute_optimal_rotation ( Z , pfs ) <EOL> Z = Z . dot ( R ) <EOL> fig = create_figure ( figsize = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> plt . subplot ( <NUM_LIT> , aspect = '<STR_LIT>' ) <EOL> wheel_cmap = gradient_cmap ( [ colors [ <NUM_LIT:0> ] , colors [ <NUM_LIT:3> ] , colors [ <NUM_LIT:2> ] , colors [ <NUM_LIT:1> ] , colors [ <NUM_LIT:0> ] ] ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> color = wheel_cmap ( ( np . pi + pfs_th [ k ] ) / ( <NUM_LIT:2> * np . pi ) ) <EOL> plt . plot ( pfs [ k , <NUM_LIT:0> ] , pfs [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] , <EOL> alpha = <NUM_LIT> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] , [ ] ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . yticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] , [ ] ) <EOL> plt . subplot ( <NUM_LIT> , aspect = '<STR_LIT>' ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> color = wheel_cmap ( ( np . pi + pfs_th [ k ] ) / ( <NUM_LIT:2> * np . pi ) ) <EOL> plt . plot ( Z [ k , <NUM_LIT:0> ] , Z [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] , <EOL> alpha = <NUM_LIT> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xticks ( [ - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> ] , [ ] ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . yticks ( [ - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> ] , [ ] ) <EOL> plt . tight_layout ( ) <EOL> plt . savefig ( os . path . join ( results_dir , "<STR_LIT>" ) ) <EOL> plt . show ( ) <EOL> def plot_mean_locations ( ) : <EOL> _ , _ , _ , _ , Ls = result <EOL> Ls_rot = [ ] <EOL> for L in Ls : <EOL> R = compute_optimal_rotation ( L , pfs ) <EOL> Ls_rot . append ( L . dot ( R ) ) <EOL> Ls_rot = np . array ( Ls_rot ) <EOL> Ls_mean = np . mean ( Ls_rot , <NUM_LIT:0> ) <EOL> fig = create_figure ( figsize = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> plt . subplot ( <NUM_LIT> , aspect = '<STR_LIT>' ) <EOL> wheel_cmap = gradient_cmap ( [ colors [ <NUM_LIT:0> ] , colors [ <NUM_LIT:3> ] , colors [ <NUM_LIT:2> ] , colors [ <NUM_LIT:1> ] , colors [ <NUM_LIT:0> ] ] ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> color = wheel_cmap ( ( np . pi + pfs_th [ k ] ) / ( <NUM_LIT:2> * np . pi ) ) <EOL> plt . plot ( pfs [ k , <NUM_LIT:0> ] , pfs [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] , <EOL> alpha = <NUM_LIT> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] , [ ] ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . yticks ( [ - <NUM_LIT> , - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ] , [ ] ) <EOL> plt . subplot ( <NUM_LIT> , aspect = '<STR_LIT>' ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> color = wheel_cmap ( ( np . pi + pfs_th [ k ] ) / ( <NUM_LIT:2> * np . pi ) ) <EOL> plt . plot ( Ls_mean [ k , <NUM_LIT:0> ] , Ls_mean [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] , <EOL> alpha = <NUM_LIT> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT:30> , <NUM_LIT:30> ) <EOL> plt . xticks ( [ ] ) <EOL> plt . ylim ( - <NUM_LIT:30> , <NUM_LIT:30> ) <EOL> plt . yticks ( [ ] ) <EOL> plt . tight_layout ( ) <EOL> plt . savefig ( os . path . join ( results_dir , "<STR_LIT>" ) ) <EOL> plt . show ( ) <EOL> def plot_mean_and_pca_locations ( result ) : <EOL> _ , _ , _ , _ , Ls = result <EOL> Ls_rot = [ ] <EOL> for L in Ls : <EOL> R = compute_optimal_rotation ( L , pfs , scale = False ) <EOL> Ls_rot . append ( L . dot ( R ) ) <EOL> Ls_rot = np . array ( Ls_rot ) <EOL> Ls_mean = np . mean ( Ls_rot , <NUM_LIT:0> ) <EOL> from pyhawkes . utils . utils import convert_continuous_to_discrete <EOL> S_dt = convert_continuous_to_discrete ( S , C , <NUM_LIT> , <NUM_LIT:0> , T ) <EOL> from scipy . ndimage . filters import gaussian_filter1d <EOL> S_smooth = np . array ( [ gaussian_filter1d ( s , <NUM_LIT:4> ) for s in S_dt . T ] ) . T <EOL> from sklearn . decomposition import PCA <EOL> pca = PCA ( n_components = <NUM_LIT:2> ) <EOL> pca . fit ( S_smooth ) <EOL> Z = pca . components_ . T <EOL> R = compute_optimal_rotation ( Z , pfs , scale = False ) <EOL> Z = Z . dot ( R ) <EOL> wheel_cmap = gradient_cmap ( [ colors [ <NUM_LIT:0> ] , colors [ <NUM_LIT:3> ] , colors [ <NUM_LIT:2> ] , colors [ <NUM_LIT:1> ] , colors [ <NUM_LIT:0> ] ] ) <EOL> fig = create_figure ( figsize = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> ax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> color = wheel_cmap ( ( np . pi + pfs_th [ k ] ) / ( <NUM_LIT:2> * np . pi ) ) <EOL> plt . plot ( Ls_mean [ k , <NUM_LIT:0> ] , Ls_mean [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] , <EOL> alpha = <NUM_LIT> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> plt . xticks ( [ - <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:2> ] ) <EOL> plt . ylim ( - <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> plt . yticks ( [ - <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:2> ] ) <EOL> ax = create_axis_at_location ( fig , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> for i , k in enumerate ( node_perm ) : <EOL> color = wheel_cmap ( ( np . pi + pfs_th [ k ] ) / ( <NUM_LIT:2> * np . pi ) ) <EOL> plt . plot ( Z [ k , <NUM_LIT:0> ] , Z [ k , <NUM_LIT:1> ] , '<STR_LIT:o>' , <EOL> markerfacecolor = color , markeredgecolor = color , <EOL> markersize = <NUM_LIT:4> + <NUM_LIT:4> * pf_size [ k ] , <EOL> alpha = <NUM_LIT> ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xticks ( [ - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT> ) <EOL> plt . yticks ( [ - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> plt . savefig ( os . path . join ( results_dir , "<STR_LIT>" ) ) <EOL> plt . show ( ) <EOL> plot_results ( results [ - <NUM_LIT:1> ] ) </s>
