-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad7b8e5
commit c1edd8a
Showing
3 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from federatedscope.core.splitters.generic.lda_splitter import LDASplitter | ||
from federatedscope.core.splitters.generic.iid_splitter import IIDSplitter | ||
|
||
__all__ = ['LDASplitter'] | ||
__all__ = ['LDASplitter', 'IIDSplitter'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import numpy as np | ||
from federatedscope.core.splitters import BaseSplitter | ||
|
||
|
||
class IIDSplitter(BaseSplitter): | ||
def __init__(self, client_num): | ||
super(IIDSplitter, self).__init__(client_num) | ||
|
||
def __call__(self, dataset, prior=None): | ||
dataset = [ds for ds in dataset] | ||
np.random.shuffle(dataset) | ||
length = len(dataset) | ||
prop = [1.0 / self.client_num for _ in range(self.client_num)] | ||
prop = (np.cumsum(prop) * length).astype(int)[:-1] | ||
data_list = np.split(dataset, prop) | ||
data_list = [x.tolist() for x in data_list] | ||
return data_list |