From 687a6d9b18501c8038b569ee7c39aabc7caefa4d Mon Sep 17 00:00:00 2001 From: Kevin Keogh Date: Mon, 15 Jan 2018 20:34:56 -0500 Subject: [PATCH] Style change and limit number of simulation results sent --- serve.go | 4 ++ sobol.go | 117 ++++++++++++++++++++++++++++++++++++ templates/assets/styles.css | 1 + 3 files changed, 122 insertions(+) create mode 100644 sobol.go diff --git a/serve.go b/serve.go index 8728137..60c766d 100644 --- a/serve.go +++ b/serve.go @@ -30,6 +30,10 @@ func index(w http.ResponseWriter, r *http.Request) { mcOpt.PriceMonteCarlo() bsOpt.PriceClosedForm() + // Only send the first 10000 levels, as the data going over + // the wire would otherwise be very significant + mcOpt.Levels = mcOpt.Levels[:1000] + options := make(map[string]Option) options["MonteCarlo"] = mcOpt options["ClosedForm"] = bsOpt diff --git a/sobol.go b/sobol.go new file mode 100644 index 0000000..844b83d --- /dev/null +++ b/sobol.go @@ -0,0 +1,117 @@ +package main + +import ( + "log" +) + +const ( + MaxDim = uint32(6) + MaxBit = uint32(30) + maxSeqNum = 1<> deg) + + for l := deg - 1; l >= 1; l-- { + if 1 & ipp == 1 { i ^= seq.iv[MaxDim * (j - 1) + k] } + ipp >>= 1 + } + + seq.iv[MaxDim * j + k] = i + } + } + + seq.isInit = true +} + +// See Press et al. 2007. +func (seq *SobolSequence) Next(dim int) []float64 { + target := make([]float64, dim) + seq.NextAt(target) + return target +} + +// NextAt is equivelent to Next, except the Sobol sequence is returned in-place. +func (seq *SobolSequence) NextAt(target []float64) { + dim := uint32(len(target)) + if dim > MaxDim { + log.Fatalf("Target dim %d is larger than MaxDim %d.\n", dim, MaxDim) + } else if seq.seqNum >= maxSeqNum { + log.Fatalf("Exceeded maximum seq num of %d for MaxBit %d.\n", + maxSeqNum, MaxBit, + ) + } + + seq.seqNum++ + + zeroIdx := uint32(0) + for zeroIdx = 0; zeroIdx < MaxBit; zeroIdx++ { + if (seq.seqNum & (1< input { float: right; margin-right: 20%; text-align: right; + max-width: 140px; } table {