Ensemble: Edit: Add Binomial distribution and minor change.

This commit is contained in:
parouby committed 2026-09-25 15:16:32 +02:00
1 parent cadffe40d6
commit f19ab9455a
6 files changed
+67 -94

No files matched your search

+22 -1
View File
@@ -195,6 +195,27 @@ class Normal(Distribution):
return np.random.normal(*lst)
class Binomial(Distribution):
_sub_classes = []
def __init__(self, id: int = -1,
name: str = "binomial", script: str = "",
status=None):
super(Binomial, self).__init__(
id=id, status=status,
name=name, script=script
)
self._labels = ["binomial_n", "binomial_p"]
self._default_values = [100.0, 0.3]
def random(self, params, nb):
lst = params.copy()
lst.append(nb)
return np.random.binomial(*lst)
class Poisson(Distribution):
_sub_classes = []
@@ -206,7 +227,7 @@ class Poisson(Distribution):
name=name, script=script
)
self._labels = ["lam"]
self._labels = ["poisson_lam"]
self._default_values = [5.0]
def random(self, params, nb):
+5 -3
View File
@@ -30,10 +30,12 @@ class DistributionList(PamhyrModelList):
new = cls(status=data['status'])
# Default distributions
d = {"status": data['status']}
new._lst = [
Uniform(status=data['status']),
Normal(status=data['status']),
Poisson(status=data['status']),
Uniform(**d),
Normal(**d),
Binomial(**d),
Poisson(**d),
]
# DB custom distributions
+33
View File
@@ -0,0 +1,33 @@
# Translate.py -- Pamhyr
# Copyright (C) 2023-2026 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QCoreApplication
from View.Ensembles.Translate import EnsemblesTranslate
_translate = QCoreApplication.translate
class EnsembleEditTranslate(EnsemblesTranslate):
def __init__(self):
super(EnsembleEditTranslate, self).__init__()
self._dict["binomial_n"] = _translate("Ensemble", "n")
self._dict["binomial_p"] = _translate("Ensemble", "p")
self._dict["poisson_lam"] = _translate("Ensemble", "Lam")
+7 -3
View File
@@ -45,6 +45,8 @@ from PyQt5.QtWidgets import (
QGroupBox, QTreeWidget,
)
from View.Ensembles.Edit.Translate import EnsembleEditTranslate
logger = logging.getLogger()
@@ -74,7 +76,9 @@ class EnsembleEditDialog(PamhyrDialog):
_pamhyr_name = "Parameters"
def __init__(self, study=None, ensemble=None,
trad=None, parent=None):
parent=None):
trad = EnsembleEditTranslate()
super(EnsembleEditDialog, self).__init__(
title=trad[self._pamhyr_name],
trad=trad,
@@ -248,7 +252,7 @@ class Ensemble1ParamsWidget(PamhyrWidget):
def _init_default_values(self):
self._values = self._ensemble.params
if len(self._values) < 1:
if len(self._values) != 1:
self._values = self._distribution.default_values.copy()
self.set_double_spin_box("doubleSpinBox_0", self._values[0])
@@ -287,7 +291,7 @@ class Ensemble2ParamsWidget(PamhyrWidget):
def _init_default_values(self):
self._values = self._ensemble.params
if len(self._values) < 2:
if len(self._values) != 2:
self._values = self._distribution.default_values.copy()
self.set_double_spin_box("doubleSpinBox_0", self._values[0])
-86
View File
@@ -197,7 +197,6 @@ class EnsemblesWindow(PamhyrWindow):
dlg = EnsembleEditDialog(
study=self._study,
ensemble=ens,
trad=self._trad,
parent=self
)
@@ -279,88 +278,3 @@ class EnsemblesWindow(PamhyrWindow):
)
)
self._table.update()
class Ensemble1ParamsDialog(PamhyrDialog):
_pamhyr_ui = "Ensemble1ParamsDialog"
_pamhyr_name = "Parameters"
def __init__(self, ensemble=None,
trad=None, parent=None):
super(Ensemble1ParamsDialog, self).__init__(
title=trad[self._pamhyr_name],
trad=trad,
options=[],
parent=parent
)
self._ensemble = ensemble
self._labels = ensemble.distribution.labels
self._init_default_labels()
self._init_default_values()
def _init_default_labels(self):
self.set_label_text("label_0", self._trad[self._labels[0]])
def _init_default_values(self):
self._values = self._ensemble.params
if len(self._values) > 0:
self.set_double_spin_box("doubleSpinBox_0", self._values[0])
@property
def values(self):
return self._values
def accept(self):
self._values = [
self.get_double_spin_box("doubleSpinBox_0"),
]
super().accept()
def reject(self):
self.close()
class Ensemble2ParamsDialog(PamhyrDialog):
_pamhyr_ui = "Ensemble2ParamsDialog"
_pamhyr_name = "Parameters"
def __init__(self, ensemble=None,
trad=None, parent=None):
super(Ensemble2ParamsDialog, self).__init__(
title=trad[self._pamhyr_name],
trad=trad,
options=[],
parent=parent
)
self._ensemble = ensemble
self._labels = ensemble.distribution.labels
self._init_default_labels()
self._init_default_values()
def _init_default_labels(self):
self.set_label_text("label_0", self._trad[self._labels[0]])
self.set_label_text("label_1", self._trad[self._labels[1]])
def _init_default_values(self):
self._values = self._ensemble.params
if len(self._values) > 0:
self.set_double_spin_box("doubleSpinBox_0", self._values[0])
self.set_double_spin_box("doubleSpinBox_1", self._values[1])
@property
def values(self):
return self._values
def accept(self):
self._values = [
self.get_double_spin_box("doubleSpinBox_0"),
self.get_double_spin_box("doubleSpinBox_1")
]
super().accept()
def reject(self):
self.close()
-1
View File
@@ -45,7 +45,6 @@ class CommonWordTranslate(PamhyrTranslate):
self._dict["loc"] = _translate("CommonWord", "Loc")
self._dict["scale"] = _translate("CommonWord", "Scale")
self._dict["lam"] = _translate("CommonWord", "Lam")
self._dict["reach"] = _translate("CommonWord", "Reach")
self._dict["reaches"] = _translate("CommonWord", "Reaches")