Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
0c795236
Commit
0c795236
authored
Oct 22, 2014
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cauchy distribution fixed
parent
bfa2747f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
dream/simulation/RandomNumberGenerator.py
dream/simulation/RandomNumberGenerator.py
+11
-2
No files found.
dream/simulation/RandomNumberGenerator.py
View file @
0c795236
...
...
@@ -26,6 +26,8 @@ Created on 14 Feb 2013
holds methods for generations of numbers from different distributions
'''
import
math
class
RandomNumberGenerator
(
object
):
def
__init__
(
self
,
obj
,
distributionType
,
mean
=
0
,
stdev
=
0
,
min
=
0
,
max
=
0
,
alpha
=
0
,
beta
=
0
,
logmean
=
0
,
logsd
=
0
,
probability
=
0
,
shape
=
0
,
scale
=
0
,
location
=
0
):
...
...
@@ -66,7 +68,6 @@ class RandomNumberGenerator(object):
elif
(
self
.
distributionType
==
"Logistic"
):
#if the distribution is Logistic
# XXX from http://stackoverflow.com/questions/3955877/generating-samples-from-the-logistic-distribution
# to check
import
math
while
1
:
x
=
G
.
Rnd
.
random
()
number
=
self
.
location
+
self
.
scale
*
math
.
log
(
x
/
(
1
-
x
))
...
...
@@ -83,7 +84,15 @@ class RandomNumberGenerator(object):
elif
(
self
.
distributionType
==
"Weibull"
):
#if the distribution is Weibull
return
G
.
Rnd
.
weibullvariate
(
self
.
scale
,
self
.
shape
)
elif
(
self
.
distributionType
==
"Cauchy"
):
#if the distribution is Cauchy
return
1
while
1
:
p
=
0.0
while
p
==
0.0
:
p
=
G
.
Rnd
.
random
()
number
=
self
.
location
+
self
.
scale
*
math
.
tan
(
math
.
pi
*
(
p
-
0.5
))
if
number
>
0
:
return
number
else
:
continue
else
:
raise
ValueError
(
"Unknown distribution %r used in %s %s"
%
(
self
.
distributionType
,
self
.
obj
.
__class__
,
self
.
obj
.
id
))
...
...
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