Metadata-Version: 2.1
Name: colocationship
Version: 0.0.1
Summary: A light package for build and analyse co-locationship
Home-page: https://github.com/Magica-Chen/co-locationship
Author: Zexun Chen
Author-email: sxtpy2010@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown

# co-locationship

"Co-locationship" as an Alternative to Social Ties in Predictability of Human Mobility.

The code was tested on Python 3.6.

## Install

The dependencies package are shown in `requirements.txt`, also, you can run 

```
pip install -r requirements.txt
```

After installing all dependencies clone the repository and do (inside the top directory):

```
pip install . 
```

This will install a copy of the code as a package. If you want to install a package that links to the cloned code, run

```
pip install --editable .
```

This makes changes to the source files in the cloned directory immediately available to everything that imports the package.

Anywhere on the system you can then import the package:

```python
import colocationship as cl
```

## Dataset

All processed datasets (Weeplaces, BrightKite, Gowalla) we used in this repo can be found in [Google Drive](https://drive.google.com/drive/folders/1C71Atf4x7eTAEazAPehih5_zkBqqfX4M?usp=sharing).

## Usage

### Build a Co-Locationship Network

```python
df_checkin = pd.read_csv("../dataset/weeplace_checkins.csv")
co_locationship = cl.Co_Locationship(df_checkin,
                                     mins_records=150,
                                     missing='-')
# generate placeid sequence
co_locationship()

# calculate basic information of co-locationship network
co_locationship.calculate_info()

# network filter, including minimum both quality control and contribution control, and minimum 10 alters requirement and ranking.
co_locationship.network_control(quality=True, 
                                contribution=True, 
                                num_alters=10, 
                                by=['userid_x', 
                                    'meetup',
                                    'N_previous'], 
                                ascending=[True, 
                                           False, 
                                           True],
                                N_previous=150)

# calculate details of co-locationship network, including cumulative cross-entropy and cumulative cross-predictability
co_locationship.calculate_network(verbose=False, filesave=True)
```

The code in `Line 6`, `Line 9`, `Line 24` may takes a long time, so it is better to run them separately, and save these interim results.

### Social relationship network

The similar code for social relationship, just slight differences.

```Python
df_friend = pd.read_csv("../dataset/weeplace_friends.csv")
social_relationship = cl.Social_Relationship(df_checkin,
                                             df_friend,mins_records=150,
                                             missing='-')

# given the same time unit, we can just the placeid sequence generated by co-locationship, otherwise, also run `social_relationship()` to generate placeid sequence again.
social_relationship.placeidT = placeidT

social_relationship.calculate_info()

srn_filtered = social_relationship.network_control(
                                contribution=True, 
                                num_alters=10, 
                                by=['userid_x', 
                                    'meetup',
                                    'N_previous'], 
                                ascending=[True, 
                                           False, 
                                           True],
                                N_previous=150,
                                freq='H')
# calculate details of co-locationship network, including cumulative cross-entropy and cumulative cross-predictability
social_relationship.calculate_network(verbose=False, filesave=True)
```

Similarly, the code in  `Line 9`, `Line 23` may takes a long time, so it is better to run them separately, and save these interim results.

### Comparison of co-locationship and social relationship

```python
# Create a comparsion class to compare these two networks
compare_v2 = cl.ComparisonNetwork([co_locationship,
                                   social_relationship],
                                  ['co-locationship',
                                   'social relationship'])

# print the number of shared users in both networks
compare_v2()

# Histogram plot comparison
compare_v2.plot_CE(l=8,w=5)

# RCCP comparison based on ranking
compare_v2.plot_errorbar(target='RCCP', l=8,w=5)

# Local similarity comparison
compare_v2.plot_similarity(local=True, l=5,w=5)

# Global similarity comparison
compare_v2.plot_similarity(local=False, l=5,w=4)

# Monotonicity statistical test
compare_v2.stats_test_monotonicity(target='RCCP')

# Consistency statistical test
consistency_test = compare_v2.stats_test_consistency(target='RCCP')
```

### Details

Details please refer to `example/example_weeplaces.ipynb`.

## Contributing

PRs accepted.

## License

MIT © Zexun Chen

