Major overhaul of temperature logic. Behavioral change.
I think the reason the temperature logic was so confused in the old code is because the Java code has a class `Temperature` that is used for graphical display *and* two variables in `formulas` that are used for most of the actual math. But somewhere along the line, some of the code in `formulas.java` started reading from `Temperature.value` as well. So the Python code was just faithfully copying that confusion. The actual abstraction here is a very simple "temperature" object with a stored value. It can be "clamped" to 100.0 for a given period. The only complication is that one of the codelets (the rule-transformer codelet) wants to get access to the "actual value" of the temperature even when it is clamped. The Python rule-transformer codelet also had a bug: it was accidentally setting `temperature.value` on the `temperature` module instead of on the `temperature.temperature` object! This turned some of its behavior into a no-op, for whatever that's worth. Lastly, the calculation of `finalTemperature` in the main program can now report 100.0 if the answer is found while the temperature is clamped. I don't fully understand why this didn't happen in the old code. I've hacked around it with `temperature.last_unclamped_value` for now, but I should TODO FIXME.
This commit is contained in:
@ -4,8 +4,6 @@ import random
|
||||
|
||||
from temperature import temperature
|
||||
|
||||
actualTemperature = Temperature = 100.0
|
||||
|
||||
|
||||
def selectListPosition(probabilities):
|
||||
total = sum(probabilities)
|
||||
@ -35,23 +33,18 @@ def weightedAverage(values):
|
||||
|
||||
|
||||
def temperatureAdjustedValue(value):
|
||||
#logging.info('Temperature: %s' % Temperature)
|
||||
#logging.info('actualTemperature: %s' % actualTemperature)
|
||||
return value ** (((100.0 - Temperature) / 30.0) + 0.5)
|
||||
return value ** (((100.0 - temperature.value()) / 30.0) + 0.5)
|
||||
|
||||
|
||||
def temperatureAdjustedProbability(value):
|
||||
if not value or value == 0.5 or not temperature.value:
|
||||
if value == 0 or value == 0.5 or temperature.value() == 0:
|
||||
return value
|
||||
if value < 0.5:
|
||||
return 1.0 - temperatureAdjustedProbability(1.0 - value)
|
||||
coldness = 100.0 - temperature.value
|
||||
coldness = 100.0 - temperature.value()
|
||||
a = math.sqrt(coldness)
|
||||
b = 10.0 - a
|
||||
c = b / 100
|
||||
d = c * (1.0 - (1.0 - value)) # as said the java
|
||||
e = (1.0 - value) + d
|
||||
f = 1.0 - e
|
||||
c = (10 - a) / 100
|
||||
f = (c + 1) * value
|
||||
return max(f, 0.5)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user