-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
several bug fixes, added normilization
- Loading branch information
Showing
10 changed files
with
227 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
plugins/machine_learning/include/machine_learning/utilities/normalization.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include "hal_core/utilities/result.h" | ||
|
||
#include <vector> | ||
|
||
namespace hal | ||
{ | ||
namespace machine_learning | ||
{ | ||
template<typename T> | ||
Result<std::monostate> normalize_vector_min_max(std::vector<T>& values) | ||
{ | ||
// Ensure T is a numeric type | ||
static_assert(std::is_arithmetic<T>::value, "Vector elements must be numeric."); | ||
|
||
if (!values.empty()) | ||
{ | ||
const auto min_val = *std::min_element(values.begin(), values.end()); | ||
const auto max_val = *std::max_element(values.begin(), values.end()); | ||
|
||
// Avoid division by zero if all elements are the same | ||
if (min_val == max_val) | ||
{ | ||
values.assign(values.size(), static_cast<T>(0.5)); | ||
return OK({}); | ||
} | ||
|
||
// Apply min-max normalization | ||
for (auto& value : values) | ||
{ | ||
value = (value - min_val) / (max_val - min_val); | ||
} | ||
} | ||
|
||
return OK({}); | ||
} | ||
|
||
} // namespace machine_learning | ||
} // namespace hal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.