Skip to content

Commit

Permalink
Add smoothed PDF, fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
zemlyansky committed Oct 26, 2018
1 parent cf7b562 commit e78f22a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"is": "^3.2.1",
"is-json": "^2.0.1",
"online-stats": "^1.3.0",
"pdfast": "^0.2.0",
"query-string": "^6.2.0",
"vue": "^2.5.17",
"vue-d3-network": "^0.1.26",
Expand Down
25 changes: 20 additions & 5 deletions src/lib/processResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Stats = require('online-stats')
const Dygraphs = require('dygraphs')
const d3 = require('d3-array')
const hist2d = require('d3-hist2d').hist2d
const pdfast = require('pdfast')
const plot2d = window['densityPlot'] // ESM WTF!!!

function createChart (chartTitle, chartData, chartLabels, chartOptions) {
Expand Down Expand Up @@ -231,6 +232,10 @@ module.exports = function processResults (v) {
// * Random scalar samples
rvs.push(k)

// Prepare needed transforms
const sorted = samples[k].slice().sort((a, b) => a - b)
const n = sorted.length

// Draw trace
createChart(k + ' trace', samples[k].map((s, si) => [si, s]), ['Sample', k])

Expand All @@ -246,17 +251,27 @@ module.exports = function processResults (v) {
createChart(
k + ' histogram',
h.map(v => [v.x0, v.length / samples[k].length]),
['Sample', k],
[k, 'p'],
{
stepPlot: true,
fillGraph: true
}
)

// ---- PDF (KDE smoothing)
const pdf = pdfast.create(samples[k], {size: 30, min: sorted[0], max: sorted[sorted.length - 1]})
console.log('PDF:', pdf)
createChart(
k + ' PDF (smooth)',
pdf.map(v => [v.x, v.y]),
[k, 'f'],
{
rollPeriod: 2,
fillGraph: true
}
)

// ---- CDF (updated)
const sorted = samples[k].sort((a, b) => a - b)
console.log(sorted.toString())
const n = sorted.length
const step = (sorted[sorted.length - 1] - sorted[0]) / 200
if (step > 0) {
let cdf = []
Expand All @@ -273,7 +288,7 @@ module.exports = function processResults (v) {
}
}
}
createChart(k + ' CDF (upd)', cdf, [k, 'p'])
createChart(k + ' CDF', cdf, [k, 'F'])
}

// ---- Quantiles
Expand Down

0 comments on commit e78f22a

Please sign in to comment.