ysights.algorithms.profiles
Agent Profile Analysis
This module provides functions for analyzing agent interest profiles and their similarity within social networks. It helps understand how agents’ interests align with their network neighbors and community structure.
Example
Analyzing profile similarity in a social network:
from ysights import YDataHandler
from ysights.algorithms.profiles import profile_topics_similarity
# Initialize data handler and extract network
ydh = YDataHandler('path/to/database.db')
network = ydh.social_network()
# Calculate interest similarity between neighbors
similarities = profile_topics_similarity(ydh, network, limit=2)
# Analyze results
for agent_id, similarity_score in similarities.items():
print(f"Agent {agent_id} has {similarity_score:.2%} interest overlap with neighbors")
Functions
|
Compute interest-based similarity between agents and their network neighbors. |
- ysights.algorithms.profiles.profile_topics_similarity(YDH, g, limit=2, from_round=None, to_round=None)[source]
Compute interest-based similarity between agents and their network neighbors.
This function calculates how well each agent’s interests align with those of their neighbors in the social network. It filters out rare interests, normalizes interest distributions, and computes the fraction of neighbors sharing the agent’s most frequent interests.
- Parameters:
YDH (YDataHandler) – YDataHandler instance for database operations
g (networkx.Graph) – Social network graph where nodes represent agents and edges represent connections
limit (int) – Minimum count threshold for including an interest (interests appearing fewer times are filtered out)
from_round (int, optional) – Starting round for filtering interests (inclusive), None for no lower bound
to_round (int, optional) – Ending round for filtering interests (inclusive), None for no upper bound
- Returns:
Dictionary mapping agent IDs to their similarity scores with neighbors. Similarity score represents the fraction of neighbors sharing at least one of the agent’s most frequent interests (range: 0.0 to 1.0)
- Return type:
Example:
from ysights import YDataHandler from ysights.algorithms.profiles import profile_topics_similarity import networkx as nx # Initialize data handler and extract social network ydh = YDataHandler('path/to/database.db') network = ydh.social_network() # Calculate similarity for all agents similarities = profile_topics_similarity(ydh, network, limit=2) # Find agents with high neighbor similarity high_similarity = {k: v for k, v in similarities.items() if v > 0.7} print(f"{len(high_similarity)} agents have >70% interest overlap with neighbors") # Calculate for specific time period early_sim = profile_topics_similarity(ydh, network, limit=2, from_round=0, to_round=500) late_sim = profile_topics_similarity(ydh, network, limit=2, from_round=500, to_round=1000) # Compare evolution for agent_id in early_sim: if agent_id in late_sim: change = late_sim[agent_id] - early_sim[agent_id] if abs(change) > 0.2: print(f"Agent {agent_id} similarity changed by {change:.2%}")
Note
Interests are normalized per agent, so agents with many posts don’t dominate the similarity calculation
The limit parameter helps focus on significant interests by filtering out occasional or accidental topic matches
Agents with no qualifying interests (after filtering) are excluded from results
See also
ysights.models.YDataHandler.YDataHandler.agent_interests(): Get agent interestsysights.models.YDataHandler.YDataHandler.social_network(): Extract social network