Merge branch 'feature-temperature-effect-analysis' into revision-2.0
This commit is contained in:
@ -5,6 +5,12 @@ from pprint import pprint
|
|||||||
class Problem:
|
class Problem:
|
||||||
def __init__(self, initial, modified, target, iterations, distributions=None, formulas=None):
|
def __init__(self, initial, modified, target, iterations, distributions=None, formulas=None):
|
||||||
self.formulas = formulas
|
self.formulas = formulas
|
||||||
|
if formulas is not None:
|
||||||
|
assert hasattr(Copycat(), 'temperature')
|
||||||
|
else:
|
||||||
|
if hasattr(Copycat(), 'temperature'):
|
||||||
|
self.formulas = set(Copycat().temperature.adj_formulas())
|
||||||
|
print(self.formulas)
|
||||||
self.initial = initial
|
self.initial = initial
|
||||||
self.modified = modified
|
self.modified = modified
|
||||||
self.target = target
|
self.target = target
|
||||||
@ -14,8 +20,7 @@ class Problem:
|
|||||||
self.distributions = self.solve()
|
self.distributions = self.solve()
|
||||||
else:
|
else:
|
||||||
self.distributions = distributions
|
self.distributions = distributions
|
||||||
if formulas is not None:
|
print(self.formulas)
|
||||||
assert hasattr(Copycat().workspace, 'temperature')
|
|
||||||
|
|
||||||
def test(self, comparison, expected=None):
|
def test(self, comparison, expected=None):
|
||||||
print('-' * 120)
|
print('-' * 120)
|
||||||
@ -41,8 +46,8 @@ class Problem:
|
|||||||
copycat = Copycat()
|
copycat = Copycat()
|
||||||
answers = dict()
|
answers = dict()
|
||||||
if self.formulas == None:
|
if self.formulas == None:
|
||||||
if hasattr(copycat.workspace, 'temperature'):
|
if hasattr(copycat, 'temperature'):
|
||||||
formula = copycat.workspace.temperature.getAdj()
|
formula = copycat.temperature.getAdj()
|
||||||
else:
|
else:
|
||||||
formula = None
|
formula = None
|
||||||
answers[formula] = copycat.run(self.initial,
|
answers[formula] = copycat.run(self.initial,
|
||||||
@ -50,12 +55,14 @@ class Problem:
|
|||||||
self.target,
|
self.target,
|
||||||
self.iterations)
|
self.iterations)
|
||||||
else:
|
else:
|
||||||
|
print(self.formulas)
|
||||||
for formula in self.formulas:
|
for formula in self.formulas:
|
||||||
copycat.temperature.useAdj(formula)
|
copycat.temperature.useAdj(formula)
|
||||||
answers[formulas] = copycat.run(self.initial,
|
answers[formula] = copycat.run(self.initial,
|
||||||
self.modified,
|
self.modified,
|
||||||
self.target,
|
self.target,
|
||||||
self.iterations)
|
self.iterations)
|
||||||
|
print('Done with {}'.format(formula))
|
||||||
return answers
|
return answers
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
|
|||||||
@ -24,19 +24,19 @@ def _entropy(temp, prob):
|
|||||||
f = (c + 1) * prob
|
f = (c + 1) * prob
|
||||||
return -f * math.log2(f)
|
return -f * math.log2(f)
|
||||||
|
|
||||||
def _weighted(temp, prob, s, u, alpha=1, beta=1):
|
def _weighted(temp, s, u):
|
||||||
weighted = (temp / 100) * s + ((100 - temp) / 100) * u
|
weighted = (temp / 100) * s + ((100 - temp) / 100) * u
|
||||||
return weighted
|
return weighted
|
||||||
|
|
||||||
def _weighted_inverse(temp, prob):
|
def _weighted_inverse(temp, prob):
|
||||||
iprob = 1 - prob
|
iprob = 1 - prob
|
||||||
return _weighted(temp, prob, iprob, prob)
|
return _weighted(temp, iprob, prob)
|
||||||
|
|
||||||
def _fifty_converge(temp, prob): # Uses .5 instead of 1-prob
|
def _fifty_converge(temp, prob): # Uses .5 instead of 1-prob
|
||||||
return _weighted(temp, prob, .5, prob)
|
return _weighted(temp, .5, prob)
|
||||||
|
|
||||||
def _soft_curve(temp, prob): # Curves to the average of the (1-p) and .5
|
def _soft_curve(temp, prob): # Curves to the average of the (1-p) and .5
|
||||||
return min(1, _weighted(temp, prob, (1.5-prob)/2, prob))
|
return min(1, _weighted(temp, (1.5-prob)/2, prob))
|
||||||
|
|
||||||
def _weighted_soft_curve(temp, prob): # Curves to the weighted average of the (1-p) and .5
|
def _weighted_soft_curve(temp, prob): # Curves to the weighted average of the (1-p) and .5
|
||||||
weight = 100
|
weight = 100
|
||||||
@ -49,25 +49,25 @@ def _weighted_soft_curve(temp, prob): # Curves to the weighted average of the (1
|
|||||||
def _alt_fifty(temp, prob):
|
def _alt_fifty(temp, prob):
|
||||||
s = .5
|
s = .5
|
||||||
u = prob ** 2 if prob < .5 else math.sqrt(prob)
|
u = prob ** 2 if prob < .5 else math.sqrt(prob)
|
||||||
return _weighted(temp, prob, s, u)
|
return _weighted(temp, s, u)
|
||||||
|
|
||||||
def _averaged_alt(temp, prob):
|
def _averaged_alt(temp, prob):
|
||||||
s = (1.5 - prob)/2
|
s = (1.5 - prob)/2
|
||||||
u = prob ** 2 if prob < .5 else math.sqrt(prob)
|
u = prob ** 2 if prob < .5 else math.sqrt(prob)
|
||||||
return _weighted(temp, prob, s, u)
|
return _weighted(temp, s, u)
|
||||||
|
|
||||||
|
|
||||||
def _working_best(temp, prob):
|
def _working_best(temp, prob):
|
||||||
s = .5 # convergence
|
s = .5 # convergence
|
||||||
r = 1.05 # 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, s, u)
|
||||||
|
|
||||||
def _soft_best(temp, prob):
|
def _soft_best(temp, prob):
|
||||||
s = .5 # convergence
|
s = .5 # convergence
|
||||||
r = 1.05 # 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, s, u)
|
||||||
|
|
||||||
def _parameterized_best(temp, prob):
|
def _parameterized_best(temp, prob):
|
||||||
# (D$66/100)*($E$64*$B68 + $G$64*$F$64)/($E$64 + $G$64)+((100-D$66)/100)*IF($B68 > 0.5, $B68^(1/$H$64), $B68^$H$64)
|
# (D$66/100)*($E$64*$B68 + $G$64*$F$64)/($E$64 + $G$64)+((100-D$66)/100)*IF($B68 > 0.5, $B68^(1/$H$64), $B68^$H$64)
|
||||||
@ -78,7 +78,24 @@ def _parameterized_best(temp, prob):
|
|||||||
s = (alpha * prob + beta * s) / (alpha + beta)
|
s = (alpha * prob + beta * s) / (alpha + beta)
|
||||||
r = 1.05
|
r = 1.05
|
||||||
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, s, u)
|
||||||
|
|
||||||
|
def _meta(temp, prob):
|
||||||
|
r = _weighted(temp, 1, 2) # Make r a function of temperature
|
||||||
|
s = .5
|
||||||
|
u = prob ** r if prob < .5 else prob ** (1/r)
|
||||||
|
return _weighted(temp, s, u)
|
||||||
|
|
||||||
|
def _meta_parameterized(temp, prob):
|
||||||
|
r = _weighted(temp, 1, 2) # Make r a function of temperature
|
||||||
|
|
||||||
|
alpha = 5
|
||||||
|
beta = 1
|
||||||
|
s = .5
|
||||||
|
s = (alpha * prob + beta * s) / (alpha + beta)
|
||||||
|
u = prob ** r if prob < .5 else prob ** (1/r)
|
||||||
|
|
||||||
|
return _weighted(temp, s, u)
|
||||||
|
|
||||||
def _none(temp, prob):
|
def _none(temp, prob):
|
||||||
return prob
|
return prob
|
||||||
@ -99,6 +116,8 @@ class Temperature(object):
|
|||||||
'best' : _working_best,
|
'best' : _working_best,
|
||||||
'sbest' : _soft_best,
|
'sbest' : _soft_best,
|
||||||
'pbest' : _parameterized_best,
|
'pbest' : _parameterized_best,
|
||||||
|
'meta' : _meta,
|
||||||
|
'pmeta' : _meta_parameterized,
|
||||||
'none' : _none}
|
'none' : _none}
|
||||||
self.diffs = 0
|
self.diffs = 0
|
||||||
self.ndiffs = 0
|
self.ndiffs = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user