 |
Crystal Ball function shown as a line
Source code name: "func_cryball.py"
Programming language: Python
Topic: Function/Custom
DMelt Version 1. Last modified: 12/11/2015. License: Pro
https://datamelt.org/code/cache/func_cryball_8542.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from java.awt import Color
from jhplot import *
from java.lang.Math import *
from org.apache.commons.math3.special.Erf import *
"""
Crystal Ball function as described in http://en.wikipedia.org/wiki/Crystal_Ball_function
"""
class MyFunc(FNon):
def value(self, x):
xmean=self.p[0]
sigma= self.p[1]
n = int(self.p[2])
alpha=self.p[3]
s=(x[0] - xmean) / sigma
A=pow( (n / abs(alpha)), n) * exp(-0.5*abs(alpha)*abs(alpha))
B= (n / abs(alpha)) - abs(alpha)
C=(n/abs(alpha)) * (1.0/(n-1)) * exp(-0.5*abs(alpha)*abs(alpha))
D=sqrt(3.14/2) * (1 + erf(abs(alpha)/1.4))
N=1.0/(sigma*(C+D))
if s> -alpha:
return N*exp( -0.5*s*s );
if s<= -alpha:
return N*A*pow((B-s), -n);
c1 = HPlot()
c1.visible(); c1.setAutoRange()
pl = MyFunc("Crystal Ball function",1,4)
pl.setParameters([0.0,1.0,3,1.0])
print pl.value([0.4])
f1=F1D(pl,-10,4)
c1.draw(f1)
You see the box below because you did not login.