Skip to content

Commit

Permalink
Format notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
terasakisatoshi committed Sep 11, 2024
1 parent c597023 commit a1c8a10
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 55 deletions.
3 changes: 2 additions & 1 deletion pluto_notebooks/compress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ Below, we compute the error for the whole tensor, which may be too expensive for
begin
# Check error
qttdataset = [qtt([i, j, k])
for i in axes(grid_qtt, 1), j in axes(grid_qtt, 1), k in axes(grid_qtt, 1)]
for i in axes(grid_qtt, 1), j in axes(grid_qtt, 1),
k in axes(grid_qtt, 1)]
qtterrors = abs.(qttdataset .- dataset_qtt)
println(
"Quantics TCI compression of the dataset with tolerance $tolerance has " *
Expand Down
2 changes: 1 addition & 1 deletion pluto_notebooks/interfacingwithitensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ begin
xmax = 3.0
qgrid = QG.DiscretizedGrid{1}(R, xmin, xmax; includeendpoint = false)
ci, ranks, errors = quanticscrossinterpolate(
Float64, f, qgrid; maxbonddim = 15)
Float64, f, qgrid; maxbonddim = 15)
end

# ╔═╡ dd3b9f0b-4300-4856-adcd-120c71dff9cd
Expand Down
46 changes: 23 additions & 23 deletions pluto_notebooks/quantics1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ begin
gr() # Use GR backend for plotting

import QuanticsGrids as QG
import TensorCrossInterpolation as TCI
import TensorCrossInterpolation as TCI

