R, BS = 110, 200 input = T.Placeholder((Ds[0], ), 'float32') in_signs = T.Placeholder((np.sum(Ds[1:-1]), ), 'bool') batch_in_signs = T.Placeholder((R, np.sum(Ds[1:-1])), 'bool') x = T.Placeholder((BS, Ds[-1]), 'float32') m0 = T.Placeholder((BS, R), 'float32') m1 = T.Placeholder((BS, R, Ds[0]), 'float32') m2 = T.Placeholder((BS, R, Ds[0], Ds[0]), 'float32') f, g, h, all_g, train_f, sigma2 = utils.create_fns(input, in_signs, Ds, x, m0, m1, m2, batch_in_signs, sigma_x=np.log(1)) output, A, b, inequalities, signs = f(np.random.randn(Ds[0]) / 4) regions = utils.search_region(all_g, g, signs) assert len(regions) <= R As = np.array([regions[s]['Ab'][0] for s in regions]) Bs = np.array([regions[s]['Ab'][1] for s in regions]) N = 140 L = 4 if Ds[0] == 1:
if Ds[0] == 1: xx = np.linspace(-3, 3, 500) else: xx = np.meshgrid(np.linspace(-3, 3, 100), np.linspace(-3, 3, 100)) xx = np.vstack([xx[0].flatten(), xx[1].flatten()]).T for ss in [0.05, 0.2, 0.5]: np.random.seed(int(sys.argv[-1]) + 10) sigma_x = np.eye(Ds[-1]) * ss for i in range(5): fig = plt.figure(figsize=(5, 5)) f, g, h, all_g, train_f = utils.create_fns(input, in_signs, Ds, x, m0, m1, m2, batch_in_signs, sigma=2) z = np.random.randn(Ds[0]) output, A, b, inequalities, signs = f(z) outpute = output + np.random.randn(Ds[-1]) * np.sqrt(0.05) regions = utils.search_region(all_g, g, signs) print(len(regions)) As = np.array([regions[s]['Ab'][0] for s in regions]) Bs = np.array([regions[s]['Ab'][1] for s in regions])
import matplotlib.pyplot as plt import utils from tqdm import tqdm from scipy.spatial import ConvexHull from multiprocessing import Pool np.random.seed(14) Ds = [1, 32, 2] mu_z = np.zeros(Ds[0]) sigma_z = np.eye(Ds[0]) sigma_x = np.eye(Ds[-1]) * 0.2 input = T.Placeholder((Ds[0], ), 'float32') in_signs = T.Placeholder((np.sum(Ds[1:-1]), ), 'bool') f, g, h, all_g = utils.create_fns(input, in_signs, Ds) x = np.random.randn(Ds[0]) output, A, b, inequalities, signs = f(x) regions = utils.search_region(all_g, g, signs) print('number of regions:', len(regions)) N = 25 L = 2. xx = np.meshgrid(np.linspace(-L, L, N), np.linspace(-L, L, N)) xx = np.hstack([xx[0].flatten()[:, None], xx[1].flatten()[:, None]]) p = list() for x in tqdm(xx): p.append(utils.algo2(x, regions, sigma_x, mu_z, sigma_z)[0]) p = np.array(p).reshape((N, N))