36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 1/**
2 * Compression measurements off the main thread, so the scrolling view never
3 * stutters while zstd -19 or the LPC fit runs. One message in (the model),
4ec0133Code against the prediction, not the integer residualJeremy Magland 4 * one message out (the ten codec results).
36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 5 */
5bab85aRatio-first chart, quantization-floor theory formula, line-segment view, fixed latent dataJeremy Magland 6import { LatentSource } from '../model/latent'
4ec0133Code against the prediction, not the integer residualJeremy Magland 7import { conditionalGaussianCodec } from '../compress/conditionalGaussian'
36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 8import {
9 initCodecs,
10 compressAll,
11 ZLIB,
12 ZSTD,
13 ANS,
14 DELTA_ZLIB,
15 DELTA_ZSTD,
16 DELTA_ANS,
36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 18 type CodecResult,
19} from '../compress/codecs'
21export interface CompressRequest {
22 id: number
23 kernel: Float64Array
24 sigma: number
25 blockSize: number
36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 27 seed: number
28}
30export interface CompressResponse {
31 id: number
32 results: CodecResult[]
33 /** Empirical std of the quantized block, for display sanity. */
34 empiricalStd: number
35 error?: string
36}
e411dffMake LPC order and compression block size controlsJeremy Magland 38const PLAIN_CODECS = [ZLIB, ZSTD, ANS, DELTA_ZLIB, DELTA_ZSTD, DELTA_ANS]
36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 39
40const post = self.postMessage as (message: CompressResponse) => void
42self.onmessage = async (e: MessageEvent<CompressRequest>) => {
43704d2Clear the analytic rate: R now comes from the timeseries-entropy estimatorJeremy Magland 43 const { id, kernel, sigma, blockSize, lpcOrder, seed } = e.data
36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 44 try {
45 await initCodecs()
43704d2Clear the analytic rate: R now comes from the timeseries-entropy estimatorJeremy Magland 46 const samples = new LatentSource(seed).window(0, blockSize, kernel, sigma)
36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 47 let sum = 0
48 let sumSq = 0
49 for (let i = 0; i < samples.length; i++) {
50 sum += samples[i]
51 sumSq += samples[i] * samples[i]
52 }
53 const mean = sum / samples.length
54 const empiricalStd = Math.sqrt(Math.max(0, sumSq / samples.length - mean * mean))
56 id,
4ec0133Code against the prediction, not the integer residualJeremy Magland 57 results: compressAll(samples, [
58 ...PLAIN_CODECS,
59 ...lpcCodecs(lpcOrder),
60 conditionalGaussianCodec(lpcOrder),
61 ]),
63 })
36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 64 } catch (err) {
4ec0133Code against the prediction, not the integer residualJeremy Magland 65 post({ id, results: [], empiricalStd: 0, error: String(err) })
36e8ceaInteractive explorer for compressibility of quantized filtered Gaussian time seriesJeremy Magland 66 }
67}