Skip to content

Commit

Permalink
reorder metadata legend before results (#181)
Browse files Browse the repository at this point in the history
* sort legend by onehot array

* add comment
  • Loading branch information
ziyuan-linn authored Aug 6, 2024
1 parent a88a3a1 commit 4e02adf
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/NeuralNetwork/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,13 @@ class DiyNeuralNetwork {
if (meta !== null) {
const label = Object.keys(meta.outputs)[0];
const vals = Object.entries(meta.outputs[label].legend);
// sort the legend array results by each item's one-hot encoding
vals.sort((a, b) => {
return (
b[1].reduce((acc, curr) => acc * 2 + curr, 0) -
a[1].reduce((acc, curr) => acc * 2 + curr, 0)
);
});

const formattedResults = unformattedResults.map((unformattedResult) => {
return vals
Expand Down

0 comments on commit 4e02adf

Please sign in to comment.