Softplus

2022. 3. 14. 13:43·.../Math
728x90
728x90

다음과 같은 함수를 softplus라고 하며, ANN에서 activation function으로 사용됨.

 

$$\begin{aligned}\zeta(x)&=\log(1+e^x)\\&=\log(1+e^{-|x|})+\max(0,x)\end{aligned}$$

  • exponential function과 Logarithmic function을 더한 함수
    (즉, Transcendental function의 하나임).
  • y=max(x,0)(ReLU)와 매우 비슷하나 $x=0$ 근처에서 값이 보다 부드럽게 변함 (미분 가능)
  • 위 식에서 $\log(1+e^x)$는 정의이고,
    실제 ML등에서 사용되는 건 $\log(1+e^{-|x|})+\max(0,x)$ 임.
    • $x$가 100정도만 되어도 정의식의 경우 numerical issue로 인해 infinity가 됨.
    • 아래의 equivalent expression은 이런 문제가 없음.
    • 아래 증명 확인.

softplus and its equivalent expression.

  • $z\ge0$인 경우, $\text{softplus}(-|z|)=\text{softplus}(-z)$가 성립함. (5) rightside에 따라 $z$를 더해주어야 함.
  • $z<0$인 경우, $\text{softplus}(-|z|)=\text{softplus}(z)$가 성립함. 이 경우엔 0을 더해준다.

Numpy (그래프)

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
x = np.linspace(-10,10,100)
y = np.log1p(np.exp(x))

plt.plot(x,y)
plt.title('softplus function')
plt.xlabel(r'$x$')
plt.ylabel(r'$\log(1+e^x)$')
plt.show()


TensorFlow

tf.keras.activations.softplus(), tf.nn.softplus() 로 제공됨.

다음과 같이 직접 custom activation function으로 구현할 수도 있음.

def my_softplus_us(z):
    return tf.math.log(1.0 + tf.exp(z))


def my_softplus_stable(z):
    return tf.math.log(1 + tf.exp(-tf.abs(z))) + tf.maximum(0., z)

https://colab.research.google.com/gist/dsaint31x/93d38fb845a7489a8a023bb3ace8c9df/softplus_tensorflow.ipynb

 

softplus_tensorflow.ipynb

Run, share, and edit Python notebooks

colab.research.google.com


Reference

https://learning.oreilly.com/library/view/hands-on-machine-learning/9781098125967/

 

Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 3rd Edition

Through a recent series of breakthroughs, deep learning has boosted the entire field of machine learning. Now, even programmers who know close to nothing about this technology can use simple, … - Selection from Hands-On Machine Learning with Scikit-Learn

www.oreilly.com

12장에서 custom activation 의 예로 softplus 소개.

728x90

'... > Math' 카테고리의 다른 글

[Statistics] Central Limit Theorem  (0) 2022.03.31
[Statistics] Moment (Probability Moment)  (0) 2022.03.31
[Math] Vector (2) : Vector Function  (0) 2022.03.28
[Math] Vector (1)  (1) 2022.03.28
[Math] Function (함수): 간략 정의  (0) 2021.09.14
'.../Math' 카테고리의 다른 글
  • [Statistics] Moment (Probability Moment)
  • [Math] Vector (2) : Vector Function
  • [Math] Vector (1)
  • [Math] Function (함수): 간략 정의
dsaint31x
dsaint31x
    반응형
    250x250
  • dsaint31x
    Dsaint31's blog
    dsaint31x
  • 전체
    오늘
    어제
    • 분류 전체보기 (785)
      • Private Life (15)
      • Programming (55)
        • DIP (116)
        • ML (34)
      • Computer (119)
        • CE (53)
        • ETC (33)
        • CUDA (3)
        • Blog, Markdown, Latex (4)
        • Linux (9)
      • ... (368)
        • Signals and Systems (115)
        • Math (176)
        • Linear Algebra (33)
        • Physics (43)
        • 인성세미나 (1)
      • 정리필요. (61)
        • 의료기기의 이해 (6)
        • PET, MRI and so on. (7)
        • PET Study 2009 (1)
        • 방사선 장해방호 (5)
        • 방사선 생물학 (3)
        • 방사선 계측 (9)
        • 기타 방사능관련 (3)
        • 고시 (9)
        • 정리 (18)
      • RI (0)
      • 원자력,방사능 관련법 (2)
  • 블로그 메뉴

    • Math
    • Programming
    • SS
    • DIP
  • 링크

    • Convex Optimization For All
  • 공지사항

    • Test
    • PET Study 2009
    • 기타 방사능관련.
  • 인기 글

  • 태그

    fourier transform
    Vector
    SS
    cv2
    Term
    function
    Optimization
    math
    Programming
    Probability
    opencv
    numpy
    random
    SIGNAL
    Python
    linear algebra
    signal_and_system
    인허가제도
    signals_and_systems
    ML
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
dsaint31x
Softplus
상단으로

티스토리툴바