Construct version 5.4.3
An agent based modeling framework
Social_Media_no_followers Struct Reference

An interaction model which recreates a social media feed to dictate interactions. More...

Inheritance diagram for Social_Media_no_followers:
Collaboration diagram for Social_Media_no_followers:

Classes

struct  default_media_user
 Class that implements the behavior of a user on the social media. More...
 
class  event_container
 Container for media_events with various restrictions More...
 
struct  media_event
 A data structure to represent a tweet, facebook post, or any other social media event. More...
 
struct  media_user
 Base class for the behavior of users on the social media. More...
 

Public Member Functions

void load_events (const std::string &fname, const dynet::datetime &start_time, float time_conversion, const std::map< std::string, unsigned int > &agent_mask=std::map< std::string, unsigned int >())
 Parses the content of a json file and loads the information into Social_Media_no_followers::list_of_events. More...
 
media_eventcreate_post (unsigned int knowledge_index, unsigned int id)
 Creates a post event and adds it to Social_Media_no_followers::list_of_events. More...
 
media_eventcreate_response (unsigned int id, media_event *parent)
 Creates a response event based on the parent event and adds it to Social_Media_no_followers::list_of_events. More...
 
media_eventcreate_quote (unsigned int id, media_event *parent)
 Creates a quote event based on the parent event and adds it to Social_Media_no_followers::list_of_events. More...
 
media_eventcreate_reply (unsigned int id, media_event *parent)
 Creates a reply event based on the parent event and adds it to Social_Media_no_followers::list_of_events. More...
 
media_eventcreate_repost (unsigned int id, media_event *parent)
 Creates a quote event based on the parent event and adds it to Social_Media_no_followers::list_of_events. More...
 
void check_list_order () const
 Checks the list of events to make sure the time stamps are sorted in descending order. More...
 
Social_Media_no_followers::media_useruser (unsigned int index)
 
 Social_Media_no_followers (const std::string &_media_name, InteractionItem::item_keys event_key, const dynet::ParameterMap &parameters, Construct &_construct)
 Base constructor for any social media model. More...
 
virtual ~Social_Media_no_followers ()
 All pointers in Social_Media_with_followers::users are deallocated.
 
virtual void load_users (const std::string &version)
 Loads the media_users into users. More...
 
void think (void) override
 Agents read events in their feed and create messages based on the read events. More...
 
void initialize (void) override
 checks for Knowledge Trust Model (opitional), and add the Knowledge_Parser to Construct::message_parsers if one is not present. More...
 
void communicate (const InteractionMessage &msg) override
 Parses messages that contain the Social_Media_no_followers::event key in their attributes. If the event contains the attribute, media_user::(read, reply, quote, and repost) are called from the receiver's index in Social_Media_no_followers::users More...
 
void cleanup (void) override
 Feeds are updated, list_of_events::removed_events are cleared, and events are erased from list_of_events that have have become inactive. More...
 
virtual void append_message (media_event *_event, InteractionMessage &msg)
 Appends the array of InteractionItems based on the submitted event and the intended receiver of the message. More...
 
virtual InteractionItem convert_to_InteractionItem (media_event *_event, unsigned int sender_index, unsigned int receiver_index) const
 Copies some or all information from the submitted event based on the sender's and receiver's node attributes. More...
 
virtual int get_feed_priority (const media_event &_event, unsigned int user)
 Returns 10 if the user is mentioned by the event or if the event is a reply to an event authored by the user. Returns 100 otherwise. More...
 
virtual void update_event_scores ()
 Goes through all events and updates media_event::score to media_event::child_size * media_event::time_stamp. More...
 
virtual void random_event_swapping (unsigned int user_index)
 Randomly swaps 10% of events in the user's feed. More...
 
virtual void update_feeds (float new_events_timestamp)
 Updates each user's feeds. More...
 
template<typename function >
auto get_events (function filter)
 
- Public Member Functions inherited from Model
 Model (Construct &_construct)
 Constructor for all models in Construct. More...
 
virtual ~Model (void)
 Virtual Deconstructor. More...
 
virtual void initialize (void)
 Function called once before any simulation cycles begin. More...
 
virtual void think (void)
 First function called in a simulation cycle. More...
 
virtual void update (void)
 Function called after the think functions in a simulation cycle. More...
 
