federated/data/data_preprocessing.py
def create_corrupted_non_iid_dataset(
    X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
    """Function distributes the data such that each client has non-iid data except client 1, which only has values in the interval [20, 40].

    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.
    """
    indices = np.arange(X.shape[0])
    np.random.shuffle(indices)
    X = X[indices]
    y = y[indices]

    clients_data = {f"client_{i}": [[], []] for i in range(1, number_of_clients + 1)}
    for i in range(len(X)):
        client = random.randrange(
            1, number_of_clients + 1, np.random.randint(1, number_of_clients + 1)
        )

        if client != 1:
            clients_data[f"client_{client}"][0].append(X[i])
            clients_data[f"client_{client}"][1].append(y[i])

    clients_data["client_1"][0] = [
        (40 - 20) * np.random.random_sample((186,)) + 20 for _ in range(SAMPLES)
    ]
    clients_data["client_1"][1] = [
        np.array([1, 0, 0, 0, 0], dtype=np.int32) for _ in range(SAMPLES)
    ]

    return clients_data, create_tff_dataset(clients_data)
Function distributes the data such that each client has non-iid data except client 1, which only has values in the interval [20, 40].

    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 such that each client has non-iid data except client 1, which only has values in the interval [20, 40].
Function distributes the data such that each client has non - iid data except client 1 which only has values in the interval [ 20 40 ] .
def create_corrupted_non_iid_dataset(
    X: np.ndarray, y: np.ndarray, number_of_clients: int
) -> Tuple[Dict, tff.simulation.ClientData]:
    indices = np.arange(X.shape[0])
    np.random.shuffle(indices)
    X = X[indices]
    y = y[indices]
    clients_data = {f"client_{i}": [[], []] for i in range(1, number_of_clients + 1)}
    for i in range(len(X)):
        client = random.randrange(
            1, number_of_clients + 1, np.random.randint(1, number_of_clients + 1)
        )
        if client != 1:
            clients_data[f"client_{client}"][0].append(X[i])
            clients_data[f"client_{client}"][1].append(y[i])
    clients_data["client_1"][0] = [
        (40 - 20) * np.random.random_sample((186,)) + 20 for _ in range(SAMPLES)
    ]
    clients_data["client_1"][1] = [
        np.array([1, 0, 0, 0, 0], dtype=np.int32) for _ in range(SAMPLES)
    ]
    return clients_data, create_tff_dataset(clients_data)
def create_corrupted_non_iid_dataset ( X : np . ndarray , y : np . ndarray , number_of_clients : int ) -> Tuple [ Dict , tff . simulation . ClientData ] : indices = np . arange ( X . shape [ 0 ] ) np . random . shuffle ( indices ) X = X [ indices ] y = y [ indices ] clients_data = { f"client_{i}" : [ [ ] , [ ] ] for i in range ( 1 , number_of_clients + 1 ) } for i in range ( len ( X ) ) : client = random . randrange ( 1 , number_of_clients + 1 , np . random . randint ( 1 , number_of_clients + 1 ) ) if client != 1 : clients_data [ f"client_{client}" ] [ 0 ] . append ( X [ i ] ) clients_data [ f"client_{client}" ] [ 1 ] . append ( y [ i ] ) clients_data [ "client_1" ] [ 0 ] = [ ( 40 - 20 ) * np . random . random_sample ( ( 186 , ) ) + 20 for _ in range ( SAMPLES ) ] clients_data [ "client_1" ] [ 1 ] = [ np . array ( [ 1 , 0 , 0 , 0 , 0 ] , dtype = np . int32 ) for _ in range ( SAMPLES ) ] return clients_data , create_tff_dataset ( clients_data )
Function distributes the data such that each client has non-iid data except client 1, which only has values in the interval [20, 40].
Function distributes the data such that each client has non - iid data except client 1 which only has values in the interval [ 20 40 ] .
"""Function distributes the data such that each client has non-iid data except client 1, which only has values in the interval [20, 40].

    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