5. twied.labelprop — SLP Inference Method

Warning

While the method is implemented it is not suggested for use without further work.

This is an implementation of the SLP location inference method.

5.1. Geometric Mean

This is an implementation of the geometric mean function.

twied.labelprop.distance.geometric_mean(points)[source]

Function which calculates the geometric mean from a list of points using the vincenty distance.

Parameters:points – List of points to find the geometric mean of.
Returns:The geometric mean of the points.

5.2. SLP Inference

This is a class which will infer user location using the SLP method.

class twied.labelprop.inference.InferSL(config, dbcollection, verbose=False)[source]

Implementation of the spatial label propagation method for infering the location of Twitter users. Generates the network around a specific user in order to locate.

Setup a InferSL instance.

Parameters:
  • config – The configuration to be used.
  • dbcollection – The MongoDB collection to connect with.
  • verbose – Boolean if to output log.
get_connections(user, network, depth=0)[source]

Recursively gets the connections around a user until at least one with enough geotags has been found.

Parameters:
  • user – The user object to continue inferring from.
  • network – An SLNetwork object containing the network.
  • depth – The depth of the recursion (default 0)
Returns:

Boolean of if the network was attempted to be extended.

get_location(netw)[source]

Infers the location of a user from a network.

Parameters:netw – An SLNetwork object
Returns:[coordinate, geodis] tuple
get_network(user_id, hidegeo=False)[source]

Gets the network surronding a user.

Parameters:user_id – The Twitter ID of the user.
Returns:An SLNetwork object with the network information.
get_user(user_id)[source]

Gets a user profile from the Twitter API and stores their geotag tweets and mentions.

Parameters:user_id – The Twitter ID of the user to find.
Returns:The data for the Twitter user with that ID.
infer(user_id, test=False)[source]

Infers a location for a user with an ID.

Parameters:user_id – The Twitter ID of the user.
Returns:[coordinate, geodis] tuple
log(message)[source]

Logs a message to the console is verbose was true in initialisation.

Parameters:message – The message to log.
class twied.labelprop.inference.SLNetwork[source]

Stores information about the users and connections in a network.