Skip to content

Commit

Permalink
independent_test
Browse files Browse the repository at this point in the history
  • Loading branch information
guang1220 committed May 31, 2022
1 parent 18a23dc commit f4df754
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions fl_code/#svm/basic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# Desc: ALL Client

sub_path=lib/python3.7/site-packages/flwr/common/parameter.py
root_path=`which python | sed 's@/bin/python@/@g'`
path=$root_path$sub_path
sed -r -i '28s/#+tensors/tensors/g' $path
sed -i '29s/tensors/#tensors/g' $path

file_name=server_IP
client_num=$1

port=8080

if [ ! -d ./log/all/ ]; then
mkdir -p ./log/all/
fi
rm -f ./log/all/*
[ -f ./$file_name ] && rm -f $file_name

while true; do
ss -tlnp | grep $port > /dev/null
if [ $? -eq 0 ]; then
let port++
else
break
fi
done

nohup python svm_server.py $port $client_num >./log/all/server.log 2>&1 &
if [ $? -eq 0 ]; then
echo "submit svm_server $port"
else
echo "submit svm_server error" && exit
fi

count=0
while [ ! -f ./$file_name ] && (($count < 10)); do
sleep 6
let count++
done

(($count >= 10)) && echo "no find $file_name" && exit

for ((i = 0; i <= $client_num - 1; i++)); do
nohup python svm_client.py $i -1 >./log/all/client$i.log 2>&1 &
if [ $? -eq 0 ]; then
echo "submit svm_client $i"
else
echo "submit svm_client $i error" && exit
fi
done

echo "all task submitted"
62 changes: 62 additions & 0 deletions fl_code/#svm/contribution_assessment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
# Desc: ALL Client

sub_path=lib/python3.7/site-packages/flwr/common/parameter.py
root_path=`which python | sed 's@/bin/python@/@g'`
path=$root_path$sub_path
sed -r -i '28s/#+tensors/tensors/g' $path
sed -i '29s/tensors/#tensors/g' $path

file_name=server_IP
client_num=$1

port=8080
[ -f ./$file_name ] && rm -f $file_name

for ((i = 0; i < $client_num; i++)); do

if [ ! -d ./log/lack_$i/ ]; then
mkdir -p ./log/lack_$i/
fi
rm -f ./log/lack_$i/*

while true; do
ss -tlnp | grep $port > /dev/null
if [ $? -eq 0 ]; then
let port++
else
break
fi
done

nohup python svm_server.py $port $(($client_num - 1)) >./log/lack_$i/server.log 2>&1 &
if [ $? -eq 0 ]; then
echo "submit svm_server $port"
else
echo "submit svm_server error" && exit
fi

count=0
while [ ! -f ./$file_name ] && (($count < 10)); do
sleep 6
let count++
done

(($count >= 10)) && echo "no find $file_name" && exit

for ((j = 0; j <= $(($client_num - 1)); j++)); do
[ $j -eq $i ] && continue
nohup python svm_client.py $j $i >./log/lack_$i/client$j.log 2>&1 &
if [ $? -eq 0 ]; then
echo "submit svm_client $j"
else
echo "submit svm_client $j error" && exit
fi
done

echo "lack $i _client Contribution assessment task submitted"
sleep 10

done

echo "all task submitted"
File renamed without changes.
2 changes: 1 addition & 1 deletion fl_code/svm/svm_client.py → fl_code/#svm/svm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ def evaluate(self, parameters, config):
model = SVC(kernel="linear", cache_size=50000, class_weight = "balanced")
model.fit(x1, y1)
local_test()
independent_test(logger, model, path, client_id)
independent_test(logger, model, client_id)
logger.info('#end')

File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions fl_code/all_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def RandomForest():
clf = RandomForestClassifier(random_state=0,class_weight='balanced',max_depth=7,n_estimators=20)
clf = clf.fit(Xtrain, Ytrain)
independent_test(logger, clf, dir_path, 'all')
independent_test(logger, clf, 'all')

def Logistic():
model = LogisticRegression(penalty="l2",class_weight='balanced',max_iter=5000, warm_start=True)
Expand All @@ -29,15 +29,15 @@ def Logistic():
ss = StandardScaler()
ss = ss.fit(x_train.loc[:, col])
x_train.loc[:, col] = ss.transform(x_train.loc[:, col])
model=model.fit(Xtrain, Ytrain)
independent_test(logger, model, dir_path, 'all')
model=model.fit(x_train, Ytrain)
independent_test(logger, model, 'all')


def xgboost():
weight = (Ytrain == 0).sum() / (Ytrain == 1).sum()
model = XGBClassifier(learning_rate=0.1, n_estimators=20,scale_pos_weight=weight)
model.fit(Xtrain, Ytrain)
independent_test(logger, model, dir_path, 'all')
independent_test(logger, model, 'all')

def SVM():
model = SVC(kernel="linear",class_weight = "balanced", cache_size=10000,probability=True)
Expand All @@ -51,7 +51,7 @@ def SVM():
x_test.loc[:, col] = ss.transform(x_test.loc[:, col])

model = model.fit(x_train, Ytrain)
independent_test(logger, model, dir_path, 'all')
independent_test(logger, model,'all')

def MLP():
model = MLPClassifier(hidden_layer_sizes=(200,200),max_iter=200,random_state=0)
Expand All @@ -66,7 +66,7 @@ def MLP():
ros = RandomOverSampler(random_state=0)
x_train_resampled, Ytrain_resampled = ros.fit_resample(x_train, Ytrain)
model = model.fit(x_train_resampled, Ytrain_resampled)
independent_test(logger, model, dir_path, 'all')
independent_test(logger, model, 'all')

if __name__ == "__main__":
dir_path=yaml.load(open('../config.yaml'),Loader=yaml.FullLoader)['use_data_dir_path']
Expand Down
2 changes: 1 addition & 1 deletion fl_code/mlp/mlp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def evaluate(self, parameters, config):

fl.client.start_numpy_client(server_ip, client=Client())
local_test()
independent_test(logger, model, path, client_id)
independent_test(logger, model,client_id)
logger.info('#end')


2 changes: 1 addition & 1 deletion fl_code/randomforest/randomforest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,5 @@ def predict_proba(self, Xtest):
fl.client.start_numpy_client(server_ip, client=client)

local_test()
independent_test(logger, client, path, client_id)
independent_test(logger, client,client_id)
logger.info('#end')
10 changes: 5 additions & 5 deletions fl_code/single_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def RandomForest(cur_client):
logger.info('test_method: {} start'.format('local_test'))
result_log(logger, Ytest, y_pred, y_score)
logger.info('test_method: {} end'.format('local_test'))
independent_test(logger, model, dir_path, cur_client)
independent_test(logger, model, cur_client)
year_by_year_test(cur_client, logger, model, dir_path)

def Logistic(cur_client):
Expand All @@ -44,7 +44,7 @@ def Logistic(cur_client):
logger.info('test_method: {} start'.format('local_test'))
result_log(logger, Ytest, y_pred, y_score)
logger.info('test_method: {} end'.format('local_test'))
independent_test(logger, model, dir_path, cur_client)
independent_test(logger, model, cur_client)
year_by_year_test(cur_client, logger, model, dir_path)

def SVM(cur_client):
Expand All @@ -63,7 +63,7 @@ def SVM(cur_client):
logger.info('test_method: {} start'.format('local_test'))
result_log(logger, Ytest, y_pred, y_score)
logger.info('test_method: {} end'.format('local_test'))
independent_test(logger, model, dir_path, cur_client)
independent_test(logger, model, cur_client)
year_by_year_test(cur_client, logger, model, dir_path)

def xgboost(cur_client):
Expand All @@ -75,7 +75,7 @@ def xgboost(cur_client):
logger.info('test_method: {} start'.format('local_test'))
result_log(logger, Ytest, y_pred, y_score)
logger.info('test_method: {} end'.format('local_test'))
independent_test(logger, model, dir_path, cur_client)
independent_test(logger, model, cur_client)
year_by_year_test(cur_client, logger, model, dir_path)

def MLP(cur_client):
Expand All @@ -96,7 +96,7 @@ def MLP(cur_client):
logger.info('test_method: {} start'.format('local_test'))
result_log(logger, Ytest, y_pred, y_score)
logger.info('test_method: {} end'.format('local_test'))
independent_test(logger, model, dir_path, cur_client)
independent_test(logger, model, cur_client)
year_by_year_test(cur_client, logger, model, dir_path)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion fl_code/xgboost/xgboost_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,5 @@ def evaluate(self, parameters, config):
fl.client.start_numpy_client(server_ip, client=client)

local_test()
independent_test(logger, client, path, client_id)
independent_test(logger, client,client_id)
logger.info('#end')

0 comments on commit f4df754

Please sign in to comment.