Commit 5827d494 authored by Malik Koné's avatar Malik Koné
Browse files

actualisation cycles.ipynb

parent b8b1a88c
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -12,26 +12,38 @@
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
},
{
"data": {
"text/plain": [
"'3.5.2 (default, Nov 12 2018, 13:43:14) \\n[GCC 5.4.0 20160609]'"
]
},
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Tested with Python 3.52\n",
"#-*-coding:utf-8-*-\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"#Works with Python 3.52\n",
"import os\n",
"os.sys.version"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -61,7 +73,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 4,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -73,8 +85,8 @@
"outputs": [],
"source": [
"CRS_NAMES = ['villes-africaines', 'python-machine-learning', 'python-plotting']\n",
"COURSE_NAME = CRS_NAMES[2]\n",
"BKF_REP = './Data/%s-forum.mydb' % COURSE_NAME\n",
"COURSE_NAME = CRS_NAMES[1]\n",
"BKF_REP = './Database/%s-forum.mydb' % COURSE_NAME\n",
"\n",
"# loading and formating the data\n",
"erep = ExpandedReplies(fn=BKF_REP)\n",
......@@ -92,7 +104,144 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 5,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
"ein.tags": "worksheet-0",
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>p_id</th>\n",
" <th>p_text</th>\n",
" <th>author_id</th>\n",
" <th>p_type</th>\n",
" <th>p_title</th>\n",
" <th>p_comment</th>\n",
" <th>p_upvote</th>\n",
" <th>full_names</th>\n",
" <th>roles</th>\n",
" <th>forum_names</th>\n",
" <th>extras</th>\n",
" <th>uid</th>\n",
" <th>rolesid</th>\n",
" <th>tid</th>\n",
" <th>rid</th>\n",
" <th>cid</th>\n",
" <th>p_typeid</th>\n",
" <th>humanized_dates</th>\n",
" <th>age</th>\n",
" <th>fid</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>dsPknEY1EeeUFw7lmNnFrg</td>\n",
" <td>I am presuming this course is in Python 3? I'v...</td>\n",
" <td>9bb0bc1d31d1b90db50a2ac701a51879</td>\n",
" <td>thread_starter</td>\n",
" <td>Python 3.x</td>\n",
" <td>nan</td>\n",
" <td>0</td>\n",
" <td>Max Russell</td>\n",
" <td>NaN</td>\n",
" <td>Week 1</td>\n",
" <td>NaN</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0</td>\n",
" <td>8 months ago</td>\n",
" <td>20736000</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>dsPknEY1EeeUFw7lmNnFrg/replies/KNqdRkaQEeejWg7...</td>\n",
" <td>We are using python 3.5. The main libraries re...</td>\n",
" <td>ac9ba679ef8c933da9a07dfc17bc3e7d</td>\n",
" <td>reply</td>\n",
" <td>nan</td>\n",
" <td>Hide 1 Reply</td>\n",
" <td>0</td>\n",
" <td>Zijian Wang</td>\n",
" <td>Teaching Staff</td>\n",
" <td>Week 1</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" <td>8 months ago</td>\n",
" <td>20736000</td>\n",
" <td>5</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" p_id \\\n",
"0 dsPknEY1EeeUFw7lmNnFrg \n",
"1 dsPknEY1EeeUFw7lmNnFrg/replies/KNqdRkaQEeejWg7... \n",
"\n",
" p_text \\\n",
"0 I am presuming this course is in Python 3? I'v... \n",
"1 We are using python 3.5. The main libraries re... \n",
"\n",
" author_id p_type p_title p_comment \\\n",
"0 9bb0bc1d31d1b90db50a2ac701a51879 thread_starter Python 3.x nan \n",
"1 ac9ba679ef8c933da9a07dfc17bc3e7d reply nan Hide 1 Reply \n",
"\n",
" p_upvote full_names roles forum_names extras uid rolesid \\\n",
"0 0 Max Russell NaN Week 1 NaN 0 0 \n",
"1 0 Zijian Wang Teaching Staff Week 1 NaN 1 1 \n",
"\n",
" tid rid cid p_typeid humanized_dates age fid \n",
"0 0 NaN NaN 0 8 months ago 20736000 5 \n",
"1 0 0.0 NaN 1 8 months ago 20736000 5 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"erdf.head(2)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -169,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 6,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -236,7 +385,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 7,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -289,7 +438,23 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 8,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
"ein.tags": "worksheet-0",
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"source": [
"# penser à ajouter les lien en face des postids... dans un df et le vertex aussi"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -303,7 +468,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Group: 863/864, lien (2, 3)/5/25\r"
"Group: 1130/1132, lien (0, 3)/7/17\r"
]
}
],
......@@ -325,7 +490,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 9,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -395,7 +560,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": null,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -404,22 +569,33 @@
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/plain": [
"<PropertyMap object with key type 'Vertex' and value type 'vector<double>', for Graph 0x7f4a98cf7320, at 0x7f4a987496a0>"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"#g.clear_filters()\n",
"# #### init blockmodel\n",
"\n",
"g.clear_filters()\n",
"# state = gti.minimize_blockmodel_dl(g, B_max=10)\n",
"\n",
"#state.candidate_pos\n",
"state.draw(output=\"img/test.png\")\n",
"gtd.draw_hierarchy(state, output=\"test\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
"ein.tags": "worksheet-0",
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"source": [
"# #### DRAW\n",
"fname = \"forum_sfdp-staff-%s-%s\" % (method, parallel)\n",
"def draw(g, pos, fname=None, init_view=None):\n",
" if init_view is None:\n",
" X = [pos[v][0] for v in g.vertices()]\n",
......@@ -441,7 +617,7 @@
" edge_color = g.ep['color']\n",
" edge_size = gtd.prop_to_size(g.ep.weight, mi=0, ma=1, log=False, power=4)\n",
" fit_view = True\n",
" output = fname\n",
" output = \"./img/%s.png\" % fname\n",
" output_size = (5000, 5000)\n",
" vcmap = plt.get_cmap('viridis')\n",
" vertex_fill_color = \"black\"\n",
......@@ -469,17 +645,14 @@
" vertex_font_size=vertex_font_size,\n",
" )\n",
"\n",
"imgdir = \"./Images\"\n",
"fname = \"%s/forum_sfdp-staff-%s-%s.png\" % (imgdir,method, parallel)\n",
"\n",
"draw(g, pos, fname)\n",
"# uncomment for backup\n",
"# g.save(\"./%s.xml.gz\" % fname) # xml same as graphml"
"g.save(\"./bkups/%s.xml.gz\" % fname) # xml same as graphml"
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 11,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -496,7 +669,7 @@
" 3.15360000e+07])"
]
},
"execution_count": 25,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
......@@ -522,7 +695,21 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 12,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
"ein.tags": "worksheet-0",
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -541,7 +728,7 @@
" Timestamp('2017-02-05 00:00:00')]"
]
},
"execution_count": 26,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
......@@ -566,7 +753,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 14,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
......@@ -606,14 +793,132 @@
" deg = g.degree_property_map('total')\n",
" g.vp.filtre.a = list(map(lambda v: deg[v] != 0, g.vertices()))\n",
" g.set_vertex_filter(g.vp.filtre)\n",
" fname = \"%s/forum_sfdp_%s_%s_%s.png\" % (imgdir, method, parallel, i, )\n",
" fname = \"forum_sfdp_%s_%s_%s\" % (method, parallel, i, )\n",
" if sum(g.vp.filtre.a) > 0:\n",
" draw(g, pos, fname='%s' % fname, init_view=init_view)\n",
" draw(g, pos, fname='sequence/%s' % fname, init_view=init_view)\n",
"\n",
" print(\"%s/%s\" % (i,len(age_bins)), end=\"\\r\")\n",
"\n",
"# file_0 c'est la plus récente, "
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"autoscroll": false,
"ein.hycell": false,
"ein.tags": "worksheet-0",
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Thanks very much, I'll try it again! \n",
">>>>\n",
"\n",
"@Sophie\n",
"Thanks, and the link is:\n",
"[3 reviews received, link removed to comply with honour code] \n",
">>>>\n",
"\n",
"@Sophie\n",
"Yes, *.1 does works.\n",
"And I have another problem in My uploading assignment, That's when I upload My file, it reminded me successful, but when I submited after I can't see if My graph and code.So I'm not sure whether when other learners preview My assignment it's as the same as My imaging.\n",
"I guess the reason why is My networking?If it's ok,please help me.\n",
"Best. \n",
">>>>\n",
"\n",
"@Beveridge\n",
"The same problem as you, the needed memory of df /= 10is too large,so the online kernel cannot work out but in offline notebook it's ok.\n",
"And for me i use A for loop to solve it as:\n",
"for item in df:\n",
"item /= 10\n",
"it's ok.\n",
"may helps. \n",
">>>>\n",
"\n",
"Yes, there is.And the following steps can help you to finish it:\n",
"1.Use range('2015-01-01',...,'2016-0101', dtype=datetime64[D]) just as the teacher did in the lecture, which is A array contianing 365days.\n",
"2.Then you can Use it as the x values to plot.the graph, and then with some manipulates you can make it to the form of 'Jan,Feb,etc'.\n",
"3.And then just fellow the url, there A good example for you:\n",
"http://matplotlib.org/examples/pylab_examples/centered_ticklabels.html \n",
">>>>\n",
"\n",
"Hi, Julian, I have reviewed yours, please review mine too.\n",
"HC EDIT \n",
">>>>\n",
"\n",
"Hi, for me i saved the code as txt file, for which it's better to copy and paste into the noline notebook.\n",
"May it helps. \n",
">>>>\n",
"\n",
"Come on, guy. At the first I had the same thought as you: the assignment is too difficult.btw now I have finished it through the whole 3 days' struggling.And what i want to say there are many useful ways to implement:\n",
"1.look though the disscussion which you have same problem with.\n",
"2.search in the stackoverflow, it's really useful.\n",
"3.In the notebook use the help() and dir() function to see the property of the things.\n",
"4.And the most import thing: you should have your own whole thinking traces.\n",
"wish you go throuth it. \n",
">>>>\n",
"\n",
"Hi Yuwon.\n",
"I'm the same case as you and then I graded Your assignment.Further if it's ok please grade for me too.By the way maybe we should report the issue to the stuff.\n",
"HC edit \n",
">>>>\n",
"\n",
"Hi Devashish.\n",
"you can download the dataset by below steps:\n",
"1.open the online assignment2 jupyter notebook.\n",
"2.cilick :file->open,then you will.in the home of the online system then there is A data folder in the category,click in and find out Your data and open to download it by using the url you just mentioned.\n",
"May it helps. \n",
">>>>\n",
"\n",
"Hi Amanda.\n",
"I think you can get help from the url:\n",
"https://www.coursera.org/learn/python-plotting/discussions/weeks/2/threads/Ke3pOA0DEeeQeQo2lD9-LA \n",
">>>>\n",
"\n",
"Hi Sachin.\n",
"In this point,you can implement it by below steps:\n",
"1.Use A for loop to iterate the value in the array and then Use A if expression to campare the value of 2015 and 2005-2014,if beyond set the value to np.nan.\n",
"2.Ps. in this position you should pay attention to the np.nan,it's A special float value, That's to say before you set the 2015 array to np.nan you should firat Use .astype() method to translate it to float form. \n",
">>>>\n",
"\n",
"Hi Sachin.\n",
"As what you say I think you can implement by first creating A total new dataframe and add columns into it one by one.\n",
"But in fact, it needn't.You can assign the value in the single column to a new variable separately such as y_max_2015,y_min_2015,etc.and then you can use them to plot. \n",
">>>>\n",
"\n",
"Hello, for me I think Your code is to complicated to watch out where is not good, but I can show My implement custom code:\n",
"1.df['m_d'] = df['date'].map( lambda x: x.strftime('%m-%d')\n",
"That's to.say you may Use map function to insure it morks for every element in the column.\n",
"2.\n",
"df['max'] = df[df['Element']]=='TAMX'\n",
"df_grouped = df['max'].groupby(['m_d']).max()\n",
"That's to say you may Use the groupby method.in A wrong way.\n",
"May it helps. \n",
">>>>\n",
"\n",
"Share my analysis of Visualization Wheel Practice.\n",
"https://mooctools.ai.umich.edu/multimeasure/424-visualization-wheel-practice/71-washington-metro-map/0b8817d72cdf2f981f16e943347d1d82f96f8dba/ \n",
">>>>\n",
"\n",
"Here is the link.\n",
"https://www.coursera.org/learn/python-plotting/peer/KOk5G/graphics-lies-misleading-visuals/review/5SfGJ_ipEeenDhK11AXZ-A\n",
"Welcome your any suggestion. \n",
">>>>\n",
"\n"
]
}
],
"source": [
"for p in erdf[erdf.full_names.str.contains('Shuang')].sort_values(by='age', ascending=False).p_text:\n",
" print(\"%s \\n>>>>\\n\" % p)"
]
}
],
"metadata": {
......
%% Cell type:code id: tags:
``` python
#Tested with Python 3.52
#-*-coding:utf-8-*-
%load_ext autoreload
%autoreload 2
#Works with Python 3.52
import os
os.sys.version
```
%%%% Output: stream
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
%%%% Output: execute_result
'3.5.2 (default, Nov 12 2018, 13:43:14) \n[GCC 5.4.0 20160609]'
%% Cell type:code id: tags:
``` python
import graph_tool as gt
import pandas as pd
import graph_tool.draw as gtd
import matplotlib.pyplot as plt
from mlkdataprep import Replies, ExpandedReplies
import numpy as np
# obsoletes imports
#import graph_tool.centrality as gtc
#import graph_tool.generation as gtg
#import graph_tool.inference as gti
#import graph_tool.topology as gtt
#from matplotlib import cm
#import func4graph as fg
```
%% Cell type:code id: tags:
``` python
CRS_NAMES = ['villes-africaines', 'python-machine-learning', 'python-plotting']
COURSE_NAME = CRS_NAMES[2]
BKF_REP = './Data/%s-forum.mydb' % COURSE_NAME
COURSE_NAME = CRS_NAMES[1]
BKF_REP = './Database/%s-forum.mydb' % COURSE_NAME
# loading and formating the data
erep = ExpandedReplies(fn=BKF_REP)
erdf = erep.df
# ~~~~#### REPLY GROUPS ####~~~~
# grouping the messages per threads dans RGS ie.REPLY GROUPS
gkeys = erdf.p_id.apply(lambda x: x.split('/')[0])
RGS = erdf.groupby(gkeys, as_index=False)
# also group the messages per users
UGS = erdf.groupby("author_id")
```
%% Cell type:code id: tags:
``` python
erdf.head(2)
```
%%%% Output: execute_result
p_id \
0 dsPknEY1EeeUFw7lmNnFrg
1 dsPknEY1EeeUFw7lmNnFrg/replies/KNqdRkaQEeejWg7...
p_text \
0 I am presuming this course is in Python 3? I'v...
1 We are using python 3.5. The main libraries re...
author_id p_type p_title p_comment \
0 9bb0bc1d31d1b90db50a2ac701a51879 thread_starter Python 3.x nan
1 ac9ba679ef8c933da9a07dfc17bc3e7d reply nan Hide 1 Reply
p_upvote full_names roles forum_names extras uid rolesid \
0 0 Max Russell NaN Week 1 NaN 0 0
1 0 Zijian Wang Teaching Staff Week 1 NaN 1 1
tid rid cid p_typeid humanized_dates age fid
0 0 NaN NaN 0 8 months ago 20736000 5
1 0 0.0 NaN 1 8 months ago 20736000 5
%% Cell type:code id: tags:
``` python
# #### L'ajout des liens (lignes) dans un thread
def cree_liens_pour_group(g, thread, users, rank, nb_groups, parallel=True, how='star'):
"""Adding links between users of the same thread.
- g is the graphe where the links are added
- thread is a group of message from the same thread
- users are the users ids from the network
- nb_groups is the number of threads in the network
- parallel: (True) if parallel edge should be created or not
- how: (star), prec, prec1, all, specify how to link users. see create_or_udpate_edge_in_
"""
# nombre de messages != nb d'utilisateurs dans cette discussion
nb_msg = len(thread)
# on loop sur les participants du group dans l'ordre du group
for (i, ui) in enumerate(thread.author_id):
# vertex id. On la récupère à l'aide de ui et users qui renvois le numero du noeud (nid)
vi = g.vertex(users.index(ui))
g.vp['age'][vi] = max(g.vp['age'][vi], thread.age.iloc[i])
# thread starteur que si i == 0, pour ce group
g.vp['thread_starter'][vi] += 1 if i == 0 else 0
for (j, uj) in enumerate(thread.author_id):
vj = g.vertex(users.index(uj))
edge_creation, seuil = create_or_update_edge_in_(thread, g, vi, vj, i, j, parallel, how=how)
if edge_creation and seuil:
p_type = thread.iloc[j].p_type
if p_type == 'reply':
g.vp['replies'][vi] += 1
elif p_type == 'reply_comment':
g.vp['comments'][vi] += 1
if edge_creation == "create":
# de j vers i (dans le sens de l'action) 'h' donne une info à 'i'
e = g.add_edge(vj, vi)
g.ep['weight'][e] = seuil
g.ep['age'][e] = thread.age.iloc[j]
g.ep["ptype"][e] = {'thread_starter': 'circle',
'reply_comment': 'arrow',
'reply': None}[p_type]
g.ep['upvote'][e] = thread.p_upvote.iloc[j]
g.ep['postid'][e] = thread.p_id.iloc[j]
g.ep['fid'][e] = thread.fid.iloc[j]
g.ep['tid'][e] = thread.tid.iloc[j]
# g.ep['color'][e] = TID_AGED_COLOR_MAP[thread.tid.iloc[j]]
g.ep['rid'][e] = thread.rid.iloc[j]
elif edge_creation == "update":
e = g.edge(vj, vi)
g.ep['age'][e] = np.min([thread.age.iloc[j], g.ep['age'][e]])
g.ep['weight'][e] += seuil
print('Group: %s/%s, lien (%s, %s)/%s' % (rank, nb_groups, i, j, nb_msg), end='\r')
```
%% Cell type:code id: tags:
``` python
def create_or_update_edge_in_(thread, g, vi, vj, i, j, parallel, how):
""" Dit si il faut créer un lien ou non entre deux sommets et renvois la force de ce lien.
- thread: un ensemble de message d'un même thread
- g le graph
- vi, vj, le sommet source, le sommet cible
- i, j les indices des sommet dans la list des messages thread
- parallel: faut-il créer des lien parallèle
- how: la façon de créer les lien (voir compute_strength)
"""
time_direction = i < j
no_self_edge = vi != vj
vi_in_vj_out_neighbourhood = vi in g.get_out_neighbours(vj)
no_staffs_nor_mentors = not (g.vp['staff_or_mentor'][vi] or g.vp['staff_or_mentor'][vj])
if time_direction and no_self_edge and no_staffs_nor_mentors:
seuil = compute_strength(thread, i, j, how)
if parallel or not vi_in_vj_out_neighbourhood:
return ("create", seuil)
else:
# dans voisin et non parallel
return ("update", seuil)
return (False, 0)
def compute_strength(thread, i, j, how):
"""Compute the strength between the ith an jth repliers in thread tid. this is were content evaluation would by taken in account
- how: prec: link to all preceding node in the thread, with strength depending on distance from linker
prec1 link to the last preceding node in the thread,
prec3: link to the last three preceding node in the thread
star: link only to the thread starter
all: link all previous user,
- prec1"""
strength = 0
# j est > i, max 54
if how == "precall":
strength = 1 / np.log(j - i + 1) # on ne peut avoir i = j
elif how == "prec1":
strength = 1 if j - i == 1 else 0
elif how == "prec3":
strength = 1 / np.log(j - i + 1) if j - i <= 3 else 0
elif how == "star":
strength = 1 if i == 0 else 0
elif how == "all":
strength = 1
else:
raise Exception("Choisissez un type de connexion valide")
return float(strength)
```
%% Cell type:code id: tags:
``` python
# ### SETTING UP THE GRAPH ####
IDS = erep.get_ids()
g = gt.Graph()
g.add_vertex(len(IDS['users']))
# ### SETTING UP VERTICES ####
# internal vertices properties
g.vertex_properties["names"] = g.new_vertex_property("string")
g.vertex_properties["staff_or_mentor"] = g.new_vertex_property("bool")
g.vertex_properties["role"] = g.new_vertex_property("int")
# Prefill those vertices properties
for (i, ui) in enumerate(IDS['users']):
vi = g.vertex(i)
g.vp['names'][vi] = erep.get_uname_from_uid(ui).split(' ')[0][:7]
g.vp['staff_or_mentor'][vi] = True if ui in IDS['staffs_n_mentors'] else False
g.vp['role'][vi] = UGS.get_group(ui).rolesid.iloc[0]
g.vertex_properties["groups"] = g.new_vertex_property("vector<int>")
g.vertex_properties["thread_starter"] = g.new_vertex_property("float")
g.vertex_properties["replies"] = g.new_vertex_property("float")
g.vertex_properties["comments"] = g.new_vertex_property("float")
g.vertex_properties["age"] = g.new_vertex_property("float")
g.vertex_properties['color'] = g.new_vertex_property("vector<float>")
# #### SETTING UP EDGES ####
g.edge_properties['upvote'] = g.new_edge_property("float")
g.edge_properties['ptype'] = g.new_edge_property("string")
g.edge_properties['postid'] = g.new_edge_property("string")
g.edge_properties['age'] = g.new_edge_property("float")
g.edge_properties['weight'] = g.new_edge_property('float')
g.edge_properties['fid'] = g.new_edge_property('float') # forum id
g.edge_properties['tid'] = g.new_edge_property('float')
g.edge_properties['rid'] = g.new_edge_property('float')
g.edge_properties['color'] = g.new_edge_property("vector<float>")
```
%% Cell type:code id: tags: