Skip to content

Commit

Permalink
fix: ensure that model prediction with makefile command works as expe…
Browse files Browse the repository at this point in the history
…cted (#234)
  • Loading branch information
sjschlapbach authored Nov 23, 2023
1 parent fc076c1 commit ac0cfce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Tools/parametric_model/predict_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import sys
import inspect
from src.models import MultiRotorModel, SimpleFixedWingModel, QuadPlaneModel
from src.models import MultiRotorModel, FixedWingModel
from src.models.model_config import ModelConfig
import src.models as models
from src.tools import DataHandler
Expand Down
25 changes: 19 additions & 6 deletions Tools/parametric_model/src/models/dynamics_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,18 @@ def generate_model_dict(self, coefficient_list, metrics_dict, model_dict):
}

def save_result_dict_to_yaml(
self, file_name="model_parameters", result_path="model_results/"
self,
file_name="model_parameters",
result_path="model_results/",
results_only=False,
):
timestr = time.strftime("%Y-%m-%d-%H-%M-%S")
file_path = result_path + file_name + "_" + timestr + ".yaml"

with open(file_path, "w") as outfile:
yaml.dump(self.result_dict, outfile, default_flow_style=False)
yaml.dump(self.fisher_metric, outfile, default_flow_style=False)
if not results_only:
yaml.dump(self.fisher_metric, outfile, default_flow_style=False)
print(
"-------------------------------------------------------------------------------"
)
Expand Down Expand Up @@ -482,15 +486,24 @@ def predict_model(self, opt_coefs_dict):
print(
"==============================================================================="
)
X, y = self.prepare_regression_matrices()
self.prepare_regression_matrices()

configuration = []
if self.estimate_forces:
configuration.append("lin")
if self.estimate_moments:
configuration.append("rot")
self.X, self.y, self.coef_name_list = self.assemble_regression_matrices(
configuration
)

c_opt_list = []
for coef in self.coef_name_list:
c_opt_list.append(opt_coefs_dict[coef])

self.initialize_optimizer()
self.optimizer.set_optimal_coefficients(c_opt_list, X, y)
self.generate_optimization_results()
self.optimizer.set_optimal_coefficients(c_opt_list, self.X, self.y)
self.generate_prediction_results()

def estimate_model(self):
print(
Expand Down Expand Up @@ -592,7 +605,7 @@ def generate_prediction_results(self):
"-------------------------------------------------------------------------------"
)
print(yaml.dump(self.result_dict["metrics"], default_flow_style=False))
self.save_result_dict_to_yaml(file_name=self.model_name)
self.save_result_dict_to_yaml(file_name=self.model_name, results_only=True)

def generate_optimization_results(self):
print(
Expand Down

0 comments on commit ac0cfce

Please sign in to comment.