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
bad574ba
Commit
bad574ba
authored
Jan 22, 2015
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Triangular added to RandomNumberGenerator. Test added for this
parent
b295d5ab
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
dream/simulation/RandomNumberGenerator.py
dream/simulation/RandomNumberGenerator.py
+4
-2
dream/tests/testRandomNumberGenerator.py
dream/tests/testRandomNumberGenerator.py
+13
-0
No files found.
dream/simulation/RandomNumberGenerator.py
View file @
bad574ba
...
...
@@ -45,7 +45,7 @@ class RandomNumberGenerator(object):
unknownDistribution
=
True
for
key
in
distribution
.
keys
():
if
key
in
[
'Fixed'
,
'Normal'
,
'Exp'
,
'Gamma'
,
'Logistic'
,
'Erlang'
,
'Geometric'
,
'Lognormal'
,
'Weibull'
,
'Cauchy'
]:
'Geometric'
,
'Lognormal'
,
'Weibull'
,
'Cauchy'
,
'Triangular'
]:
unknownDistribution
=
False
break
if
unknownDistribution
:
...
...
@@ -54,7 +54,7 @@ class RandomNumberGenerator(object):
# pop irrelevant keys
for
key
in
distribution
.
keys
():
if
key
not
in
[
'Fixed'
,
'Normal'
,
'Exp'
,
'Gamma'
,
'Logistic'
,
'Erlang'
,
'Geometric'
,
'Lognormal'
,
'Weibull'
,
'Cauchy'
]:
'Geometric'
,
'Lognormal'
,
'Weibull'
,
'Cauchy'
,
'Triangular'
]:
distribution
.
pop
(
key
,
None
)
self
.
distribution
=
distribution
self
.
distributionType
=
distribution
.
keys
()[
0
]
...
...
@@ -132,6 +132,8 @@ class RandomNumberGenerator(object):
return
number
else
:
continue
elif
(
self
.
distributionType
==
"Triangular"
):
#if the distribution is Triangular
return
G
.
numpyRnd
.
random
.
triangular
(
left
=
self
.
min
,
right
=
self
.
max
,
mode
=
self
.
mean
)
else
:
raise
ValueError
(
"Unknown distribution %r used in %s %s"
%
(
self
.
distributionType
,
self
.
obj
.
__class__
,
self
.
obj
.
id
))
...
...
dream/tests/testRandomNumberGenerator.py
View file @
bad574ba
...
...
@@ -56,6 +56,19 @@ class RandomNumberGeneratorTestCase(TestCase):
self
.
assertTrue
(
number
>=
0
)
self
.
assertTrue
(
number
<=
3
)
def
testTriangular
(
self
):
rng
=
RandomNumberGenerator
(
obj
,
distribution
=
{
'Triangular'
:
{
'min'
:
1
,
'max'
:
3
,
'mean'
:
2
}
})
for
i
in
range
(
10
):
number
=
rng
.
generateNumber
()
self
.
assertTrue
(
number
>=
1
)
self
.
assertTrue
(
number
<=
3
)
def
testNormalWrongParameter
(
self
):
rng
=
RandomNumberGenerator
(
obj
,
distribution
=
{
'Normal'
:
...
...
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