C.W.K.
Stream
Lesson 02 of 05 · published

The Ultimate Normalizer: Compressing Extreme Scales

~10 min · normalization, compression, decibels

Level 0Math Novice
0 XP0/59 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

When Numbers Span Universes

Some quantities live across wild scales. Brightness of stars from the Sun to a distant galaxy. Earthquake magnitudes from a barely-felt tremor to a continent-shifting catastrophe. Sound from a whisper to a jet engine. Probabilities in a language model from "very common" to "essentially never."

Plotting these on a linear scale fails — the small values get crushed into invisibility. Logarithms compress. They turn exponential ranges into linear-feeling ones.

Decibels: Your Ears Already Do This

The decibel scale measures sound intensity logarithmically: . 0 dB is the threshold of hearing. 60 dB is conversation. 120 dB is a jet engine. Each 10 dB step is a 10× change in actual sound energy. Your ears already perceive sound this way — you hear "twice as loud" when intensity multiplies by ~10. Engineers built dB to match human perception, which itself is logarithmic.

Why AI Loves Logs

Three jobs:

  1. Numerical stability. Multiplying tiny probabilities together () underflows to zero in float32. Adding their logs (-50 + -50 = -100) doesn't.
  2. Loss functions. Cross-entropy loss is . The log gives gentler gradients near correct predictions and harsher penalties for very-wrong predictions — exactly the asymmetry we want.
  3. Visualization. Loss curves are usually plotted on a log y-axis so the early dramatic drops don't compress the late subtle improvements out of view.
Log = compressor for extreme ranges. Linear thinking dies on data spanning orders of magnitude. Switch to log and the structure reappears.

Code

Compress wild ranges to linear-feeling steps·python
import numpy as np

# Star brightness — orders of magnitude apart
brightness = np.array([1e-3, 1e-1, 1e1, 1e3, 1e5, 1e7])

# Linear plot would compress small ones
print(brightness)

# Log scale makes them comparable
print(np.log10(brightness))   # [-3 -1  1  3  5  7]

# Decibels — exact same idea on sound intensity
intensity = np.array([1e-12, 1e-9, 1e-6, 1e-3, 1])
dB = 10 * np.log10(intensity / 1e-12)
print(dB)       # [  0  30  60  90 120]

External links

Exercise

Generate 100 random numbers between 1 and 10000. Plot a histogram on a linear x-axis, then on a log x-axis. Notice how the log-scale histogram becomes interpretable while the linear one is dominated by the few large values.
Hint
np.random.uniform(1, 10000, 100) then plt.xscale('log'). Many real-world quantities (file sizes, incomes, city populations) need log scales to be readable.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue
💛 by Pippahappy

Comments 2

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.
  1. Elechemist
    Elechemist

    큰 값 몇개에 밀려버리면 선형분포는 그 부분만 우뚝솟아서 다른 항목의 숫자를 잘 인지하지못하도록 압축시켜버림

    로그스케일을 하면 때에 따라 이부분이 개선됨, 이게 맞나? 나는 가로로 로그스케일을 쓰긴했는데 주식차트같은 경우 세로로 로그스케일을 많이씀

    import numpy as np import matplotlib.pyplot as plt

    rng = np.random.default_rng(42)

    1~10000에 걸쳐 자릿수가 고르게 퍼지도록 로그 균등 생성 (현실 데이터의 전형)

    data = 10 ** rng.uniform(0, 4, 100)

    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))

    선형 x축 히스토그램

    ax1.hist(data, bins=30, color='#378ADD', edgecolor='white') ax1.set_title("Linear x-axis") ax1.set_xlabel("value") ax1.set_ylabel("count")

    로그 x축 히스토그램 — 로그 간격 구간 사용

    bins = np.logspace(0, 4, 30) ax2.hist(data, bins=bins, color='#1D9E75', edgecolor='white') ax2.set_xscale('log') ax2.set_title("Log x-axis") ax2.set_xlabel("value (log scale)") ax2.set_ylabel("count")

    plt.tight_layout() plt.savefig('loghist.png', dpi=130)

    💛 by Pippahappy
    1. Pippa
      Pippa· warmElechemistElechemist

      맞아요. 큰 값 몇 개가 선형축에서 화면을 지배하면 나머지가 한쪽에 눌려 보이는데, 로그축은 비율 기준으로 간격을 다시 펼쳐줘요. 주식 차트의 세로 로그축은 가격의 “차이”보다 “수익률 비율”을 보려는 선택이고, 이 예제의 가로 로그축은 값의 크기 구간을 비율로 나누려는 선택이에요.