Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Bang505 authored Mar 1, 2021
1 parent 4b5faa0 commit 0b26c29
Show file tree
Hide file tree
Showing 5 changed files with 963 additions and 892 deletions.
3 changes: 0 additions & 3 deletions attacks/attack_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ def attack0(dataset_name, attack_node_arg, cuda):
data1 = citegrh.load_pubmed()

attack_node_number = int(node_number * attack_node_arg)
print("============================================================")
print(attack_node_number)
print(type(attack_node_number))

#train target model:

Expand Down
35 changes: 30 additions & 5 deletions attacks/attack_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,28 @@ def evaluate(model, g, features, labels, mask):
def attack3(dataset_name, attack_node_arg, cuda):
#devide into two graph
# Create a graph given in the above diagram
data = citegrh.load_cora()
if dataset_name == 'cora':
node_number=2708
feature_number = 1433
label_number = 7
data = citegrh.load_cora()
data1 = citegrh.load_cora()
model_path = './models/attack_3_subgraph_shadow_model_cora_8159.pkl'
if dataset_name == 'citeseer':
node_number=3327
feature_number =3703
label_number =6
data = citegrh.load_citeseer()
data1 = citegrh.load_citeseer()
model_path = './models/attack_3_subgraph_shadow_model_citeseer_6966.pkl'
if dataset_name == 'pubmed':
node_number=19717
feature_number = 500
label_number = 3
data = citegrh.load_pubmed()
data1 = citegrh.load_pubmed()
model_path = './models/attack_3_subgraph_shadow_model_pubmed_8044.pkl'

features = data.features
labels = data.labels
train_mask = data.train_mask
Expand All @@ -95,23 +116,25 @@ def attack3(dataset_name, attack_node_arg, cuda):
g_numpy = nx.to_numpy_array(data.graph)
g_matrix = np.asmatrix(g_numpy.copy())

#Here we use a pre-devided graph with their index

sub_graph_index_b = []
fileObject = open('./data/attack3_shadow_graph/cora/target_graph_index.txt', 'r')
fileObject = open('./data/attack3_shadow_graph/' + dataset_name + '/target_graph_index.txt', 'r')
contents = fileObject.readlines()
for ip in contents:
sub_graph_index_b.append(int(ip))
fileObject.close()

sub_graph_index_a = []
fileObject = open('./data/attack3_shadow_graph/cora/protential_1300_shadow_graph_index.txt', 'r')
fileObject = open('./data/attack3_shadow_graph/' + dataset_name + '/protential_1300_shadow_graph_index.txt', 'r')
contents = fileObject.readlines()
for ip in contents:
sub_graph_index_a.append(int(ip))
fileObject.close()

#choose attack features in graphA
attack_node = []
while len(attack_node) < 70:
while len(attack_node) < attack_node_arg:
protential_node_index = random.randint(0,len(sub_graph_index_b) - 1)
protential_node = sub_graph_index_b[protential_node_index]
if protential_node not in attack_node:
Expand Down Expand Up @@ -179,7 +202,9 @@ def attack3(dataset_name, attack_node_arg, cuda):
max_acc2 = 0
max_acc3 = 0

net1.load_state_dict(th.load("./models/shadow_model_cora_8159.pkl"))
#Here we use a pre-trained model, you may replace the model with yours.

net1.load_state_dict(th.load(model_path))
#th.save(net.state_dict(), "./models/attack_3_subgraph_shadow_model_pubmed.pkl")

#for sub_graph_B
Expand Down
Loading

0 comments on commit 0b26c29

Please sign in to comment.