hack: Generalize geom mean to negative values...

by falling back to the arithmetic mean if there are any
This commit is contained in:
NunoSempere 2022-04-11 14:08:35 -04:00
parent 2e4c76a257
commit 981b2ca568
2 changed files with 11 additions and 2 deletions

View File

@ -4,7 +4,7 @@ import {
numToAlphabeticalString,
formatLargeOrSmall,
avg,
geomMean,
hackyGeomMean,
} from "../lib/utils.js";
/* Functions */
@ -315,7 +315,7 @@ export function CreateTable({ tableRows }) {
<td className="">{abridgeArrayAndDisplay(row.distances)}</td>
<td>&nbsp;&nbsp;&nbsp;</td>
<td className="">
{formatLargeOrSmall(geomMean(row.distances))}
{formatLargeOrSmall(hackyGeomMean(row.distances))}
</td>
</tr>
))}

View File

@ -102,6 +102,15 @@ export const geomMean = (arr) => {
return result;
};
export const hackyGeomMean = (arr) => {
let nonPositiveNumbers = arr.filter((x) => x <= 0);
if (nonPositiveNumbers.length == 0) {
return geomMean(arr);
} else {
return avg(arr);
}
};
export function conservativeNumMergeSortSteps(n) {
return Math.ceil((expectedNumMergeSortSteps(n) + maxMergeSortSteps(n)) / 2);
}