concept-collection / stan-remote-sampling
stan-remote-sampling / src / mergeChains.ts
20 lines · 631 BBlameHistoryRaw
1import type { ChainResult, MultiChainResult } from "./types";
3export const mergeChainResults = (
4 chainResults: ChainResult[],
5 computeTimeSec: number,
6): MultiChainResult => {
7 const sorted = [...chainResults].sort((a, b) => a.chainId - b.chainId);
8 const paramNames = sorted[0].paramNames;
9 // concatenate draws across chains, per parameter
10 const draws = paramNames.map((_, p) => sorted.flatMap((c) => c.draws[p]));
11 return {
12 paramNames,
13 draws,
14 numChains: sorted.length,
15 computeTimeSec,
16 consoleText: sorted
17 .map((c) => `--- chain ${c.chainId} ---\n${c.consoleText}`)
18 .join("\n"),
19 };
20};