Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure that model prediction with makefile command works as expected #234

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading