# Trashold functions



```python
# initialize environment
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import sympy as sy
x = np.linspace(-5.0,5.0,1000)
dx = x[1]-x[0]

def clamp( x, xmin, xmax):
    x[x<xmin] = xmin
    x[x>xmax] = xmax
    return x
    
def deriv(f):
    return (f[1:]-f[:-1])/dx

def plotFunc(func):
    fs   = func (x)
    dfs  = deriv(fs)
    ddfs = deriv(dfs)
    plt.subplot(311); plt.plot( x,fs)
    plt.subplot(312); plt.plot( x[1:]-0.5*dx, dfs  )
    plt.subplot(313); plt.plot( x[2:]    -dx, ddfs )
```

### Sigmoide derivs




```python
def softmax_exp(x):
    expx = np.exp(x)
    return x*expx/(1+expx)

def softmax_sqrt(x):
    return 0.5*( np.sqrt( 1 + x*x ) + x )

def smoothstep_sqrt(x):
    return 0.5*( x/np.sqrt( 1 + x*x ) + 1 )

plt.figure(figsize=(6,15))
plotFunc( softmax_sqrt )
plotFunc( smoothstep_sqrt )

plt.subplot(311); plt.ylim(-2.0,2.0); plt.grid()
plt.subplot(312); plt.ylim(-2.0,2.0); plt.grid()
plt.subplot(313); plt.ylim(-4.0,4.0); plt.grid()
```

### Plynominal Smoothstep

from /home/prokop/Dropbox/MyDevSW/Python/_math/FunctionApproximation/TreshholdFunctions.py



```python
def stepP3(x):
    # integral of (1-x)*x shifted
    x = clamp(x.copy(),0.0,1.0)
    return (3-2*x)*x**2 

def stepP5a(x):
    # double integrel of stepP3:  0.5 - (3-2*x)*x**2
    x = clamp(x.copy(),0.0,1.0)
    return (-x**4/4 + x**5/10 + x**2/4)*10 

def stepP5b(x):
    # integral of (x**2)*((1-x)**2)
    x = clamp(x.copy(),0.0,1.0)
    return (x**3/3 - x**4/2 + x**5/5)*30  

def stepP5c(x):
    # integral of  
    x = clamp(x.copy(),0.0,1.0)
    return x - (2.0/3)*x**3 + x**5/5  

def stepLorenz(x, w=1.0):
    x = clamp(x.copy(),0.0,1.0)
    return w/(w+x**2) - w/(w+(1-x)**2)

plt.figure(figsize=(6,15))

plotFunc(stepP3 )
plotFunc(stepP5a)
plotFunc(stepP5b)

plt.subplot(311); plt.xlim(-1.0,2.0); plt.grid()
plt.subplot(312); plt.xlim(-1.0,2.0); plt.grid()
plt.subplot(313); plt.xlim(-1.0,2.0); plt.grid()

```


```python

```


```python

```


```python

```

07a1880fc5b6528bc002f0186ae8e48861b0b53a
ipynb
Jupyter Notebook
projects/NumericsNotes/TrasholdFunctions.ipynb
ProkopHapala/SimpleSimulationEngine
240f9b7e85b3a6eda7a27dc15fe3f7b8c08774c5
MIT
2016-12-04T04:45:12.000Z
2022-03-24T09:39:28.000Z
projects/NumericsNotes/TrasholdFunctions.ipynb
Aki78/FlightAI
9c5480f2392c9c89b9fee4902db0c4cde5323a6c
MIT
projects/NumericsNotes/TrasholdFunctions.ipynb
Aki78/FlightAI
9c5480f2392c9c89b9fee4902db0c4cde5323a6c
MIT
2019-02-09T12:31:06.000Z
2019-04-28T02:24:50.000Z
Qwen/Qwen-72B
1. YES
2. YES