mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2025-09-09 16:17:22 +00:00
tra-analysis v 3.0.0 aggregate PR (#73)
* reflected doc changes to README.md
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* tra_analysis v 2.1.0-alpha.1
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* changed setup.py to use __version__ from source
added Topic and keywords
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* updated Supported Platforms in README.md
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* moved required files back to parent
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* moved security back to parent
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* moved security back to parent
moved contributing back to parent
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* add PR template
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* moved to parent folder
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* moved meta files to .github folder
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* Analysis.py v 3.0.1
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* updated test_analysis for submodules, and added missing numpy import in Sort.py
* fixed item one of Issue #58
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* readded cache searching in postCreateCommand
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* added myself as an author
* feat: created kivy gui boilerplate
* added Kivy to requirements.txt
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* feat: gui with placeholders
* fix: changed config.json path
* migrated docker base image to debian
Signed-off-by: ltcptgeneral <learthurgo@gmail.com>
* style: spaces to tabs
* migrated to ubuntu
Signed-off-by: ltcptgeneral <learthurgo@gmail.com>
* fixed issues
Signed-off-by: ltcptgeneral <learthurgo@gmail.com>
* fix: docker build?
* fix: use ubuntu bionic
* fix: get kivy installed
* @ltcptgeneral can't spell
* optim dockerfile for not installing unused packages
* install basic stuff while building the container
* use prebuilt image for development
* install pylint on base image
* rename and use new kivy
* tests: added tests for Array and CorrelationTest
Both are not working due to errors
* use new thing
* use 20.04 base
* symlink pip3 to pip
* use pip instead of pip3
* equation.Expression.py v 0.0.1-alpha
added corresponding .pyc to .gitignore
* parser.py v 0.0.2-alpha
* added pyparsing to requirements.txt
* parser v 0.0.4-alpha
* Equation v 0.0.1-alpha
* added Equation to tra_analysis imports
* tests: New unit tests for submoduling (#66)
* feat: created kivy gui boilerplate
* migrated docker base image to debian
Signed-off-by: ltcptgeneral <learthurgo@gmail.com>
* migrated to ubuntu
Signed-off-by: ltcptgeneral <learthurgo@gmail.com>
* fixed issues
Signed-off-by: ltcptgeneral <learthurgo@gmail.com>
* fix: docker build?
* fix: use ubuntu bionic
* fix: get kivy installed
* @ltcptgeneral can't spell
* optim dockerfile for not installing unused packages
* install basic stuff while building the container
* use prebuilt image for development
* install pylint on base image
* rename and use new kivy
* tests: added tests for Array and CorrelationTest
Both are not working due to errors
* fix: Array no longer has *args and CorrelationTest functions no longer have self in the arguments
* use new thing
* use 20.04 base
* symlink pip3 to pip
* use pip instead of pip3
* tra_analysis v 2.1.0-alpha.2
SVM v 1.0.1
added unvalidated SVM unit tests
Signed-off-by: ltcptgeneral <learthurgo@gmail.com>
* fixed version number
Signed-off-by: ltcptgeneral <learthurgo@gmail.com>
* tests: added tests for ClassificationMetric
* partially fixed and commented out svm unit tests
* fixed some SVM unit tests
* added installing pytest to devcontainer.json
* fix: small fixes to KNN
Namely, removing self from parameters and passing correct arguments to KNeighborsClassifier constructor
* fix, test: Added tests for KNN and NaiveBayes.
Also made some small fixes in KNN, NaiveBayes, and RegressionMetric
* test: finished unit tests except for StatisticalTest
Also made various small fixes and style changes
* StatisticalTest v 1.0.1
* fixed RegressionMetric unit test
temporarily disabled CorrelationTest unit tests
* tra_analysis v 2.1.0-alpha.3
* readded __all__
* fix: floating point issues in unit tests for CorrelationTest
Co-authored-by: AGawde05 <agawde05@gmail.com>
Co-authored-by: ltcptgeneral <learthurgo@gmail.com>
Co-authored-by: Dev Singh <dev@devksingh.com>
Co-authored-by: jzpan1 <panzhenyu2014@gmail.com>
* fixed depreciated escape sequences
* ficed tests, indent, import in test_analysis
* changed version to 3.0.0
added backwards compatibility
* ficed pytest install in container
* removed GUI changes
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* incremented version to rc.1 (release candidate 1)
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* fixed NaiveBayes __changelog__
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* fix: __setitem__ == to single =
* Array v 1.0.1
* Revert "Array v 1.0.1"
This reverts commit 59783b79f7
.
* Array v 1.0.1
* Array.py v 1.0.2
added more Array unit tests
* cleaned .gitignore
tra_analysis v 3.0.0-rc2
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
* added *.pyc to gitignore
finished subdividing test_analysis
* feat: gui layout + basic func
* Froze and removed superscript (data-analysis)
* remove data-analysis deps install for devcontainer
* tukey pairwise comparison and multicomparison but no critical q-values
* quick patch for devcontainer.json
* better fix for devcontainer.json
* fixed some styling in StatisticalTest
removed print statement in StatisticalTest unit tests
* update analysis tests to be more effecient
* don't use loop for test_nativebayes
* removed useless secondary docker files
* tra-analysis v 3.0.0
Co-authored-by: James Pan <panzhenyu2014@gmail.com>
Co-authored-by: AGawde05 <agawde05@gmail.com>
Co-authored-by: zpan1 <72054510+zpan1@users.noreply.github.com>
Co-authored-by: Dev Singh <dev@devksingh.com>
Co-authored-by: = <=>
Co-authored-by: Dev Singh <dsingh@imsa.edu>
Co-authored-by: zpan1 <zpan@imsa.edu>
This commit is contained in:
@@ -0,0 +1,237 @@
|
||||
import math
|
||||
import sys
|
||||
import re
|
||||
|
||||
if sys.version_info >= (3,):
|
||||
xrange = range
|
||||
basestring = str
|
||||
|
||||
class ExpressionObject(object):
|
||||
def __init__(self,*args,**kwargs):
|
||||
super(ExpressionObject,self).__init__(*args,**kwargs)
|
||||
|
||||
def toStr(self,args,expression):
|
||||
return ""
|
||||
|
||||
def toRepr(self,args,expression):
|
||||
return ""
|
||||
|
||||
def __call__(self,args,expression):
|
||||
pass
|
||||
|
||||
class ExpressionValue(ExpressionObject):
|
||||
def __init__(self,value,*args,**kwargs):
|
||||
super(ExpressionValue,self).__init__(*args,**kwargs)
|
||||
self.value = value
|
||||
|
||||
def toStr(self,args,expression):
|
||||
if (isinstance(self.value,complex)):
|
||||
V = [self.value.real,self.value.imag]
|
||||
E = [0,0]
|
||||
B = [0,0]
|
||||
out = ["",""]
|
||||
for i in xrange(2):
|
||||
if V[i] == 0:
|
||||
E[i] = 0
|
||||
B[i] = 0
|
||||
else:
|
||||
E[i] = int(math.floor(math.log10(abs(V[i]))))
|
||||
B[i] = V[i]*10**-E[i]
|
||||
if E[i] in [0,1,2,3] and str(V[i])[-2:] == ".0":
|
||||
B[i] = int(V[i])
|
||||
E[i] = 0
|
||||
if E[i] in [-1,-2] and len(str(V[i])) <= 7:
|
||||
B[i] = V[i]
|
||||
E[i] = 0
|
||||
if i == 1:
|
||||
fmt = "{{0:+{0:s}}}"
|
||||
else:
|
||||
fmt = "{{0:-{0:s}}}"
|
||||
if type(B[i]) == int:
|
||||
out[i] += fmt.format('d').format(B[i])
|
||||
else:
|
||||
out[i] += fmt.format('.5f').format(B[i]).rstrip("0.")
|
||||
if i == 1:
|
||||
out[i] += "\\imath"
|
||||
if E[i] != 0:
|
||||
out[i] += "\\times10^{{{0:d}}}".format(E[i])
|
||||
return "\\left(" + ''.join(out) + "\\right)"
|
||||
elif (isinstance(self.value,float)):
|
||||
V = self.value
|
||||
E = 0
|
||||
B = 0
|
||||
out = ""
|
||||
if V == 0:
|
||||
E = 0
|
||||
B = 0
|
||||
else:
|
||||
E = int(math.floor(math.log10(abs(V))))
|
||||
B = V*10**-E
|
||||
if E in [0,1,2,3] and str(V)[-2:] == ".0":
|
||||
B = int(V)
|
||||
E = 0
|
||||
if E in [-1,-2] and len(str(V)) <= 7:
|
||||
B = V
|
||||
E = 0
|
||||
if type(B) == int:
|
||||
out += "{0:-d}".format(B)
|
||||
else:
|
||||
out += "{0:-.5f}".format(B).rstrip("0.")
|
||||
if E != 0:
|
||||
out += "\\times10^{{{0:d}}}".format(E)
|
||||
return "\\left(" + out + "\\right)"
|
||||
else:
|
||||
return out
|
||||
else:
|
||||
return str(self.value)
|
||||
|
||||
def toRepr(self,args,expression):
|
||||
return str(self.value)
|
||||
|
||||
def __call__(self,args,expression):
|
||||
return self.value
|
||||
|
||||
def __repr__(self):
|
||||
return "<{0:s}.{1:s}({2:s}) object at {3:0=#10x}>".format(type(self).__module__,type(self).__name__,str(self.value),id(self))
|
||||
|
||||
class ExpressionFunction(ExpressionObject):
|
||||
def __init__(self,function,nargs,form,display,id,isfunc,*args,**kwargs):
|
||||
super(ExpressionFunction,self).__init__(*args,**kwargs)
|
||||
self.function = function
|
||||
self.nargs = nargs
|
||||
self.form = form
|
||||
self.display = display
|
||||
self.id = id
|
||||
self.isfunc = isfunc
|
||||
|
||||
def toStr(self,args,expression):
|
||||
params = []
|
||||
for i in xrange(self.nargs):
|
||||
params.append(args.pop())
|
||||
if self.isfunc:
|
||||
return str(self.display.format(','.join(params[::-1])))
|
||||
else:
|
||||
return str(self.display.format(*params[::-1]))
|
||||
|
||||
def toRepr(self,args,expression):
|
||||
params = []
|
||||
for i in xrange(self.nargs):
|
||||
params.append(args.pop())
|
||||
if self.isfunc:
|
||||
return str(self.form.format(','.join(params[::-1])))
|
||||
else:
|
||||
return str(self.form.format(*params[::-1]))
|
||||
|
||||
def __call__(self,args,expression):
|
||||
params = []
|
||||
for i in xrange(self.nargs):
|
||||
params.append(args.pop())
|
||||
return self.function(*params[::-1])
|
||||
|
||||
def __repr__(self):
|
||||
return "<{0:s}.{1:s}({2:s},{3:d}) object at {4:0=#10x}>".format(type(self).__module__,type(self).__name__,str(self.id),self.nargs,id(self))
|
||||
|
||||
class ExpressionVariable(ExpressionObject):
|
||||
def __init__(self,name,*args,**kwargs):
|
||||
super(ExpressionVariable,self).__init__(*args,**kwargs)
|
||||
self.name = name
|
||||
|
||||
def toStr(self,args,expression):
|
||||
return str(self.name)
|
||||
|
||||
def toRepr(self,args,expression):
|
||||
return str(self.name)
|
||||
|
||||
def __call__(self,args,expression):
|
||||
if self.name in expression.variables:
|
||||
return expression.variables[self.name]
|
||||
else:
|
||||
return 0 # Default variables to return 0
|
||||
|
||||
def __repr__(self):
|
||||
return "<{0:s}.{1:s}({2:s}) object at {3:0=#10x}>".format(type(self).__module__,type(self).__name__,str(self.name),id(self))
|
||||
|
||||
class Core():
|
||||
|
||||
constants = {}
|
||||
unary_ops = {}
|
||||
ops = {}
|
||||
functions = {}
|
||||
smatch = re.compile(r"\s*,")
|
||||
vmatch = re.compile(r"\s*"
|
||||
"(?:"
|
||||
"(?P<oct>"
|
||||
"(?P<octsign>[+-]?)"
|
||||
r"\s*0o"
|
||||
"(?P<octvalue>[0-7]+)"
|
||||
")|(?P<hex>"
|
||||
"(?P<hexsign>[+-]?)"
|
||||
r"\s*0x"
|
||||
"(?P<hexvalue>[0-9a-fA-F]+)"
|
||||
")|(?P<bin>"
|
||||
"(?P<binsign>[+-]?)"
|
||||
r"\s*0b"
|
||||
"(?P<binvalue>[01]+)"
|
||||
")|(?P<dec>"
|
||||
"(?P<rsign>[+-]?)"
|
||||
r"\s*"
|
||||
r"(?P<rvalue>(?:\d+\.\d+|\d+\.|\.\d+|\d+))"
|
||||
"(?:"
|
||||
"[Ee]"
|
||||
r"(?P<rexpoent>[+-]?\d+)"
|
||||
")?"
|
||||
"(?:"
|
||||
r"\s*"
|
||||
r"(?P<sep>(?(rvalue)\+|))?"
|
||||
r"\s*"
|
||||
"(?P<isign>(?(rvalue)(?(sep)[+-]?|[+-])|[+-]?)?)"
|
||||
r"\s*"
|
||||
r"(?P<ivalue>(?:\d+\.\d+|\d+\.|\.\d+|\d+))"
|
||||
"(?:"
|
||||
"[Ee]"
|
||||
r"(?P<iexpoent>[+-]?\d+)"
|
||||
")?"
|
||||
"[ij]"
|
||||
")?"
|
||||
")"
|
||||
")")
|
||||
nmatch = re.compile(r"\s*([a-zA-Z_][a-zA-Z0-9_]*)")
|
||||
gsmatch = re.compile(r'\s*(\()')
|
||||
gematch = re.compile(r'\s*(\))')
|
||||
|
||||
def recalculateFMatch(self):
|
||||
|
||||
fks = sorted(self.functions.keys(), key=len, reverse=True)
|
||||
oks = sorted(self.ops.keys(), key=len, reverse=True)
|
||||
uks = sorted(self.unary_ops.keys(), key=len, reverse=True)
|
||||
self.fmatch = re.compile(r'\s*(' + '|'.join(map(re.escape,fks)) + ')')
|
||||
self.omatch = re.compile(r'\s*(' + '|'.join(map(re.escape,oks)) + ')')
|
||||
self.umatch = re.compile(r'\s*(' + '|'.join(map(re.escape,uks)) + ')')
|
||||
|
||||
def addFn(self,id,str,latex,args,func):
|
||||
self.functions[id] = {
|
||||
'str': str,
|
||||
'latex': latex,
|
||||
'args': args,
|
||||
'func': func}
|
||||
|
||||
def addOp(self,id,str,latex,single,prec,func):
|
||||
if single:
|
||||
raise RuntimeError("Single Ops Not Yet Supported")
|
||||
self.ops[id] = {
|
||||
'str': str,
|
||||
'latex': latex,
|
||||
'args': 2,
|
||||
'prec': prec,
|
||||
'func': func}
|
||||
|
||||
def addUnaryOp(self,id,str,latex,func):
|
||||
self.unary_ops[id] = {
|
||||
'str': str,
|
||||
'latex': latex,
|
||||
'args': 1,
|
||||
'prec': 0,
|
||||
'func': func}
|
||||
|
||||
def addConst(self,name,value):
|
||||
self.constants[name] = value
|
@@ -0,0 +1,2 @@
|
||||
from . import equation_base as equation_base
|
||||
from .ExpressionCore import ExpressionValue, ExpressionFunction, ExpressionVariable, Core
|
@@ -0,0 +1,106 @@
|
||||
try:
|
||||
import numpy as np
|
||||
has_numpy = True
|
||||
except ImportError:
|
||||
import math
|
||||
has_numpy = False
|
||||
try:
|
||||
import scipy.constants
|
||||
has_scipy = True
|
||||
except ImportError:
|
||||
has_scipy = False
|
||||
import operator as op
|
||||
from .similar import sim, nsim, gsim, lsim
|
||||
|
||||
def equation_extend(core):
|
||||
def product(*args):
|
||||
if len(args) == 1 and has_numpy:
|
||||
return np.prod(args[0])
|
||||
else:
|
||||
return reduce(op.mul,args,1)
|
||||
|
||||
def sumargs(*args):
|
||||
if len(args) == 1:
|
||||
return sum(args[0])
|
||||
else:
|
||||
return sum(args)
|
||||
|
||||
core.addOp('+',"({0:s} + {1:s})","\\left({0:s} + {1:s}\\right)",False,3,op.add)
|
||||
core.addOp('-',"({0:s} - {1:s})","\\left({0:s} - {1:s}\\right)",False,3,op.sub)
|
||||
core.addOp('*',"({0:s} * {1:s})","\\left({0:s} \\times {1:s}\\right)",False,2,op.mul)
|
||||
core.addOp('/',"({0:s} / {1:s})","\\frac{{{0:s}}}{{{1:s}}}",False,2,op.truediv)
|
||||
core.addOp('%',"({0:s} % {1:s})","\\left({0:s} \\bmod {1:s}\\right)",False,2,op.mod)
|
||||
core.addOp('^',"({0:s} ^ {1:s})","{0:s}^{{{1:s}}}",False,1,op.pow)
|
||||
core.addOp('**',"({0:s} ^ {1:s})","{0:s}^{{{1:s}}}",False,1,op.pow)
|
||||
core.addOp('&',"({0:s} & {1:s})","\\left({0:s} \\land {1:s}\\right)",False,4,op.and_)
|
||||
core.addOp('|',"({0:s} | {1:s})","\\left({0:s} \\lor {1:s}\\right)",False,4,op.or_)
|
||||
core.addOp('</>',"({0:s} </> {1:s})","\\left({0:s} \\oplus {1:s}\\right)",False,4,op.xor)
|
||||
core.addOp('&|',"({0:s} </> {1:s})","\\left({0:s} \\oplus {1:s}\\right)",False,4,op.xor)
|
||||
core.addOp('|&',"({0:s} </> {1:s})","\\left({0:s} \\oplus {1:s}\\right)",False,4,op.xor)
|
||||
core.addOp('==',"({0:s} == {1:s})","\\left({0:s} = {1:s}\\right)",False,5,op.eq)
|
||||
core.addOp('=',"({0:s} == {1:s})","\\left({0:s} = {1:s}\\right)",False,5,op.eq)
|
||||
core.addOp('~',"({0:s} ~ {1:s})","\\left({0:s} \\approx {1:s}\\right)",False,5,sim)
|
||||
core.addOp('!~',"({0:s} !~ {1:s})","\\left({0:s} \\not\\approx {1:s}\\right)",False,5,nsim)
|
||||
core.addOp('!=',"({0:s} != {1:s})","\\left({0:s} \\neg {1:s}\\right)",False,5,op.ne)
|
||||
core.addOp('<>',"({0:s} != {1:s})","\\left({0:s} \\neg {1:s}\\right)",False,5,op.ne)
|
||||
core.addOp('><',"({0:s} != {1:s})","\\left({0:s} \\neg {1:s}\\right)",False,5,op.ne)
|
||||
core.addOp('<',"({0:s} < {1:s})","\\left({0:s} < {1:s}\\right)",False,5,op.lt)
|
||||
core.addOp('>',"({0:s} > {1:s})","\\left({0:s} > {1:s}\\right)",False,5,op.gt)
|
||||
core.addOp('<=',"({0:s} <= {1:s})","\\left({0:s} \\leq {1:s}\\right)",False,5,op.le)
|
||||
core.addOp('>=',"({0:s} >= {1:s})","\\left({0:s} \\geq {1:s}\\right)",False,5,op.ge)
|
||||
core.addOp('=<',"({0:s} <= {1:s})","\\left({0:s} \\leq {1:s}\\right)",False,5,op.le)
|
||||
core.addOp('=>',"({0:s} >= {1:s})","\\left({0:s} \\geq {1:s}\\right)",False,5,op.ge)
|
||||
core.addOp('<~',"({0:s} <~ {1:s})","\\left({0:s} \lessapprox {1:s}\\right)",False,5,lsim)
|
||||
core.addOp('>~',"({0:s} >~ {1:s})","\\left({0:s} \\gtrapprox {1:s}\\right)",False,5,gsim)
|
||||
core.addOp('~<',"({0:s} <~ {1:s})","\\left({0:s} \lessapprox {1:s}\\right)",False,5,lsim)
|
||||
core.addOp('~>',"({0:s} >~ {1:s})","\\left({0:s} \\gtrapprox {1:s}\\right)",False,5,gsim)
|
||||
core.addUnaryOp('!',"(!{0:s})","\\neg{0:s}",op.not_)
|
||||
core.addUnaryOp('-',"-{0:s}","-{0:s}",op.neg)
|
||||
core.addFn('abs',"abs({0:s})","\\left|{0:s}\\right|",1,op.abs)
|
||||
core.addFn('sum',"sum({0:s})","\\sum\\left({0:s}\\right)",'+',sumargs)
|
||||
core.addFn('prod',"prod({0:s})","\\prod\\left({0:s}\\right)",'+',product)
|
||||
if has_numpy:
|
||||
core.addFn('floor',"floor({0:s})","\\lfloor {0:s} \\rfloor",1,np.floor)
|
||||
core.addFn('ceil',"ceil({0:s})","\\lceil {0:s} \\rceil",1,np.ceil)
|
||||
core.addFn('round',"round({0:s})","\\lfloor {0:s} \\rceil",1,np.round)
|
||||
core.addFn('sin',"sin({0:s})","\\sin\\left({0:s}\\right)",1,np.sin)
|
||||
core.addFn('cos',"cos({0:s})","\\cos\\left({0:s}\\right)",1,np.cos)
|
||||
core.addFn('tan',"tan({0:s})","\\tan\\left({0:s}\\right)",1,np.tan)
|
||||
core.addFn('re',"re({0:s})","\\Re\\left({0:s}\\right)",1,np.real)
|
||||
core.addFn('im',"re({0:s})","\\Im\\left({0:s}\\right)",1,np.imag)
|
||||
core.addFn('sqrt',"sqrt({0:s})","\\sqrt{{{0:s}}}",1,np.sqrt)
|
||||
core.addConst("pi",np.pi)
|
||||
core.addConst("e",np.e)
|
||||
core.addConst("Inf",np.Inf)
|
||||
core.addConst("NaN",np.NaN)
|
||||
else:
|
||||
core.addFn('floor',"floor({0:s})","\\lfloor {0:s} \\rfloor",1,math.floor)
|
||||
core.addFn('ceil',"ceil({0:s})","\\lceil {0:s} \\rceil",1,math.ceil)
|
||||
core.addFn('round',"round({0:s})","\\lfloor {0:s} \\rceil",1,round)
|
||||
core.addFn('sin',"sin({0:s})","\\sin\\left({0:s}\\right)",1,math.sin)
|
||||
core.addFn('cos',"cos({0:s})","\\cos\\left({0:s}\\right)",1,math.cos)
|
||||
core.addFn('tan',"tan({0:s})","\\tan\\left({0:s}\\right)",1,math.tan)
|
||||
core.addFn('re',"re({0:s})","\\Re\\left({0:s}\\right)",1,complex.real)
|
||||
core.addFn('im',"re({0:s})","\\Im\\left({0:s}\\right)",1,complex.imag)
|
||||
core.addFn('sqrt',"sqrt({0:s})","\\sqrt{{{0:s}}}",1,math.sqrt)
|
||||
core.addConst("pi",math.pi)
|
||||
core.addConst("e",math.e)
|
||||
core.addConst("Inf",float("Inf"))
|
||||
core.addConst("NaN",float("NaN"))
|
||||
if has_scipy:
|
||||
core.addConst("h",scipy.constants.h)
|
||||
core.addConst("hbar",scipy.constants.hbar)
|
||||
core.addConst("m_e",scipy.constants.m_e)
|
||||
core.addConst("m_p",scipy.constants.m_p)
|
||||
core.addConst("m_n",scipy.constants.m_n)
|
||||
core.addConst("c",scipy.constants.c)
|
||||
core.addConst("N_A",scipy.constants.N_A)
|
||||
core.addConst("mu_0",scipy.constants.mu_0)
|
||||
core.addConst("eps_0",scipy.constants.epsilon_0)
|
||||
core.addConst("k",scipy.constants.k)
|
||||
core.addConst("G",scipy.constants.G)
|
||||
core.addConst("g",scipy.constants.g)
|
||||
core.addConst("q",scipy.constants.e)
|
||||
core.addConst("R",scipy.constants.R)
|
||||
core.addConst("sigma",scipy.constants.e)
|
||||
core.addConst("Rb",scipy.constants.Rydberg)
|
@@ -0,0 +1,49 @@
|
||||
_tol = 1e-5
|
||||
|
||||
def sim(a,b):
|
||||
if (a==b):
|
||||
return True
|
||||
elif a == 0 or b == 0:
|
||||
return False
|
||||
if (a<b):
|
||||
return (1-a/b)<=_tol
|
||||
else:
|
||||
return (1-b/a)<=_tol
|
||||
|
||||
def nsim(a,b):
|
||||
if (a==b):
|
||||
return False
|
||||
elif a == 0 or b == 0:
|
||||
return True
|
||||
if (a<b):
|
||||
return (1-a/b)>_tol
|
||||
else:
|
||||
return (1-b/a)>_tol
|
||||
|
||||
def gsim(a,b):
|
||||
if a >= b:
|
||||
return True
|
||||
return (1-a/b)<=_tol
|
||||
|
||||
def lsim(a,b):
|
||||
if a <= b:
|
||||
return True
|
||||
return (1-b/a)<=_tol
|
||||
|
||||
def set_tol(value=1e-5):
|
||||
r"""Set Error Tolerance
|
||||
|
||||
Set the tolerance for detriming if two numbers are simliar, i.e
|
||||
:math:`\left|\frac{a}{b}\right| = 1 \pm tolerance`
|
||||
|
||||
Parameters
|
||||
----------
|
||||
value: float
|
||||
The Value to set the tolerance to show be very small as it respresents the
|
||||
percentage of acceptable error in detriming if two values are the same.
|
||||
"""
|
||||
global _tol
|
||||
if isinstance(value,float):
|
||||
_tol = value
|
||||
else:
|
||||
raise TypeError(type(value))
|
Reference in New Issue
Block a user