using QuanticsTCI: QuanticsTCI, quanticscrossinterpolate, integral
end
Expand All @@ -27,18 +27,18 @@ md"""

# ╔═╡ a6c64c0d-6e01-4044-8f09-283d35f51518
begin
# defines mutable struct `SemiLogy` and sets shorthands `semilogy` and `semilogy!`
@userplot SemiLogy
@recipe function f(t::SemiLogy)
x = t.args[begin]
y = t.args[end]
ε = nextfloat(0.0)
yscale := :log10
# Warning: Invalid negative or zero value 0.0 found at series index 16 for log10 based yscale
# prevent log10(0) from being -Inf
(x, ε .+ y)
end
# defines mutable struct `SemiLogy` and sets shorthands `semilogy` and `semilogy!`
@userplot SemiLogy
@recipe function f(t::SemiLogy)
x = t.args[begin]
y = t.args[end]
ε = nextfloat(0.0)

yscale := :log10
# Warning: Invalid negative or zero value 0.0 found at series index 16 for log10 based yscale
# prevent log10(0) from being -Inf
(x, ε .+ y)
end
end

# ╔═╡ e241cb1b-d6f4-4017-bd9c-91269a7d44cb
Expand Down Expand Up @@ -132,11 +132,11 @@ Here, we've created the object `ci` of type `QuanticsTensorCI2{Float64}`. This c

# ╔═╡ b48a3427-cd90-4d80-a97c-bde4b7da6716
let
for i in [1, 2, 3, 2^R] # Linear indices
# restore original coordinate `x` from linear index `i`
x = QG.grididx_to_origcoord(qgrid, i)
println("x: $(x), i: $(i), tci: $(ci(i)), ref: $(f(x))")
end
for i in [1, 2, 3, 2^R] # Linear indices
# restore original coordinate `x` from linear index `i`
x = QG.grididx_to_origcoord(qgrid, i)
println("x: $(x), i: $(i), tci: $(ci(i)), ref: $(f(x))")
end
end

# ╔═╡ d3f8d6ce-92e0-4a2b-b904-18969197936c
Expand Down Expand Up @@ -171,7 +171,7 @@ let
maxindex = QG.origcoord_to_grididx(qgrid, 2.0^(-23))
testindices = Int.(round.(LinRange(1, maxindex, 1000)))

xs = [QG.grididx_to_origcoord(qgrid, i) for i in testindices]
xs = [QG.grididx_to_origcoord(qgrid, i) for i in testindices]
ys = f.(xs)
yci = ci.(testindices)
plt = plot(title = "x vs interpolation error: $(nameof(f))",
Expand Down Expand Up @@ -300,10 +300,10 @@ One can construct a QTT representation of this function on the domain $[-10, 10)
# ╔═╡ 7407ef57-02ee-4a28-8557-d258486f2918
# Function of interest
function oscillation_fn(x)
return (
sinc(x) + 3 * exp(-0.3 * (x - 4)^2) * sinc(x - 4) - cos(4 * x)^2 -
2 * sinc(x + 10) * exp(-0.6 * (x + 9)) + 4 * cos(2 * x) * exp(-abs(x + 5)) +
6 * 1 / (x - 11) + sqrt(abs(x)) * atan(x / 15))
return (
sinc(x) + 3 * exp(-0.3 * (x - 4)^2) * sinc(x - 4) - cos(4 * x)^2 -
2 * sinc(x + 10) * exp(-0.6 * (x + 9)) + 4 * cos(2 * x) * exp(-abs(x + 5)) +
6 * 1 / (x - 11) + sqrt(abs(x)) * atan(x / 15))
end

# ╔═╡ 68cac44c-41a6-498d-9957-dd3da91679c8
Expand Down
40 changes: 20 additions & 20 deletions pluto_notebooks/quantics1d_advanced.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ However, since the implementation treats `B` as a untyped global variables, Juli

# ╔═╡ f3653d4d-283f-4758-8b57-90e34a6ed53c
begin
# Define callable struct
Base.@kwdef struct Ritter2024 <: Function
B::Float64 = 2^(-30)
end
# Make Ritter2024 be "callable" object.
function (obj::Ritter2024)(x)
B = obj.B
return cos(x / B) * cos(x / (4 * sqrt(5) * B)) * exp(-x^2) + 2 * exp(-x)
end
f = Ritter2024()
nothing
# Define callable struct
Base.@kwdef struct Ritter2024 <: Function
B::Float64 = 2^(-30)
end

# Make Ritter2024 be "callable" object.
function (obj::Ritter2024)(x)
B = obj.B
return cos(x / B) * cos(x / (4 * sqrt(5) * B)) * exp(-x^2) + 2 * exp(-x)
end

f = Ritter2024()
nothing
end

# ╔═╡ 9fe50058-6f68-4d63-93e2-0ee209cf3f0f
Expand Down Expand Up @@ -120,13 +120,13 @@ In the following code, we generate initial pivots by finding local maxima of $|f

# ╔═╡ cb628558-99dc-4fb3-b636-e939fa1895f6
begin
nrandominitpivot = 5
# random initial pivot
initialpivots = [TCI.optfirstpivot(qf, localdims, [rand(1:d) for d in localdims])
for _ in 1:nrandominitpivot]
qf.(initialpivots) # Function values at initial pivots
nrandominitpivot = 5

# random initial pivot
initialpivots = [TCI.optfirstpivot(qf, localdims, [rand(1:d) for d in localdims])
for _ in 1:nrandominitpivot]

qf.(initialpivots) # Function values at initial pivots
end

# ╔═╡ a7fe45e4-81ea-4e0d-95c9-e8f170a85df2
Expand Down
4 changes: 2 additions & 2 deletions pluto_notebooks/quantics2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ Checking the error on the same slices as before, we see that the approximation i
# ╔═╡ d68328cd-ce39-4c55-b89a-b6d45f9a90e3
# Function that evaluates log10 of the interplation error at (x, y)
function errflog10(x, y)
i = origcoord_to_grididx(grid, (x, y))
log10(nextfloat(0.0) + abs(f(grididx_to_origcoord(grid, i)...) - qtci(i)))
i = origcoord_to_grididx(grid, (x, y))
log10(nextfloat(0.0) + abs(f(grididx_to_origcoord(grid, i)...) - qtci(i)))
end

# ╔═╡ 2e41e949-5cb2-42f2-afea-09d1737cf708
Expand Down
22 changes: 14 additions & 8 deletions pluto_notebooks/welcome.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local iv = try
Base.loaded_modules[Base.PkgId(
Base.UUID("6e696c72-6542-2067-7265-42206c756150"),
"AbstractPlutoDingetjes")].Bonds.initial_value
catch
b -> missing
end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
Expand Down Expand Up @@ -172,11 +178,11 @@ Having trouble? Try the following command in your Julia's REPL:

# ╔═╡ b924c45f-2699-44d8-a526-a1554b49635e
begin
slider_x = @bind x Slider(1:10)
slider_y = @bind y Slider(1:5)
slider_z = @bind z Slider(1:100)
slider_x = @bind x Slider(1:10)

slider_y = @bind y Slider(1:5)

slider_z = @bind z Slider(1:100)
end

# ╔═╡ 2279092c-2af2-4c8c-964f-6f7eb4ed2d3f
Expand All @@ -188,8 +194,8 @@ md"""

# ╔═╡ b533b429-cd3f-4b76-bf38-59c0c8f78e77
begin
@show x + y
@show z
@show x + y
@show z
end

# ╔═╡ 00000000-0000-0000-0000-000000000001
Expand Down

0 comments on commit a1c8a10

Please sign in to comment.