Last active
August 29, 2015 14:23
-
-
Save CrashenX/01de59ae142cefef3138 to your computer and use it in GitHub Desktop.
Normalize Over Positive and Negative Weights
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
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)) |
Author
CrashenX
commented
Jun 24, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment