Mean-centre Normalisation

Perform mean centralisation - simply just subtracts mean.

Parameters:
  • feature (ndarra) –

    feature array to normalise

  • return_params (bool, default: False ) –

    Change to True to return parameters of normalisation. Defaults to False.

Raises:
  • ValueError

    Raise error if feature array is >2D

Returns:
  • normalsied features (ndarray): Normalised features.

Source code in GPyEDS/mean_centre_normalisation.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def mean_centre(feature, return_params = False):
    """Perform mean centralisation - simply just subtracts mean.

    Args:
        feature (ndarra): feature array to normalise
        return_params (bool, optional): Change to True to return parameters of normalisation. Defaults to False.

    Raises:
        ValueError: Raise error if feature array is >2D

    Returns:
        normalsied features (ndarray): Normalised features.
    """


    params = []

    norm = np.zeros_like(feature)

    if len(feature.shape) == 2:
        for i in range(feature.shape[1]):
            temp_mean = feature[:,i].mean()
            norm[:,i] = feature[:,i] - temp_mean
            params.append(np.asarray([temp_mean]))

    elif len(feature.shape) == 1:
        temp_mean = feature[:].mean()
        norm[:] = feature[:] - temp_mean
        params.append(np.asarray([temp_mean]))

    else:
        raise ValueError("Feature array must be either 1D or 2D numpy array.")


    if return_params == True:
        return norm, params
    else:
        return norm