def updateValue(self): self.rawImportance = self.__calculateRawImportance() intraStringHappiness = self.__calculateIntraStringHappiness() self.intraStringUnhappiness = 100.0 - intraStringHappiness interStringHappiness = 0.0 if self.correspondence: interStringHappiness = self.correspondence.totalStrength self.interStringUnhappiness = 100.0 - interStringHappiness averageHappiness = (intraStringHappiness + interStringHappiness) / 2 self.totalUnhappiness = 100.0 - averageHappiness if self.clampSalience: self.intraStringSalience = 100.0 self.interStringSalience = 100.0 else: from formulas import weightedAverage self.intraStringSalience = weightedAverage( ((self.relativeImportance, 0.2), (self.intraStringUnhappiness, 0.8))) self.interStringSalience = weightedAverage( ((self.relativeImportance, 0.8), (self.interStringUnhappiness, 0.2))) self.totalSalience = (self.intraStringSalience + self.interStringSalience) / 2.0 logging.info('Set salience of %s to %f = (%f + %f)/2', self.__str__(), self.totalSalience, self.intraStringSalience, self.interStringSalience)
def updateValue(self): self.rawImportance = self.__calculateRawImportance() intraStringHappiness = self.__calculateIntraStringHappiness() self.intraStringUnhappiness = 100.0 - intraStringHappiness interStringHappiness = 0.0 if self.correspondence: interStringHappiness = self.correspondence.totalStrength self.interStringUnhappiness = 100.0 - interStringHappiness averageHappiness = (intraStringHappiness + interStringHappiness) / 2 self.totalUnhappiness = 100.0 - averageHappiness if self.clampSalience: self.intraStringSalience = 100.0 self.interStringSalience = 100.0 else: from formulas import weightedAverage self.intraStringSalience = weightedAverage(( (self.relativeImportance, 0.2), (self.intraStringUnhappiness, 0.8))) self.interStringSalience = weightedAverage(( (self.relativeImportance, 0.8), (self.interStringUnhappiness, 0.2))) self.totalSalience = (self.intraStringSalience + self.interStringSalience) / 2.0 logging.info('Set salience of %s to %f = (%f + %f)/2', self.__str__(), self.totalSalience, self.intraStringSalience, self.interStringSalience)
def updateInternalStrength(self): if not (self.descriptor and self.relation): self.internalStrength = 0.0 return averageDepth = (self.descriptor.conceptualDepth + self.relation.conceptualDepth) / 2.0 averageDepth **= 1.1 # see if the object corresponds to an object # if so, see if the descriptor is present (modulo slippages) in the # corresponding object changedObjects = [o for o in workspace.initial.objects if o.changed] changed = changedObjects[0] sharedDescriptorTerm = 0.0 if changed and changed.correspondence: targetObject = changed.correspondence.objectFromTarget slippages = workspace.slippages() slipnode = self.descriptor.applySlippages(slippages) if not targetObject.described(slipnode): self.internalStrength = 0.0 return sharedDescriptorTerm = 100.0 conceptual_height = (100.0 - self.descriptor.conceptualDepth) / 10.0 sharedDescriptorWeight = conceptual_height ** 1.4 depthDifference = 100.0 - abs(self.descriptor.conceptualDepth - self.relation.conceptualDepth) weights = ((depthDifference, 12), (averageDepth, 18), (sharedDescriptorTerm, sharedDescriptorWeight)) self.internalStrength = weightedAverage(weights) if self.internalStrength > 100.0: self.internalStrength = 100.0
def updateInternalStrength(self): if not (self.descriptor and self.relation): self.internalStrength = 0.0 return averageDepth = (self.descriptor.conceptualDepth + self.relation.conceptualDepth) / 2.0 averageDepth **= 1.1 # see if the object corresponds to an object # if so, see if the descriptor is present (modulo slippages) in the # corresponding object changedObjects = [o for o in workspace.initial.objects if o.changed] changed = changedObjects[0] sharedDescriptorTerm = 0.0 if changed and changed.correspondence: targetObject = changed.correspondence.objectFromTarget slippages = workspace.slippages() slipnode = self.descriptor.applySlippages(slippages) if not targetObject.described(slipnode): self.internalStrength = 0.0 return sharedDescriptorTerm = 100.0 conceptual_height = (100.0 - self.descriptor.conceptualDepth) / 10.0 sharedDescriptorWeight = conceptual_height**1.4 depthDifference = 100.0 - abs(self.descriptor.conceptualDepth - self.relation.conceptualDepth) weights = ((depthDifference, 12), (averageDepth, 18), (sharedDescriptorTerm, sharedDescriptorWeight)) self.internalStrength = weightedAverage(weights) if self.internalStrength > 100.0: self.internalStrength = 100.0
def updateInternalStrength(self): relatedBondAssociation = self.groupCategory.getRelatedNode(slipnet.bondCategory).degreeOfAssociation() bondWeight = relatedBondAssociation ** 0.98 length = len(self.objectList) if length == 1: lengthFactor = 5.0 elif length == 2: lengthFactor = 20.0 elif length == 3: lengthFactor = 60.0 else: lengthFactor = 90.0 lengthWeight = 100.0 - bondWeight weightList = ((relatedBondAssociation, bondWeight), (lengthFactor, lengthWeight)) self.internalStrength = formulas.weightedAverage(weightList)
def updateInternalStrength(self): relatedBondAssociation = self.groupCategory.getRelatedNode( slipnet.bondCategory).degreeOfAssociation() bondWeight = relatedBondAssociation**0.98 length = len(self.objectList) if length == 1: lengthFactor = 5.0 elif length == 2: lengthFactor = 20.0 elif length == 3: lengthFactor = 60.0 else: lengthFactor = 90.0 lengthWeight = 100.0 - bondWeight weightList = ((relatedBondAssociation, bondWeight), (lengthFactor, lengthWeight)) self.internalStrength = formulas.weightedAverage(weightList)
def updateTemperature(self): logging.debug('updateTemperature') workspace.assessTemperature() ruleWeakness = 100.0 if workspace.rule: workspace.rule.update_strength() ruleWeakness = 100.0 - workspace.rule.total_strength values = ((workspace.totalUnhappiness, 0.8), (ruleWeakness, 0.2)) slightly_above_actual_temperature = formulas.actualTemperature + 0.001 logging.info('actualTemperature: %f' % slightly_above_actual_temperature) formulas.actualTemperature = formulas.weightedAverage(values) logging.info('unhappiness: %f, weakness: %f, actualTemperature: %f' % ( workspace.totalUnhappiness + 0.001, ruleWeakness + 0.001, formulas.actualTemperature + 0.001)) if temperature.clamped: formulas.actualTemperature = 100.0 logging.info('actualTemperature: %f' % (formulas.actualTemperature + 0.001)) temperature.update(formulas.actualTemperature) if not self.clampTemperature: formulas.Temperature = formulas.actualTemperature temperature.update(formulas.Temperature)
def updateTemperature(self): logging.debug('updateTemperature') workspace.assessTemperature() ruleWeakness = 100.0 if workspace.rule: workspace.rule.updateStrength() ruleWeakness = 100.0 - workspace.rule.totalStrength values = ((workspace.totalUnhappiness, 0.8), (ruleWeakness, 0.2)) above_actual_temperature = formulas.actualTemperature + 0.001 logging.info('actualTemperature: %f', above_actual_temperature) formulas.actualTemperature = formulas.weightedAverage(values) logging.info('unhappiness: %f, weakness: %f, actualTemperature: %f', workspace.totalUnhappiness + 0.001, ruleWeakness + 0.001, formulas.actualTemperature + 0.001) if temperature.clamped: formulas.actualTemperature = 100.0 logging.info('actualTemperature: %f', formulas.actualTemperature + 0.001) temperature.update(formulas.actualTemperature) if not self.clampTemperature: formulas.Temperature = formulas.actualTemperature temperature.update(formulas.Temperature)
def updateTotalStrength(self): """Recalculate the total strength based on internal and external strengths""" weights = ((self.internalStrength, self.internalStrength), (self.externalStrength, 100 - self.internalStrength)) strength = formulas.weightedAverage(weights) self.totalStrength = strength
def updateTotalStrength(self): """Recalculate the total strength based on internal and external strengths""" weights = ((self.internalStrength, self.internalStrength), (self.externalStrength, 100 - self.internalStrength)) strength = formulas.weightedAverage(weights) self.totalStrength = strength