英語613639 views
高校物理160203 views
りんご209490 views
MathPython497343 views
いろは3010814 views
高校化学2924392 views
Computer368106 views
数学講師2886227 views
LaTeX962153 views
中学数学623755 views
Help
Tools
NewsSpreadsheetCalendarBookkeepingSlidesTier ListPen ToolIllustrationCrayonWatercolorPixel ArtASCII ArtPerspectiveEndless StairsGraphMind MapER DiagramFamily TreeMemeCurved TextImage EditorMosaicRetro FilterPencil SketchSwirl EffectOCR/HighlighterMakeup EditorFaviconVideo TrimmerScrolling VideoVideo TitleColor PickerColor ExtractorBonfireFireworksWater RippleWater SplashBreaking GlassWood GrainMarble TextureCSS ButtonIcon MakerBar ChartGrouped Bar ChartStacked Bar ChartPie ChartLine ChartArea ChartStacked Area ChartScatter Plot3D Bar Chart3D Pie ChartBar Chart RaceBubble ChartPopulation PyramidPictogramEarningsCandlestick ChartInvestment RiskMortgage SimulatorCalculatorMatrix CalculatorFunction GraphPolynomial ExpansionVenn DiagramField VisualizerRubik's Cube Group TheoryTraveling SalesmanVoronoi and DelaunayFractalColumn ArithmeticDraw Math FiguresArithmetic AnimationArithmetic Word ProblemsCounting with Tree DiagramsCube NetsRolling DiceCross SectionsMotion PathMechanicsWavesElectromagnetic WavesLight and LensesThermodynamicsHow Semiconductors WorkMolecular StructuresAtomic OrbitalsElectrochemical CellsChemical EquilibriumCrystal LatticesBuffer pHPeriodic TableComplex IonsDNA Double HelixCell DivisionMembrane ChannelsNerve ImpulseMuscle ContractionHormones and HomeostasisRock ClassificationWeatherConstellationsSolar and Lunar Eclipses3D ModelingFloor PlanSeismic StructuresIntersection TurnMaglevCooking AnimationOrigamiLive Viewer CountGeoJSON MapRailway MapPopulation MapCrime MapLand Price MapSchool MapShrine and Castle MapHouse of Representatives MapWord MapSolitaireReversiHakoiri MusumeChessHamburgerRippleSlide Puzzle MakerNeon PinballNovel MakerJapanese Typing PracticePiano Score EditorMusic TheoryShogi StrategyPiano Rhythm Game

English

双曲線関数(sinh, cosh, tanh)と逆双曲線関数|Python

双曲線関数は三角関数と似た性質を持ちながら、指数関数で定義される関数群だ。物理学では特殊相対性理論や懸垂線(カテナリー)の記述に登場し、機械学習では活性化関数として使われる。Python の math モジュールで計算できる。

双曲線関数の定義

双曲線正弦 、双曲線余弦 、双曲線正接 は次のように定義される。

import math

x = 1

print(math.sinh(x))  # 1.1752011936438014
print(math.cosh(x))  # 1.5430806348152437
print(math.tanh(x))  # 0.7615941559557649

# 定義式で確認
print((math.e**x - math.e**(-x)) / 2)  # 1.1752011936438014(sinh と一致)

三角関数との類似点と相違点

三角関数と双曲線関数は多くの公式が似ている。ただし、符号が異なる場合がある。

三角関数

(ピタゴラスの定理)。単位円 上の点を表す。

双曲線関数

。双曲線 上の点を表す。

import math

x = 2

# 三角関数の恒等式
print(math.sin(x)**2 + math.cos(x)**2)  # 1.0

# 双曲線関数の恒等式
print(math.cosh(x)**2 - math.sinh(x)**2)  # 1.0000000000000002(≈ 1)

関数の形状

sinh は奇関数で原点を通り、 で急激に増加する。cosh は偶関数で最小値 )を持つ。tanh から の範囲に収まり、S 字型のカーブを描く。

import math

# sinh は奇関数
print(math.sinh(-2))  # -3.6268604078470186
print(math.sinh(2))   # 3.626860407847019

# cosh は偶関数、最小値 1
print(math.cosh(0))   # 1.0
print(math.cosh(-2))  # 3.7621956910836314
print(math.cosh(2))   # 3.7621956910836314

# tanh は -1 ~ 1 に収まる
print(math.tanh(-10))  # -0.9999999958776927
print(math.tanh(0))    # 0.0
print(math.tanh(10))   # 0.9999999958776927

逆双曲線関数

逆双曲線関数は asinhacoshatanh で計算する。

import math

# asinh: 定義域は全実数
print(math.asinh(0))   # 0.0
print(math.asinh(1))   # 0.8813735870195429

# acosh: 定義域は x ≥ 1
print(math.acosh(1))   # 0.0
print(math.acosh(2))   # 1.3169578969248166

# atanh: 定義域は -1 < x < 1
print(math.atanh(0))   # 0.0
print(math.atanh(0.5)) # 0.5493061443340548

acosh でのみ定義され、atanh の開区間でのみ定義される。範囲外の値を渡すと ValueError になる。

import math

# acosh(0.5) は定義されない
# math.acosh(0.5)  # ValueError: math domain error

# atanh(1) も定義されない
# math.atanh(1)  # ValueError: math domain error

対数による表現

逆双曲線関数は対数で表現できる。

import math

x = 2

# asinh を対数で計算
asinh_log = math.log(x + math.sqrt(x**2 + 1))
print(asinh_log)        # 1.4436354751788103
print(math.asinh(x))    # 1.4436354751788103(一致)

応用例:懸垂線(カテナリー)

両端を固定した鎖やケーブルが重力で垂れ下がる曲線は「懸垂線」と呼ばれ、 で表される。

import math

def catenary(x, a=1):
    """懸垂線の方程式"""
    return a * math.cosh(x / a)

# x = 0 で最小値
print(catenary(0))    # 1.0
print(catenary(1))    # 1.5430806348152437
print(catenary(-1))   # 1.5430806348152437(対称)

吊り橋のケーブルや送電線の形状を計算するときに使われる。

応用例:機械学習の活性化関数

tanh はニューラルネットワークの活性化関数として使われる。出力が から に正規化され、勾配消失問題がシグモイド関数より軽減される。

import math

def tanh_activation(inputs):
    """tanh 活性化関数を適用"""
    return [math.tanh(x) for x in inputs]

inputs = [-2, -1, 0, 1, 2]
outputs = tanh_activation(inputs)
print(outputs)
# [-0.964..., -0.761..., 0.0, 0.761..., 0.964...]

現在では ReLU 系の活性化関数が主流だが、LSTM や GRU などの RNN では今でも tanh が使われている。

その他の双曲線関数

math モジュールには含まれていないが、双曲線余割 、双曲線正割 、双曲線余接 も定義できる。

import math

def csch(x):
    return 1 / math.sinh(x)

def sech(x):
    return 1 / math.cosh(x)

def coth(x):
    return math.cosh(x) / math.sinh(x)

print(sech(0))  # 1.0(cosh(0) = 1 の逆数)
print(coth(1))  # 1.3130352854993312

これらは信号処理やソリトン理論など、特殊な分野で登場する。