Random scattered analysis
This commit is contained in:
@ -89,6 +89,7 @@ class Copycat(object):
|
|||||||
d['avgtemp'] = d.pop('sumtemp') / d['count']
|
d['avgtemp'] = d.pop('sumtemp') / d['count']
|
||||||
d['avgtime'] = d.pop('sumtime') / d['count']
|
d['avgtime'] = d.pop('sumtime') / d['count']
|
||||||
print('The formula {} provided:'.format(formula))
|
print('The formula {} provided:'.format(formula))
|
||||||
|
print('Average difference: {}'.format(self.temperature.getAverageDifference()))
|
||||||
pprint(answers)
|
pprint(answers)
|
||||||
|
|
||||||
return answers
|
return answers
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class Rule(WorkspaceStructure):
|
|||||||
return
|
return
|
||||||
averageDepth = (self.descriptor.conceptualDepth +
|
averageDepth = (self.descriptor.conceptualDepth +
|
||||||
self.relation.conceptualDepth) / 2.0
|
self.relation.conceptualDepth) / 2.0
|
||||||
averageDepth **= 1.1
|
averageDepth **= 1.1 # LSaldyt: This value (1.1) seems 100% contrived.
|
||||||
# see if the object corresponds to an object
|
# see if the object corresponds to an object
|
||||||
# if so, see if the descriptor is present (modulo slippages) in the
|
# if so, see if the descriptor is present (modulo slippages) in the
|
||||||
# corresponding object
|
# corresponding object
|
||||||
@ -45,15 +45,15 @@ class Rule(WorkspaceStructure):
|
|||||||
self.internalStrength = 0.0
|
self.internalStrength = 0.0
|
||||||
return
|
return
|
||||||
sharedDescriptorTerm = 100.0
|
sharedDescriptorTerm = 100.0
|
||||||
conceptual_height = (100.0 - self.descriptor.conceptualDepth) / 10.0
|
conceptual_height = (100.0 - self.descriptor.conceptualDepth) / 10.0 # LSaldyt: 10?
|
||||||
sharedDescriptorWeight = conceptual_height ** 1.4
|
sharedDescriptorWeight = conceptual_height ** 1.4 # LSaldyt: 1.4 is also seemingly contrived
|
||||||
depthDifference = 100.0 - abs(self.descriptor.conceptualDepth -
|
depthDifference = 100.0 - abs(self.descriptor.conceptualDepth -
|
||||||
self.relation.conceptualDepth)
|
self.relation.conceptualDepth)
|
||||||
weights = ((depthDifference, 12),
|
weights = ((depthDifference, 12), # LSaldyt: ???
|
||||||
(averageDepth, 18),
|
(averageDepth, 18), # ????
|
||||||
(sharedDescriptorTerm, sharedDescriptorWeight))
|
(sharedDescriptorTerm, sharedDescriptorWeight)) # 12 and 18 can be reduced to 2 and 3, depending on sharedDescriptorWeight
|
||||||
self.internalStrength = formulas.weightedAverage(weights)
|
self.internalStrength = formulas.weightedAverage(weights)
|
||||||
if self.internalStrength > 100.0:
|
if self.internalStrength > 100.0: # LSaldyt: A better formula wouldn't need to do this.
|
||||||
self.internalStrength = 100.0
|
self.internalStrength = 100.0
|
||||||
|
|
||||||
def ruleEqual(self, other):
|
def ruleEqual(self, other):
|
||||||
|
|||||||
@ -58,7 +58,7 @@ def _averaged_alt(temp, prob):
|
|||||||
|
|
||||||
def _working_best(temp, prob):
|
def _working_best(temp, prob):
|
||||||
s = .5 # convergence
|
s = .5 # convergence
|
||||||
r = 2 # power
|
r = 1.05 # power
|
||||||
u = prob ** r if prob < .5 else prob ** (1/r)
|
u = prob ** r if prob < .5 else prob ** (1/r)
|
||||||
return _weighted(temp, prob, s, u)
|
return _weighted(temp, prob, s, u)
|
||||||
|
|
||||||
@ -76,6 +76,8 @@ class Temperature(object):
|
|||||||
'alt_fifty' : _alt_fifty,
|
'alt_fifty' : _alt_fifty,
|
||||||
'average_alt' : _averaged_alt,
|
'average_alt' : _averaged_alt,
|
||||||
'best' : _working_best}
|
'best' : _working_best}
|
||||||
|
self.diffs = 0
|
||||||
|
self.ndiffs = 0
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.actual_value = 100.0
|
self.actual_value = 100.0
|
||||||
@ -108,7 +110,14 @@ class Temperature(object):
|
|||||||
def getAdjustedProbability(self, value):
|
def getAdjustedProbability(self, value):
|
||||||
temp = self.value()
|
temp = self.value()
|
||||||
prob = value
|
prob = value
|
||||||
return self._adjustmentFormulas[self.adjustmentType](temp, prob)
|
adjusted = self._adjustmentFormulas[self.adjustmentType](temp, prob)
|
||||||
|
|
||||||
|
self.diffs += abs(adjusted - prob)
|
||||||
|
self.ndiffs += 1
|
||||||
|
return adjusted
|
||||||
|
|
||||||
|
def getAverageDifference(self):
|
||||||
|
return self.diffs / self.ndiffs
|
||||||
|
|
||||||
def useAdj(self, adj):
|
def useAdj(self, adj):
|
||||||
print('Changing to adjustment formula {}'.format(adj))
|
print('Changing to adjustment formula {}'.format(adj))
|
||||||
|
|||||||
@ -101,8 +101,6 @@ class Workspace(object):
|
|||||||
def getUpdatedTemperature(self):
|
def getUpdatedTemperature(self):
|
||||||
'''
|
'''
|
||||||
Calculation of global tolerance towards irrelevance
|
Calculation of global tolerance towards irrelevance
|
||||||
|
|
||||||
temp = weightedAverage(totalUnhappiness(.8), ruleWeakness(.2))
|
|
||||||
'''
|
'''
|
||||||
self.calculateIntraStringUnhappiness()
|
self.calculateIntraStringUnhappiness()
|
||||||
self.calculateInterStringUnhappiness()
|
self.calculateInterStringUnhappiness()
|
||||||
|
|||||||
3
tests.py
3
tests.py
@ -25,7 +25,6 @@ class TestCopycat(unittest.TestCase):
|
|||||||
self.longMessage = True # new in Python 2.7
|
self.longMessage = True # new in Python 2.7
|
||||||
|
|
||||||
def assertProbabilitiesLookRoughlyLike(self, actual, expected, iterations):
|
def assertProbabilitiesLookRoughlyLike(self, actual, expected, iterations):
|
||||||
|
|
||||||
answerKeys = set(list(actual.keys()) + list(expected.keys()))
|
answerKeys = set(list(actual.keys()) + list(expected.keys()))
|
||||||
degreesFreedom = len(answerKeys)
|
degreesFreedom = len(answerKeys)
|
||||||
chiSquared = 0
|
chiSquared = 0
|
||||||
@ -41,7 +40,7 @@ class TestCopycat(unittest.TestCase):
|
|||||||
chiSquared += (O - E) ** 2 / E
|
chiSquared += (O - E) ** 2 / E
|
||||||
|
|
||||||
if chiSquared >= _chiSquared_table[degreesFreedom]:
|
if chiSquared >= _chiSquared_table[degreesFreedom]:
|
||||||
self.fail('Significant different between expected and actual answer distributions: \n' +
|
self.fail('Significant difference between expected and actual answer distributions: \n' +
|
||||||
'Chi2 value: {} with {} degrees of freedom'.format(chiSquared, degreesFreedom))
|
'Chi2 value: {} with {} degrees of freedom'.format(chiSquared, degreesFreedom))
|
||||||
|
|
||||||
def run_testcase(self, initial, modified, target, iterations, expected):
|
def run_testcase(self, initial, modified, target, iterations, expected):
|
||||||
|
|||||||
Reference in New Issue
Block a user