From 8accd8a306d913f39ca057d74e745b0757222888 Mon Sep 17 00:00:00 2001 From: troyyyyy Date: Wed, 13 Dec 2023 13:45:32 +0800 Subject: [PATCH] [FIX] remove unnecessary functions in utils --- abl/reasoning/reasoner.py | 2 +- abl/utils/__init__.py | 2 -- abl/utils/utils.py | 69 -------------------------------------- docs/API/abl.reasoning.rst | 17 +++++----- docs/API/abl.utils.rst | 1 - 5 files changed, 9 insertions(+), 82 deletions(-) diff --git a/abl/reasoning/reasoner.py b/abl/reasoning/reasoner.py index ff0bed7..e18b663 100644 --- a/abl/reasoning/reasoner.py +++ b/abl/reasoning/reasoner.py @@ -11,7 +11,7 @@ from ..utils.utils import confidence_dist, hamming_dist class Reasoner: """ - Base class for reasoner. + Reasoner for minimizing the inconsistency between the knowledge base and learning models. Parameters ---------- diff --git a/abl/utils/__init__.py b/abl/utils/__init__.py index 8036130..cf22485 100644 --- a/abl/utils/__init__.py +++ b/abl/utils/__init__.py @@ -1,7 +1,6 @@ from .cache import Cache, abl_cache from .logger import ABLLogger, print_log from .utils import ( - calculate_revision_num, confidence_dist, flatten, hamming_dist, @@ -13,7 +12,6 @@ __all__ = [ "Cache", "ABLLogger", "print_log", - "calculate_revision_num", "confidence_dist", "flatten", "hamming_dist", diff --git a/abl/utils/utils.py b/abl/utils/utils.py index 9718dd1..49146be 100644 --- a/abl/utils/utils.py +++ b/abl/utils/utils.py @@ -112,38 +112,6 @@ def confidence_dist(pred_prob, candidates): return 1 - np.prod(pred_prob[cols, candidates], axis=1) -def block_sample(X, Z, Y, sample_num, seg_idx): - """ - Extract a block of samples from lists X, Z, and Y. - - Parameters - ---------- - X, Z, Y : list - Input lists from which to extract the samples. - sample_num : int - The number of samples per block. - seg_idx : int - The block index to extract. - - Returns - ------- - tuple of lists - The extracted block samples from X, Z, and Y. - - Example - ------- - >>> X = [1, 2, 3, 4, 5, 6] - >>> Z = ['a', 'b', 'c', 'd', 'e', 'f'] - >>> Y = [10, 11, 12, 13, 14, 15] - >>> block_sample(X, Z, Y, 2, 1) - ([3, 4], ['c', 'd'], [12, 13]) - """ - start_idx = sample_num * seg_idx - end_idx = sample_num * (seg_idx + 1) - - return (data[start_idx:end_idx] for data in (X, Z, Y)) - - def to_hashable(x): """ Convert a nested list to a nested tuple so it is hashable. @@ -184,40 +152,3 @@ def restore_from_hashable(x): return x -def calculate_revision_num(parameter, total_length): - """ - Convert a float parameter to an integer, based on a total length. - - Parameters - ---------- - parameter : int or float - The parameter to convert. If float, it should be between 0 and 1. - If int, it should be non-negative. If -1, it will be replaced with total_length. - total_length : int - The total length to calculate the parameter from if it's a fraction. - - Returns - ------- - int - The calculated parameter. - - Raises - ------ - TypeError - If parameter is not an int or a float. - ValueError - If parameter is a float not in [0, 1] or an int below 0. - """ - if not isinstance(parameter, (int, float)): - raise TypeError("Parameter must be of type int or float.") - - if parameter == -1: - return total_length - elif isinstance(parameter, float): - if not (0 <= parameter <= 1): - raise ValueError("If parameter is a float, it must be between 0 and 1.") - return round(total_length * parameter) - else: - if parameter < 0: - raise ValueError("If parameter is an int, it must be non-negative.") - return parameter diff --git a/docs/API/abl.reasoning.rst b/docs/API/abl.reasoning.rst index 765746c..03e2ea3 100644 --- a/docs/API/abl.reasoning.rst +++ b/docs/API/abl.reasoning.rst @@ -3,25 +3,24 @@ abl.reasoning .. currentmodule:: abl.reasoning -Reasoning ---------- +Knowledge Base +-------------- .. autosummary:: :toctree: generated :nosignatures: :template: classtemplate.rst - Reasoner + KBBase + GroundKB + PrologKB -Knowledge Base --------------- +Reasoner +--------- .. autosummary:: :toctree: generated :nosignatures: :template: classtemplate.rst - KBBase - GroundKB - PrologKB - + Reasoner \ No newline at end of file diff --git a/docs/API/abl.utils.rst b/docs/API/abl.utils.rst index 9fcdaea..7c4a76f 100644 --- a/docs/API/abl.utils.rst +++ b/docs/API/abl.utils.rst @@ -32,7 +32,6 @@ Utils :nosignatures: :template: classtemplate.rst - calculate_revision_num confidence_dist flatten hamming_dist