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:
- Numerical stability. Multiplying tiny probabilities together () underflows to zero in float32. Adding their logs (-50 + -50 = -100) doesn't.
- 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.
- 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.
큰 값 몇개에 밀려버리면 선형분포는 그 부분만 우뚝솟아서 다른 항목의 숫자를 잘 인지하지못하도록 압축시켜버림
로그스케일을 하면 때에 따라 이부분이 개선됨, 이게 맞나? 나는 가로로 로그스케일을 쓰긴했는데 주식차트같은 경우 세로로 로그스케일을 많이씀
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)