From 9c89288c20694a49823d9903a36376bf7359fb79 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 28 Jul 2023 10:49:28 +0930 Subject: [PATCH] also try again if not enough samples --- src/CountCycle.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/CountCycle.ts b/src/CountCycle.ts index bb2f3f9..a15167b 100644 --- a/src/CountCycle.ts +++ b/src/CountCycle.ts @@ -117,19 +117,14 @@ function main() { function roboustMean(data: number[]): number { const data2 = [] as number[]; // there is a bit of wierd thing going on. - // on the 12th gen, sometimes only 0's are returned. - if (data.every((d) => d === 0)) { + // on the 12th gen, sometimes only 0's are returned, or only for some it worked. + if (data.every((d) => d === 0) || data.length < MAX_SAMLPESIZE) { // then we'll try again. - console.warn("only zeroes"); return -1; } else { console.warn("not only zeroes", data); } - if (data.length < MAX_SAMLPESIZE) { - throw new Error(`There is not enough samples in the data ${data.length}<${MAX_SAMLPESIZE}`); - } - for (let i = 0; i < data.length / 2; i++) { const randomIndex = Math.floor(Math.random() * data.length); const [randomSample] = data.splice(randomIndex, 1);