#174Network — total trainable parametersEasy

Network — total trainable parameters

Background

A feedforward network is a list of layer sizes, e.g. [i, h, o]. The input layer holds no weights — parameters live between consecutive layers. So the total is the sum of each dense layer's parameter count:

total=(ss+1+s+1)\text{total} = \sum_{\ell} \bigl(s_{\ell}\,s_{\ell+1} + s_{\ell+1}\bigr)

where ss_\ell are the layer sizes in order.

Problem statement

Implement network_params(sizes) returning the total number of trainable parameters for a fully connected network described by the list sizes.

Input

  • sizes — list of int layer sizes, input first, output last (length 1\ge 1).

Output

Returns an int: the summed parameters over all consecutive layer pairs.

Examples

Example 1 — the lesson's i=3, h=4, o=2 net

Input:  sizes = [3, 4, 2]
Output: 26

Explanation: (34+4)+(42+2)=16+10=26(3\cdot4+4) + (4\cdot2+2) = 16 + 10 = 26.

Example 2 — a single layer

Input:  sizes = [5, 3]
Output: 18

Explanation: one dense layer, 53+3=185\cdot3+3 = 18.

Constraints

  • The input layer contributes no parameters; only count between consecutive sizes.
  • A list with one element (just an input) has 0 parameters.
  • Return a plain int.

Notes

  • This is the network's capacity in raw scalar count. More/wider layers grow it fast — more flexible, but easier to overfit.
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • example lesson net
  • reference single layer
  • sample input only