def __init__(self, MAX_ATTRIBUTE_NUMBER=0): super().__init__() self._reducts = CReductSet() self._core = Bitset(MAX_ATTRIBUTE_NUMBER) self._core.reset()
class CReduct: def __init__(self, MAX_ATTRIBUTE_NUMBER=0): self.__attributes = Bitset(MAX_ATTRIBUTE_NUMBER) self.__attributes.reset() self.__name = "" self.__choice = False def setName(self, index): self.__name = "R" + str(index) def getChoice(self): return self.__choice def setChoice(self, boolean): self.__choice = boolean def isChosen(self): return self.__choice def getName(self): return self.__name def getAttributes(self): return self.__attributes def getAttributesAsInt(self): return self.__attributes.toInt() def loadFromProject(self, redNodePtr, attrInd): pass def saveToProject(self, pDoc, pRedNode, attrNames): pass
class CReduct: def __init__(self, MAX_ATTRIBUTE_NUMBER=0): self.__attributes = Bitset(MAX_ATTRIBUTE_NUMBER) self.__attributes.reset() self.__name = "" self.__choice = False def setName(self, index): self.__name = "R" + str(index) def getChoice(self): return self.__choice def setChoice(self, boolean): self.__choice = boolean def isChosen(self): return self.__choice def getName(self): return self.__name def getAttributes(self): return self.__attributes def getAttributesAsInt(self): return self.__attributes.toInt() def loadFromProject(self, redNodePtr, attrInd): pass def saveToProject(self, pDoc , pRedNode , attrNames): pass
def __init__(self): self.__antecedent = HashableDict() self.__consequent = HashableDict() self.__cost = 0.0 self.__support = 1 self.__antSupport = 1 self.__strength = 0.0 self.__coverage = 0.0 self.__certainty = 1.0 self.__parameters = HashableDict() self.__signature = Bitset(64)
def __init__(self): self._systemName = "" self._systemType = "" self._attributes = Bitset() self._attributeNumber = 0 self._attributeNames = [] self._attributeIndexes = HashableDict self._attributeTypes = [] self._attributeCosts = [] self._attributeValues = HashableDict self._objects = CInformTable() self._objectNumber = 0 self._discernMatrix = CDiscernMatrix() self._attributes.reset() self._discernMatrix = None
def __init__(self): self._systemName = "" self._systemType = "" self._attributes = Bitset() self._attributeNumber = 0 self._attributeNames = [] self._attributeIndexes = HashableDict self._attributeTypes = [] self._attributeCosts = [] self._attributeValues = HashableDict self._objects = CInformTable() self._objectNumber = 0 self._discernMatrix = CDiscernMatrix() self._attributes.reset() self._discernMatrix = None
class BasicInformSystem2(BasicInformSystem): def __init__(self, MAX_ATTRIBUTE_NUMBER=0): super().__init__() self._reducts = CReductSet() self._core = Bitset(MAX_ATTRIBUTE_NUMBER) self._core.reset() def getObjectName(self, index): return super().getObjectName(index) def compDependDegreeForAttributes(self, conAttr, decAttributes): return super().compDependDegreeForAttributes(conAttr, decAttributes) def setAttributeValues(self, attributeValues): super().setAttributeValues(attributeValues) def getAttributeIndexes(self): return super().getAttributeIndexes() def setAttributeNames(self, attributeNames): super().setAttributeNames(attributeNames) def setSystemType(self, systemType): super().setSystemType(systemType) def setAttributeCosts(self, attributeCosts): super().setAttributeCosts(attributeCosts) def getObjects(self): return super().getObjects() def getDiscernMatrix(self): return super().getDiscernMatrix() def compDependDegreeForAttribute(self, conAttr, decAttr): return super().compDependDegreeForAttribute(conAttr, decAttr) def getAttributeCosts(self): return super().getAttributeCosts() def getAttributeName(self, index): return super().getAttributeName(index) def getAttributeNumber(self): return super().getAttributeNumber() def setAttributeIndexes(self, attributeIndexes): super().setAttributeIndexes(attributeIndexes) def setAttributes(self, bits=0): super().setAttributes(bits) def setObject(self, index, globalState): super().setObject(index, globalState) def compNondetRules(self, conAttr, decAttr): return super().compNondetRules(conAttr, decAttr) def getName(self): return super().getName() def getInformTable(self): return super().getInformTable() def setInformTable(self, informTable): super().setInformTable(informTable) def getAttributeNames(self): return super().getAttributeNames() def setAttributeTypes(self, attributeTypes): super().setAttributeTypes(attributeTypes) def setAttributeNumber(self, attributeNumber): super().setAttributeNumber(attributeNumber) def getAttributeValues(self): return super().getAttributeValues() def setObjectNumber(self, objectNumber): super().setObjectNumber(objectNumber) def getAttributeType(self, index): return super().getAttributeType(index) def getSystemType(self): return super().getSystemType() def setObjectName(self, index, name): super().setObjectName(index, name) def compDiscernMatrix(self): super().compDiscernMatrix() def getObject(self, index): return super().getObject(index) def setName(self, name): super().setName(name) def getAttributes(self): return super().getAttributes() def getObjectNumber(self): return super().getObjectNumber() def getAttributeTypes(self): return super().getAttributeTypes() def setObjects(self, objects): super().setObjects(objects) def computeReducts(self): firstCComputingRules = CComputingRules() implicents = CImplArray() implicants = CImplArray() self.compDiscernMatrix() i = 0 j = 0 while i < self._objectNumber: while j < i: if self.getDiscernMatrix().getImplicant(i, j).any(): implicents.append(self.getDiscernMatrix().getImplicant(i, j)) if self.getDiscernMatrix().getImplicant(i, j).count(1) == 1: self._core.orOperat(self.getDiscernMatrix().getImplicant(i, j)) j += 1 i += 1 if implicents.size() != 0: implicants.assignOperator(firstCComputingRules.minimDiscFunc(implicents)) self._reducts.write(implicants, self.getAttributeNumber()) def computeReductsUsingAttributes(self, startIndex, stopIndex): self._reducts.removeAll() firstCComputingRules = CComputingRules() implicents = CImplArray() implicants = CImplArray() i = startIndex while i <= stopIndex: j = startIndex while j < i: if self.getDiscernMatrix().getImplicant(i, j).any(): implicents.append(self.getDiscernMatrix().getImplicant(i, j)) if self.getDiscernMatrix().getImplicant(i, j).count(1) == 1: self._core.orOperat(self.getDiscernMatrix().getImplicant(i, j)) j += 1 i += 1 if implicents.size() != 0: implicants.assignOperator(firstCComputingRules.minimDiscFunc(implicents)) self._reducts.write(implicants, self.getAttributeNumber()) def saveReducts(self, file): pass def chooseAllReducts(self): for i in range(self.getReducts().size()): self.getReduct(i).setChoice(True) def chooseReducts(self, reductList): for i in range(len(reductList)): self.getReduct(reductList[i]).setChoice(True) def getReducts(self): return self._reducts def getReduct(self, index): return self._reducts.getReduct(index)
def process_result_value(self, value, dialect): return Bitset.fromstring(value)
class BasicInformSystem: def __init__(self): self._systemName = "" self._systemType = "" self._attributes = Bitset() self._attributeNumber = 0 self._attributeNames = [] self._attributeIndexes = HashableDict self._attributeTypes = [] self._attributeCosts = [] self._attributeValues = HashableDict self._objects = CInformTable() self._objectNumber = 0 self._discernMatrix = CDiscernMatrix() self._attributes.reset() self._discernMatrix = None def getName(self): return self._systemName def setName(self, name): self._systemName = name def getSystemType(self): return self._systemType def setSystemType(self, systemType): self._systemType = systemType def getAttributes(self): return self._attributes def setAttributes(self, bits=0): self._attributes = Bitset(bits) def getAttributeNumber(self): return self._attributeNumber def setAttributeNumber(self, attributeNumber): self._attributeNumber = attributeNumber def getAttributeNames(self): return self._attributeNames def setAttributeNames(self, attributeNames): self._attributeNames = attributeNames def getAttributeName(self, index): if 0 <= index < len(self._attributeNames): return self._attributeNames[index] else: return "" def getAttributeIndexes(self): return self._attributeIndexes def setAttributeIndexes(self, attributeIndexes): self._attributeIndexes = attributeIndexes def getAttributeType(self, index): if 0 <= index < len(self._attributeTypes): return self._attributeTypes[index] else: return "" def getAttributeTypes(self): return self._attributeTypes def setAttributeTypes(self, attributeTypes): self._attributeTypes = attributeTypes def getAttributeCosts(self): return self._attributeCosts def setAttributeCosts(self, attributeCosts): self._attributeCosts =attributeCosts def getAttributeValues(self): return self._attributeValues def setAttributeValues(self, attributeValues): self._attributeValues = attributeValues def getObjectNumber(self): return self._objectNumber def setObjectNumber(self, objectNumber): self._objectNumber = objectNumber def getDiscernMatrix(self): return self._discernMatrix def getObject(self, index): if type(index) == int: return self._objects.getObject(index) else: raise TypeError(index) def setObject(self, index, globalState): self._objects.setObject(index, globalState) def getObjects(self): return self._objects def setObjects(self, objects): self._objects = objects def getObjectName(self, index): if index < self._objectNumber: return self._objects.getObject(index).getName() else: return "" def setObjectName(self, index, name): self._objects.getObject(index).setName(name) def getInformTable(self): return self._objects def setInformTable(self, informTable): self._objects.copyInstance(informTable) def compDiscernMatrix(self): self._objectNumber = self._objects.size() self._discernMatrix = CDiscernMatrix(self._objectNumber, self._attributeNumber) for i in range(self._objectNumber): for j in range(self._objectNumber): for k in range(self._attributeNumber): x = self.getObject(i).getDescriptors().get(k) y = self.getObject(j).getDescriptors().get(k) if x != y: self._discernMatrix.getImplicant(i, j).setValue(k) def compNondetRules(self, conAttr, decAttr): ruleSet = CRuleSet() tempRulesSet = CRuleSet() tempDiscMatrix = CDiscernMatrix(self._objectNumber, self._attributeNumber) for i in range(self._objectNumber): for j in range(self._objectNumber): for k in range(len(conAttr)): x = self.getObject(i).getDescriptors().get(conAttr[k]) y = self.getObject(j).getDescriptors().get(conAttr[k]) if x == y: tempDiscMatrix.getImplicant(i, j).setValue(conAttr[k]) newDiscMatrix = CDiscernMatrix(self._objectNumber, self._attributeNumber) for i in range(self._objectNumber): for j in range(self._objectNumber): if j != i: firstAttr = self.getObject(i).getDescriptors().get(decAttr) secondAttr = self.getObject(j).getDescriptors().get(decAttr) if firstAttr != secondAttr: newDiscMatrix.getImplicant(i, j).assignOperator(tempDiscMatrix.getImplicant(i, j)) for i in range(self._objectNumber): tempRulesSet.removeAll() numberOfRules = 0 for j in range(self._objectNumber): if newDiscMatrix.getImplicant(i, j).any(): tempRulesSet.insert(numberOfRules, CRule()) for implicantIndex in range(newDiscMatrix.getImplicant(i, j).size()): if newDiscMatrix.getImplicant(i, j).test(implicantIndex): valueOfAttribute = self._objects.getObject(i).getDescriptors().get(implicantIndex) tempRulesSet.getRule(numberOfRules).getAntecedent().add(implicantIndex, valueOfAttribute) value = self._objects.getObject(i).getDescriptors().get(decAttr) tempRulesSet.getRule(numberOfRules).getConsequent().add(decAttr, value) numberOfRules += 1 tempRulesSet.removeRules(0x00) for i in range(len(tempRulesSet.getRuleArray())): ruleSet.append(tempRulesSet.getRule(i)) # ruleSet.appendRuleSet(tempRulesSet) return ruleSet def compDependDegreeForAttribute(self, conAttr, decAttr): checkList = [] totalCount = 0 for i in range(self._objectNumber): checkList.append(False) for i in range(self._objectNumber - 1): if not checkList[i]: count = 1 mark = False for j in range(i+1, self._objectNumber): if self.getObject(i).compareUsingAttributesList(self.getObject(j), conAttr): checkList[j] = True if self.getObject(i).compareUsingAttribute(self.getObject(j), decAttr): count += 1 else: mark = True if not mark: totalCount += count if not checkList[self._objectNumber - 1]: totalCount += 1 return float(totalCount)/float(self._objectNumber) def compDependDegreeForAttributes(self, conAttr, decAttributes): checkList = [] totalCount = 0 for i in range(self._objectNumber): checkList.append(False) for i in range(self._objectNumber - 1): if not checkList[i]: count = 1 mark = False for j in range(i + 1, self._objectNumber): if self.getObject(i).compareUsingAttributesList(self.getObject(j), conAttr): checkList[j] = True if self.getObject(i).compareUsingAttributesList(self.getObject(j), decAttributes): count += 1 else: mark = True if not mark: totalCount += count if not checkList[self._objectNumber - 1]: totalCount += 1 return float(totalCount) / float(self._objectNumber)
def setAttributes(self, bits=0): self._attributes = Bitset(bits)
class BasicInformSystem: def __init__(self): self._systemName = "" self._systemType = "" self._attributes = Bitset() self._attributeNumber = 0 self._attributeNames = [] self._attributeIndexes = HashableDict self._attributeTypes = [] self._attributeCosts = [] self._attributeValues = HashableDict self._objects = CInformTable() self._objectNumber = 0 self._discernMatrix = CDiscernMatrix() self._attributes.reset() self._discernMatrix = None def getName(self): return self._systemName def setName(self, name): self._systemName = name def getSystemType(self): return self._systemType def setSystemType(self, systemType): self._systemType = systemType def getAttributes(self): return self._attributes def setAttributes(self, bits=0): self._attributes = Bitset(bits) def getAttributeNumber(self): return self._attributeNumber def setAttributeNumber(self, attributeNumber): self._attributeNumber = attributeNumber def getAttributeNames(self): return self._attributeNames def setAttributeNames(self, attributeNames): self._attributeNames = attributeNames def getAttributeName(self, index): if 0 <= index < len(self._attributeNames): return self._attributeNames[index] else: return "" def getAttributeIndexes(self): return self._attributeIndexes def setAttributeIndexes(self, attributeIndexes): self._attributeIndexes = attributeIndexes def getAttributeType(self, index): if 0 <= index < len(self._attributeTypes): return self._attributeTypes[index] else: return "" def getAttributeTypes(self): return self._attributeTypes def setAttributeTypes(self, attributeTypes): self._attributeTypes = attributeTypes def getAttributeCosts(self): return self._attributeCosts def setAttributeCosts(self, attributeCosts): self._attributeCosts = attributeCosts def getAttributeValues(self): return self._attributeValues def setAttributeValues(self, attributeValues): self._attributeValues = attributeValues def getObjectNumber(self): return self._objectNumber def setObjectNumber(self, objectNumber): self._objectNumber = objectNumber def getDiscernMatrix(self): return self._discernMatrix def getObject(self, index): if type(index) == int: return self._objects.getObject(index) else: raise TypeError(index) def setObject(self, index, globalState): self._objects.setObject(index, globalState) def getObjects(self): return self._objects def setObjects(self, objects): self._objects = objects def getObjectName(self, index): if index < self._objectNumber: return self._objects.getObject(index).getName() else: return "" def setObjectName(self, index, name): self._objects.getObject(index).setName(name) def getInformTable(self): return self._objects def setInformTable(self, informTable): self._objects.copyInstance(informTable) def compDiscernMatrix(self): self._objectNumber = self._objects.size() self._discernMatrix = CDiscernMatrix(self._objectNumber, self._attributeNumber) for i in range(self._objectNumber): for j in range(self._objectNumber): for k in range(self._attributeNumber): x = self.getObject(i).getDescriptors().get(k) y = self.getObject(j).getDescriptors().get(k) if x != y: self._discernMatrix.getImplicant(i, j).setValue(k) def compNondetRules(self, conAttr, decAttr): ruleSet = CRuleSet() tempRulesSet = CRuleSet() tempDiscMatrix = CDiscernMatrix(self._objectNumber, self._attributeNumber) for i in range(self._objectNumber): for j in range(self._objectNumber): for k in range(len(conAttr)): x = self.getObject(i).getDescriptors().get(conAttr[k]) y = self.getObject(j).getDescriptors().get(conAttr[k]) if x == y: tempDiscMatrix.getImplicant(i, j).setValue(conAttr[k]) newDiscMatrix = CDiscernMatrix(self._objectNumber, self._attributeNumber) for i in range(self._objectNumber): for j in range(self._objectNumber): if j != i: firstAttr = self.getObject(i).getDescriptors().get(decAttr) secondAttr = self.getObject(j).getDescriptors().get( decAttr) if firstAttr != secondAttr: newDiscMatrix.getImplicant(i, j).assignOperator( tempDiscMatrix.getImplicant(i, j)) for i in range(self._objectNumber): tempRulesSet.removeAll() numberOfRules = 0 for j in range(self._objectNumber): if newDiscMatrix.getImplicant(i, j).any(): tempRulesSet.insert(numberOfRules, CRule()) for implicantIndex in range( newDiscMatrix.getImplicant(i, j).size()): if newDiscMatrix.getImplicant(i, j).test(implicantIndex): valueOfAttribute = self._objects.getObject( i).getDescriptors().get(implicantIndex) tempRulesSet.getRule( numberOfRules).getAntecedent().add( implicantIndex, valueOfAttribute) value = self._objects.getObject(i).getDescriptors().get( decAttr) tempRulesSet.getRule(numberOfRules).getConsequent().add( decAttr, value) numberOfRules += 1 tempRulesSet.removeRules(0x00) for i in range(len(tempRulesSet.getRuleArray())): ruleSet.append(tempRulesSet.getRule(i)) # ruleSet.appendRuleSet(tempRulesSet) return ruleSet def compDependDegreeForAttribute(self, conAttr, decAttr): checkList = [] totalCount = 0 for i in range(self._objectNumber): checkList.append(False) for i in range(self._objectNumber - 1): if not checkList[i]: count = 1 mark = False for j in range(i + 1, self._objectNumber): if self.getObject(i).compareUsingAttributesList( self.getObject(j), conAttr): checkList[j] = True if self.getObject(i).compareUsingAttribute( self.getObject(j), decAttr): count += 1 else: mark = True if not mark: totalCount += count if not checkList[self._objectNumber - 1]: totalCount += 1 return float(totalCount) / float(self._objectNumber) def compDependDegreeForAttributes(self, conAttr, decAttributes): checkList = [] totalCount = 0 for i in range(self._objectNumber): checkList.append(False) for i in range(self._objectNumber - 1): if not checkList[i]: count = 1 mark = False for j in range(i + 1, self._objectNumber): if self.getObject(i).compareUsingAttributesList( self.getObject(j), conAttr): checkList[j] = True if self.getObject(i).compareUsingAttributesList( self.getObject(j), decAttributes): count += 1 else: mark = True if not mark: totalCount += count if not checkList[self._objectNumber - 1]: totalCount += 1 return float(totalCount) / float(self._objectNumber)
class CRule: def __init__(self): self.__antecedent = HashableDict() self.__consequent = HashableDict() self.__cost = 0.0 self.__support = 1 self.__antSupport = 1 self.__strength = 0.0 self.__coverage = 0.0 self.__certainty = 1.0 self.__parameters = HashableDict() self.__signature = Bitset(64) def __eq__(self, other): if isinstance(other, self.__class__): if len(self.getAntecedent()) == len(other.getAntecedent()) \ and len(self.getConsequent()) == len(other.getConsequent()): if self.getAntecedent().__eq__(other.getAntecedent()) \ and self.getConsequent().__eq__(other.getConsequent()): return True else: return False else: return False else: return False def getAntecedent(self): return self.__antecedent def setAntecedent(self, antecedent): if isinstance(antecedent, HashableDict): self.__antecedent = antecedent else: raise TypeError(antecedent) def getConsequent(self): return self.__consequent def setConsequent(self, consequent): if isinstance(consequent, HashableDict): self.__consequent = consequent else: raise TypeError(consequent) def setParameter(self, name, value): if type(name) == str and type(value) == str: self.__parameters.add(name, value) else: raise TypeError(name, value) def getParameter(self, name): return self.__parameters[name] def getParameters(self): return self.__parameters def computeCost(self, costArray): for key in self.__antecedent.keys(): self.__cost += costArray[key] def setSupport(self, value): self.__support = value def getSupport(self): return self.__support def increaseSupport(self, value): self.__support += value def increaseAntSupport(self, value): self.__antSupport += value def setStrength(self, value): self.__strength = value def getStrength(self): return self.__strength def computeStrength(self, objectNumber): self.__strength = float(self.__support) / float(objectNumber) def setCoverage(self, value): self.__coverage = value def getCoverage(self): return self.__coverage def computeCoverage(self, valuesOfAttr): count = 0 for key, value in self.__consequent.items(): if valuesOfAttr.get(key): valueOfAttribute = valuesOfAttr.get(key) if valueOfAttribute.get(value): count = valueOfAttribute.get(value) else: continue else: continue self.__coverage = float(self.__support) / float(count) def getCertainty(self): return self.__certainty def computeCertainty(self): self.__certainty = float(self.__support) / float(self.__antSupport) def computeSignature(self): self.__signature.reset() for key in self.__antecedent.keys(): self.__signature.setValue(key) for key in self.__consequent.keys(): self.__signature.setValue(key) def checkAttribute(self, index): return self.__signature.test(index) def equalOperator(self, rule): if isinstance(rule, self.__class__): return self.__eq__(rule) else: raise TypeError(rule)
from Bitset import Bitset print("--------------Creating second bitset-------------") secondBitset = Bitset(6) secondBitset.setAll() print(secondBitset.getBitsetList()) print("--------------Creating first bitset--------------") firstBitset = Bitset(6) print(firstBitset.getBitsetList()) print("--------------append method----------------------") firstBitset.append(0) firstBitset.append(1) print(firstBitset.getBitsetList()) print("--------------append string method---------------") firstBitset.appendString("0") firstBitset.appendString("1") print(firstBitset.getBitsetList()) print("--------------set value method-------------------") firstBitset.setValue(0)
def __init__(self, MAX_ATTRIBUTE_NUMBER=0): self.__attributes = Bitset(MAX_ATTRIBUTE_NUMBER) self.__attributes.reset() self.__name = "" self.__choice = False
print(firstGlobalState.getName()) print("--------------creating second global state--------") secondGlobalState = CGlobalState() secondGlobalState.addDescriptor(1, 1.1) secondGlobalState.addDescriptor(3, 3.0) print(secondGlobalState.getDescriptors()) print("--------------comparing using attribute list------") print(firstGlobalState.compareUsingAttributesList(secondGlobalState, [1, 2])) fistBitset = Bitset(2) fistBitset.setAll() print("--------------comparing using bitset--------------") print(firstGlobalState.compareUsingBitset(secondGlobalState, fistBitset)) print("--------------comparing using attribute-----------") print(firstGlobalState.compareUsingAttribute(secondGlobalState, 1)) print("--------------assign operator---------------------") thirdGlobalState = firstGlobalState.assignOperator(secondGlobalState) print(thirdGlobalState.getDescriptors())
def __init__(self, MAX_ATTRIBUTE_NUMBER=0): self.__attributes = Bitset(MAX_ATTRIBUTE_NUMBER) self.__attributes.reset() self.__name = "" self.__choice = False
def process_result_value(self, value, dialect): return Bitset.fromstring(value)
def setAttributes(self, bits=0): self._attributes = Bitset(bits)