pyevoc.analysis.temporal_stability#
Temporal stability and quadrant mobility for PyEvoc.
This module reconstructs temporal EVOC/HEM dynamics from token-level data and a reference EVOC quadrant table.
It supports three main periodisation strategies:
custom: user-supplied cuts or breaks;equal_days/equal_width: periods with approximately equal calendar duration;equal_posts/equal_count: periods with approximately equal numbers of posts/documents.
The module computes:
period-specific term quadrants;
stable nucleus terms;
volatile core terms;
quadrant mobility and stability indices;
transition diagnostics;
temporal engagement diagnostics;
optional HTML report.
The implementation is compatible with the rebuilt PyEvoc package schema
(doc_id) and with the original notebook schema (post_id).
- class pyevoc.analysis.temporal_stability.TemporalStabilityConfig(n_periods=4, time_period_mode='equal_posts', custom_time_breaks=None, custom_time_cuts=None, period_labels=None, right=True, alpha=0.5, max_rank_value=5.0, use_users_for_frequency=True, focal_upos=<factory>, round_digits=2, diffusion_multiplier=100.0, time_col='time', doc_col='doc_id', user_col='user_id', term_col='term', upos_col='upos', r_pos_col='r_pos', r_str_col='r_str', expected_min_timestamp=None, expected_max_timestamp=None, warn_on_time_range_mismatch=False, output_dir='evoc_outputs', write_html_report=True, show_tables=False, verbose=True)[source]#
Bases:
objectConfiguration for temporal stability analysis.
- Parameters:
n_periods (int)
time_period_mode (str)
right (bool)
alpha (float)
max_rank_value (float)
use_users_for_frequency (bool)
round_digits (int)
diffusion_multiplier (float)
time_col (str)
doc_col (str)
user_col (str)
term_col (str)
upos_col (str)
r_pos_col (str)
r_str_col (str)
expected_min_timestamp (str | None)
expected_max_timestamp (str | None)
warn_on_time_range_mismatch (bool)
write_html_report (bool)
show_tables (bool)
verbose (bool)
- pyevoc.analysis.temporal_stability.quadrant_entropy(x)[source]#
Compute entropy of quadrant memberships.
- pyevoc.analysis.temporal_stability.safe_std(x, ddof=1)[source]#
Return standard deviation with safe handling of degenerate inputs.
- pyevoc.analysis.temporal_stability.safe_spearman(x, y)[source]#
Compute Spearman correlation with safe handling of constants.
- pyevoc.analysis.temporal_stability.quarter_label_from_timestamp(ts)[source]#
Return a quarterly label from a timestamp.
- pyevoc.analysis.temporal_stability.quarter_start_utc(ts)[source]#
Return the UTC start of the quarter containing
ts.- Parameters:
ts (object)
- Return type:
Timestamp
- pyevoc.analysis.temporal_stability.next_quarter_start_utc(ts)[source]#
Return the UTC start of the next quarter after
ts.- Parameters:
ts (object)
- Return type:
Timestamp
- pyevoc.analysis.temporal_stability.validate_time_range(observed_min, observed_max, expected_min=None, expected_max=None)[source]#
Compare observed and expected time ranges.
- pyevoc.analysis.temporal_stability.normalise_threshold_table(pos_thresholds_round_df=None, evoc_quadrants_df=None, *, round_digits=2)[source]#
Return internal POS-specific thresholds with exact and rounded columns.
- Parameters:
pos_thresholds_round_df (DataFrame | None)
evoc_quadrants_df (DataFrame | None)
round_digits (int)
- Return type:
DataFrame
- pyevoc.analysis.temporal_stability.build_threshold_display_table(thresholds)[source]#
Return a display-ready threshold table.
- Parameters:
thresholds (DataFrame)
- Return type:
DataFrame
- pyevoc.analysis.temporal_stability.build_time_periods(df, *, time_col='time', doc_col='doc_id', user_col='user_id', n_periods=4, mode='equal_posts', custom_time_breaks=None, custom_time_cuts=None, period_labels=None, right=True, time_range_reference_df=None, expected_min_timestamp=None, expected_max_timestamp=None, warn_on_time_range_mismatch=False)[source]#
Assign observations to temporal periods.
Supported modes#
customUse user-defined breaks or internal cuts.
equal_daysorequal_widthGenerate periods with approximately equal calendar duration.
equal_postsorequal_countGenerate periods with approximately equal numbers of unique posts.
quartersGenerate calendar-quarter periods.
- Parameters:
- Return type:
tuple[DataFrame, DataFrame, list[Timestamp], dict[str, object]]
- pyevoc.analysis.temporal_stability.compute_period_quadrants(tokens_df, evoc_quadrants_df, pos_thresholds_round_df=None, *, alpha=0.5, max_rank_value=5.0, use_users_for_frequency=True, focal_upos=None, round_digits=2, diffusion_multiplier=100.0)[source]#
Reconstruct period-specific term quadrants.
- pyevoc.analysis.temporal_stability.add_term_diffusion_summary(term_table, all_period_quadrants)[source]#
Add mean and maximum relative diffusion summaries.
- Parameters:
term_table (DataFrame)
all_period_quadrants (DataFrame)
- Return type:
DataFrame
- pyevoc.analysis.temporal_stability.compute_stability_metrics(all_period_quadrants, n_periods)[source]#
Compute term-level and transition-level temporal stability metrics.
- pyevoc.analysis.temporal_stability.compute_temporal_engagement(periodised_df, *, time_col='time', doc_col='doc_id', user_col='user_id')[source]#
Compute engagement diagnostics at post/user level.
- pyevoc.analysis.temporal_stability.dataframe_to_html_table(df, title, *, max_rows=100, cols=None)[source]#
Convert a dataframe to a compact HTML table section.
- pyevoc.analysis.temporal_stability.write_temporal_report_html(results, output_file, *, max_rows=80)[source]#
Write a compact HTML report for temporal stability analysis.
- pyevoc.analysis.temporal_stability.run_temporal_stability_analysis(df, evoc_quadrants_df, pos_thresholds_round_df=None, *, n_periods=4, time_period_mode='equal_posts', custom_time_breaks=None, custom_time_cuts=None, period_labels=None, alpha=0.5, max_rank_value=5.0, use_users_for_frequency=True, focal_upos=None, round_digits=2, diffusion_multiplier=100.0, time_range_reference_df=None, count_reference_df=None, expected_min_timestamp=None, expected_max_timestamp=None, warn_on_time_range_mismatch=False, output_dir='evoc_outputs', write_html_report=True, show_tables=True, config=None)[source]#
Run the complete temporal stability analysis.
- Parameters:
df (DataFrame)
evoc_quadrants_df (DataFrame)
pos_thresholds_round_df (DataFrame | None)
n_periods (int)
time_period_mode (str)
alpha (float)
max_rank_value (float)
use_users_for_frequency (bool)
round_digits (int)
diffusion_multiplier (float)
time_range_reference_df (DataFrame | None)
count_reference_df (DataFrame | None)
expected_min_timestamp (object | None)
expected_max_timestamp (object | None)
warn_on_time_range_mismatch (bool)
write_html_report (bool)
show_tables (bool)
config (TemporalStabilityConfig | None)
- Return type: