FRsūtil̲s
A fuzzy-rough reasoning utilities library
 
Loading...
Searching...
No Matches
itfrs.py
Go to the documentation of this file.
1# frutil/models/itfrs.py
2"""
3ITFRS implementation.
4"""
5import sys
6import os
7
8sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
9
10
11from approximations import FuzzyRoughModel
12import tnorms
13import implicators
14import numpy as np
15import similarities
16
18 def __init__(self, similarity_matrix: np.ndarray, labels: np.ndarray, tnorm: tnorms.TNorm, implicator):
19 super().__init__(similarity_matrix, labels)
20 self.tnorm = tnorm
21 self.implicator = np.vectorize(implicator)
22
24 label_mask = (self.labels[:, None] == self.labels[None, :]).astype(float)
25 implication_vals = self.implicator(self.similarity_matrix, label_mask)
26
27 # Since for the calculations of lower approximation,
28 # we calculate Inf which is basically a minimum,
29 # to exclude the same instance from calculations we don’t
30 # need anything because the diagonal is set to 1.0 which
31 # is ignored by min operator. To be sure all is correct,
32 # inside code, we set main diagonal to 1.0
33 np.fill_diagonal(implication_vals, 1.0)
34 return np.min(implication_vals, axis=1)
35
37 label_mask = (self.labels[:, None] == self.labels[None, :]).astype(float)
38 tnorm_vals = self.tnorm(self.similarity_matrix, label_mask)
39
40 # Since for the calculations of upper approximation,
41 # we calculate sup which is basically a maximum,
42 # to exclude the same instance from calculations we
43 # need to set the main diagonal to 0.0 which is ignored
44 # by max operator. Otherwise all upper approxamations will be 1.0.
45 np.fill_diagonal(tnorm_vals, 0.0)
46 return np.max(tnorm_vals, axis=1)
__init__(self, np.ndarray similarity_matrix, np.ndarray labels, tnorms.TNorm tnorm, implicator)
Definition itfrs.py:18