forked from tswsxk/EduData
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from tswsxk/master
v0.0.5: support graph construction and analysis
- Loading branch information
Showing
8 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# coding: utf-8 | ||
# 2019/12/12 @ tongshiwei | ||
|
||
import json | ||
from longling import wf_open | ||
from tqdm import tqdm | ||
import numpy as np | ||
|
||
|
||
def dense_graph(ku_num, tar): | ||
with wf_open(tar) as wf: | ||
for i in range(ku_num): | ||
for j in range(ku_num): | ||
if i != j: | ||
print(json.dumps([i, j]), file=wf) | ||
|
||
|
||
def _count_to_probability(count_graph): | ||
_transition_graph = np.asarray(count_graph) | ||
|
||
_transition_graph = (_transition_graph.T / _transition_graph.sum(axis=-1)).T | ||
|
||
return _transition_graph.tolist() | ||
|
||
|
||
def _output_graph(graph, tar): | ||
ku_num = len(graph) | ||
|
||
with wf_open(tar) as wf: | ||
for i in range(ku_num): | ||
for j in range(ku_num): | ||
if i != j and graph[i][j] > 0: | ||
print(json.dumps([i, j, graph[i][j]]), file=wf) | ||
|
||
|
||
def correct_transition_graph(ku_num, *src, tar): | ||
count_graph = [[0] * ku_num for _ in range(ku_num)] | ||
|
||
for filename in src: | ||
with open(filename) as f: | ||
for line in tqdm(f, "constructing transition graph"): | ||
if not line.strip(): # pragma: no cover | ||
continue | ||
seq = json.loads(line) | ||
pre_c = None | ||
for eid, r in seq: | ||
if pre_c is not None: | ||
if eid != pre_c and r == 1: | ||
count_graph[pre_c][eid] += 1 | ||
elif r == 1: | ||
# count_graph[pre_c][eid] += 1 | ||
pass | ||
if r == 1: | ||
pre_c = eid | ||
else: | ||
pre_c = None | ||
|
||
_transition_graph = _count_to_probability(count_graph) | ||
|
||
_output_graph(_transition_graph, tar) | ||
|
||
|
||
def transition_graph(ku_num, *src, tar): | ||
count_graph = [[0] * ku_num for _ in range(ku_num)] | ||
|
||
for filename in src: | ||
with open(filename) as f: | ||
for line in tqdm(f, "constructing transition graph"): | ||
if not line.strip(): # pragma: no cover | ||
continue | ||
seq = json.loads(line) | ||
pre = None | ||
for eid, _ in seq: | ||
if pre is not None: | ||
if eid != pre: | ||
count_graph[pre][eid] += 1 | ||
else: | ||
# count_graph[pre][eid] += 1 | ||
pass | ||
pre = eid | ||
|
||
_transition_graph = _count_to_probability(count_graph) | ||
_output_graph(_transition_graph, tar) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Constructing Knowledge graph | ||
|
||
## Reference | ||
[1] Piech C, Bassen J, Huang J, et al. Deep knowledge tracing[C]//Advances in neural information processing systems. 2015: 505-513. | ||
[2] Nakagawa H, Iwasawa Y, Matsuo Y. Graph-based Knowledge Tracing: Modeling Student Proficiency Using Graph Neural Network[C]//IEEE/WIC/ACM International Conference on Web Intelligence. ACM, 2019: 156-163. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# coding: utf-8 | ||
# 2019/12/13 @ tongshiwei | ||
|
||
# redirect to test_junyi.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# coding: utf-8 | ||
# 2019/12/13 @ tongshiwei | ||
|
||
# redirect to test_junyi.py |