virtual void communicate (const InteractionMessage &msg)
 Function called after the update functions in a simulation cycle. More...
 
virtual void cleanup (void)
 Function called after the Model::communicate functions in a simulation cycle. More...
 
void add_base_model_to_model_manager (const std::string &base_model_name)
 Adds a derived model under the name of the base model and disables the model manager from calling its functions.
 

Public Attributes

const std::string interval_time_duration = "interval time duration"
 
const std::string maximum_post_inactivity = "maximum post inactivity"
 
event_container list_of_events
 The list of all current events in this social media. New events should be added to the front of this list.
 
const Nodesetagents = ns_manager.get_nodeset(nodeset_names::agents)
 
const Nodesetknowledge = ns_manager.get_nodeset(nodeset_names::knowledge)
 
Graph< float > * ktrust_net = nullptr
 Pointer to the graph with name "knowledge trust network".
 
Graph< std::map< unsigned int, float > > * kttm = nullptr
 Pointer to the graph with name "knowledge trust transactive memory network".
 
CommunicationMedium medium
 The medium used for all messages created by this model.
 
const InteractionItem::item_keys event_key
 The item key added to all messages created by this model.
 
std::vector< std::vector< media_event * > > users_feed
 Each user's feed of events with the first dimension corresponding to each user. More...
 
std::vector< unsigned int > read_count
 
float age
 The maximum time a post can exist without its tree being added to.
 
float dt
 The time duration between time steps.
 
float time = 0.0f
 The current time period.
 
std::string media_name
 The prefix for some of the node attributes names parsed by the media_user class.
 
Graph< bool > & knowledge_net = graph_manager.load_required(graph_names::knowledge, agents, knowledge)
 Pointer to the graph with name "knowledge network".
 
const Graph< bool > & active_agents = graph_manager.load_optional(graph_names::active, true, agents, sparse, ns_manager.get_nodeset(nodeset_names::time), sparse)
 Pointer to the graph with name "agent active time network".
 
std::vector< media_user * > users
 The list of users. More...
 
std::function< bool(media_event &)> current_timestep = [this](media_event& _event) { return _event.time_stamp > time - 0.5f * dt; }
 
std::function< bool(media_event &)> previous_timestep = [this](media_event& _event) { return _event.time_stamp > time - 1.5f * dt; }
 
std::function< bool(media_event &)> active = [this](media_event& _event) { return _event.last_used > time - age; }
 
- Public Attributes inherited from Model
Constructconstruct
 
GraphManagergraph_manager
 
NodesetManagerns_manager
 
Randomrandom
 
bool valid
 If member is false, the model's functions are not called.
 

Detailed Description

An interaction model which recreates a social media feed to dictate interactions.

This model uses the media_event data structure to represent and track the event tree/cascade. Agents create events which are stored in Social_Media_no_followers::list_of_events. These events can be created sponateously or in response to reading an event. What actions are taken depends on how classes derived from media_user implement the virtual functions. Future developers may wish to modify the underlying structure of this model. For that reason, a set of virtual functions have been implemented for modifying how feeds are updated, and how InteractionMessagess are created based on read events.

Updating feeds is handled by Social_Media_no_followers::update_feeds and dictate how the feeds are ordered. New events are added to the feed and old/read event are removed. An event is old when Social_Media_no_followers::time * Social_Media_no_followers::dt - media_event::last_used > Social_Media_no_followers::age. New events are grouped by user by events that mention that user or responds to them. The other group contains all other events. Both groups are sorted by their score which is equal to media_event::time_stamp * media_event::child_size(). The groups are then combined for each user with mentions and responses first. Finally 10% of the entire feed is stochastically swapped to sprinkle new content into the front of a users feed.

All information that is to be conveyed in messages is handled by Social_Media_no_followers::append_message. Because additional information may added to events than what is currently developed, this will allow developers to add the additional information in the messages being passed around based on the event being read. This function only appends the message items and does not create the message that will be added to the message queue. The message sender is the author of the event being read, and is not always the case that the event submitted to the function is the same event being read. In the case where the events differ, the author of that event should be added as an alter in the InteractionItem.

