communities

This module defines structures for handling members, static and evolving communities.

class dyn.core.communities.Membership

Bases: object

This class gathers evolving and static communities along their members and ensures their coherency.

Attr evolving_communities

evolving communities with ids as keys

Attr static_communities

static communities with ids as keys

Attr members

members with ids as keys

Warning

This class ensures coherency of data as long as you only modify them through its methods!

add_evolving_community(evolving_community_id)

Create and add evolving community by id if not present.

Parameters

evolving_community_id

Return type

EvolvingCommunity

Returns

evolving community with given id

add_member(member_id)

Create and add member by id if not present.

Parameters

member_id

Return type

Member

Returns

member with given id

add_static_community(static_community_id, snapshot)

Create and add static community by id if not present.

Parameters

static_community_id

Return type

StaticCommunity

Returns

static community with given id

attach_member(member_id, static_community_id)

Attach static community to evolving community.

Parameters
  • member_id

  • static_community_id

Raises
  • IndexError

    • If member_id member doesn’t exist

    • If static_community_id static community doesn’t exist

  • ValueError – If member is already in an other community at same snapshot

attach_static_community(static_community_id, evolving_community_id)

Attach static community to evolving community.

Parameters
  • static_community_id

  • evolving_community_id

Raises
  • IndexError

    • If static_community_id static community doesn’t exist

    • If evolving_community_id static community doesn’t exist

  • ValueError – If evolving community already exists at same snapshot

commlist(snapshot)

Return commlist representing data at given snapshot.

Parameters

snapshot (int) –

Return type

Tcommlist

Returns

property community_graph: EvolvingCommunitiesGraph

Return community flow graph representing data.

Return type

EvolvingCommunitiesGraph

Returns

detach_member(member_id, snapshot)

Detach member from its static community at given snapshot (by id).

Parameters
  • member_id

  • snapshot (int) –

Raises

IndexError – If member_id member doesn’t exist

detach_static_community(static_community_id)

Detach static community from its evolving community (by id).

Parameters

static_community_id

Raises

IndexError – If static_community_id static community doesn’t exist

classmethod from_community_graph(graph)

Create membership object from community flow graph.

As community flow graph is not as complete, only evolving and static communities are added (no members).

Parameters

graph (EvolvingCommunitiesGraph) –

Return type

Membership

Returns

membership object

classmethod from_tcommlist(tcommlist_)

Create membership object from tcommlist.

Parameters

tcommlist

Return type

Membership

Returns

membership object

property snapshots: List[int]

Return all existing snapshots.

Return type

List[int]

Returns

property tcommlist: Tcommlist

Return tcommlist representing current data.

Return type

Tcommlist

Returns

class dyn.core.communities.Tcommlist(data=None)

Bases: object

This class defines the Tcommlist format.

Parameters

data (Union[List[TcommlistRow], DataFrame, None]) –

append(row)

Append a single row to Tcommlist.

Parameters

row (TcommlistRow) –

Raises

TypeError – if row type is not a TcommlistRow

commlist(snapshot)

Return commlist at given snapshot.

Parameters

snapshot (int) –

Return type

Tcommlist

Returns

commlist

property commlists: Dict[int, Tcommlist]

Return commlists as a dictionary.

Return type

Dict[int, Tcommlist]

Returns

commlists

Note

This is as fast as calling :method:`commlist` once.

property community_flow_graph: EvolvingCommunitiesGraph

Return community flow graph.

Return type

EvolvingCommunitiesGraph

Returns

drop_duplicates()

Remove duplicated rows.

Return type

Tcommlist

Returns

Tcommlist without duplicates

Note

A new Tcommlist object is returned (original is not modified)

sort()

Sort Tcommlist.

Sorting is done by following rules (in decreasing priority):
  • snapshot (ascending order)

  • evolving_community_id (ascending order)

  • node_id

Return type

Tcommlist

Returns

sorted Tcommlist

Note

A new Tcommlist object is returned (original is not modified)

class dyn.core.communities.TcommlistRow(node_id, evolving_community_id, snapshot)

Bases: object

This class defines a single row in Tcommlist format.

evolving_community_id: Any
node_id: Any
snapshot: int
property static_community_id: str
Return type

str