ysights.viz.paradox_viz

Paradox Visualization Functions

This module provides visualization functions for the visibility paradox analysis. It includes density scatter plots, histograms, and population size effect visualizations to help understand asymmetries in content visibility within social networks.

Functions:
  • paradox_density_scatter: 2D density scatter plot comparing user and neighbor visibility

  • paradox_histogram: Distribution of paradox scores across users

  • paradox_size_impact: Line plots showing how paradox varies with population fraction

Example

Visualizing the visibility paradox:

from ysights import YDataHandler
from ysights.algorithms import visibility_paradox, user_visibility_vs_neighbors
from ysights.viz import paradox_density_scatter, paradox_histogram

ydh = YDataHandler('path/to/database.db')
network = ydh.social_network()

# Get visibility data
user_vis, neighbor_vis = user_visibility_vs_neighbors(ydh, network)

# Density scatter plot
fig = paradox_density_scatter(
    user_vis, neighbor_vis,
    xlabel='User Impressions',
    ylabel='Avg Neighbor Impressions',
    title='Visibility Paradox'
)
fig.show()

# Calculate full paradox with statistics
paradox_results = visibility_paradox(ydh, network, N=100)

# Histogram of paradox scores
fig = paradox_histogram(paradox_results, bins=50)
fig.show()

Functions

paradox_density_scatter(x, y[, xlabel, ...])

paradox_histogram(x[, bins, title])

Plot a histogram of the visibility paradox data.

paradox_significance_per_degree_class(results)

Visualize statistical significance and average paradox score per node degree class.

paradox_size_impact(data)

Analyze the impact of network size on the visibility paradox.

paradox_temporal_evolution(results)

Visualize the temporal evolution of the visibility paradox (INCREMENTAL).

ysights.viz.paradox_viz.paradox_density_scatter(x, y, xlabel='Impressions', ylabel='Avg. Neighbors Impressions', title='')[source]
Parameters:
  • x

  • y

  • xlabel

  • ylabel

  • title

Returns:

Example usage: >>> from ysights import algorithms, viz, YDataHandler >>> handler = YDataHandler(“path_to_your_database.db”) >>> network = handler.social_network() >>> x, y = algorithms.user_visibility_vs_neighbors(handler, network) >>> viz.paradox_density_scatter(x, y, xlabel=’Impressions’, ylabel=’Avg. Neighbors Impressions’, title=”Visibility Paradox”)

ysights.viz.paradox_viz.paradox_histogram(x, bins=30, title='Friendship Paradox')[source]

Plot a histogram of the visibility paradox data.

Parameters:
  • x

  • bins

  • title

Returns:

Example usage: >>> from ysights import algorithms, viz, YDataHandler >>> handler = YDataHandler(“path_to_your_database.db”) >>> network = handler.social_network() >>> results = algorithms.visibility_paradox(handler, network, N=0) >>> viz.paradox_histogram(results[‘nodes_coefficients’], bins=10, title=”Visibility Paradox Histogram”)

ysights.viz.paradox_viz.paradox_size_impact(data)[source]

Analyze the impact of network size on the visibility paradox.

Parameters:
  • YDH – YDataHandler, the data handler containing the YSocial simulation data

  • g – networkx.Graph, the social network graph

  • N – int, number of null models to generate for statistical testing

Returns:

dict with size impact results

ysights.viz.paradox_viz.paradox_significance_per_degree_class(results)[source]

Visualize statistical significance and average paradox score per node degree class.

This function creates a dual-axis plot showing: - Left y-axis: Statistical significance (p-values) as a trend line - Right y-axis: Average paradox score per degree class as a trend line

Parameters:

results – dict, output from visibility_paradox_per_degree_class containing: - ‘bin_centers’: array of bin centers for x-axis - ‘p_values’: array of p-values for statistical significance - ‘paradox_scores’: array of average paradox scores per bin - ‘bin_counts’: array of node counts per bin

Returns:

matplotlib figure

Example

>>> from ysights import YDataHandler
>>> from ysights.algorithms.paradox import visibility_paradox_per_degree_class
>>> from ysights.viz import paradox_significance_per_degree_class
>>>
>>> ydh = YDataHandler('path/to/database.db')
>>> network = ydh.social_network()
>>>
>>> results = visibility_paradox_per_degree_class(ydh, network, N=100, num_bins=10)
>>> fig = paradox_significance_per_degree_class(results)
>>> fig.show()
ysights.viz.paradox_viz.paradox_temporal_evolution(results)[source]

Visualize the temporal evolution of the visibility paradox (INCREMENTAL).

This function creates a dual-axis plot showing: - Left y-axis: Statistical significance (p-values) as a trend line over time - Right y-axis: Paradox scores as a trend line over time

The plot shows INCREMENTAL/CUMULATIVE data - each time point includes all data from the simulation start up to that point, showing how the paradox evolves as more data accumulates.

Parameters:

results – dict, output from visibility_paradox_temporal containing: - ‘time_points’: list of (day, hour, round_id) tuples - ‘p_values’: array of p-values for statistical significance - ‘paradox_scores’: array of paradox scores over time (cumulative) - ‘temporal_granularity’: tuple of (days, hours) used

Returns:

matplotlib figure

Example

>>> from ysights import YDataHandler
>>> from ysights.algorithms.paradox import visibility_paradox_temporal
>>> from ysights.viz import paradox_temporal_evolution
>>>
>>> ydh = YDataHandler('path/to/database.db')
>>> network = ydh.social_network()
>>>
>>> # Compute incremental paradox evolution
>>> results = visibility_paradox_temporal(ydh, network, temporal_granularity=(1, 0), N=50)
>>> fig = paradox_temporal_evolution(results)
>>> fig.show()