Social_Media_no_followers::media_user represents the agents operating on this social media. The base class provides a template for how the Social_Media asks how a user should respond to information. Classes derived from Social_Media_no_followers::media_user such as Social_Media_no_followers::default_media_user details the behavior of agents. Agents can be asked how many events they wish to read via Social_Media_no_followers::media_user::get_read_count(). Similarily an agent can be asked by Social_Media_no_followers whether they wish to reply to an event they're reading via Social_Media_no_followers::media_user::reply(). Customs users can be created via the API. Social_Media_no_followers::load_users will call the API function create_custom_media_user_no_followers if it is present in the library to fill pointers in Social_Media_no_followers::users.

Constructor & Destructor Documentation

◆ Social_Media_no_followers()

Social_Media_no_followers::Social_Media_no_followers ( const std::string &  _media_name,
InteractionItem::item_keys  event_key,
const dynet::ParameterMap parameters,
Construct _construct 
)

Base constructor for any social media model.

This class does not define the model's name. Instead derived classes must do so when initializing the Model constructor.

Parameters
_media_nameThe name of the social media and is stored in Social_Media_with_followers::media_name. This affects the node attributes that are searched for in defining a Social_Media_no_followers::default_media_user.
parametersA parameter map that should contain the keys "interval time duration" and "maximum post inactivity" as floats.
_constructThe construct pointer that is passed to the Model constructor.
event_keyThe item key that the social media uses to identify an InteractionItem that contains one of its feed indexes.
Here is the call graph for this function:

Member Function Documentation

◆ append_message()

void Social_Media_no_followers::append_message ( media_event _event,
InteractionMessage msg 
)
virtual

Appends the array of InteractionItems based on the submitted event and the intended receiver of the message.

Reimplemented in Reddit.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_list_order()

void Social_Media_no_followers::check_list_order ( ) const

Checks the list of events to make sure the time stamps are sorted in descending order.

To avoid floating point percision conflicts an event's time stamp is compared with the next event's time stamp - dt*.5.

summary>

Here is the caller graph for this function:

◆ cleanup()

void Social_Media_no_followers::cleanup ( void  )
overridevirtual

Feeds are updated, list_of_events::removed_events are cleared, and events are erased from list_of_events that have have become inactive.

Reimplemented from Model.

Reimplemented in Social_Media_with_followers.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ communicate()

void Social_Media_no_followers::communicate ( const InteractionMessage msg)
overridevirtual

Parses messages that contain the Social_Media_no_followers::event key in their attributes. If the event contains the attribute, media_user::(read, reply, quote, and repost) are called from the receiver's index in Social_Media_no_followers::users

Reimplemented from Model.

Reimplemented in Social_Media_with_followers.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_to_InteractionItem()

InteractionItem Social_Media_no_followers::convert_to_InteractionItem ( media_event _event,
unsigned int  sender_index,
unsigned int  receiver_index 
) const
virtual

Copies some or all information from the submitted event based on the sender's and receiver's node attributes.

If the event's user is the receiver, an empty item is returned. If the receiver's node attribute "can receive knowledge" is false, all knowledge and knowledge trust information is removed. If the receiver's node attribute "can receive knowledge trust" is false, all knowledge trust information is removed. If the receiver can receive both knowledge and knowledge trust, but the event's user does not equal the sender, the sender index is added to InteractionItem::indexes under the key InteractionItem::item_keys::alter.

Returns
An InteractionItem with content copied from the submitted event with some, none, or all information filtered.

Reimplemented in SM_nf_emotions, and SM_wf_emotions.

Here is the caller graph for this function:

◆ create_post()

media_event * Social_Media_no_followers::create_post ( unsigned int  knowledge_index,
unsigned int  id 
)
inline

Creates a post event and adds it to Social_Media_no_followers::list_of_events.

Set required member values such as type, id, time_stamp, last_used, and sets the knowledge information.

Parameters
knowledge_indexUses InteractionItem::set_knowledge_item to set the knowledge index of the event.
idAgent index of the event's author.
Returns
Returns the newly created event.

Example

int main()
{
unsigned int agent_index = 4;
unsigned int knowledge_index = 5;
float knowledge_trust = 0.3;
new_event = media.create_post(knowledge_index, agent_index);
new_event.set_knowledge_trust_item(knowledge_index, knowledge_trust);
}
InteractionItem & set_knowledge_trust_item(unsigned int knowledge_index, float ktrust) noexcept
Sets an item to become a knowledge trust item.
Definition: InteractionMessage.cpp:70
An interaction model which recreates a social media feed to dictate interactions.
Definition: SocialMedia.h:47
media_event * create_post(unsigned int knowledge_index, unsigned int id)
Creates a post event and adds it to Social_Media_no_followers::list_of_events.
Definition: SocialMedia.h:681

