def run_iterations_chunked(f, bounds, num_iterations=3, chunk_size=5): X = [np.zeros(len(bounds))] y = np.array([f(x) for x in X]).flatten() for jj in range(num_iterations): sample_X = None for cc in range(chunk_size): sample, prob, pred, samples, vals, stds, sample_probs, prob_of_fail, pred_runtimes = bayes.next_sample( X, y, bounds, current_X=sample_X, improvement=0.1) if sample_X is None: sample_X = np.array([sample]) else: sample_X = np.append(sample_X, np.array([sample]), axis=0) sample_X = np.append(X, np.array([sample]), axis=0) X = np.append(X, sample_X, axis=0) y = np.array([f(x) for x in X]).flatten()
def run_iterations(f, bounds, num_iterations=20): X = [np.zeros(len(bounds))] y = np.array([f(x) for x in X]).flatten() for jj in range(num_iterations): sample, prob, pred, samples, vals, stds, sample_probs, prob_of_fail, pred_runtimes = bayes.next_sample( X, y, bounds, improvement=0.1) print("X: {} prob(I): {} pred: {} value: {}".format( sample, prob, pred, f(sample))) X = np.append(X, np.array([sample]), axis=0) y = np.array([f(x) for x in X]).flatten()
def test_nans(): f = squiggle X = np.array([np.random.uniform([0.], [5.]) for x in range(200)]) Y = np.array([np.nan] * 200) sample, prob, pred, samples, vals, stds, sample_probs, prob_of_fail, pred_runtimes = bayes.next_sample( X, Y, [[-10, 10]]) assert sample[0] < 10. # trying all NaNs X += np.array([np.random.uniform([0.], [5.]) for x in range(200)]) Y += np.array([np.nan] * 200) sample, prob, pred, samples, vals, stds, sample_probs, prob_of_fail, pred_runtimes = bayes.next_sample( X, Y, [[-10, 10]]) assert sample[0] < 10.
def test_squiggle_int(): f = squiggle X = np.array([np.random.uniform([0.], [5.]) for x in range(200)]) Y = np.array([f(x) for x in X]).flatten() sample, prob, pred, samples, vals, stds, sample_probs, prob_of_fail, pred_runtimes = bayes.next_sample( X, Y, [[-10, 10]]) assert sample[0] < 0., "Greater than 0 {}".format(sample[0])
def test_squiggle(): f = squiggle # we sample a ton of positive examples, ignoring the negative side X = np.array([np.random.uniform([0.], [5.]) for x in range(200)]) Y = np.array([f(x) for x in X]).flatten() sample, prob, pred, samples, vals, stds, sample_probs, prob_of_fail, pred_runtimes = bayes.next_sample( X, Y, [[-5., 5.]], improvement=1.0) assert sample[0] < 0., "Greater than 0 {}".format(sample[0]) # we sample missing a big chunk between 1 and 3 X = np.append( np.array([np.random.uniform([0.], [1.]) for x in range(200)]), np.array([np.random.uniform([0.], [1.]) + 4. for x in range(200)]), axis=0, ) Y = np.array([f(x) for x in X]).flatten() sample, prob, pred, samples, vals, stds, sample_probs, prob_of_fail, pred_runtimes = bayes.next_sample( X, Y, [[0., 4.]]) assert sample[0] > 1. and sample[ 0] < 4., "Sample outside of 1-3 range: {}".format(sample[0])