mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-11-10 06:54:44 +00:00
analysis pkg v 1.0.0.7
This commit is contained in:
parent
b6ac05a66e
commit
9b412b51a8
@ -1,6 +1,6 @@
|
|||||||
Metadata-Version: 2.1
|
Metadata-Version: 2.1
|
||||||
Name: analysis
|
Name: analysis
|
||||||
Version: 1.0.0.6
|
Version: 1.0.0.7
|
||||||
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
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
# Titan Robotics Team 2022: CUDA-based Regressions Module
|
# Titan Robotics Team 2022: CUDA-based Regressions Module
|
||||||
# Written by Arthur Lu & Jacob Levine
|
# Written by Arthur Lu & Jacob Levine
|
||||||
# Notes:
|
# Notes:
|
||||||
# this should be imported as a python module using 'import regression'
|
# this module has been automatically inegrated into analysis.py, and should be callable as a class from the package
|
||||||
# this should be included in the local directory or environment variable
|
|
||||||
# this module is cuda-optimized and vectorized (except for one small part)
|
# this module is cuda-optimized and vectorized (except for one small part)
|
||||||
# setup:
|
# setup:
|
||||||
|
|
||||||
__version__ = "1.0.0.002"
|
__version__ = "1.0.0.003"
|
||||||
|
|
||||||
# changelog should be viewed using print(regression.__changelog__)
|
# changelog should be viewed using print(analysis.regression.__changelog__)
|
||||||
__changelog__ = """
|
__changelog__ = """
|
||||||
|
1.0.0.003:
|
||||||
|
- bug fixes
|
||||||
1.0.0.002:
|
1.0.0.002:
|
||||||
-Added more parameters to log, exponential, polynomial
|
-Added more parameters to log, exponential, polynomial
|
||||||
-Added SigmoidalRegKernelArthur, because Arthur apparently needs
|
-Added SigmoidalRegKernelArthur, because Arthur apparently needs
|
||||||
to train the scaling and shifting of sigmoids
|
to train the scaling and shifting of sigmoids
|
||||||
|
|
||||||
1.0.0.001:
|
1.0.0.001:
|
||||||
-initial release, with linear, log, exponential, polynomial, and sigmoid kernels
|
-initial release, with linear, log, exponential, polynomial, and sigmoid kernels
|
||||||
-already vectorized (except for polynomial generation) and CUDA-optimized
|
-already vectorized (except for polynomial generation) and CUDA-optimized
|
||||||
@ -22,6 +22,7 @@ __changelog__ = """
|
|||||||
|
|
||||||
__author__ = (
|
__author__ = (
|
||||||
"Jacob Levine <jlevine@imsa.edu>",
|
"Jacob Levine <jlevine@imsa.edu>",
|
||||||
|
"Arthur Lu <learthurgo@gmail.com>"
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
@ -39,35 +40,13 @@ __all__ = [
|
|||||||
'CustomTrain'
|
'CustomTrain'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
global device
|
||||||
# imports (just one for now):
|
|
||||||
|
|
||||||
import torch
|
|
||||||
|
|
||||||
device = "cuda:0" if torch.torch.cuda.is_available() else "cpu"
|
device = "cuda:0" if torch.torch.cuda.is_available() else "cpu"
|
||||||
|
|
||||||
#todo: document completely
|
#todo: document completely
|
||||||
|
|
||||||
def factorial(n):
|
def set_device(self, new_device):
|
||||||
if n==0:
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
return n*factorial(n-1)
|
|
||||||
def num_poly_terms(num_vars, power):
|
|
||||||
if power == 0:
|
|
||||||
return 0
|
|
||||||
return int(factorial(num_vars+power-1) / factorial(power) / factorial(num_vars-1)) + num_poly_terms(num_vars, power-1)
|
|
||||||
|
|
||||||
def take_all_pwrs(vec,pwr):
|
|
||||||
#todo: vectorize (kinda)
|
|
||||||
combins=torch.combinations(vec, r=pwr, with_replacement=True)
|
|
||||||
out=torch.ones(combins.size()[0])
|
|
||||||
for i in torch.t(combins):
|
|
||||||
out *= i
|
|
||||||
return torch.cat(out,take_all_pwrs(vec, pwr-1))
|
|
||||||
|
|
||||||
def set_device(new_device):
|
|
||||||
global device
|
|
||||||
device=new_device
|
device=new_device
|
||||||
|
|
||||||
class LinearRegKernel():
|
class LinearRegKernel():
|
||||||
@ -154,20 +133,39 @@ class PolyRegKernel():
|
|||||||
power=None
|
power=None
|
||||||
def __init__(self, num_vars, power):
|
def __init__(self, num_vars, power):
|
||||||
self.power=power
|
self.power=power
|
||||||
num_terms=num_poly_terms(num_vars, power)
|
num_terms=self.num_poly_terms(num_vars, power)
|
||||||
self.weights=torch.rand(num_terms, requires_grad=True, device=device)
|
self.weights=torch.rand(num_terms, requires_grad=True, device=device)
|
||||||
self.bias=torch.rand(1, requires_grad=True, device=device)
|
self.bias=torch.rand(1, requires_grad=True, device=device)
|
||||||
self.parameters=[self.weights,self.bias]
|
self.parameters=[self.weights,self.bias]
|
||||||
|
def num_poly_terms(self,num_vars, power):
|
||||||
|
if power == 0:
|
||||||
|
return 0
|
||||||
|
return int(self.factorial(num_vars+power-1) / self.factorial(power) / self.factorial(num_vars-1)) + self.num_poly_terms(num_vars, power-1)
|
||||||
|
def factorial(self,n):
|
||||||
|
if n==0:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return n*self.factorial(n-1)
|
||||||
|
def take_all_pwrs(self, vec, pwr):
|
||||||
|
#todo: vectorize (kinda)
|
||||||
|
combins=torch.combinations(vec, r=pwr, with_replacement=True)
|
||||||
|
out=torch.ones(combins.size()[0]).to(device).to(torch.float)
|
||||||
|
for i in torch.t(combins).to(device).to(torch.float):
|
||||||
|
out *= i
|
||||||
|
if pwr == 1:
|
||||||
|
return out
|
||||||
|
else:
|
||||||
|
return torch.cat((out,self.take_all_pwrs(vec, pwr-1)))
|
||||||
def forward(self,mtx):
|
def forward(self,mtx):
|
||||||
#TODO: Vectorize the last part
|
#TODO: Vectorize the last part
|
||||||
cols=[]
|
cols=[]
|
||||||
for i in torch.t(mtx):
|
for i in torch.t(mtx):
|
||||||
cols.append(take_all_pwrs(i,self.power))
|
cols.append(self.take_all_pwrs(i,self.power))
|
||||||
new_mtx=torch.t(torch.stack(cols))
|
new_mtx=torch.t(torch.stack(cols))
|
||||||
long_bias=self.bias.repeat([1,mtx.size()[1]])
|
long_bias=self.bias.repeat([1,mtx.size()[1]])
|
||||||
return torch.matmul(self.weights,new_mtx)+long_bias
|
return torch.matmul(self.weights,new_mtx)+long_bias
|
||||||
|
|
||||||
def SGDTrain(kernel, data, ground, loss=torch.nn.MSELoss(), iterations=1000, learning_rate=.1, return_losses=False):
|
def SGDTrain(self, kernel, data, ground, loss=torch.nn.MSELoss(), iterations=1000, learning_rate=.1, return_losses=False):
|
||||||
optim=torch.optim.SGD(kernel.parameters, lr=learning_rate)
|
optim=torch.optim.SGD(kernel.parameters, lr=learning_rate)
|
||||||
data_cuda=data.to(device)
|
data_cuda=data.to(device)
|
||||||
ground_cuda=ground.to(device)
|
ground_cuda=ground.to(device)
|
||||||
@ -192,7 +190,7 @@ def SGDTrain(kernel, data, ground, loss=torch.nn.MSELoss(), iterations=1000, lea
|
|||||||
optim.step()
|
optim.step()
|
||||||
return kernel
|
return kernel
|
||||||
|
|
||||||
def CustomTrain(kernel, optim, data, ground, loss=torch.nn.MSELoss(), iterations=1000, return_losses=False):
|
def CustomTrain(self, kernel, optim, data, ground, loss=torch.nn.MSELoss(), iterations=1000, return_losses=False):
|
||||||
data_cuda=data.to(device)
|
data_cuda=data.to(device)
|
||||||
ground_cuda=ground.to(device)
|
ground_cuda=ground.to(device)
|
||||||
if (return_losses):
|
if (return_losses):
|
||||||
|
Binary file not shown.
BIN
analysis-master/dist/analysis-1.0.0.6.tar.gz
vendored
BIN
analysis-master/dist/analysis-1.0.0.6.tar.gz
vendored
Binary file not shown.
BIN
analysis-master/dist/analysis-1.0.0.7-py3-none-any.whl
vendored
Normal file
BIN
analysis-master/dist/analysis-1.0.0.7-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
analysis-master/dist/analysis-1.0.0.7.tar.gz
vendored
Normal file
BIN
analysis-master/dist/analysis-1.0.0.7.tar.gz
vendored
Normal file
Binary file not shown.
@ -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.006",
|
version="1.0.0.007",
|
||||||
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",
|
||||||
|
Loading…
Reference in New Issue
Block a user