diff options
author | andreas128 <Andreas> | 2017-09-10 19:28:45 +0200 |
---|---|---|
committer | andreas128 <Andreas> | 2017-09-10 19:28:45 +0200 |
commit | dd46ed939e56a4e56c3dcec60cce1b93c8786a4a (patch) | |
tree | ad37fba573a82a8d5ad82b764d74a80b4c198a9c /dpd/src/Model.py | |
parent | 6e580248099ce4995ff0ba957d9f9ba64cfdfff2 (diff) | |
download | dabmod-dd46ed939e56a4e56c3dcec60cce1b93c8786a4a.tar.gz dabmod-dd46ed939e56a4e56c3dcec60cce1b93c8786a4a.tar.bz2 dabmod-dd46ed939e56a4e56c3dcec60cce1b93c8786a4a.zip |
Use ridge regression
Diffstat (limited to 'dpd/src/Model.py')
-rw-r--r-- | dpd/src/Model.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/dpd/src/Model.py b/dpd/src/Model.py index 4ccf0be..827027a 100644 --- a/dpd/src/Model.py +++ b/dpd/src/Model.py @@ -13,7 +13,7 @@ logging_path = os.path.dirname(logging.getLoggerClass().root.handlers[0].baseFil import numpy as np import matplotlib.pyplot as plt - +from sklearn import linear_model class Model: """Calculates new coefficients using the measurement and the old @@ -25,8 +25,8 @@ class Model: MER, coefs_am, coefs_pm, - learning_rate_am=0.1, - learning_rate_pm=0.1, + learning_rate_am=1., + learning_rate_pm=1., plot=False): self.c = c self.SA = SA @@ -124,7 +124,9 @@ class Model: self.mses_am.append(mse) self.errs_am.append(np.mean(err**2)) - a_delta = np.linalg.lstsq(rx_A, err)[0] + reg = linear_model.Ridge(alpha=0.00001) + reg.fit(rx_A, err) + a_delta = reg.coef_ new_coefs_am = self.coefs_am - self.learning_rate_am * a_delta new_coefs_am = new_coefs_am * (self.coefs_am[0] / new_coefs_am[0]) return new_coefs_am @@ -143,7 +145,9 @@ class Model: err_phase = phase_diff_est - phase_diff_choice self.errs_pm.append(np.mean(np.abs(err_phase ** 2))) - p_delta = np.linalg.lstsq(phase_A, err_phase)[0] + reg = linear_model.Ridge(alpha=0.00001) + reg.fit(phase_A, err_phase) + p_delta = reg.coef_ new_coefs_pm = self.coefs_pm - self.learning_rate_pm * p_delta return new_coefs_pm, phase_diff_choice |