Created
March 15, 2016 12:06
-
-
Save jinhwanlazy/ba088dc458acb84bbca0 to your computer and use it in GitHub Desktop.
Successive Mean Quantization Transtform. Straightforward recursive implementation.
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 SMQT(data, level): | |
ret = [0] * len(data) | |
def MQU(idx, depth): | |
if depth == 0 or not idx: | |
return | |
mean = sum(data[i] for i in idx) / len(idx) | |
D0, D1 = [], [] | |
for i in idx: | |
(D0 if data[i] <= mean else D1).append(i) | |
for i in D1: | |
ret[i] += 2 ** (depth-1) | |
MQU(D0, depth-1) | |
MQU(D1, depth-1) | |
MQU(range(len(data)), level) | |
return ret | |
from random import random | |
from pprint import pprint as print | |
level = 2 | |
data_size = 16 | |
data = [random() for _ in range(data_size)] | |
print(data) | |
print(SMQT(data, level)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment