Skip to content

Commit

Permalink
fixing linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chancejohnstone committed Oct 22, 2024
1 parent 29695ef commit 0a70e0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
9 changes: 4 additions & 5 deletions baselines/fedht/fedht/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ def aggregate_hardthreshold(
if num_keep <= 0:
raise ValueError("k must be a positive integer.")

"""Compute weighted average."""
# Calculate the total number of examples used during training
num_examples_total = sum(num_examples for (_, num_examples) in results)

Expand All @@ -438,10 +437,10 @@ def aggregate_hardthreshold(
# ignoring second element in results[i] skips over number of observations
# j: iterates through all layers of a model
# k: iterates through the slices of each layer
for i in range(len(results)):
for j in range(len(results[i][0])):
for k in range(len(results[i][0][j])):
results[i][0][j][k] = hardthreshold(results[i][0][j][k], num_keep)
for i, layer in enumerate(results):
for j, sub_layer in enumerate(layer[0]):
for k, weight in enumerate(sub_layer):
results[i][0][j][k] = hardthreshold(weight, num_keep)

weighted_weights1 = [
[layer * num_examples for layer in weights]
Expand Down
14 changes: 7 additions & 7 deletions baselines/fedht/fedht/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ def partition_data(data, num_partitions):
X, y = data
partition_size = len(X) // num_partitions
# Create partitions
partitionsX = [
partitions_x = [
X[i * partition_size : (i + 1) * partition_size] for i in range(num_partitions)
]
partitionsy = [
partitions_y = [
y[i * partition_size : (i + 1) * partition_size] for i in range(num_partitions)
]

# Handle any remaining items
if len(data) % num_partitions != 0:
# partitions[-1] = partitions[-1] + data[num_partitions * partition_size:]
partitionsX[-1] = np.vstack(
(partitionsX[-1], X[num_partitions * partition_size :])
partitions_x[-1] = np.vstack(
(partitions_x[-1], X[num_partitions * partition_size :])
)
partitionsy[-1] = np.vstack(
(partitionsy[-1], y[num_partitions * partition_size :])
partitions_y[-1] = np.vstack(
(partitions_y[-1], y[num_partitions * partition_size :])
)

return partitionsX, partitionsy
return partitions_x, partitions_y


def sim_data(ni: int, num_clients: int, num_features: int, alpha=1, beta=1):
Expand Down

0 comments on commit 0a70e0a

Please sign in to comment.