Complexity

Constant

Iterator validity

No changes. list_of_events.begin returns a different iterator value.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

Here is the call graph for this function:

◆ create_quote()

media_event * Social_Media_no_followers::create_quote ( unsigned int  id,
media_event parent 
)
inline

Creates a quote event based on the parent event and adds it to Social_Media_no_followers::list_of_events.

Uses Social_Media_no_followers::create_response to create the event, sets the event's type to media_event::event_type::quote, and adds the newly created event to the parent's quotes.

Parameters
parentPointer to the parent event for this response.
idAgent index of the event's author.
Returns
Returns the newly created event.

Example

int main()
{
unsigned int agent_index = 4;
media_event* parent;
float knowledge_trust = 0.3;
new_event = media.create_quote(knowledge_index, parent);
new_event.set_knowledge_trust_item(knowledge_index, knowledge_trust);
}
media_event * create_quote(unsigned int id, media_event *parent)
Creates a quote event based on the parent event and adds it to Social_Media_no_followers::list_of_eve...
Definition: SocialMedia.h:798

Complexity

Constant

Iterator validity

No changes. list_of_events.begin returns a different iterator value.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

Here is the call graph for this function:

◆ create_reply()

media_event * Social_Media_no_followers::create_reply ( unsigned int  id,
media_event parent 
)
inline

Creates a reply event based on the parent event and adds it to Social_Media_no_followers::list_of_events.

Uses Social_Media_no_followers::create_response to create the event, sets the event's type to media_event::event_type::quote, and adds the newly created event to the parent's quotes.

Parameters
parentPointer to the parent event for this response.
idAgent index of the event's author.
Returns
Returns the newly created event.

Example

int main()
{
unsigned int agent_index = 4;
media_event* parent;
float knowledge_trust = 0.3;
new_event = media.create_quote(knowledge_index, parent);
new_event.set_knowledge_trust_item(knowledge_index, knowledge_trust);
}

Complexity

Constant

Iterator validity

No changes. list_of_events.begin returns a different iterator value.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

Here is the call graph for this function:

◆ create_repost()

media_event * Social_Media_no_followers::create_repost ( unsigned int  id,
media_event parent 
)
inline

Creates a quote event based on the parent event and adds it to Social_Media_no_followers::list_of_events.

Uses Social_Media_no_followers::create_response to create the event, sets the event's type to media_event::event_type::quote, and adds the newly created event to the parent's quotes.

Parameters
parentPointer to the parent event for this response.
idAgent index of the event's author.
Returns
Returns the newly created event.

Example

int main()
{
unsigned int agent_index = 4;
media_event* parent;
float knowledge_trust = 0.3;
new_event = media.create_quote(knowledge_index, parent);
new_event.set_knowledge_trust_item(knowledge_index, knowledge_trust);
}

Complexity

Constant

Iterator validity

No changes. list_of_events.begin returns a different iterator value.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

Here is the call graph for this function:

◆ create_response()

media_event * Social_Media_no_followers::create_response ( unsigned int  id,
media_event parent 
)
inline

Creates a response event based on the parent event and adds it to Social_Media_no_followers::list_of_events.

Set required member values such as id, time_stamp, last_used, and sets the knowledge information. The event type is expected to be set by the calling function. Additionally, handles linking the created event to the parent event. The calling function is expected to link the parent event to the created event by placing the created event in the appropriate data structure in the parent event. The last_used value is also updated for each event in the root event's tree.

Parameters
parentPointer to the parent event for this response.
idAgent index of the event's author.
Returns
Returns the newly created event.

Example

int main()
{
unsigned int agent_index = 4;
media_event* parent;
new_event = media.create_response(agent_index, parent);
new_event.type = media_event::event_type::reply;
parent->replies.insert(new_event);
}
event_type type
The type of event this is i.e. "post","repost", "quote", or "reply".
Definition: SocialMedia.h:187
media_event * create_response(unsigned int id, media_event *parent)
Creates a response event based on the parent event and adds it to Social_Media_no_followers::list_of_...
Definition: SocialMedia.h:740

Complexity

Linear with number of event's in the root event's tree.

Iterator validity

