Skip to content

Instantly share code, notes, and snippets.

@jinhwanlazy
Created Mar 15, 2016
Embed
What would you like to do?
Successive Mean Quantization Transtform. Straightforward recursive implementation.
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