Skip to content

Commit

Permalink
Move stan_stats to external mcmc-stats package
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Jan 30, 2025
1 parent ccdaaac commit f41bdc1
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 2,912 deletions.
1 change: 1 addition & 0 deletions gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@octokit/rest": "^21.0.0",
"@vercel/analytics": "^1.3.1",
"jszip": "^3.10.1",
"mcmc-stats": "^0.0.1",
"monaco-editor": "^0.52.2",
"plotly.js-cartesian-dist": "^2.35.2",
"pyodide": "^0.27.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import {
SecondaryColoredTableHead,
} from "@SpComponents/StyledTables";
import {
compute_effective_sample_size,
compute_split_potential_scale_reduction,
} from "@SpUtil/stan_stats/stan_stats";
import {
computeMean,
computePercentile,
computeStdDev,
} from "@SpUtil/stan_stats/summaryStats";
effective_sample_size,
split_potential_scale_reduction,
percentile,
mean,
std_deviation,
} from "mcmc-stats";

import { FunctionComponent, useMemo } from "react";

const columns = [
Expand Down Expand Up @@ -94,20 +93,20 @@ const SummaryPanel: FunctionComponent<SummaryProps> = ({
const pDrawsSorted = [...pDraws].sort((a, b) => a - b);
const ess = computeEss(pDraws, drawChainIds);
const rhat = computeRhat(pDraws, drawChainIds);
const stdDev = computeStdDev(pDraws);
const stdDev = std_deviation(pDraws);
const values = columns.map((column) => {
if (column.key === "mean") {
return computeMean(pDraws);
return mean(pDraws);
} else if (column.key === "mcse") {
return stdDev / Math.sqrt(ess);
} else if (column.key === "stdDev") {
return stdDev;
} else if (column.key === "5%") {
return computePercentile(pDrawsSorted, 0.05);
return percentile(pDrawsSorted, 0.05);
} else if (column.key === "50%") {
return computePercentile(pDrawsSorted, 0.5);
return percentile(pDrawsSorted, 0.5);
} else if (column.key === "95%") {
return computePercentile(pDrawsSorted, 0.95);
return percentile(pDrawsSorted, 0.95);
} else if (column.key === "nEff") {
return ess;
} else if (column.key === "nEff/s") {
Expand Down Expand Up @@ -177,13 +176,13 @@ const drawsByChain = (draws: number[], chainIds: number[]): number[][] => {

const computeEss = (x: number[], chainIds: number[]) => {
const draws = drawsByChain(x, chainIds);
const ess = compute_effective_sample_size(draws);
const ess = effective_sample_size(draws);
return ess;
};

const computeRhat = (x: number[], chainIds: number[]) => {
const draws = drawsByChain(x, chainIds);
const rhat = compute_split_potential_scale_reduction(draws);
const rhat = split_potential_scale_reduction(draws);
return rhat;
};

Expand Down
225 changes: 0 additions & 225 deletions gui/src/app/util/stan_stats/fft.ts

This file was deleted.

Loading

0 comments on commit f41bdc1

Please sign in to comment.