Skip to content

Instantly share code, notes, and snippets.

@CrashenX
Last active August 29, 2015 14:23
Show Gist options
  • Save CrashenX/01de59ae142cefef3138 to your computer and use it in GitHub Desktop.
Save CrashenX/01de59ae142cefef3138 to your computer and use it in GitHub Desktop.
Normalize Over Positive and Negative Weights
from math import e, exp
def print_8_cent_0(l0, l1):
print(l0)
print(l1)
print(sum(l1))
print(l1[3]/l1[0])
print(l1[7]/l1[4])
print(l1[3]/l1[1])
print(l1[7]/l1[5])
print(l1[3]/l1[2])
print(l1[7]/l1[6])
print(l1[4]/l1[3])
print('===============')
def print_4_pos(l0, l1):
print(l0)
print(l1)
print(sum(l1))
print(l1[3]/l1[0])
print(l1[3]/l1[1])
print(l1[3]/l1[2])
print('===============')
def print_2_pos(l0, l1):
print(l0)
print(l1)
print(sum(l1))
print(l1[1]/l1[0])
print('===============')
def prob0(l):
tot = 0
normalized = [exp(x) for x in l]
tot = sum(normalized)
return map(lambda x: x/tot, normalized)
# TODO(Jesse): This function seems pretty close to correct
def prob1(l):
tot = 0
normalized = [exp(x)**(1 / e) for x in l]
tot = sum(normalized)
return map(lambda x: x/tot, normalized)
l0 = [-4, -3, -2, -1, 1, 2, 3, 4]
l1 = [1, 2, 3, 4]
l2 = [-1, 0, 1, 2]
l3 = [2, 4]
print_8_cent_0(l0, prob0(l0))
print_8_cent_0(l0, prob1(l0))
print_4_pos(l1, prob0(l1))
print_4_pos(l1, prob1(l1))
print_4_pos(l2, prob0(l2))
print_4_pos(l2, prob1(l2))
print_2_pos(l3, prob0(l3))
print_2_pos(l3, prob1(l3))
@CrashenX
Copy link
Author

[-4, -3, -2, -1, 1, 2, 3, 4]
[0.0002145634525943983, 0.0005832439342387867, 0.0015854213880002563, 0.004309622149451414, 0.03184403982749059, 0.08656107480779378, 0.23529739670190988, 0.6396046377385208]
1.0
20.0855369232
20.0855369232
7.38905609893
7.38905609893
2.71828182846
2.71828182846
7.38905609893
===============
[-4, -3, -2, -1, 1, 2, 3, 4]
[0.018169516424865428, 0.02624891642909215, 0.03792096595144067, 0.05478320076849197, 0.1143361134372242, 0.16517770843552468, 0.23862692673204425, 0.3447366518213166]
1.0
3.01511605964
3.01511605964
2.08706522863
2.08706522863
1.44466786101
1.44466786101
2.08706522863
===============
[1, 2, 3, 4]
[0.03205860328008499, 0.08714431874203257, 0.23688281808991013, 0.6439142598879722]
1.0
20.0855369232
7.38905609893
2.71828182846
===============
[1, 2, 3, 4]
[0.13250562986208964, 0.19142662486461684, 0.27654789268348495, 0.39951985258980854]
1.0
3.01511605964
2.08706522863
1.44466786101
===============
[-1, 0, 1, 2]
[0.03205860328008499, 0.08714431874203257, 0.23688281808991013, 0.6439142598879724]
1.0
20.0855369232
7.38905609893
2.71828182846
===============
[-1, 0, 1, 2]
[0.13250562986208964, 0.19142662486461684, 0.2765478926834849, 0.3995198525898085]
1.0
3.01511605964
2.08706522863
1.44466786101
===============
[2, 4]
[0.11920292202211756, 0.8807970779778824]
1.0
7.38905609893
===============
[2, 4]
[0.3239322547267065, 0.6760677452732935]
1.0
2.08706522863
===============

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment