analysis.py v 1.1.13.001

analysis pkg v 1.0.0.006
This commit is contained in:
art 2020-03-05 13:18:33 -06:00
parent b669e55283
commit a0e1293361
9 changed files with 43 additions and 35 deletions

View File

@ -1,6 +1,6 @@
Metadata-Version: 2.1 Metadata-Version: 2.1
Name: analysis Name: analysis
Version: 1.0.0.5 Version: 1.0.0.6
Summary: analysis package developed by Titan Scouting for The Red Alliance Summary: analysis package developed by Titan Scouting for The Red Alliance
Home-page: https://github.com/titanscout2022/tr2022-strategy Home-page: https://github.com/titanscout2022/tr2022-strategy
Author: The Titan Scouting Team Author: The Titan Scouting Team

View File

@ -7,10 +7,14 @@
# current benchmark of optimization: 1.33 times faster # current benchmark of optimization: 1.33 times faster
# setup: # setup:
__version__ = "1.1.13.000" __version__ = "1.1.13.001"
# changelog should be viewed using print(analysis.__changelog__) # changelog should be viewed using print(analysis.__changelog__)
__changelog__ = """changelog: __changelog__ = """changelog:
1.1.13.001:
- bug fix with linear regression not returning a proper value
- cleaned up regression
- fixed bug with polynomial regressions
1.1.13.000: 1.1.13.000:
- fixed all regressions to now properly work - fixed all regressions to now properly work
1.1.12.006: 1.1.12.006:
@ -343,28 +347,27 @@ def histo_analysis(hist_data):
return None return None
def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _iterations = 10000, lr = 0.01, _iterations_ply = 10000, lr_ply = 0.01): # inputs, outputs expects N-D array def regression(inputs, outputs, args): # inputs, outputs expects N-D array
regressions = [] regressions = []
Regression().set_device(ndevice)
if 'lin' in args: # formula: ax + b if 'lin' in args: # formula: ax + b
try: try:
X = np.array(inputs).reshape(-1,1) X = np.array(inputs)
y = np.array(outputs) y = np.array(outputs)
model = sklearn.linear_model.LinearRegression().fit(X, y) def func(x, a, b):
ret = model.coef_.flatten().tolist() return a * x + b
ret.append(model.intercept_)
regressions.append((ret, model.score(X,y))) popt, pcov = scipy.optimize.curve_fit(func, X, y)
regressions.append((popt.flatten().tolist(), None))
except Exception as e: except Exception as e:
print(e)
pass pass
if 'log' in args: # formula: a log (b(x + c)) + d if 'log' in args: # formula: a log (b(x + c)) + d
@ -383,8 +386,7 @@ def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _itera
regressions.append((popt.flatten().tolist(), None)) regressions.append((popt.flatten().tolist(), None))
except Exception as e: except Exception as e:
print(e)
pass pass
if 'exp' in args: # formula: a e ^ (b(x + c)) + d if 'exp' in args: # formula: a e ^ (b(x + c)) + d
@ -404,10 +406,12 @@ def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _itera
except Exception as e: except Exception as e:
print(e)
pass pass
if 'ply' in args: # formula: a + bx^1 + cx^2 + dx^3 + ... if 'ply' in args: # formula: a + bx^1 + cx^2 + dx^3 + ...
inputs = [inputs]
outputs = [outputs]
plys = [] plys = []
limit = len(outputs[0]) limit = len(outputs[0])
@ -443,8 +447,7 @@ def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _itera
regressions.append((popt.flatten().tolist(), None)) regressions.append((popt.flatten().tolist(), None))
except Exception as e: except Exception as e:
print(e)
pass pass
return regressions return regressions

View File

