mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-11-13 22:56:18 +00:00
analysis.py v 2.3.0
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
9a9a27cf44
commit
f03101e09c
@ -7,10 +7,12 @@
|
|||||||
# current benchmark of optimization: 1.33 times faster
|
# current benchmark of optimization: 1.33 times faster
|
||||||
# setup:
|
# setup:
|
||||||
|
|
||||||
__version__ = "2.2.3"
|
__version__ = "2.3.0"
|
||||||
|
|
||||||
# changelog should be viewed using print(analysis.__changelog__)
|
# changelog should be viewed using print(analysis.__changelog__)
|
||||||
__changelog__ = """changelog:
|
__changelog__ = """changelog:
|
||||||
|
2.3.0:
|
||||||
|
- overhauled Array class
|
||||||
2.2.3:
|
2.2.3:
|
||||||
- fixed spelling of RandomForest
|
- fixed spelling of RandomForest
|
||||||
- made n_neighbors required for KNN
|
- made n_neighbors required for KNN
|
||||||
@ -786,7 +788,7 @@ class CorrelationTest:
|
|||||||
def anova_oneway(self, *args): #expects arrays of samples
|
def anova_oneway(self, *args): #expects arrays of samples
|
||||||
|
|
||||||
results = scipy.stats.f_oneway(*args)
|
results = scipy.stats.f_oneway(*args)
|
||||||
return {"F-value": results[0], "p-value": results[1]}
|
return {"f-value": results[0], "p-value": results[1]}
|
||||||
|
|
||||||
def pearson(self, x, y):
|
def pearson(self, x, y):
|
||||||
|
|
||||||
@ -986,80 +988,111 @@ class StatisticalTest:
|
|||||||
|
|
||||||
class Array(): # tests on nd arrays independent of basic_stats
|
class Array(): # tests on nd arrays independent of basic_stats
|
||||||
|
|
||||||
def elementwise_mean(self, *args): # expects arrays that are size normalized
|
def __init__(self, narray):
|
||||||
|
|
||||||
return np.mean([*args], axis = 0)
|
self.array = np.array(narray)
|
||||||
|
|
||||||
def elementwise_median(self, *args):
|
def __str__(self):
|
||||||
|
|
||||||
return np.median([*args], axis = 0)
|
return str(self.array)
|
||||||
|
|
||||||
def elementwise_stdev(self, *args):
|
def elementwise_mean(self, *args, axis = 0): # expects arrays that are size normalized
|
||||||
|
if len(*args) == 0:
|
||||||
|
return np.mean(self.array, axis = axis)
|
||||||
|
else:
|
||||||
|
return np.mean([*args], axis = axis)
|
||||||
|
|
||||||
return np.std([*args], axis = 0)
|
def elementwise_median(self, *args, axis = 0):
|
||||||
|
|
||||||
def elementwise_variance(self, *args):
|
if len(*args) == 0:
|
||||||
|
return np.median(self.array, axis = axis)
|
||||||
|
else:
|
||||||
|
return np.median([*args], axis = axis)
|
||||||
|
|
||||||
return np.var([*args], axis = 0)
|
def elementwise_stdev(self, *args, axis = 0):
|
||||||
|
|
||||||
def elementwise_npmin(self, *args):
|
if len(*args) == 0:
|
||||||
|
return np.std(self.array, axis = axis)
|
||||||
|
else:
|
||||||
|
return np.std([*args], axis = axis)
|
||||||
|
|
||||||
return np.amin([*args], axis = 0)
|
def elementwise_variance(self, *args, axis = 0):
|
||||||
|
|
||||||
def elementwise_npmax(self, *args):
|
if len(*args) == 0:
|
||||||
|
return np.var(self.array, axis = axis)
|
||||||
|
else:
|
||||||
|
return np.var([*args], axis = axis)
|
||||||
|
|
||||||
return np.amax([*args], axis = 0)
|
def elementwise_npmin(self, *args, axis = 0):
|
||||||
|
|
||||||
def elementwise_stats(self, *args):
|
if len(*args) == 0:
|
||||||
|
return np.amin(self.array, axis = axis)
|
||||||
|
else:
|
||||||
|
return np.amin([*args], axis = axis)
|
||||||
|
|
||||||
_mean = self.elementwise_mean(*args)
|
def elementwise_npmax(self, *args, axis = 0):
|
||||||
_median = self.elementwise_median(*args)
|
|
||||||
_stdev = self.elementwise_stdev(*args)
|
if len(*args) == 0:
|
||||||
_variance = self.elementwise_variance(*args)
|
return np.amax(self.array, axis = axis)
|
||||||
_min = self.elementwise_npmin(*args)
|
else:
|
||||||
_max = self.elementwise_npmax(*args)
|
return np.amax([*args], axis = axis)
|
||||||
|
|
||||||
|
def elementwise_stats(self, *args, axis = 0):
|
||||||
|
|
||||||
|
_mean = self.elementwise_mean(*args, axis = axis)
|
||||||
|
_median = self.elementwise_median(*args, axis = axis)
|
||||||
|
_stdev = self.elementwise_stdev(*args, axis = axis)
|
||||||
|
_variance = self.elementwise_variance(*args, axis = axis)
|
||||||
|
_min = self.elementwise_npmin(*args, axis = axis)
|
||||||
|
_max = self.elementwise_npmax(*args, axis = axis)
|
||||||
|
|
||||||
return _mean, _median, _stdev, _variance, _min, _max
|
return _mean, _median, _stdev, _variance, _min, _max
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
|
||||||
|
return self.array[key]
|
||||||
|
|
||||||
|
def __setitem__(self, key, value):
|
||||||
|
|
||||||
|
self.array[key] == value
|
||||||
|
|
||||||
def normalize(self, array):
|
def normalize(self, array):
|
||||||
|
|
||||||
a = np.atleast_1d(np.linalg.norm(array))
|
a = np.atleast_1d(np.linalg.norm(array))
|
||||||
a[a==0] = 1
|
a[a==0] = 1
|
||||||
return array / np.expand_dims(a, -1)
|
return array / np.expand_dims(a, -1)
|
||||||
|
|
||||||
def add(self, *args):
|
def __add__(self, other):
|
||||||
|
|
||||||
temp = np.array([])
|
return self.array + other
|
||||||
|
|
||||||
for a in args:
|
def __sub__(self, other):
|
||||||
temp += a
|
|
||||||
|
|
||||||
return temp
|
return self.array - other
|
||||||
|
|
||||||
def mul(self, *args):
|
def __neg__(self):
|
||||||
|
|
||||||
temp = np.array([])
|
return -self.array
|
||||||
|
|
||||||
for a in args:
|
def __abs__(self):
|
||||||
temp *= a
|
|
||||||
|
|
||||||
return temp
|
return abs(self.array)
|
||||||
|
|
||||||
def neg(self, array):
|
def __invert__(self):
|
||||||
|
|
||||||
return -array
|
return 1/self.array
|
||||||
|
|
||||||
def inv(self, array):
|
def __mul__(self, other):
|
||||||
|
|
||||||
return 1/array
|
return self.array.dot(other)
|
||||||
|
|
||||||
def dot(self, a, b):
|
def __rmul__(self, other):
|
||||||
|
|
||||||
return np.dot(a, b)
|
return self.array.dot(other)
|
||||||
|
|
||||||
def cross(self, a, b):
|
def cross(self, other):
|
||||||
|
|
||||||
return np.cross(a, b)
|
return np.cross(self.array, b)
|
||||||
|
|
||||||
def sort(self, array): # depreciated
|
def sort(self, array): # depreciated
|
||||||
warnings.warn("Array.sort has been depreciated in favor of Sort")
|
warnings.warn("Array.sort has been depreciated in favor of Sort")
|
||||||
|
Loading…
Reference in New Issue
Block a user