Commit fa2497ae authored by Chetan Sharma's avatar Chetan Sharma
Browse files

Saving progress

parent 61bc7546
...@@ -9,37 +9,24 @@ ...@@ -9,37 +9,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "ename": "AttributeError",
"output_type": "stream", "evalue": "Can't get attribute 'RawDataPacket' on <module '__main__'>",
"text": [ "output_type": "error",
"0.003175\n" "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m~/anaconda3/envs/ampd/lib/python3.8/shelve.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 110\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 111\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcache\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 112\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyError\u001b[0m: '6'",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-2-aae045e25021>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mshelve\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'results'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mdb\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mtest_name\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mTEST_NAMES\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mdb\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mtest_name\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0mdata_points\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecompose_packet\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresults\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/envs/ampd/lib/python3.8/shelve.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 112\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mBytesIO\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkeyencoding\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 114\u001b[0;31m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mUnpickler\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 115\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwriteback\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 116\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcache\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: Can't get attribute 'RawDataPacket' on <module '__main__'>"
] ]
},
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f9bf7983e50>]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD7CAYAAABjVUMJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3deXwV9b3/8deHhAQIOwRlXwSVRdYj4FK91qq4opUqahV/YnGj1VZtqa0tUu+96q21KlZFsUVQQFyxrVpbtNVqMQmLLAKGiBD2NUAwkOXz++MMNg2BHCAnk5Pzfj4e53HOmfnO5DPDYd7fmTlnxtwdERFJPvXCLkBERMKhABARSVIKABGRJKUAEBFJUgoAEZEkpQAQEUlSMQWAmQ0zs+Vmlmtm4yoZn25mM4Pxc82sSzC8i5l9ZWYLgsdT5aYZZGaLgmkeMzOrroUSEZGqVRkAZpYCPAGcD/QCrjKzXhWajQa2u3t34BHgwXLjVrp7/+Bxc7nhTwJjgB7BY9iRL4aIiByu1BjaDAZy3T0PwMxmAMOBpeXaDAfGB69fBiYeqkdvZm2Bpu7+cfD+eeBS4K1DFdK6dWvv0qVLDCWLiMh+OTk5W9w9s+LwWAKgPbCm3Pt8YMjB2rh7iZkVAK2CcV3NbD6wE/i5u38QtM+vMM/2VRXSpUsXsrOzYyhZRET2M7MvKxseSwBU1pOveP2Ig7VZD3Ry961mNgh43cx6xzjP6IzNxhA9VESnTp1iKFdERGIRy0ngfKBjufcdgHUHa2NmqUAzYJu773X3rQDungOsBI4P2neoYp4E001y94i7RzIzD9iDERGRIxRLAGQBPcysq5mlASOB2RXazAZGBa9HAHPc3c0sMziJjJl1I3qyN8/d1wO7zGxocK7gOuCNalgeER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R3NPA+QLAGQD3Qs974DB+5Cft0m2M1sBmw71LRmVp/oxv8Fd381LpXXnHiso9OAS8xsFdHd3G+a2bR4FF9D4rGO8oF8d9+/9/gy0UBIVPFYR98CvnD3ze5eDLwKnBqX6mvG0ayjQ82zQxXzPECyBEAW0MPMuppZGtGTKrMrtJkNjApejwDmBMfSZgMjg7PyXYEewCfBMcvJwGfu/psaWYr4qvZ15O4/dfcO7t4lmN8cd0/knls81tEGYI2ZnRBMczawNN4LEkfVvo6IHvoZamaNgv93ZxM955aojmYdVcrd1wO7zGxosI6uA96ospKwz4jX1AO4gOg3dVYCPwuGTQAuCV43AGYRPfH0CdCt3LQ/C6ZbTnBmneiZeAc+BRYEjwvCXs7atI4qzPu/SPBvAcVrHQH9gezgs/Q60CLs5ayF6+g+YBmwGJgKpIe9nCGuo1VE9wZ2E+359wqGR4L1sxKYSPBD30M99EtgEZEklSyHgEREpAIFgIhIklIAiIgkKQWAiEiSUgCIiCQpBYCISJJSAIiIJCkFgIhIkvr/+NRz8TwE55UAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
} }
], ],
"source": [ "source": [
...@@ -48,7 +35,7 @@ ...@@ -48,7 +35,7 @@
"import shelve\n", "import shelve\n",
"import logging\n", "import logging\n",
"import queue\n", "import queue\n",
"from collect_data import DataPoint, RawDataPacket\n", "# from collect_data import DataPoint, RawDataPacket\n",
"from matplotlib import pyplot as plt\n", "from matplotlib import pyplot as plt\n",
"from scipy.signal import medfilt\n", "from scipy.signal import medfilt\n",
"\n", "\n",
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Data Verification # Data Verification
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import numpy as np import numpy as np
import time import time
import shelve import shelve
import logging import logging
import queue import queue
from collect_data import DataPoint, RawDataPacket # from collect_data import DataPoint, RawDataPacket
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from scipy.signal import medfilt from scipy.signal import medfilt
TEST_NAMES = ['6'] TEST_NAMES = ['6']
results = list() results = list()
with shelve.open('results') as db: with shelve.open('results') as db:
for test_name in TEST_NAMES: for test_name in TEST_NAMES:
results += db[test_name] results += db[test_name]
data_points = list(map(lambda x: x.decompose_packet(), results)) data_points = list(map(lambda x: x.decompose_packet(), results))
print(data_points[0].W) print(data_points[0].W)
x = list(map(lambda x: x.f_r, data_points)) x = list(map(lambda x: x.f_r, data_points))
y = list(map(lambda x: x.T, data_points)) y = list(map(lambda x: x.T, data_points))
plt.figure() plt.figure()
plt.plot(x, y) plt.plot(x, y)
``` ```
%%%% Output: stream %%%% Output: error
0.003175
%%%% Output: execute_result
[<matplotlib.lines.Line2D at 0x7f9bf7983e50>]
%%%% Output: display_data
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~/anaconda3/envs/ampd/lib/python3.8/shelve.py in __getitem__(self, key)
110 try:
--> 111 value = self.cache[key]
112 except KeyError:
KeyError: '6'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
<ipython-input-2-aae045e25021> in <module>
13 with shelve.open('results') as db:
14 for test_name in TEST_NAMES:
---> 15 results += db[test_name]
16
17 data_points = list(map(lambda x: x.decompose_packet(), results))
~/anaconda3/envs/ampd/lib/python3.8/shelve.py in __getitem__(self, key)
112 except KeyError:
113 f = BytesIO(self.dict[key.encode(self.keyencoding)])
--> 114 value = Unpickler(f).load()
115 if self.writeback:
116 self.cache[key] = value
AttributeError: Can't get attribute 'RawDataPacket' on <module '__main__'>
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%matplotlib notebook %matplotlib notebook
new_data = list(map(lambda x: RawDataPacket(x.D, x.W, x.R, x.N, x.f_r, x.w, x.measurements), results)) new_data = list(map(lambda x: RawDataPacket(x.D, x.W, x.R, x.N, x.f_r, x.w, x.measurements), results))
data_points = list(map(lambda x: x.decompose_packet_sorta(), new_data)) data_points = list(map(lambda x: x.decompose_packet_sorta(), new_data))
plt.figure() plt.figure()
last_time = 0 last_time = 0
for tTs, tFys, Ts, Fys in data_points: for tTs, tFys, Ts, Fys in data_points:
times = [t + last_time for t in tTs] times = [t + last_time for t in tTs]
stuff = Ts stuff = Ts
filter_size = 3 filter_size = 3
fc = int((filter_size + 1) / 2) fc = int((filter_size + 1) / 2)
plt.plot(times[fc: -fc], medfilt(stuff, filter_size)[fc: -fc]) plt.plot(times[fc: -fc], medfilt(stuff, filter_size)[fc: -fc])
last_time = times[-1] last_time = times[-1]
``` ```
%%%% Output: display_data %%%% Output: display_data
%%%% Output: display_data %%%% Output: display_data
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Plan ## Plan
We have three datasets. Two variables are tweaked across dataset. We want to perform some kind of regression to figure out our cutting force coefficients. We have three datasets. Two variables are tweaked across dataset. We want to perform some kind of regression to figure out our cutting force coefficients.
Regression is linear if we only vary feed, but becomes nonlinear once we incorporate WOC. Regression is linear if we only vary feed, but becomes nonlinear once we incorporate WOC.
First, maybe just try using a linear regressor for both? First, maybe just try using a linear regressor for both?
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from scipy.optimize import least_squares from scipy.optimize import least_squares
def single_residual(d, K_tc, K_te, p): def single_residual(d, K_tc, K_te, p):
return T_exp_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te, p) - d.T return T_exp_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te, p) - d.T
def gen_train_pairs(): def gen_train_pairs():
X = [[d.D, d.N, d.R, d.W, d.f_r, d.w] for d in data_points] X = [[d.D, d.N, d.R, d.W, d.f_r, d.w] for d in data_points]
y = [d.T for d in data_points] y = [d.T for d in data_points]
return (X, y) return (X, y)
residual_array = np.vectorize(single_residual) residual_array = np.vectorize(single_residual)
def objective(x): def objective(x):
K_tc = x[0] K_tc = x[0]
K_te = x[1] K_te = x[1]
p = x[2] p = x[2]
return residual_array(data_points, K_tc, K_te, p) return residual_array(data_points, K_tc, K_te, p)
class NonLinRegressor: class NonLinRegressor:
def fit(self, X, Y): def fit(self, X, Y):
self.coef = least_squares(lambda coef: [self.evaluate(x, coef) - y for x, y in zip(X, Y)], self.coef).x self.coef = least_squares(lambda coef: [self.evaluate(x, coef) - y for x, y in zip(X, Y)], self.coef).x
return self return self
def predict(self, X): def predict(self, X):
return [self.evaluate(x, self.coef) for x in X] return [self.evaluate(x, self.coef) for x in X]
def get_params(self, deep=True): def get_params(self, deep=True):
return {} return {}
def set_params(self, **params): def set_params(self, **params):
... ...
def score(self, X, Y): def score(self, X, Y):
u = sum([(y_true - y_pred) ** 2 for y_true, y_pred in zip(Y, self.predict(X))]) u = sum([(y_true - y_pred) ** 2 for y_true, y_pred in zip(Y, self.predict(X))])
y_true_mean = np.mean(Y) y_true_mean = np.mean(Y)
v = sum([(y_true - y_true_mean) ** 2 for y_true in Y]) v = sum([(y_true - y_true_mean) ** 2 for y_true in Y])
return (1 - u/v) return (1 - u/v)
class TRegressor(NonLinRegressor): class TRegressor(NonLinRegressor):
def __init__(self): def __init__(self):
self.coef = [0,0,1] self.coef = [0,0,1]
def evaluate(self, x, coef): def evaluate(self, x, coef):
return T_exp_lin(*x, coef[0], coef[1], coef[2]) return T_exp_lin(*x, coef[0], coef[1], coef[2])
class FRegressor(NonLinRegressor): class FRegressor(NonLinRegressor):
def __init__(self): def __init__(self):
self.coef = [0,0,0,0, 0, 0] self.coef = [0,0,0,0, 0, 0]
def evaluate(self, x, coef): def evaluate(self, x, coef):
return F_exp_lin(*x, *coef)[0][1] return F_exp_lin(*x, *coef)[0][1]
estimator = TRegressor() estimator = TRegressor()
regressor = RANSACRegressor(base_estimator = estimator, min_samples = 5) regressor = RANSACRegressor(base_estimator = estimator, min_samples = 5)
X, y = gen_train_pairs() X, y = gen_train_pairs()
# y = [d.Fy * 9.81 ** 2 for d in data_points] # y = [d.Fy * 9.81 ** 2 for d in data_points]
regressor.fit(X, y) regressor.fit(X, y)
# K_tc, K_te, K_rc, K_re, p, q = regressor.estimator_.coef # K_tc, K_te, K_rc, K_re, p, q = regressor.estimator_.coef
K_tc, K_te, p = regressor.estimator_.coef K_tc, K_te, p = regressor.estimator_.coef
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# print(K_tc, K_te, K_rc, K_re, p, q) # print(K_tc, K_te, K_rc, K_re, p, q)
y_est = list(map(lambda d : T_exp_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te, p), data_points)) y_est = list(map(lambda d : T_exp_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te, p), data_points))
# y_est = list(map(lambda d : F_exp_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te, K_rc, K_re, p, q), data_points)) # y_est = list(map(lambda d : F_exp_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te, K_rc, K_re, p, q), data_points))
# y_est = np.array(y_est) # y_est = np.array(y_est)
# y_est = np.squeeze(y_est)[:, 1] # y_est = np.squeeze(y_est)[:, 1]
# print(y_est) # print(y_est)
plt.figure() plt.figure()
plt.plot(x, y) plt.plot(x, y)
plt.plot(x, y_est) plt.plot(x, y_est)
``` ```
%%%% Output: execute_result %%%% Output: execute_result
[<matplotlib.lines.Line2D at 0x7fc984255c10>] [<matplotlib.lines.Line2D at 0x7fc984255c10>]
%%%% Output: display_data %%%% Output: display_data
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from sklearn.linear_model import RANSACRegressor, LinearRegression from sklearn.linear_model import RANSACRegressor, LinearRegression
from models import T_x_vector, T_lin, T_exp_lin, calc_h_a, calc_f_t, F_exp_lin from models import T_x_vector, T_lin, T_exp_lin, calc_h_a, calc_f_t, F_exp_lin
def dataPoint_to_X(d): def dataPoint_to_X(d):
return T_x_vector(d.D, d.N, d.R, d.W, d.f_r, d.w) return T_x_vector(d.D, d.N, d.R, d.W, d.f_r, d.w)
def single_residual(d, K_tc, K_te, p): def single_residual(d, K_tc, K_te, p):
return T_exp_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te, p) - d.T return T_exp_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te, p) - d.T
residual_array = np.vectorize(single_residual) residual_array = np.vectorize(single_residual)
def objective(x): def objective(x):
K_tc = x[0] K_tc = x[0]
K_te = x[1] K_te = x[1]
p = x[2] p = x[2]
return residual_array(data_points, K_tc, K_te, p) return residual_array(data_points, K_tc, K_te, p)
X = list(map(dataPoint_to_X, data_points)) X = list(map(dataPoint_to_X, data_points))
estimator = LinearRegression(fit_intercept=False) estimator = LinearRegression(fit_intercept=False)
regressor = RANSACRegressor(base_estimator = estimator) regressor = RANSACRegressor(base_estimator = estimator)
regressor.fit(X, y) regressor.fit(X, y)
K_tc, K_te = regressor.estimator_.coef_ K_tc, K_te = regressor.estimator_.coef_
print("K_tc = ", K_tc, ", K_te = ", K_te) print("K_tc = ", K_tc, ", K_te = ", K_te)
x_h_a = np.linspace(0.1e-3, 4e-3, 100) x_h_a = np.linspace(0.1e-3, 4e-3, 100)
y_h_a = [calc_h_a(6.35e-3 / 2 , x, calc_f_t(3, 0.0016, 500)) for x in x_h_a] y_h_a = [calc_h_a(6.35e-3 / 2 , x, calc_f_t(3, 0.0016, 500)) for x in x_h_a]
``` ```
%%%% Output: stream %%%% Output: stream
K_tc = 858494934.9591976 , K_te = -696.3150933941946 K_tc = 858494934.9591976 , K_te = -696.3150933941946
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Now we check if we actually fit anything useful Now we check if we actually fit anything useful
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
y_est = list(map(lambda d : T_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te), data_points)) y_est = list(map(lambda d : T_lin(d.D, d.N, d.R, d.W, d.f_r, d.w, K_tc, K_te), data_points))
plt.figure() plt.figure()
plt.plot(x, y) plt.plot(x, y)
plt.plot(x, y_est) plt.plot(x, y_est)
plt.figure() plt.figure()
plt.plot(x_h_a, y_h_a) plt.plot(x_h_a, y_h_a)
plt.plot([0.00079375, 0.0015875, 0.003175], [0,0,0], 'd') plt.plot([0.00079375, 0.0015875, 0.003175], [0,0,0], 'd')
``` ```
%%%% Output: execute_result %%%% Output: execute_result
[<matplotlib.lines.Line2D at 0x7f22f8fe0640>] [<matplotlib.lines.Line2D at 0x7f22f8fe0640>]
%%%% Output: display_data %%%% Output: display_data
%%%% Output: display_data %%%% Output: display_data
......
from ml import LinearModel
from fake_cut import Fake_Cut
from objects import EndMill, Conditions
PARAMS = [858494934.9591976, -696.3150933941946, 858494934.9591976, -696.3150933941946]
# ERROR = [0.01, 0.01]
# NOISE = [0.1, 0.1]
ERROR = [0, 0]
NOISE = [0, 0]
CONDITIONS = Conditions(1e-3, 3.175e-3, 5e-3, 5000, EndMill(3, 3.175e-3, 3.175e-3, 10e-3, 10e-3))
model = LinearModel()
cut = Fake_Cut(PARAMS, ERROR, NOISE)
data = cut.cut(CONDITIONS)
model.ingest_datum(data)
print("{0:.20f}".format(model.params[1]))
\ No newline at end of file
...@@ -62,10 +62,11 @@ class Cut: ...@@ -62,10 +62,11 @@ class Cut:
self._logger.info("Layer prepared for clearing") self._logger.info("Layer prepared for clearing")
def cut(self, W, f_r, w): def cut(self, conditions):
""" """
Performs a stroke of facing. Returns a data blob. Performs a stroke of facing. Returns a data blob.
""" """
_, W, f_r, w, _ = conditions.unpack()
X_START = x_cut - self.endmill.r_c + W X_START = x_cut - self.endmill.r_c + W
if X_START > self.X_END: if X_START > self.X_END:
raise MachineCrash("Cutting too far in X direction: X = " + str(X_START)) raise MachineCrash("Cutting too far in X direction: X = " + str(X_START))
......
from models import T_lin, F_lin
from objects import Conditions, Data
import numpy as np
class Fake_Cut:
def __init__(self, params, error, noise):
"""
Args:
params: list of format [K_tc, K_te, K_rc, K_re]
error: list of standard deviations of format [o_T, o_Fy]. Simulates the sensor being "wrong" sometimes.
error: list of standard deviations of format [o_T, o_Fy]. Simulates the sensor being noisy.
"""
self.params = params
self.error = error
self.noise = noise
def cut(self, conditions : Conditions):
# use prediction as output
T = T_lin(conditions, *self.params[:2])
_, Fy = F_lin(conditions, *self.params)
# add sensor error
T_error = np.random.normal(T, self.error[0])
Fy_error = np.random.normal(Fy, self.error[1])
# add sensor noise
T_noisy = np.random.normal(T_error, self.noise[0], (100))
Fy_noisy = np.random.normal(Fy_error, self.noise[1], (100))
# generate fake times
t = np.linspace(0, 1, 100)
# return fake reading
return Data(*conditions.unpack(), np.array([t, T_noisy]), np.stack([t, Fy_noisy]))
\ No newline at end of file
...@@ -5,7 +5,7 @@ from sklearn import linear_model ...@@ -5,7 +5,7 @@ from sklearn import linear_model
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from models import T_lin, F_lin, T_x_vector, Fy_x_vector from models import T_lin, F_lin, T_x_vector, Fy_x_vector
from objects import Data, Reading, EndMill, Prediction from objects import Data, Conditions, EndMill, Prediction
class Model(abc.ABC): class Model(abc.ABC):
""" """
...@@ -40,19 +40,21 @@ class LinearModel(Model): ...@@ -40,19 +40,21 @@ class LinearModel(Model):
self.training_T_y = list() self.training_T_y = list()
self.training_Fy_x = list() self.training_Fy_x = list()
self.training_Fy_y = list() self.training_Fy_y = list()
self.regressor_T = linear_model.Lasso(fit_intercept = False, warm_start=True) self.regressor_T = linear_model.LinearRegression(fit_intercept = False)
self.regressor_Fy = linear_model.Lasso(fit_intercept = False, warm_start=True) self.regressor_Fy = linear_model.LinearRegression(fit_intercept = False)
self.params = np.array([0,0,0,0]) self.params = np.array([0,0,0,0])
def ingest_datum(self, datum): def ingest_datum(self, datum):
# decompose # decompose
D, W, f_r, w, endmill, Ts, Fys = datum.D, datum.W, datum.f_r, datum.w, datum.endmill, datum.Ts, datum.Fys _, _, _, _, _, Ts, Fys = datum.unpack()
R, N = endmill.R, endmill, N T, Fy = np.median(Ts[1, :]), np.median(Fys[1, :])
T, Fy = np.median(Ts[:, 1]), np.median(Fys[:, 1])
# get linear coefficients # get linear coefficients
T_x = T_x_vector(D, N, R, W, f_r, w) T_x = T_x_vector(datum.conditions())
Fy_x = Fy_x_vector(D, N, R, W, f_r, w) Fy_x = Fy_x_vector(datum.conditions())
print("T", T)
print("coef times real K_tc", T_x[1] * 858494934.9591976)
# add to training set # add to training set
self.training_T_x.append(T_x) self.training_T_x.append(T_x)
...@@ -68,24 +70,25 @@ class LinearModel(Model): ...@@ -68,24 +70,25 @@ class LinearModel(Model):
# calculate best fit from data # calculate best fit from data
self.regressor_T.fit(self.training_T_x, self.training_T_y) self.regressor_T.fit(self.training_T_x, self.training_T_y)
K_tc, K_te = self.regressor.coef_ K_tc, K_te = self.regressor_T.coef_
print(K_tc, K_te)
self.params[0], self.params[1] = K_tc, K_te self.params[0], self.params[1] = K_tc, K_te
# transform Fy into a smaller linear problem and fit # transform Fy into a smaller linear problem and fit
intercepts = training_Fy_x @ np.array([K_tc, K_te, 0, 0])[np.newaxis].T intercepts = training_Fy_x @ np.array([K_tc, K_te, 0, 0])[np.newaxis].T
training_Fy_y_no_intercepts = training_Fy_y - intercepts training_Fy_y_no_intercepts = training_Fy_y - intercepts
self.regressor_Fy.fit(training_Fy_x[:, 2:], training_Fy_y_no_intercepts) self.regressor_Fy.fit(training_Fy_x[:, 2:], training_Fy_y_no_intercepts)
K_rc, K_re = self.regressor_Fy.coef_
self.params[0], self.params[1] = K_rc, K_re
def predict_one(self, conditions): def predict_one(self, conditions):
# decompose # decompose
D, W, f_r, w, endmill = conditions.D, conditions.W, conditions.f_r, conditions.w, conditions.endmill
R, N = endmill.R, endmill, N
# evaluate # evaluate
T = T_lin(D, N, R, W, f_r, w, self.params[0], self.params[1]) T = T_lin(conditions, *self.params[:2])
F = F_lin(D, N, R, W, f_r, w, *self.params) F = F_lin(conditions, *self.params)
# repack and return # repack and return
return Prediction(D, W, f_r, w, endmill, T, F) return Prediction(conditions, T, F)
import numpy as np import numpy as np
def calc_h_a(R, W, f_t): from objects import Conditions, Data, Prediction, MachineChar
def calc_f_t(conditions : Conditions):
D, W, f_r, w, endmill = conditions.unpack()
N = endmill.N
return (2 * np.pi * f_r) / (N * w)
def calc_h_a(conditions : Conditions):
D, W, f_r, w, endmill = conditions.unpack()
R = endmill.r_c
f_t = calc_f_t(conditions)
phi_st = np.pi - np.arccos(1 - W / R) phi_st = np.pi - np.arccos(1 - W / R)
phi_ex = np.pi phi_ex = np.pi
return -f_t * (np.cos(phi_ex) - np.cos(phi_st)) / (phi_ex - phi_st) return -f_t * (np.cos(phi_ex) - np.cos(phi_st)) / (phi_ex - phi_st)
def calc_f_t(N, f_r, w):
return (2 * np.pi * f_r) / (N * w)
# exponential models, account for strange decrease in cutting forces as chip thickness increases. # exponential models, account for strange decrease in cutting forces as chip thickness increases.
def T_exp_lin(D, N, R, W, f_r, w, K_TC, K_te, p): def T_exp_lin(conditions : Conditions, K_TC, K_te, p):
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
h_a = calc_h_a(R, W, f_t) N, R, _, _, _ = endmill.unpack()
f_t = calc_f_t(conditions)
h_a = calc_h_a(conditions)
K_tc = K_TC * h_a ** -p K_tc = K_TC * h_a ** -p
return ((D * N) * (K_te * R * np.arccos(1 - W/R) + K_tc * W * f_t)) / (2 * np.pi) return ((D * N) * (K_te * R * np.arccos(1 - W/R) + K_tc * W * f_t)) / (2 * np.pi)
def F_exp_lin(D, N, R, W, f_r, w, K_TC, K_te, K_RC, K_re, p, q): def F_exp_lin(conditions : Conditions, K_TC, K_te, K_RC, K_re, p, q):
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
h_a = calc_h_a(R, W, f_t) N, R, _, _, _ = endmill.unpack()
f_t = calc_f_t(conditions)
h_a = calc_h_a(conditions)
K_tc = K_TC * h_a ** -p K_tc = K_TC * h_a ** -p
K_rc = K_RC * h_a ** -q K_rc = K_RC * h_a ** -q
Fx = - ((D*N*(K_tc*W**2*f_t + K_rc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_tc*W*f_t - 2*K_re*W + 2*K_te*W**(1/2)*(2*R - W)**(1/2) + K_rc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) - (D*K_rc*N*f_t*np.arccos((R - W)/R))/(4*np.pi) Fx = - ((D*N*(K_tc*W**2*f_t + K_rc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_tc*W*f_t - 2*K_re*W + 2*K_te*W**(1/2)*(2*R - W)**(1/2) + K_rc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) - (D*K_rc*N*f_t*np.arccos((R - W)/R))/(4*np.pi)
...@@ -26,36 +38,42 @@ def F_exp_lin(D, N, R, W, f_r, w, K_TC, K_te, K_RC, K_re, p, q): ...@@ -26,36 +38,42 @@ def F_exp_lin(D, N, R, W, f_r, w, K_TC, K_te, K_RC, K_re, p, q):
# linear models, easier to fit and more simple # linear models, easier to fit and more simple
def T_lin(D, N, R, W, f_r, w, K_tc, K_te): def T_lin(conditions, K_tc, K_te):
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
N, R, _, _, _ = endmill.unpack()
f_t = calc_f_t(conditions)
return ((D * N) * (K_te * R * np.arccos(1 - W/R) + K_tc * W * f_t)) / (2 * np.pi) return ((D * N) * (K_te * R * np.arccos(1 - W/R) + K_tc * W * f_t)) / (2 * np.pi)
def F_lin(D, N, R, W, f_r, w, K_tc, K_te, K_rc, K_re): def F_lin(conditions, K_tc, K_te, K_rc, K_re):
f_t = calc_f_t(N, f_r, w) D, W, f_r, w, endmill = conditions.unpack()
N, R, _, _, _ = endmill.unpack()
f_t = calc_f_t(conditions)
Fx = - ((D*N*(K_tc*W**2*f_t + K_rc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_tc*W*f_t - 2*K_re*W + 2*K_te*W**(1/2)*(2*R - W)**(1/2) + K_rc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) - (D*K_rc*N*f_t*np.arccos((R - W)/R))/(4*np.pi) Fx = - ((D*N*(K_tc*W**2*f_t + K_rc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_tc*W*f_t - 2*K_re*W + 2*K_te*W**(1/2)*(2*R - W)**(1/2) + K_rc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) - (D*K_rc*N*f_t*np.arccos((R - W)/R))/(4*np.pi)
Fy = (D*K_tc*N*f_t*np.arccos((R - W)/R))/(4*np.pi) - ((D*N*(K_rc*W**2*f_t - K_tc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_te*W + 2*K_rc*W*f_t + 2*K_re*W**(1/2)*(2*R - W)**(1/2) - K_tc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi) Fy = (D*K_tc*N*f_t*np.arccos((R - W)/R))/(4*np.pi) - ((D*N*(K_rc*W**2*f_t - K_tc*W**(3/2)*f_t*(2*R - W)**(1/2)))/4 - (D*N*R*(2*K_te*W + 2*K_rc*W*f_t + 2*K_re*W**(1/2)*(2*R - W)**(1/2) - K_tc*W**(1/2)*f_t*(2*R - W)**(1/2)))/4)/(R**2*np.pi)
return np.array([Fx, Fy]) return np.array([Fx, Fy])
# coefficient calculators for linear regression # coefficient calculators for linear regression
def T_x_vector(D, N, R, W, f_r, w): def T_x_vector(conditions : Conditions):
""" """