示例#1
0
文件: Relations.py 项目: orsic/NENR
 def isReflexive(set: FS.FuzzySet):
     if not Relations.isUTimesURelation(set):
         return False
     domain = set.getDomain()
     """:type: Domain.Domain"""
     domains = domain.getDomains()
     for i in domains[0]:
         if set.getValueAt((i, i)) != 1.0:
             return False
     return True
示例#2
0
文件: Relations.py 项目: orsic/NENR
 def isSymmetric(set: FS.FuzzySet):
     if not Relations.isUTimesURelation(set):
         return False
     domain = set.getDomain()
     """:type: Domain.Domain"""
     domains = domain.getDomains()
     for i in domains[0]:
         for j in domains[0]:
             if set.getValueAt((i,j)) != set.getValueAt((j,i)):
                 return False
     return True
示例#3
0
文件: Relations.py 项目: orsic/NENR
 def isMinMaxTransitive(set: FS.FuzzySet):
     if not Relations.isUTimesURelation(set):
         return False
     domain = set.getDomain()
     """:type: Domain.Domain"""
     domains = domain.getDomains()
     for u in domains[0]:
         for v in domains[0]:
             tmp = []
             for w in domains[0]:
                 tmp.append(min(set.getValueAt((u, w)), set.getValueAt((w, v))))
             if set.getValueAt((u, v)) < max(tmp):
                     return False
     return True
示例#4
0
    def __init__(self, labels, lowerLimit, upperLimit):
        self.FuzzySets_ = list()
        self.MergePoints_ = list()
        for label in range(labels):
            #Compute the half of the triangle's base
            halfBase = (upperLimit - lowerLimit) / (labels - 1)
            #We add the half of the triangle's base n times to the lower limit,
            #depending on the linguistic label and the point we want to obtain
            #(left, mid, right)
            leftPoint = lowerLimit + halfBase * (label - 1)
            midPoint = lowerLimit + halfBase * (label)
            rightPoint = lowerLimit + halfBase * (label + 1)
            if (label == 0):
                leftPoint = midPoint
            elif (label == labels - 1):
                rightPoint = midPoint

#We create the fuzzy set
            self.FuzzySets_.append(
                FuzzySet(leftPoint, midPoint, rightPoint, label))

            #We add the merge point
            if (label > 0):
                self.MergePoints_.append(midPoint - (
                    (midPoint - self.FuzzySets_[label - 1].getMidPoint()) / 2))
示例#5
0
文件: Relations.py 项目: orsic/NENR
 def compositionOfBinaryRelations(r1: FS.FuzzySet, r2: FS.FuzzySet):
     domain1, domain2 = r1.getDomain(), r2.getDomain()
     """:type: Domain.Domain"""
     assert domain1.getNumberOfComponents() == 2 and domain2.getNumberOfComponents() == 2
     domains1, domains2 = domain1.getDomains(), domain2.getDomains()
     for i,j in zip(domains1[1], domains2[0]):
         assert(i == j)
     X = domains1[0]
     Y = domains2[1]
     composition = FS.MutableFuzzySet(DM.CompositeDomain.combine(DM.SimpleDomain([x for x in X]), DM.SimpleDomain([y for y in Y])))
     for x in domains1[0]:
             for z in domains2[1]:
                 mins = []
                 for y in domains1[1]:
                     mins.append( min(r1.getValueAt((x,y)), r2.getValueAt((y,z))) )
                 composition.set((x,z), max(mins))
     return composition
示例#6
0
文件: Relations.py 项目: orsic/NENR
 def isUTimesURelation(set: FS.FuzzySet):
     domain = set.getDomain()
     """:type: Domain.Domain"""
     if domain.getNumberOfComponents() != 2:
         return False
     domains = domain.getDomains()
     for a, b in zip(domains[0], domains[1]):
         if a != b:
             return False
     return True
 def load_from_xml(self, file_name):
     DOM_tree = minidom.parse(file_name)
     sets_root = DOM_tree.childNodes.item(0)
     set_nodes = sets_root.getElementsByTagName("set")
     for set_node in set_nodes:
         what = set_node.getAttributeNode("what").childNodes[0].toxml()
         subset_nodes = set_node.getElementsByTagName("subset")
         subsets = dict()
         for subset_node in subset_nodes:
             value = subset_node.getAttributeNode("value").childNodes[0].toxml()
             point_nodes = subset_node.getElementsByTagName("point")
             points = [{'x': float(point_node.getAttributeNode("x").childNodes[0].toxml()),
                        'y': float(point_node.getAttributeNode("y").childNodes[0].toxml())} for point_node in
                       point_nodes]
             subsets[value] = FuzzySubSet(points, value)
         self.fuzzy_sets[what] = FuzzySet(subsets)