Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
synthetic-data/tf_wgan_bds_test.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
70 lines (58 sloc)
1.62 KB
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
# -*- coding: utf-8 -*- | |
""" | |
Runs max_iters tests of tf_wgan_bds and saves results to a log file | |
@author: Joseph Pedersen | |
""" | |
import sys | |
old_stdout = sys.stdout | |
from datetime import datetime | |
dt = datetime.now().strftime('%Y%m%d_%H%M') | |
log_file = open("logs/test_tf_wgan_bds_"+dt,"w") | |
sys.stdout = log_file | |
import os | |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' | |
import pickle as pkl | |
import tf_wgan_bds as twb | |
# Create array to store results | |
resultsQ = [] | |
resultsD = [] | |
max_iters = 1000 | |
# Arguments for np_wgan_bds.setup() | |
eps = 0.01 | |
layers = 3 | |
random=True | |
max_nodes=1000 | |
# Print settings | |
print(f' max_iters: {max_iters}') | |
print(f' eps: {eps}') | |
print(f' layers: {layers}') | |
print(f' random: {random}') | |
print(f' max_nodes: {max_nodes}') | |
# Test the bounds `max_iters` times | |
for i in range(max_iters): | |
if i % max(1,max_iters//10) == 0: | |
print(f"iteration {i}",file=old_stdout) | |
# compute bounds and grads on practice data | |
d = twb.setup(eps = eps, | |
layers = layers, | |
random=random, | |
max_nodes=max_nodes) | |
# test the bounds and grads | |
c = twb.test(d) | |
resultsQ.append(c['overallQ']) | |
resultsD.append(c['overallD']) | |
if resultsQ[-1] != True: | |
dump_dict = { | |
'd' : d, | |
'c' : c} | |
break | |
# If the bounds are violated, record the results | |
if resultsQ[-1] != True: | |
print(f'bounds failed on iteration {i}') | |
with open('bad_results_'+dt+'.pkl','wb') as f: | |
pkl.dump(dump_dict,f) | |
else: | |
print("all grads within bounds") | |
print(f"max of all D is {max(resultsD)}") | |
sys.stdout = old_stdout | |
log_file.close() |