From 87841dbea96be8c33cb50b9d247340f59c287a78 Mon Sep 17 00:00:00 2001 From: liubangya Date: Fri, 18 Feb 2022 17:45:29 -0600 Subject: [PATCH] BUG: mistake message when empty minerlist UPDATE: now reward shows up directly UPDATE: 32.72 bins/channel instead of 30 bins/channel --- .../java/com/example/decentspec_v3/Config.java | 2 +- .../com/example/decentspec_v3/FLWorker.java | 17 ++++++++++++++--- .../java/com/example/decentspec_v3/MyUtils.java | 12 ++++++------ .../federated_learning/FileAccessor.java | 4 ++-- .../federated_learning/HTTPAccessor.java | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/example/decentspec_v3/Config.java b/app/src/main/java/com/example/decentspec_v3/Config.java index d63f38c..9b4326e 100644 --- a/app/src/main/java/com/example/decentspec_v3/Config.java +++ b/app/src/main/java/com/example/decentspec_v3/Config.java @@ -12,7 +12,7 @@ public class Config { public static final int BAUD_RATE = 115200; // ML related - public static final int ML_TASK_INTERVAL = 1000; // check the condition per 5s + public static final int ML_TASK_INTERVAL = 5000; // check the condition per 5s public static final boolean LIMIT_TRAIN_SIZE = true; public static final int MAX_LOCAL_SET_SIZE = 5000; // too large the size will lead to too long time training public static final boolean USE_DUMMY_DATASET = false; // use local GPS_power.dat diff --git a/app/src/main/java/com/example/decentspec_v3/FLWorker.java b/app/src/main/java/com/example/decentspec_v3/FLWorker.java index 4bbe4df..68858fa 100644 --- a/app/src/main/java/com/example/decentspec_v3/FLWorker.java +++ b/app/src/main/java/com/example/decentspec_v3/FLWorker.java @@ -75,11 +75,23 @@ public void run() { public void run() { while (!Thread.currentThread().isInterrupted()) { try { + TrainingPara mTPara; // REMOTE ready: new global available - TrainingPara mTPara = mTrigger.getNewGlobal(); + if (mTrigger.wifiReady()) + updateReward(); + else { + Thread.sleep(ML_TASK_INTERVAL); + continue; + } + if (mTrigger.chargerReady()) + mTPara = mTrigger.getNewGlobal(); + else { + Thread.sleep(ML_TASK_INTERVAL); + continue; + } // LOCAL ready: wifi, battery, and local files SampleFile dataFile = mTrigger.getDataset(mTPara); // TODO change it to file list instead fo a single file - if (dataFile != null && mTPara != null) { + if (dataFile != null) { /* use this file to make a local train */ oneLocalTraining(dataFile, mTPara); // end of one time training @@ -179,7 +191,6 @@ private void oneLocalTraining(SampleFile file, TrainingPara mTrainingPara) { } // end of ML cycle ================================================================= updateNumbers(); - updateReward(); cleanup(); } diff --git a/app/src/main/java/com/example/decentspec_v3/MyUtils.java b/app/src/main/java/com/example/decentspec_v3/MyUtils.java index fd8a9fe..5a4e63a 100644 --- a/app/src/main/java/com/example/decentspec_v3/MyUtils.java +++ b/app/src/main/java/com/example/decentspec_v3/MyUtils.java @@ -47,14 +47,14 @@ public static String genConfigData(int configIndex) { int bandwidth = SAMPLE_PARA_BD[configIndex]; return String.format("%s\n\r1\n\r%d\n\r%d\n\r%d\n\r%s\n\r", SAMPLE_START_SIGNAL, center_freq, bandwidth, SAMPLE_RATE_INTERVAL, SAMPLE_END_SIGNAL); } - public static double[] powerMerge(double[] small_bins, int merge_per_bins) { - if (merge_per_bins == 0) + public static double[] powerMerge(double[] small_bins, double bins_per_merge) { + if (bins_per_merge == 0) return null; int len = small_bins.length; - double[] merged_bins = new double[len / merge_per_bins]; - for (int i = 0; i < len; i = i + merge_per_bins) { - if ((len - i) >= merge_per_bins) { - merged_bins[i / merge_per_bins] = merge(Arrays.copyOfRange(small_bins, i, i + merge_per_bins)); + double[] merged_bins = new double[(int)(len / bins_per_merge)]; + for (double i = 0; i < len; i = i + bins_per_merge) { + if ((len - (int)i) >= (int)bins_per_merge) { + merged_bins[(int)(i / bins_per_merge)] = merge(Arrays.copyOfRange(small_bins, (int) Math.round(i), (int) Math.round(i + bins_per_merge))); } } return merged_bins; diff --git a/app/src/main/java/com/example/decentspec_v3/federated_learning/FileAccessor.java b/app/src/main/java/com/example/decentspec_v3/federated_learning/FileAccessor.java index a427797..2994485 100644 --- a/app/src/main/java/com/example/decentspec_v3/federated_learning/FileAccessor.java +++ b/app/src/main/java/com/example/decentspec_v3/federated_learning/FileAccessor.java @@ -97,8 +97,8 @@ private Pair tvMultiPreprocess(double[] doubleList, Training inList = Arrays.copyOfRange(doubleList, 0, 2); if (inList[0] == 0.0 || inList[1] == 0.0) return null; - double[] outListResource = Arrays.copyOfRange(doubleList, 3, 30 * 8 + 3); - outList = MyUtils.powerMerge(outListResource, 30); + double[] outListResource = Arrays.copyOfRange(doubleList, 3, 256 + 3); + outList = MyUtils.powerMerge(outListResource, 30.72); return standardize(inList, outList, tp); } private Pair ltePreprocess(double[] doubleList, TrainingPara tp) { diff --git a/app/src/main/java/com/example/decentspec_v3/federated_learning/HTTPAccessor.java b/app/src/main/java/com/example/decentspec_v3/federated_learning/HTTPAccessor.java index 0cf1207..d4a0f3e 100644 --- a/app/src/main/java/com/example/decentspec_v3/federated_learning/HTTPAccessor.java +++ b/app/src/main/java/com/example/decentspec_v3/federated_learning/HTTPAccessor.java @@ -81,7 +81,7 @@ public void onErrorResponse(VolleyError error) { }); HTTPQueue.add(stringRequest); join(); - return tp.MINER_LIST.size() != 0; + return responded; } public double fetchReward(String myId) {