federated/data/data_preprocessing.py
def create_uniform_dataset(
    X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
    """Function distributes the data equally such that each client holds equal amounts of each class.

    Args:
        X (np.ndarray): Input.\n
        y (np.ndarray): Output.\n
        number_of_clients (int): Number of clients.\n
    Returns:
        [Dict, tff.simulation.ClientData]: A dictionary and a tensorflow federated dataset containing the distributed dataset.
    """
    clients_data = {f"client_{i}": [[], []] for i in range(1, number_of_clients + 1)}
    for i in range(len(X)):
        clients_data[f"client_{(i%number_of_clients)+1}"][0].append(X[i])
        clients_data[f"client_{(i%number_of_clients)+1}"][1].append(y[i])

    return clients_data, create_tff_dataset(clients_data)
Function distributes the data equally such that each client holds equal amounts of each class.

    Args:
        X (np.ndarray): Input.\n
        y (np.ndarray): Output.\n
        number_of_clients (int): Number of clients.\n
    Returns:
        [Dict, tff.simulation.ClientData]: A dictionary and a tensorflow federated dataset containing the distributed dataset.
    
Function distributes the data equally such that each client holds equal amounts of each class.
Function distributes the data equally such that each client holds equal amounts of each class .
def create_uniform_dataset(
    X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
    clients_data = {f"client_{i}": [[], []] for i in range(1, number_of_clients + 1)}
    for i in range(len(X)):
        clients_data[f"client_{(i%number_of_clients)+1}"][0].append(X[i])
        clients_data[f"client_{(i%number_of_clients)+1}"][1].append(y[i])
    return clients_data, create_tff_dataset(clients_data)
def create_uniform_dataset ( X : np . ndarray , y : np . ndarray , number_of_clients : int ) -> Tuple [ Dict , tff . simulation . ClientData ] : clients_data = { f"client_{i}" : [ [ ] , [ ] ] for i in range ( 1 , number_of_clients + 1 ) } for i in range ( len ( X ) ) : clients_data [ f"client_{(i%number_of_clients)+1}" ] [ 0 ] . append ( X [ i ] ) clients_data [ f"client_{(i%number_of_clients)+1}" ] [ 1 ] . append ( y [ i ] ) return clients_data , create_tff_dataset ( clients_data )
Function distributes the data equally such that each client holds equal amounts of each class.
Function distributes the data equally such that each client holds equal amounts of each class .
"""Function distributes the data equally such that each client holds equal amounts of each class.

    Args:
        X (np.ndarray): Input.\n
        y (np.ndarray): Output.\n
        number_of_clients (int): Number of clients.\n
    Returns:
        [Dict, tff.simulation.ClientData]: A dictionary and a tensorflow federated dataset containing the distributed dataset.
    """
A dictionary and a tensorflow federated dataset containing the distributed dataset.
A dictionary and a tensorflow federated dataset containing the distributed dataset .
[Dict, tff.simulation.ClientData]
X
np.ndarray
None
y
np.ndarray
None
number_of_clients
int
Number of clients.\n
Number of clients . \ n