Created
September 8, 2015 20:12
-
-
Save arogozhnikov/45440f0b9a06be6774b0 to your computer and use it in GitHub Desktop.
Shortest isotonic transform function in the world. Generates increasing formula.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isotonic_transform(x, y, alpha=0.001): | |
target = y + 0. | |
output = numpy.zeros(len(x)) | |
steps = 2 ** numpy.arange(int(numpy.log2(len(x)) - 1))[::-1] | |
print steps | |
for i in range(100): | |
for step in steps: | |
penalty = 2 * (target - output) | |
diffs = - (output[step:] - output[:-step]) | |
diffs = diffs.clip(0) | |
misorder_penalty = numpy.zeros(len(x)) | |
misorder_penalty[step:] += diffs / 2. | |
misorder_penalty[:-step] -= diffs / 2. | |
output += alpha * penalty + misorder_penalty | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment