Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tools
frackit
Commits
8a99f1ac
Commit
8a99f1ac
authored
May 03, 2020
by
Dennis Gläser
Browse files
[python][sampling] add box point sampler allowing for custom distros
parent
34dd59f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/frackit/sampling/__init__.py
View file @
8a99f1ac
from
._sampling
import
*
class
BoxPointSampler
:
"""Class to sample random points within a box."""
def
__init__
(
self
,
samplerX
,
samplerY
,
samplerZ
):
"""Create the sampler from random variable samplers for the coordinate directions."""
self
.
samplerX
=
samplerX
self
.
samplerY
=
samplerY
self
.
samplerZ
=
samplerZ
def
sample
(
self
):
x
=
self
.
samplerX
()
y
=
self
.
samplerY
()
z
=
self
.
samplerZ
()
from
frackit.geometry
import
Point_3
return
Point_3
(
x
,
y
,
z
)
# creator for a uniform sampler within an interval
def
uniformIntervalSamplerCreator
():
def
makeSampler
(
min
,
max
):
import
random
def
doSample
():
return
random
.
uniform
(
min
,
max
)
return
doSample
return
makeSampler
def
makeBoxPointSampler
(
box
,
samplerCreatorX
=
uniformIntervalSamplerCreator
(),
samplerCreatorY
=
uniformIntervalSamplerCreator
(),
samplerCreatorZ
=
uniformIntervalSamplerCreator
()):
"""Creates a BoxPointSampler using the provided creators for samplers on intervals.
The creators default to uniform interval sampler creators if nothing is specified."""
# make samplers
samplerX
=
samplerCreatorX
(
box
.
xMin
(),
box
.
xMax
())
samplerY
=
samplerCreatorY
(
box
.
yMin
(),
box
.
yMax
())
samplerZ
=
samplerCreatorZ
(
box
.
zMin
(),
box
.
zMax
())
return
BoxPointSampler
(
samplerX
,
samplerY
,
samplerZ
)
Write
Preview
Supports
Markdown
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