Skip to content
Snippets Groups Projects
Commit e1378f99 authored by rink's avatar rink
Browse files

add option to pass in absolute tolerance

parent f68833ff
No related branches found
No related tags found
No related merge requests found
......@@ -22,14 +22,14 @@ def true_func(x):
# Y = 2 + 1.5 * X + epsilon # Linear relationship with variance increasing
# Y = 1 + np.exp(X / 4) + epsilon
# Y = 1 + np.exp(X / 4) + np.sin((2*np.pi/5)*X)
return 1 + np.exp(x / 4) + np.sin((2*np.pi/5)*x)
return 1 + np.exp(x / 4) + 3*np.sin((2*np.pi/5)*x)
# Generate synthetic dataset
def make_data(num_points=1000):
np.random.seed(42)
X = np.random.rand(num_points, 1) * 10
# epsilon = np.random.normal(0, X/2, size=(num_points, 1)) # Noise increasing with X
epsilon = np.random.normal(0, 0.5 + X/10, size=(num_points, 1))
epsilon = np.random.normal(0, 0.25 + X/5, size=(num_points, 1))
Y = true_func(X)
Y_eps = Y + epsilon
......@@ -42,7 +42,7 @@ def make_data(num_points=1000):
def build_quantile_model(q):
model = tf.keras.models.Sequential([
tf.keras.layers.InputLayer(shape=(1,)),
tf.keras.layers.Dense(64, activation='relu'), # Hidden layer
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(1) # Output layer
......@@ -53,7 +53,7 @@ def build_quantile_model(q):
def build_bulk_quantile_model():
model = tf.keras.models.Sequential([
tf.keras.layers.InputLayer(shape=(1,)),
tf.keras.layers.Dense(64, activation='relu'), # Hidden layer
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(1) # Output layer
......@@ -64,7 +64,7 @@ def build_bulk_quantile_model():
def build_mae_model():
model = tf.keras.models.Sequential([
tf.keras.layers.InputLayer(shape=(1,)),
tf.keras.layers.Dense(64, activation='relu'), # Hidden layer
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(1) # Output layer
......@@ -76,7 +76,7 @@ def build_mae_model():
def build_mse_model():
model = tf.keras.models.Sequential([
tf.keras.layers.InputLayer(shape=(1,)),
tf.keras.layers.Dense(64, activation='relu'), # Hidden layer
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(1) # Output layer
......@@ -119,7 +119,7 @@ def run(num_points=1000, num_plot_pts=200):
# Plot the results
plt.figure(figsize=(8, 6))
plt.scatter(X_test, Y_test, alpha=0.3, label="Test Data")
plt.scatter(X_test[:, 0], Y_test[:, 0], alpha=0.3, label="Test Data")
plt.plot(X_range, predictions[0.05], label="Quantile 0.05", color='red')
plt.plot(X_range, predictions[0.5], label="Quantile 0.5 (Median)", color='green')
plt.plot(X_range, predictions[0.95], label="Quantile 0.95", color='blue')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment