Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Kamil Shakirov
alexandria
Commits
b8bd1033
Unverified
Commit
b8bd1033
authored
Feb 04, 2013
by
aarvid
Committed by
Attila Lendvai
Feb 16, 2014
Browse files
Fixed bug in gaussianrandom when min or max is nil but not both.
parent
1f3ae3aa
Changes
1
Hide whitespace changes
Inline
Sidebyside
numbers.lisp
View file @
b8bd1033
...
...
@@ 18,31 +18,35 @@ normal distribution around 0.0d0.
Sufficiently positive MIN or negative MAX will cause the algorithm used to
take a very long time. If MIN is positive it should be close to zero, and
similarly if MAX is negative it should be close to zero."
(
labels
((
gauss
()
(
loop
for
x1
=
(

(
random
2.0d0
)
1.0d0
)
for
x2
=
(

(
random
2.0d0
)
1.0d0
)
for
w
=
(
+
(
expt
x1
2
)
(
expt
x2
2
))
when
(
<
w
1.0d0
)
do
(
let
((
v
(
sqrt
(
/
(
*
2.0d0
(
log
w
))
w
))))
(
return
(
values
(
*
x1
v
)
(
*
x2
v
))))))
(
guard
(
x
min
max
)
(
unless
(
<=
min
x
max
)
(
tagbody
:retry
(
multiplevaluebind
(
x1
x2
)
(
gauss
)
(
when
(
<=
min
x1
max
)
(
setf
x
x1
)
(
go
:done
))
(
when
(
<=
min
x2
max
)
(
setf
x
x2
)
(
go
:done
))
(
go
:retry
))
:done
))
x
))
(
multiplevaluebind
(
g1
g2
)
(
gauss
)
(
values
(
guard
g1
(
or
min
g1
)
(
or
max
g1
))
(
guard
g2
(
or
min
g2
)
(
or
max
g2
))))))
(
macrolet
((
valid
(
x
)
`
(
<=
(
or
min
,
x
)
,
x
(
or
max
,
x
))
))
(
labels
((
gauss
()
(
loop
for
x1
=
(

(
random
2.0d0
)
1.0d0
)
for
x2
=
(

(
random
2.0d0
)
1.0d0
)
for
w
=
(
+
(
expt
x1
2
)
(
expt
x2
2
))
when
(
<
w
1.0d0
)
do
(
let
((
v
(
sqrt
(
/
(
*
2.0d0
(
log
w
))
w
))))
(
return
(
values
(
*
x1
v
)
(
*
x2
v
))))))
(
guard
(
x
)
(
unless
(
valid
x
)
(
tagbody
:retry
(
multiplevaluebind
(
x1
x2
)
(
gauss
)
(
when
(
valid
x1
)
(
setf
x
x1
)
(
go
:done
))
(
when
(
valid
x2
)
(
setf
x
x2
)
(
go
:done
))
(
go
:retry
))
:done
))
x
))
(
multiplevaluebind
(
g1
g2
)
(
gauss
)
(
values
(
guard
g1
)
(
guard
g2
))))))
(
declaim
(
inline
iota
))
(
defun
iota
(
n
&key
(
start
0
)
(
step
1
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment