Skip to content

Commit

Permalink
Update tensor_prod.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Spinachboul authored Jan 15, 2024
1 parent fe33b1d commit 33880bf
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions docs/src/tensor_prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Generating Data and Plotting

```@example tensor
function tensor_product_function(x)
a = 0.5
return prod(cos.(a*pi*x))
end
```
Expand All @@ -30,16 +31,6 @@ ub = 5.0 # Upper bound of sampling range
n = 30 # Number of training points
```

Visualize training data and the true function
```@example tensor
function plot_data_and_true_function(x_train, y_train, x_test, y_test, a, lb, ub)
xs = range(lb, ub, length=1000)
plot(xs, tensor_product_function.(xs, a), label="True Function", legend=:top)
scatter!(x_train, repeat([y_train], length(x_train)), label="Training Points", xlims=(lb,ub), ylims=(-1,1))
scatter!(x_test, repeat([y_test], length(x_test)), label="Test Points")
end
```

Generate training and test data
```@example tensor
x_train = sample(n, lb, ub, SobolSample()) # Sample training data points
Expand Down Expand Up @@ -85,7 +76,7 @@ end
Plot true function vs. model predictions
```@example tensor
xs = lb:0.01:ub
plot(xs, f.(xs), label="True function", legend=:top, color=:black)
plot(xs, tensor_product_function.(xs), label="True function", legend=:top, color=:black)
plot!(xs, loba_surrogate.(xs), label="Lobachevsky", legend=:top, color=:red)
plot!(xs, krig_surrogate.(xs), label="Kriging", legend=:top, color=:blue)
```
Expand Down

0 comments on commit 33880bf

Please sign in to comment.