All problems

Counting Sparsity From L1

mediumPythonEnsembles & Regularization

The flat size charge has done its work and Ardwick Mutual's pricing model comes back with a fitted weight for every feature. The desk now wants to know how much of the model it can delete. A weight that has been pushed all the way down contributes nothing to a price, so its feature can be dropped from the model and never collected again — which saves a data feed, not just a multiplication. In practice a weight rarely lands on exactly zero, because the trainer stops once it is close enough, so switched-off has to be judged against a cut-off.

Task: Print how many of the model's features have been switched off.

Input

The first line holds one integer n, the number of weights. The second line holds the n fitted weights separated by single spaces; some may be negative.

Output

One line holding a single count: how many weights are switched off. A weight is switched off when its size, ignoring its sign, is strictly under 0.001 — so a weight of exactly 0.001 does not count, and a weight of -0.0004 does. Count the switched-off weights, not the ones still standing.

Example:

Input:
5
0.5 0.0001 0.0 3.2 0.0005

Output:
3

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…