Skip to content

Commit

Permalink
add android helper functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasakesson committed Sep 26, 2023
1 parent 3e7bbac commit 9eb669f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 2 additions & 0 deletions fedn/fedn/network/dashboard/templates/context.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ <h6 class="card-subtitle text-muted">{{ message }}</h6>
<select class="form-control" id="helper" name="helper" required>
<option value='kerashelper'>kerashelper</option>
<option value='pytorchhelper'>pytorchhelper</option>
<option value='androidhelper'>androidhelper</option>

</select>
</div>

Expand Down
32 changes: 16 additions & 16 deletions fedn/fedn/utils/plugins/androidhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@


class Helper(HelperBase):
""" FEDn helper class for keras.Sequential. """
""" FEDn helper class for android json model weights. """

def __init__(self):
""" Initialize helper. """
self.name = "kerashelper"
self.name = "androidhelper"
super().__init__()

# function to calculate an incremental weighted average of the weights
def increment_average(self, model, model_next, num_examples, total_examples):
""" Incremental weighted average of model weights.
:param model: Current model weights.
:type model: list of numpy arrays.
:param model_next: New model weights.
:type model_next: list of numpy arrays.
:param num_examples: Number of examples in new model.
:type num_examples: int
:param total_examples: Total number of examples.
:type total_examples: int
:return: Incremental weighted average of model weights.
:rtype: list of numpy arrays.
"""
:param model: Current model weights.
:type model: list of numpy arrays.
:param model_next: New model weights.
:type model_next: list of numpy arrays.
:param num_examples: Number of examples in new model.
:type num_examples: int
:param total_examples: Total number of examples.
:type total_examples: int
:return: Incremental weighted average of model weights.
:rtype: list of numpy arrays.
"""
# Incremental weighted average
w = num_examples / total_examples
weights = []
for i in range(len(model)):
weights.append(w * model[i] + (1 - w) * model_next[i])
weights = {}
for i in model.keys():
weights[i] = list(w * np.array(model[i]) + (1 - w) * np.array(model_next[i]))

return weights

Expand Down

0 comments on commit 9eb669f

Please sign in to comment.