Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
full domain provided in conditional complexity computation; parameter…
…s updated for synthetic experiments
  • Loading branch information
kbudhath committed Aug 29, 2017
1 parent 8363da4 commit c37a138
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cisc.py
Expand Up @@ -37,9 +37,9 @@ def cisc(X, Y):
# scXgY = sum(stochastic_complexity(Z, len(domX)) for Z in mXgY.itervalues())

# weighted one
scYgX = sum((len(Z) * 1.0) / len(X) * stochastic_complexity(Z)
scYgX = sum((len(Z) * 1.0) / len(X) * stochastic_complexity(Z, len(domY))
for Z in mYgX.itervalues())
scXgY = sum((len(Z) * 1.0) / len(X) * stochastic_complexity(Z)
scXgY = sum((len(Z) * 1.0) / len(X) * stochastic_complexity(Z, len(domX))
for Z in mXgY.itervalues())

ciscXtoY = scX + scYgX
Expand Down
43 changes: 22 additions & 21 deletions test_synthetic.py
Expand Up @@ -48,7 +48,7 @@ def map_randomly(Xd, fXd):

def generate_X(src, size):
if src == "uniform":
maxX = random.randint(2, 10)
maxX = random.randint(1, 10)
X = [random.randint(1, maxX) for i in xrange(size)]
elif src == "multinomial":
p_nums = [random.randint(1, 10) for i in xrange(random.randint(2, 11))]
Expand All @@ -64,9 +64,9 @@ def generate_X(src, size):
p = random.uniform(0.1, 0.9)
X = np.random.geometric(p, size).tolist()
elif src == "hypergeometric":
ngood = random.randint(1, 41)
nbad = random.randint(1, 41)
nsample = random.randint(1, min(41, ngood + nbad))
ngood = random.randint(1, 40)
nbad = random.randint(1, 40)
nsample = random.randint(1, min(40, ngood + nbad))
X = np.random.hypergeometric(ngood, nbad, nsample, size).tolist()
elif src == "poisson":
lam = random.randint(1, 10)
Expand All @@ -80,7 +80,6 @@ def generate_X(src, size):

def generate_additive_N(size):
t = random.randint(1, 7)
t = random.randint(1, 3)
suppN = range(-t, t + 1)
N = [random.choice(suppN) for i in xrange(size)]
return N
Expand Down Expand Up @@ -182,7 +181,7 @@ def _decision_rate(srcX):


def test_accuracy():
nsim = 1000
nsim = 5000
size = 5000
level = 0.05
suppfX = range(-7, 8)
Expand All @@ -191,8 +190,9 @@ def test_accuracy():
print "-" * 58
print "%18s%10s%10s%10s%10s" % ("TYPE_X", "DC", "DR", "CISC", "CRISP")
print "-" * 58
sys.stdout.flush()

fp = open("results/accuracy-dtype.dat", "w")
fp = open("results/acc-dtype.dat", "w")
fp.write("%s\t%s\t%s\t%s\t%s\n" %
("dtype", "dc", "dr", "cisc", "crisp"))
for srcX in srcsX:
Expand All @@ -214,14 +214,16 @@ def test_accuracy():
nc_cisc += int(cisc_score[0] < cisc_score[1])
nc_crisp += int(crisp_score[0] < crisp_score[1])

acc_dc = nc_dc / nsim
acc_dr = nc_dr / nsim
acc_cisc = nc_cisc / nsim
acc_crisp = nc_crisp / nsim
acc_dc = nc_dc * 100 / nsim
acc_dr = nc_dr * 100 / nsim
acc_cisc = nc_cisc * 100 / nsim
acc_crisp = nc_crisp * 100 / nsim
print "%18s%10.2f%10.2f%10.2f%10.2f" % (srcX, acc_dc, acc_dr, acc_cisc, acc_crisp)
sys.stdout.flush()
fp.write("%s\t%.2f\t%.2f\t%.2f\t%.2f\n" %
(srcX, acc_dc, acc_dr, acc_cisc, acc_crisp))
print "-" * 58
sys.stdout.flush()
fp.close()


Expand Down Expand Up @@ -488,13 +490,13 @@ def test_hypercompression():


def test_sample_size():
nsim = 2
nsim = 5000
level = 0.05
sizes = [100, 500, 1000, 2500, 5000, 10000]
suppfX = range(-7, 8)
srcX = "uniform"
srcX = "geometric"

fp = open("results/accuracy-size.dat", "w")
fp = open("results/acc-size.dat", "w")
diffs = []
fp.write("%s\t%s\t%s\t%s\t%s\n" % ("size", "dc", "dr", "cisc", "crisp"))
# progress(0, len(sizes))
Expand All @@ -517,19 +519,18 @@ def test_sample_size():
nc_cisc += int(cisc_score[0] < cisc_score[1])
nc_crisp += int(crisp_score[0] < crisp_score[1])

acc_dc = nc_dc / nsim
acc_dr = nc_dr / nsim
acc_cisc = nc_cisc / nsim
acc_crisp = nc_crisp / nsim
acc_dc = nc_dc * 100 / nsim
acc_dr = nc_dr * 100 / nsim
acc_cisc = nc_cisc * 100 / nsim
acc_crisp = nc_crisp * 100 / nsim
print "%d\t%.2f\t%.2f\t%.2f\t%.2f" % (size, acc_dc, acc_dr, acc_cisc, acc_crisp)
sys.stdout.flush()
fp.write("%d\t%.2f\t%.2f\t%.2f\t%.2f\n" %
(size, acc_dc, acc_dr, acc_cisc, acc_crisp))
# progress(k + 1, len(sizes))
fp.close()


if __name__ == "__main__":
test_accuracy()
test_sample_size()
test_size_runtime()
test_domain_runtime()
test_accuracy()

0 comments on commit c37a138

Please sign in to comment.