Skip to content

Commit

Permalink
Move random number generation functions into a specific module
Browse files Browse the repository at this point in the history
  • Loading branch information
franko committed Oct 24, 2011
1 parent ffa6842 commit 20403d1
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 418 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ endif

SUBDIRS = $(LUADIR)

C_SRC_FILES = gs-types.c lua-utils.c random.c randist.c \
C_SRC_FILES = gs-types.c lua-utils.c lua-rng.c randist.c \
pdf.c cdf.c sf.c lua-graph.c lua-gsl.c

LUA_BASE_FILES = base.lua matrix-init.lua misc.lua integ-init.lua fft-init.lua import.lua bspline.lua cgsl.lua check.lua csv.lua demo-init.lua gsl-check.lua gslext.lua linfit.lua roots.lua strict.lua template.lua time.lua
Expand Down
2 changes: 1 addition & 1 deletion cdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_sf_erf.h>

#include "random.h"
#include "lua-rng.h"
#include "cdf.h"

#define CONCAT2x(a,b) a ## _ ## b
Expand Down
4 changes: 2 additions & 2 deletions demos/anim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local function demo1()
plt:show()
local a = 15.0
plt:limits(-a, -a, a, a)
local r = rng()
local r = rng.new()
for k = 1, 50 do
local x, y = (2*r:get()-1)*a, (2*r:get()-1)*a
local d = rnd.gaussian(r, 0.015*a) + 0.03*a
Expand Down Expand Up @@ -68,7 +68,7 @@ end

local function demo3()
local p = plot 'box plot'
local r = rng()
local r = rng.new()
r:set(os.time())
p:addline(rect(-10, -10, 10, 10), 'blue', {{'dash', 7, 3}})
p.sync = false
Expand Down
2 changes: 1 addition & 1 deletion demos/bspline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local function demo1()
local x = matrix.new(n, 1, xsmp)
local y = matrix.new(n, 1, |i| f(xsmp(i)))

local r = rng()
local r = rng.new()
local w = matrix.alloc(n, 1)
for i = 1, n do
local yi = y[i]
Expand Down
2 changes: 1 addition & 1 deletion demos/linfit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local function demo1()
local a, b = 0.55, -2.4
local xsmp = |i| (i-1)/(n-1) * x1

local r = rng()
local r = rng.new()
local x = matrix.new(n, 1, xsmp)
local y = matrix.new(n, 1, |i| a*xsmp(i) + b + rnd.gaussian(r, 0.4))

Expand Down
4 changes: 2 additions & 2 deletions demos/nlinfit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local function demo1()

local xref = matrix.vec {5, 0.1, 1}

local r = num.rng()
local r = rng.new()
r:set(0)

yrf = matrix.new(n, 1, |i| model(xref, i-1) + num.rnd.gaussian(r, 0.1))
Expand Down Expand Up @@ -59,7 +59,7 @@ local function demo2()
local px = matrix.vec {1.55, -1.1, 12.5}
local p0 = matrix.vec {2.5, -1.5, 5.3}
local xs = |i| (i-1)/n
local r = num.rng()
local r = rng.new()

local fmodel = function(p, t, J)
local e, s = exp(p[2] * t), sin(p[3] * t)
Expand Down
2 changes: 1 addition & 1 deletion demos/plot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end

local function demo2()
local N = 800
local r = rng()
local r = rng.new()
local f = |x| 1/sqrt(2*pi) * exp(-x^2/2)
local p = plot('Simulated Gaussian Distribution')
local b = ibars(sample(|x| rnd.poisson(r, floor(f(x)*N)) / N, -3, 3, 25))
Expand Down
99 changes: 0 additions & 99 deletions examples/anim.lua

This file was deleted.

38 changes: 0 additions & 38 deletions examples/bspline.lua

This file was deleted.

108 changes: 0 additions & 108 deletions examples/nlinfit.lua

This file was deleted.

Loading

0 comments on commit 20403d1

Please sign in to comment.