fedn.utils.helpers.plugins package

Submodules

fedn.utils.helpers.plugins.numpyhelper module

class fedn.utils.helpers.plugins.numpyhelper.Helper[source]

Bases: HelperBase

FEDn helper class for models weights/parameters that can be transformed to numpy ndarrays.

add(m1, m2, a=1.0, b=1.0)[source]

m1*a + m2*b

Parameters:
  • model (list of ndarrays) – Current model weights.

  • model_next (list of ndarrays) – New model weights.

Returns:

Incremental weighted average of model weights.

Return type:

list of ndarrays

divide(m1, m2)[source]

Subtract weights.

Parameters:
  • m1 (list of ndarrays) – Current model weights.

  • m2 (list of ndarrays) – New model weights.

Returns:

m1/m2.

Return type:

list of ndarrays

increment_average(m1, m2, n, N)[source]

Update a weighted incremental average of model weights.

Parameters:
  • m1 – Current parameters.

  • m2 – next parameters.

  • n (int) – Number of examples used for updating m2.

  • N (int) – Total number of examples (accumulated).

Returns:

Updated incremental weighted average.

Return type:

list of numpy ndarray

load(fh)[source]

Load weights from file or filelike.

Parameters:

fh – file path, filehandle, filelike.

Returns:

List of weights in numpy format.

multiply(m1, m2)[source]

Multiply m1 by m2.

Parameters:
  • m1 (list of ndarrays) – Current model weights.

  • m2 (list of ndarrays) – New model weights.

Returns:

m1.*m2

Return type:

list of ndarrays

norm(m)[source]

Return the norm (L1) of model weights.

Parameters:

m (list of ndarrays) – Current model weights.

Returns:

norm of m

Return type:

float

ones(m1, a)[source]

Return a list of numpy arrays of the same shape as m1, filled with ones.

Parameters:
  • m1 (list of ndarrays) – Current model weights.

  • a (float) – Scalar value.

Returns:

list of numpy arrays of the same shape as m1, filled with ones.

Return type:

list of ndarrays

power(m1, a)[source]

m1 raised to the power of m2.

Parameters:
  • m1 (list of ndarrays) – Current model weights.

  • m2 – New model weights.

Returns:

m1.^m2

Return type:

list of ndarrays

save(weights, path=None)[source]

Serialize weights to file. The serialized model must be a single binary object.

Parameters:
  • weights – List of weights in numpy format.

  • path – Path to file.

Returns:

Path to file.

sqrt(m1)[source]

Sqrt of m1, element-wise.

Parameters:
  • m1 – Current model weights.

  • model_next (list of ndarrays) – New model weights.

Returns:

sqrt(m1)

Return type:

list of ndarrays

subtract(m1, m2, a=1.0, b=1.0)[source]

m1*a - m2*b.

Parameters:
  • m1 (list of ndarrays) – Current model weights.

  • m2 (list of ndarrays) – New model weights.

Returns:

m1*a-m2*b

Return type:

list of ndarrays