diff --git a/papers/formulas/best.py b/papers/formulas/best.py new file mode 100644 index 0000000..395be83 --- /dev/null +++ b/papers/formulas/best.py @@ -0,0 +1,21 @@ +def _working_best(temp, prob): + s = .5 # convergence + r = 1.05 # power + u = prob ** r if prob < .5 else prob ** (1/r) + return _weighted(temp, prob, s, u) + +def _soft_best(temp, prob): + s = .5 # convergence + r = 1.05 # power + u = prob ** r if prob < .5 else prob ** (1/r) + return _weighted(temp, prob, s, u) + +def _parameterized_best(temp, prob): + alpha = 5 + beta = 1 + s = .5 + s = (alpha * prob + beta * s) / (alpha + beta) + r = 1.05 + u = prob ** r if prob < .5 else prob ** (1/r) + return _weighted(temp, prob, s, u) + diff --git a/papers/formulas/entropy.py b/papers/formulas/entropy.py new file mode 100644 index 0000000..8743e1e --- /dev/null +++ b/papers/formulas/entropy.py @@ -0,0 +1,12 @@ +import math + +def _entropy(temp, prob): + if prob == 0 or prob == 0.5 or temp == 0: + return prob + if prob < 0.5: + return 1.0 - _original(temp, 1.0 - prob) + coldness = 100.0 - temp + a = math.sqrt(coldness) + c = (10 - a) / 100 + f = (c + 1) * prob + return -f * math.log2(f) diff --git a/papers/formulas/original.py b/papers/formulas/original.py new file mode 100644 index 0000000..c80f482 --- /dev/null +++ b/papers/formulas/original.py @@ -0,0 +1,12 @@ +import math + +def _original(temp, prob): + if prob == 0 or prob == 0.5 or temp == 0: + return prob + if prob < 0.5: + return 1.0 - _original(temp, 1.0 - prob) + coldness = 100.0 - temp + a = math.sqrt(coldness) + c = (10 - a) / 100 + f = (c + 1) * prob + return max(f, 0.5) diff --git a/papers/formulas/weighted.py b/papers/formulas/weighted.py new file mode 100644 index 0000000..74aefd2 --- /dev/null +++ b/papers/formulas/weighted.py @@ -0,0 +1,28 @@ +def _weighted(temp, prob, s, u, alpha=1, beta=1): + weighted = (temp / 100) * s + ((100 - temp) / 100) * u + return weighted + +def _weighted_inverse(temp, prob): + iprob = 1 - prob + return _weighted(temp, prob, iprob, prob) + +# Uses .5 instead of 1-prob +def _fifty_converge(temp, prob): + return _weighted(temp, prob, .5, prob) + +# Curves to the average of the (1-p) and .5 +def _soft_curve(temp, prob): + return min(1, _weighted(temp, prob, (1.5-prob)/2, prob)) + +# Curves to the weighted average of the (1-p) and .5 +def _weighted_soft_curve(temp, prob): + weight = 100 + gamma = .5 # convergance value + alpha = 1 # gamma weight + beta = 3 # iprob weight + curved = min(1, + (temp / weight) * + ((alpha * gamma + beta * (1 - prob)) / + (alpha + beta)) + + ((weight - temp) / weight) * prob) + return curved diff --git a/papers/paper.tex b/papers/paper.tex index 0adbe54..adf9415 100644 --- a/papers/paper.tex +++ b/papers/paper.tex @@ -150,7 +150,10 @@ The original formulas being used to do this were overly complicated. In summary, many formulas were tested in a spreadsheet, and an optimal one was chosen that replicated the desired behavior. [] -\lstinputlisting[language=Python]{test.py} +\lstinputlisting[language=Python]{formulas/original.py} +\lstinputlisting[language=Python]{formulas/entropy.py} +\lstinputlisting[language=Python]{formulas/weighted.py} +\lstinputlisting[language=Python]{formulas/best.py} \subsection{Steps/plan}