Construct version 5.4.4
An agent based modeling framework
|
An interaction model which recreates a social media feed to dictate interactions. More...
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... | |
virtual 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. More... | |
virtual 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_events. More... | |
virtual 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_events. More... | |
virtual media_event * | create_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... | |
virtual media_event * | create_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... | |
virtual void | finalize_event (media_event *_event) |
Allows each model to intercept the created event. 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_user & | user (unsigned int index) |
Social_Media_no_followers (const std::string &_media_name, InteractionItem::item_keys event_key, const dynet::ParameterMap ¶meters, 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 media_user * | get_default_media_user (const Node &node) |
Gets the default media user for a social media class. More... | |
void | think (void) override |
Agents read events in their feed and create messages based on the read events. More... | |
void | initialize (void) override |
Loads users using Social_Media_no_followers::load_user and adds 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 bool | intercept (InteractionItem &item, unsigned int sender, unsigned int receiver, const CommunicationMedium *medium) |
Allows for models to effect change to items created by other models. 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 | |
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 Nodeset & | agents = ns_manager.get_nodeset(nodeset_names::agents) |
const Nodeset & | knowledge = ns_manager.get_nodeset(nodeset_names::knowledge) |
const 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; } |
std::function< void(Social_Media_no_followers *, unsigned int)> | feed_update_output |
std::function< void(Social_Media_no_followers *)> | cleanup_output |
Public Attributes inherited from Model | |
Construct & | construct |
GraphManager & | graph_manager |
NodesetManager & | ns_manager |
Random & | random |
bool | valid |
If member is false, the model's functions are not called. | |
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 by replacing Social_Media_no_followers::load_user.
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.
_media_name | The 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. |
parameters | A parameter map that should contain the keys "interval time duration" and "maximum post inactivity" as floats. |
_construct | The construct pointer that is passed to the Model constructor. |
event_key | The item key that the social media uses to identify an InteractionItem that contains one of its feed indexes. |
|
virtual |
Appends the array of InteractionItems based on the submitted event and the intended receiver of the message.
summary> Gathers the set of events that an agent should read based on what event they just read.
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>
|
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.
|
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.
|
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.
Reimplemented in SM_nf_emotions, and SM_wf_emotions.
|
inlinevirtual |
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.
knowledge_index | Uses InteractionItem::set_knowledge_item to set the knowledge index of the event. |
id | Agent index of the event's author. |
Example
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.
|
inlinevirtual |
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.
parent | Pointer to the parent event for this response. |
id | Agent index of the event's author. |
Example
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.
|
inlinevirtual |
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.
parent | Pointer to the parent event for this response. |
id | Agent index of the event's author. |
Example
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.
|
inlinevirtual |
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.
parent | Pointer to the parent event for this response. |
id | Agent index of the event's author. |
Example
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.
|
inlinevirtual |
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.
parent | Pointer to the parent event for this response. |
id | Agent index of the event's author. |
Example
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.
Reimplemented in Reddit.
|
inlinevirtual |
Allows each model to intercept the created event.
Models may add, remove, or modify content in the event or completely stop its creation all together. This function should be called on every event created after the event has been populated with information. By default, this function is called at the end of Social_Media_no_followers::default_media_user::enrich_event.
|
inlinevirtual |
Gets the default media user for a social media class.
Reimplemented in SM_nf_emotions, SM_wf_emotions, Reddit, and Social_Media_with_followers.
|
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.
|
overridevirtual |
Loads users using Social_Media_no_followers::load_user and adds Knowledge_Parser to Construct::message_parsers if one is not present.
Reimplemented from Model.
Reimplemented in Facebook_wf, and Twitter_wf.
|
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.
fname | Name of the json file to be loaded and may contain the full path to the file. |
start_time | The time that corresponds to the initialization time step which is one time step before time node at index 0. |
time_conversion | The 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_mask | An 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.
|
virtual |
Randomly swaps 10% of events in the user's feed.
Reimplemented in Reddit.
|
overridevirtual |
Agents read events in their feed and create messages based on the read events.
Reimplemented from Model.
|
virtual |
Goes through all events and updates media_event::score to media_event::child_size * media_event::time_stamp.
Reimplemented in Reddit.
|
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.
new_events_timestamp | Any events with time stamp greater than this value are treated as new events and added to each user's feeds. |
const Nodeset& Social_Media_no_followers::agents = ns_manager.get_nodeset(nodeset_names::agents) |
summary>
std::vector<media_user*> Social_Media_no_followers::users |
The list of users.
summary>
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>