Repository navigation
Expand file tree
/
Copy pathRandomUploadByParticipant.lua
More file actions
107 lines (79 loc) · 2.68 KB
/
Copy pathRandomUploadByParticipant.lua
File metadata and controls
107 lines (79 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--[[RandomUploadByParticipant
Main file that conducts several rounds over all partcipants in which particpants are randomly chosen to interact with the server.
1- has multiple rounds
2- each round iterates over all the participants and randomly chooses which of the participants will interact with the server. The chosen particpants will train, upload and download to and from the server over multiples epoch
3-At the end of the round, we will print the result of the confusion matrix of the Reference User and how many participants interacted with ther Server.
--]]
--[[
Gameplan : 1-
--]]
require 'nn'
require 'torch'
require 'dataset-mnist'
require 'image'
require 'optim'
require 'Helper'
--Basic Parameters
batchSize= 10
learningRate=0.01
weightDecay=1e-7
NumParticipant=20
NumRefUser =10
theta_u_perc=0.1
epoch=20
torch.manualSeed(46)
-- log results to files
trainLogger = optim.Logger(paths.concat("logs", 'train.log'))
testLogger = optim.Logger(paths.concat("logs", 'test.log'))
RefUserLogger=optim.Logger(paths.concat("logs",'RefUserLogger.log'))
ServerLogger=optim.Logger(paths.concat("logs",'ServerLogger.log'))
--model design
classes = {'1','2','3','4','5','6','7','8','9','10'}
geometry = {32,32}
-- log results to files
trainLogger = optim.Logger(paths.concat("logs", 'train.log'))
testLogger = optim.Logger(paths.concat("logs", 'test.log'))
--loss Criterion
criterion=nn.ClassNLLCriterion()
--Dataset- MNIST
nbTrainingPatches = 600
nbTestingPatches = 10000
-- Confusion Matrix
confusion = optim.ConfusionMatrix(classes)
-- create test sets and normalize
testData = mnist.loadTestSet(nbTestingPatches, geometry)
testData:normalizeGlobal(mean, std)
ReferenceUserTrainData = mnist.loadTrainSet(60, geometry, 4550)
ReferenceUserTrainData:normalizeGlobal(mean, std)
--Creating NN table
--creating multiple NN using for loop
Server=CreateNN()
Sparams, SgradParams=Server:getParameters()
NeuralNet={}
ReferenceUser={}
for i = 1,NumRefUser do
ReferenceUser[i]=CreateNN()
end
for i = 1,NumParticipant do
NeuralNet[i]=CreateNN()
end
for round=1, NumRefUser do
ParticipantInteractionPerRound=0
for k=1, NumParticipant do
randNum=torch.uniform()
if randNum>0.5 then
ParticipantInteractionPerRound=ParticipantInteractionPerRound+1
print("=====Participant: "..k .." Selected. RandNum: "..randNum)
helper.DriverTrain(NeuralNet[k], k)
else print("=====Participant: "..k .." Rejected. RandNum: "..randNum)
end
end
print("=======Completed Round: " ..round)
print("Participant Interaction: "..ParticipantInteractionPerRound)
helper.ReferenceUserDriver(ReferenceUser[round])
end
--plotting to file
--Initializing everything to zero
epoch=1
Sparams:zero()
SgradParams:zero()