Ensemble: Function: Rename get_sample to random and use np.random.

This commit is contained in:
parouby committed 2026-09-10 11:40:57 +02:00
1 parent f5a7cd5984
commit 6e029beafc
5 files changed
+14 -19

No files matched your search

+3 -3
View File
@@ -130,7 +130,7 @@ class Ensemble(SQLSubModel):
None
)
rdata = cls._decode_params(params, params_len)
rdata = list(cls._decode_params(params, params_len))
new_ensemble = cls(
id, name=name,
@@ -201,9 +201,9 @@ class Ensemble(SQLSubModel):
return struct.unpack(data_format, bparams)
def get_sample(self, nb):
def random(self, nb):
return np.nditer(
self._function.get_sample(
self._function.random(
self._params, nb
)
)
+6 -11
View File
@@ -135,7 +135,7 @@ class Function(SQLSubModel):
if predicate(self, data):
modifier(self, data)
def get_sample(self, r):
def random(self, r):
raise NotImplementedMethodeError(cls, cls._load)
@@ -154,16 +154,11 @@ class Uniform(Function):
name=name, script=script
)
def get_sample(self, ens_range, nb):
b = ens_range[0]
t = ens_range[1]
def random(self, ens_range, nb):
lst = ens_range.copy()
lst.append(nb)
step = (t - b) / nb
r = np.arange(b, t, step)
np.random.shuffle(r)
return r
return np.random.uniform(*lst)
class Custom(Function):
@@ -179,7 +174,7 @@ class Custom(Function):
self._type = "custom"
def get_sample(self, ens_range, nb):
def random(self, ens_range, nb):
try:
# Run script to (re)define the sample function
f = eval(self._script)