Python_files package

Submodules

Python_files.cascade_class module

this is the class version of the previous code

class Python_files.cascade_class.Cascade(json)

Bases: object

Get_N()
Get_T()
Get_alpha()
Get_beta()
Get_history()
Get_mu()
Get_p()
Set_N(value)
Set_T(value)
Set_beta(value)
Set_history(value)
Set_p(value)
compute_MAP(prior_params=[0.02, 0.0002, 0.01, 0.001, - 0.1], max_n_star=1, display=False)

Returns the pair of the estimated logdensity of a posteriori and parameters (as a numpy array)

history – (n,2) numpy array containing marked time points (t_i,m_i) t – current time (i.e end of observation window) alpha – power parameter of the power-law mark distribution mu – min value parameter of the power-law mark distribution prior_params – list (mu_p, mu_beta, sig_p, sig_beta, corr) of hyper parameters of the prior

– where: – mu_p: is the prior mean value of p – mu_beta: is the prior mean value of beta – sig_p: is the prior standard deviation of p – sig_beta: is the prior standard deviation of beta – corr: is the correlation coefficient between p and beta

max_n_star – maximum authorized value of the branching factor (defines the upper bound of p) display – verbose flag to display optimization iterations (see ‘disp’ options of optim.optimize)

loglikelihood()

Returns the loglikelihood of a Hawkes process with exponential kernel computed with a linear time complexity

params – parameter tuple (p,beta) of the Hawkes process history – (n,2) numpy array containing marked time points (t_i,m_i) t – current time (i.e end of observation window)

Python_files.hawkes_estimator module

The aim of this code is to estimate the cascade’s parameters.

Python_files.hawkes_tools module

The aim of this code is to provide statistical tools for cascade’s parameters estimation.

Python_files.hawkes_tools.compute_MAP(history, t, alpha, mu, prior_params=[0.02, 0.0002, 0.01, 0.001, - 0.1], max_n_star=1, display=False)

Returns the pair of the estimated logdensity of a posteriori and parameters (as a numpy array)

history – (n,2) numpy array containing marked time points (t_i,m_i) t – current time (i.e end of observation window) alpha – power parameter of the power-law mark distribution mu – min value parameter of the power-law mark distribution prior_params – list (mu_p, mu_beta, sig_p, sig_beta, corr) of hyper parameters of the prior

– where: – mu_p: is the prior mean value of p – mu_beta: is the prior mean value of beta – sig_p: is the prior standard deviation of p – sig_beta: is the prior standard deviation of beta – corr: is the correlation coefficient between p and beta

max_n_star – maximum authorized value of the branching factor (defines the upper bound of p) display – verbose flag to display optimization iterations (see ‘disp’ options of optim.optimize)

Python_files.hawkes_tools.loglikelihood(params, history, t)

Returns the loglikelihood of a Hawkes process with exponential kernel computed with a linear time complexity

params – parameter tuple (p,beta) of the Hawkes process history – (n,2) numpy array containing marked time points (t_i,m_i) t – current time (i.e end of observation window)

Python_files.learner module

The aim of this code is to estimate the cascade’s parameters.

Python_files.logger module

class Python_files.logger.KafkaHandler(hostlist, topic='logs', tls=None)

Bases: logging.Handler

Class to instantiate the kafka logging facility.

close()

Close the producer and clean up.

emit(record)

Emit the provided record to the kafka_client producer.

flush(timeout=None)

Flush the objects.

class Python_files.logger.Logger(columns=[{'field': 't', 'length': 5, 'align': '>', 'name': 'time'}, {'field': 'source', 'length': 9, 'align': '^', 'name': 'source'}, {'field': 'level', 'length': 8, 'align': '^', 'name': 'level'}, {'field': 'message', 'length': None, 'align': '<', 'name': 'message'}], log_sep=None, skip_line=True, levels={}, sources={})

Bases: object

accept_field(field, fields)
add_postprocessor(field, f)
add_preprocessor(field, f)
default_columns = [{'field': 't', 'length': 5, 'align': '>', 'name': 'time'}, {'field': 'source', 'length': 9, 'align': '^', 'name': 'source'}, {'field': 'level', 'length': 8, 'align': '^', 'name': 'level'}, {'field': 'message', 'length': None, 'align': '<', 'name': 'message'}]
draw_line(c)
get_terminal_width()
log(entry, log_sep=None)
print(entry, log_sep=None)
Python_files.logger.get_logger(name, debug=False, topic='logs', broker_list='localhost:9091,localhost:9092', levels=[])
Python_files.logger.postprocess_color(colors, default_color='white')
Python_files.logger.preprocess_time()

Python_files.predictor module

The aim of this code is predict the number of retweet thanks to the estimated parameters.

Python_files.predictor_tools module

This code is aimed to provide tools for prediction process.

Python_files.predictor_tools.predictions(params, history, alpha, mu, T=None)

Returns the expected total numbers of points for a set of time points

params – parameter tuple (p,beta) of the Hawkes process history – (n,2) numpy array containing marked time points (t_i,m_i) alpha – power parameter of the power-law mark distribution mu – min value parameter of the power-law mark distribution T – 1D-array of times (i.e ends of observation window)

Module contents