adding histnet
This commit is contained in:
parent
24719ed0af
commit
d5610c7821
|
|
@ -17,7 +17,7 @@ quapy.method.aggregative module
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
.. automodule:: quapy.method._neural
|
.. automodule:: quapy.method._quanet
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
plot = None
|
plot = None
|
||||||
|
|
||||||
__version__ = '0.2.1.post1'
|
__version__ = '0.2.2'
|
||||||
|
|
||||||
|
|
||||||
def _default_cls():
|
def _default_cls():
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,21 @@
|
||||||
"""
|
"""
|
||||||
HistNetQ implementation.
|
HistNetQ implementation, see the original paper:
|
||||||
|
|
||||||
|
Pérez-Mon, O., Moreo, A., Coz, JJ del, & González, P. (2025).
|
||||||
|
Quantification using permutation-invariant networks based on histograms.
|
||||||
|
Neural Computing and Applications, 37(5), 3505-3520.
|
||||||
|
|
||||||
Ported from the reference implementation at https://github.com/pglez84/histnetq (the `HistNet`/
|
Ported from the reference implementation at https://github.com/pglez84/histnetq (the `HistNet`/
|
||||||
`DLQuantification` classes in that repo), adapted to QuaPy's own protocol-based sample generation
|
`DLQuantification` classes in that repo), adapted to QuaPy's own protocol-based sample generation
|
||||||
(replacing that repo's custom, `quantificationlib`-backed bag generators) and restricted, for now, to
|
(replacing that repo's custom, `quantificationlib`-backed bag generators) and restricted, for now, to
|
||||||
the "hard" differentiable histogram variant:
|
the "hard" differentiable histogram variant by:
|
||||||
|
|
||||||
Yusuf, I., Igwegbe, G., and Azeez, O. "Differentiable Histogram with Hard-Binning."
|
Yusuf, I., Igwegbe, G., and Azeez, O. "Differentiable Histogram with Hard-Binning."
|
||||||
arXiv preprint arXiv:2012.06311 (2020).
|
arXiv preprint arXiv:2012.06311 (2020).
|
||||||
|
|
||||||
The overall architecture is: feature_extraction -> Sigmoid -> histogram layer -> small MLP -> softmax,
|
The overall architecture is: feature_extraction -> Sigmoid -> histogram layer -> small MLP -> softmax,
|
||||||
trained by minimizing a quantification loss over samples ("bags") of known prevalence, rather than
|
trained by minimizing a quantification loss over samples ("bags") of known prevalence, rather than
|
||||||
over individually labeled instances (in the spirit of QuaNet, see method/_neural.py).
|
over individually labeled instances (in the spirit of QuaNet, see method/_quanet.py).
|
||||||
"""
|
"""
|
||||||
import copy
|
import copy
|
||||||
import os
|
import os
|
||||||
|
|
@ -177,10 +181,17 @@ class HistNetQ(BaseQuantifier):
|
||||||
Implementation of `HistNetQ <https://github.com/pglez84/histnetq>`_, a neural network for
|
Implementation of `HistNetQ <https://github.com/pglez84/histnetq>`_, a neural network for
|
||||||
quantification that learns a differentiable histogram-based representation of a sample, trained
|
quantification that learns a differentiable histogram-based representation of a sample, trained
|
||||||
end-to-end by minimizing a quantification loss over many samples ("bags") of known prevalence.
|
end-to-end by minimizing a quantification loss over many samples ("bags") of known prevalence.
|
||||||
|
The method was proposed in `Pérez-Mon, O., Moreo, A., Coz, JJ del, & González, P. (2025).
|
||||||
|
Quantification using permutation-invariant networks based on histograms.
|
||||||
|
Neural Computing and Applications, 37(5), 3505-3520.
|
||||||
|
<https://link.springer.com/article/10.1007/s00521-024-10721-1>`_
|
||||||
|
|
||||||
HistNetQ does not follow the classify-then-aggregate pattern of :class:`quapy.method.aggregative.
|
HistNetQ does not follow the classify-then-aggregate pattern of :class:`quapy.method.aggregative.
|
||||||
AggregativeQuantifier`; like :class:`quapy.method.meta.QuaNet`, it is trained and evaluated
|
AggregativeQuantifier`. Such classical approach is termed asymmetric, in the sense that quantifiers
|
||||||
end-to-end on whole samples rather than on individually labeled instances.
|
learn from labelled instances and perform inference over bags.
|
||||||
|
Like :class:`quapy.method.meta.QuaNet`, HistNetQ is trained and evaluated
|
||||||
|
end-to-end on whole samples rather than on individually labeled instances, following a symmetric problem setting
|
||||||
|
(learning from bags, predicting on bags).
|
||||||
|
|
||||||
Training data can be provided in two ways:
|
Training data can be provided in two ways:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@ from quapy.method.base import BaseQuantifier, BinaryQuantifier
|
||||||
from quapy.method.aggregative import CC, ACC, PACC, HDy, EMQ, AggregativeQuantifier, AggregativeSoftQuantifier
|
from quapy.method.aggregative import CC, ACC, PACC, HDy, EMQ, AggregativeQuantifier, AggregativeSoftQuantifier
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from . import _neural
|
from . import _quanet
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
_neural = None
|
_quanet = None
|
||||||
|
|
||||||
|
|
||||||
if _neural:
|
if _quanet:
|
||||||
QuaNet = _neural.QuaNetTrainer
|
QuaNet = _quanet.QuaNetTrainer
|
||||||
else:
|
else:
|
||||||
QuaNet = "QuaNet is not available due to missing torch package"
|
QuaNet = "QuaNet is not available due to missing torch package"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ class TestMethods(unittest.TestCase):
|
||||||
estim_prevalences2 = model2.predict(dataset.test.X)
|
estim_prevalences2 = model2.predict(dataset.test.X)
|
||||||
self.assertTrue(check_prevalence_vector(estim_prevalences2))
|
self.assertTrue(check_prevalence_vector(estim_prevalences2))
|
||||||
|
|
||||||
|
|
||||||
def test_composable(self):
|
def test_composable(self):
|
||||||
try:
|
try:
|
||||||
from quapy.method.composable import check_compatible_qunfold_version
|
from quapy.method.composable import check_compatible_qunfold_version
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue