8000 Refactor simulation function by mmcdermott · Pull Request #173 · getguesstimate/guesstimate-app · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor simulation function #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/lib/guesstimator/samplers/DistributionLognormal.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import math from 'mathjs';
var jStat = require('jstat').jStat;
import {Sample} from './Sampler.js'
import {jStat} from 'jstat'

export var Sampler = {
sample(formatted, n) {
sample({high, low}, n) {
// This assumes a centered 90% confidence interval, e.g. the left endpoint
// marks 0.05% on the CDF, the right 0.95%.
const logHigh = math.log(formatted.high)
const logLow = math.log(formatted.low)
const logHigh = math.log(high)
const logLow = math.log(low)

const mean = (logHigh + logLow)/2
const mean = math.mean(logHigh, logLow)
const stdev = (logHigh-logLow) / (2*1.645)

const getSample = () => jStat.lognormal.sample(mean, stdev)
let results = Array.apply(null, {length: n}).map( getSample)

results = Array.isArray(results) ? results : [results]

return { values: results.map(n => n) }
return { values: Sample(n, () => jStat.lognormal.sample(mean, stdev)) }
}
}

5 changes: 2 additions & 3 deletions src/lib/propagation/metric-propagation.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ export default class MetricPropagation {

if (errors[0]) { this.halted = true }
return errors
} else { return [null, null] }
} else {
return [null, null]
}
}
return [null, null]
}

_needsMoreSamples(graph) {
Expand Down
0