No changes. list_of_events.begin returns a different iterator value.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_feed_priority()

int Social_Media_no_followers::get_feed_priority ( const media_event _event,
unsigned int  user 
)
virtual

Returns 10 if the user is mentioned by the event or if the event is a reply to an event authored by the user. Returns 100 otherwise.

Reimplemented in SM_wf_emotions, Reddit, and Social_Media_with_followers.

Here is the caller graph for this function:

◆ initialize()

void Social_Media_no_followers::initialize ( void  )
overridevirtual

checks for Knowledge Trust Model (opitional), and add the Knowledge_Parser to Construct::message_parsers if one is not present.

Reimplemented from Model.

Reimplemented in Facebook_wf, and Twitter_wf.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_events()

void Social_Media_no_followers::load_events ( const std::string &  fname,
const dynet::datetime &  start_time,
float  time_conversion,
const std::map< std::string, unsigned int > &  agent_mask = std::map<std::string, unsigned int>() 
)
inline

Parses the content of a json file and loads the information into Social_Media_no_followers::list_of_events.

The json is assumed to be in the Twitter API v2 format. Construct specific information such as knowledge is parsed in the "entities" element in each event. Ex. "entities": {"mentions": ["mentioned_user"], "attributes": ["knowledge"], "indexes": {"knowledge":4}} After all events are loaded, update_feeds is called with "start_time" as its argument.

Parameters
fnameName of the json file to be loaded and may contain the full path to the file.
start_timeThe time that corresponds to the initialization time step which is one time step before time node at index 0.
time_conversionThe conversion between seconds and Social_Media_no_followers::dt. Example if Social_Media_no_followers::dt equals 2 hours, time_conversion should equal 7200.
agent_maskAn optional parameter that is used to assign indexes for authors. When used, the agent_mask is searched for the key equal to "author_id" value in each corrsponding json element. The index corresponding index for that key is then used as the index for the loaded event's user. Otherwise, the agent nodeset is searched for a node matching the "author_id" value and that node's index is used for the event's user.

Exception Safety

All events in the json file must have an "id" field. A #dynet::could_not_find_property_key is thrown if the field is not found. Events that do not contain "created_at" or "author_id" are discarded.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_users()

virtual void Social_Media_no_followers::load_users ( const std::string &  version)
inlinevirtual

Loads the media_users into users.

Reimplemented in SM_nf_emotions, SM_wf_emotions, Reddit, and Social_Media_with_followers.

Here is the caller graph for this function:

◆ random_event_swapping()

void Social_Media_no_followers::random_event_swapping ( unsigned int  user_index)
virtual

Randomly swaps 10% of events in the user's feed.

Reimplemented in Reddit.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ think()

void Social_Media_no_followers::think ( void  )
overridevirtual

Agents read events in their feed and create messages based on the read events.

Reimplemented from Model.

Here is the call graph for this function:

◆ update_event_scores()

void Social_Media_no_followers::update_event_scores ( )
virtual

Goes through all events and updates media_event::score to media_event::child_size * media_event::time_stamp.

Reimplemented in Reddit.

Here is the caller graph for this function:

◆ update_feeds()

void Social_Media_no_followers::update_feeds ( float  new_events_timestamp)
virtual

Updates each user's feeds.

For each user, only feed items after the index contained in the user's corresponding element in read_count are kept in their feed. Additionally new events created in this time step are added to their feed. Events are then grouped by using Social_Media_no_followers::get_feed_priority. Events with a similar integer return from this function are grouped with any negative value return being discarded. Each group is then sorted using Social_Media_no_followers::update_event_scores. These groups are then ordered into the feed with the lowest priority values being first to be read. Finally 10% of events are randomly swapped using Social_Media_no_followers::random_event_swapping.

Parameters
new_events_timestampAny events with time stamp greater than this value are treated as new events and added to each user's feeds.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ agents

const Nodeset& Social_Media_no_followers::agents = ns_manager.get_nodeset(nodeset_names::agents)

summary>

◆ interval_time_duration

const std::string Social_Media_no_followers::interval_time_duration = "interval time duration"

summary>

◆ users

std::vector<media_user*> Social_Media_no_followers::users

The list of users.

summary>

◆ users_feed

std::vector<std::vector<media_event*> > Social_Media_no_followers::users_feed

Each user's feed of events with the first dimension corresponding to each user.

summary>