gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorLesley De Cruz <none>2012年01月02日 21:40:05 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年01月03日 23:33:28 +0100
commit4e954abe5934a37bf043f1218f2a0fb1093da4d4 (patch)
tree11cfbf81d599f36f890e7025c7de7a3838186411
parenta8e58671b54faec5abf8dfffa1747044e4dad23d (diff)
downloadgsl-shell-4e954abe5934a37bf043f1218f2a0fb1093da4d4.tar.gz
Return function to continue monte_vegas integration
Diffstat
-rw-r--r--monte-vegas.lua 23
1 files changed, 15 insertions, 8 deletions
diff --git a/monte-vegas.lua b/monte-vegas.lua
index 0cca6370..3f8575ec 100644
--- a/monte-vegas.lua
+++ b/monte-vegas.lua
@@ -337,6 +337,7 @@ end
-- @return result the result of the integration
-- @return sigma the estimated error or standard deviation
-- @return num_int the number of runs required to calculate the integral
+-- @return run function to compute the integral again via run(calls)
local function monte_vegas(f, a, b, calls, r, chidev)
calls = calls or 5e5
local rget = r and function() return r:get() end or random
@@ -349,15 +350,21 @@ local function monte_vegas(f, a, b, calls, r, chidev)
state:clear_stage1() -- clear results
state:rebin_stage2(1e4) -- intialise grid for 1e4 calls
local result,sigma = state:integrate(f,a,rget)
- local n = 0
+ local n
-- full (stage 1)
- repeat
- state:clear_stage1() -- forget previous results, but not the grid
- state:rebin_stage2(calls/state.iterations) -- initialise grid for calls/iterations calls
- result,sigma = state:integrate(f,a,rget)
- n=n+1
- until abs(state.chisq - 1) < chidev
- return result, sigma, n
+ local run = function (c)
+ calls = c or calls
+ n=0
+ repeat
+ state:clear_stage1() -- forget previous results, but not the grid
+ state:rebin_stage2(calls/state.iterations) -- initialise grid for calls/iterations calls
+ result,sigma = state:integrate(f,a,rget)
+ n=n+1
+ until abs(state.chisq - 1) < chidev
+ return result,sigma,n
+ end
+ result, sigma, n = run(calls)
+ return result, sigma, n, run
end
return monte_vegas
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月18日 05:03:11 +0000

AltStyle によって変換されたページ (->オリジナル) /