@ -7,10 +7,14 @@
# current benchmark of optimization: 1.33 times faster # current benchmark of optimization: 1.33 times faster
# setup: # setup:
__version__ = "1.1.13.000" __version__ = "1.1.13.001"
# changelog should be viewed using print(analysis.__changelog__) # changelog should be viewed using print(analysis.__changelog__)
__changelog__ = """changelog: __changelog__ = """changelog:
1.1.13.001:
- bug fix with linear regression not returning a proper value
- cleaned up regression
- fixed bug with polynomial regressions
1.1.13.000: 1.1.13.000:
- fixed all regressions to now properly work - fixed all regressions to now properly work
1.1.12.006: 1.1.12.006:
@ -343,28 +347,27 @@ def histo_analysis(hist_data):
return None return None
def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _iterations = 10000, lr = 0.01, _iterations_ply = 10000, lr_ply = 0.01): # inputs, outputs expects N-D array def regression(inputs, outputs, args): # inputs, outputs expects N-D array
regressions = [] regressions = []
Regression().set_device(ndevice)
if 'lin' in args: # formula: ax + b if 'lin' in args: # formula: ax + b
try: try:
X = np.array(inputs).reshape(-1,1) X = np.array(inputs)
y = np.array(outputs) y = np.array(outputs)
model = sklearn.linear_model.LinearRegression().fit(X, y) def func(x, a, b):
ret = model.coef_.flatten().tolist() return a * x + b
ret.append(model.intercept_)
regressions.append((ret, model.score(X,y))) popt, pcov = scipy.optimize.curve_fit(func, X, y)
regressions.append((popt.flatten().tolist(), None))
except Exception as e: except Exception as e:
print(e)
pass pass
if 'log' in args: # formula: a log (b(x + c)) + d if 'log' in args: # formula: a log (b(x + c)) + d
@ -383,8 +386,7 @@ def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _itera
regressions.append((popt.flatten().tolist(), None)) regressions.append((popt.flatten().tolist(), None))
except Exception as e: except Exception as e:
print(e)
pass pass
if 'exp' in args: # formula: a e ^ (b(x + c)) + d if 'exp' in args: # formula: a e ^ (b(x + c)) + d
@ -404,10 +406,12 @@ def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _itera
except Exception as e: except Exception as e:
print(e)
pass pass
if 'ply' in args: # formula: a + bx^1 + cx^2 + dx^3 + ... if 'ply' in args: # formula: a + bx^1 + cx^2 + dx^3 + ...
inputs = [inputs]
outputs = [outputs]
plys = [] plys = []
limit = len(outputs[0]) limit = len(outputs[0])
@ -443,8 +447,7 @@ def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _itera
regressions.append((popt.flatten().tolist(), None)) regressions.append((popt.flatten().tolist(), None))
except Exception as e: except Exception as e:
print(e)
pass pass
return regressions return regressions

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@ import setuptools
setuptools.setup( setuptools.setup(
name="analysis", # Replace with your own username name="analysis", # Replace with your own username
version="1.0.0.005", version="1.0.0.006",
author="The Titan Scouting Team", author="The Titan Scouting Team",
author_email="titanscout2022@gmail.com", author_email="titanscout2022@gmail.com",
description="analysis package developed by Titan Scouting for The Red Alliance", description="analysis package developed by Titan Scouting for The Red Alliance",

View File

@ -70,8 +70,10 @@ __all__ = [
from analysis import analysis as an from analysis import analysis as an
import data as d import data as d
import time import time
import warnings
def main(): def main():
warnings.filterwarnings("ignore")
while(True): while(True):
current_time = time.time() current_time = time.time()
@ -152,19 +154,19 @@ def simplestats(data, test):
return an.histo_analysis([list(range(len(data))), data]) return an.histo_analysis([list(range(len(data))), data])
if(test == "regression_linear"): if(test == "regression_linear"):
return an.regression('cpu', [list(range(len(data)))], [data], ['lin'], _iterations = 5000) return an.regression(list(range(len(data))), data, ['lin'])
if(test == "regression_logarithmic"): if(test == "regression_logarithmic"):
return an.regression('cpu', [list(range(len(data)))], [data], ['log'], _iterations = 5000) return an.regression(list(range(len(data))), data, ['log'])
if(test == "regression_exponential"): if(test == "regression_exponential"):
return an.regression('cpu', [list(range(len(data)))], [data], ['exp'], _iterations = 5000) return an.regression(list(range(len(data))), data, ['exp'])
if(test == "regression_polynomial"): if(test == "regression_polynomial"):
return an.regression('cpu', [list(range(len(data)))], [data], ['ply'], _iterations = 5000) return an.regression(list(range(len(data))), data, ['ply'])
if(test == "regression_sigmoidal"): if(test == "regression_sigmoidal"):
return an.regression('cpu', [list(range(len(data)))], [data], ['sig'], _iterations = 5000) return an.regression(list(range(len(data))), data, ['sig'])
def push_to_database(apikey, competition, results, metrics): def push_to_database(apikey, competition, results, metrics):