Skip to content

Commit

Permalink
also try again if not enough samples
Browse files Browse the repository at this point in the history
  • Loading branch information
dderjoel committed Jul 28, 2023
1 parent 31d36db commit 9c89288
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/CountCycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9c89288

Please sign in to comment.