Skip to content

v-code01/chebabs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chebabs

MiniSom's _chebyshev_distance returns the signed maximum coordinate difference max(x - w) instead of the Chebyshev distance, the maximum absolute difference max|x - w|. The Chebyshev distance is the L-infinity norm and is non-negative; the signed maximum can be negative and is not a metric. Chebyshev is one of the four documented activation_distance options and feeds the best-matching-unit search, which takes the argmin over the map, so choosing it selects the neuron with the most negative signed difference, the farthest one when a weight exceeds the input, silently inverting the assignment. The sibling _manhattan_distance uses the L1 norm with absolute values, so the fault is this branch's missing absolute value.

The code

minisom, minisom.py, MiniSom._chebyshev_distance, current release and current main (identical), lines 362-363 (main 507-508), registered as an activation_distance option at line 244:

def _chebyshev_distance(self, x, w):
    return max(subtract(x, w), axis=-1)          # signed max; should be max(abs(subtract(x, w)))

where max is numpy's amax. The sibling _manhattan_distance (line 359) is linalg.norm(subtract(x, w), ord=1, axis=-1), which takes the absolute value, and the correct Chebyshev distance is max(abs(subtract(x, w)), axis=-1).

What it does

The Chebyshev distance as the signed maximum or the maximum absolute difference, over a small map of weights and the sample x = [1, 1]:

signed max (minisom):
[[ 1. -9.]
 [-4. -1.]]
max abs (correct):
[[1. 9.]
 [4. 1.]]
signed has negative distances: True
best-matching unit: signed (0, 1) (weight [10.0, 10.0]), correct (0, 0) (weight [0.0, 0.0])

Driving the real library:

chebyshev distance: lib [[1.0, -9.0], [-4.0, -1.0]] vs correct [[1.0, 9.0], [4.0, 1.0]]
  has negative distances: True, matches correct: False
BMU: lib (0, 1) weight [10.0, 10.0] vs correct (0, 0) weight [0.0, 0.0], inverted True
siblings: euclidean ok True, manhattan ok True
library test x-w = [0.0, 2.0], all >= 0 True, signed==abs True

The real chebyshev distance returns negative values, and the best-matching unit is (0, 1), the neuron with weight [10, 10], the farthest one, while the true nearest neuron is (0, 0) with weight [0, 0]. The base cases isolate the fault: the euclidean and manhattan distances match their exact definitions on the same input, and the library's own chebyshev test uses a sample above its weights, so the signed maximum coincides with the maximum absolute value and the test passes, masking the fault.

Scope

The chebyshev distance is not the default, but it is a documented, first-class, one-of-four activation_distance metric, a primary constructor knob, and choosing it corrupts the best-matching-unit selection that underlies training, quantization_error, activation_response, and win_map. The failure is silent: finite numbers are returned and the map trains, but every unit assignment can be inverted to the farthest neuron. The error is a missing absolute value, not floating-point round-off, and the manhattan sibling takes the absolute value. The fix is max(abs(subtract(x, w)), axis=-1).

Layout

  • excerpt.py: the chebyshev distance and the manhattan sibling quoted with the flags that name the fault, and the correct maximum-absolute form.
  • distance.py: the Chebyshev distance as the signed maximum or the maximum absolute difference, so the signed form goes negative and its argmin selects the farthest neuron.
  • consequence.py: the real MiniSom chebyshev distance and best-matching-unit search, the inverted BMU, the correct siblings, and the library test that coincidentally passes.
  • test_chebabs.py: the model signed form is negative and inverts the BMU while the absolute form does not, the real distance is negative and wrong, the real BMU is inverted, the siblings are correct, and the library test case is non-negative.

Reproduce

python distance.py
python consequence.py
python test_chebabs.py

The distance is quoted from current main; the values are produced by the real MiniSom. The fix is to take the maximum of the absolute differences.

About

MiniSom's `_chebyshev_distance` returns the signed maximum coordinate difference `max(x - w)` instead of the Chebyshev distance, the maximum absolute difference `max|x - w|`. The Chebyshev distance is the L-infinity norm and is non-negative; the signed maximum can be negative and is not a metric.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages