ipfml.utils

Utils functions of ipfml package (normalization, integral…)

Functions

get_entropy(arr) Returns the computed entropy from arr
get_entropy_contribution_of_i(arr, i) Returns the entropy contribution i column
get_entropy_without_i(arr, i) Returns the computed entropy from arr without contribution of i
get_indices_of_highest_values(arr, n) Returns indices of n highest values from list or 1D numpy array
get_indices_of_lowest_values(arr, n) Returns indices of n highest values from list or 1D numpy array
integral_area_simps(y_values, dx) Returns area under curves from provided data points using Simpsons rule
integral_area_trapz(y_values, dx) Returns area under curves from provided data points using Trapezium rule
normalize_2D_arr(arr) Return array normalize from its min and max values
normalize_arr(arr) Normalize data of 1D array shape
normalize_arr_with_range(arr, min, max) Normalize data of 1D array shape
ipfml.utils.get_entropy(arr)[source]

Returns the computed entropy from arr

Parameters:arr – numpy array
Returns:entropy score computed

Example:

>>> from ipfml import utils
>>> import numpy as np
>>> arr = np.arange(10)
>>> entropy = utils.get_entropy(arr)
>>> int(entropy)
0
ipfml.utils.get_entropy_contribution_of_i(arr, i)[source]

Returns the entropy contribution i column

Parameters:
  • arr – numpy array
  • i – column index
Returns:

entropy contribution score computed

Example:

>>> from ipfml import utils
>>> import numpy as np
>>> arr = np.arange(10)
>>> entropy = utils.get_entropy_contribution_of_i(arr, 3)
>>> int(entropy)
0
ipfml.utils.get_entropy_without_i(arr, i)[source]

Returns the computed entropy from arr without contribution of i

Parameters:
  • arr – numpy array
  • i – column index
Returns:

entropy score computed

Example:

>>> from ipfml import utils
>>> import numpy as np
>>> arr = np.arange(10)
>>> entropy = utils.get_entropy_without_i(arr, 3)
>>> int(entropy)
0
ipfml.utils.get_indices_of_highest_values(arr, n)[source]

Returns indices of n highest values from list or 1D numpy array

Parameters:
  • arr – List of numpy array
  • n – number of highest elements wanted
Returns:

n indices of highest values

Example:

>>> from ipfml import utils
>>> import numpy as np
>>> arr = np.arange(10)
>>> indices = utils.get_indices_of_highest_values(arr, 2)
>>> indices
array([9, 8])
ipfml.utils.get_indices_of_lowest_values(arr, n)[source]

Returns indices of n highest values from list or 1D numpy array

Parameters:
  • arr – List of numpy array
  • n – number of highest elements wanted
Returns:

n indices of highest values

Example:

>>> from ipfml import utils
>>> import numpy as np
>>> arr = np.arange(10)
>>> indices = utils.get_indices_of_lowest_values(arr, 2)
>>> indices
array([0, 1])
ipfml.utils.integral_area_simps(y_values, dx)[source]

Returns area under curves from provided data points using Simpsons rule

Parameters:
  • y_values – y values of curve
  • dx – number of unit for x axis
Returns:

Area under curves obtained from these points

Example:

>>> from ipfml import utils
>>> import numpy as np
>>> y_values = np.array([5, 20, 4, 18, 19, 18, 7, 4])
>>> area = utils.integral_area_simps(y_values, dx=5)
>>> area
460.0
ipfml.utils.integral_area_trapz(y_values, dx)[source]

Returns area under curves from provided data points using Trapezium rule

Parameters:
  • y_values – y values of curve
  • dx – number of unit for x axis
Returns:

Area under curves obtained from these points

Example:

>>> from ipfml import utils
>>> import numpy as np
>>> y_values = np.array([5, 20, 4, 18, 19, 18, 7, 4])
>>> area = utils.integral_area_trapz(y_values, dx=5)
>>> area
452.5
ipfml.utils.normalize_2D_arr(arr)[source]

Return array normalize from its min and max values

Parameters:arr – 2D Numpy array
Returns:Normalized 2D Numpy array

Example:

>>> from PIL import Image
>>> from ipfml import utils
>>> from ipfml.processing import transform
>>> img = Image.open('./images/test_img.png')
>>> img_mscn = transform.rgb_to_mscn(img)
>>> img_normalized = utils.normalize_2D_arr(img_mscn)
>>> img_normalized.shape
(200, 200)
ipfml.utils.normalize_arr(arr)[source]

Normalize data of 1D array shape

Parameters:arr – array data of 1D shape
Returns:Normalized 1D array

Example:

>>> from ipfml import utils
>>> import numpy as np
>>> arr = np.arange(5)
>>> arr_normalized = utils.normalize_arr(arr)
>>> arr_normalized[1]
0.1
ipfml.utils.normalize_arr_with_range(arr, min, max)[source]

Normalize data of 1D array shape

Parameters:arr – array data of 1D shape
Returns:Normalized 1D Numpy array

Example:

>>> from ipfml import utils
>>> import numpy as np
>>> arr = np.arange(11)
>>> arr_normalized = utils.normalize_arr_with_range(arr, 0, 20)
>>> arr_normalized[1]
0.05