Skip to content

Commit 3f71356

Browse files
committed
Activate global pivot search by default and document it
1 parent a80ee50 commit 3f71356

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

docs/src/index.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,22 @@ tci, ranks, errors = TCI.crossinterpolate2(
117117
```
118118
This algorithm optimizes the given index set (in this case `[1, 2, 3, 4, 5]`) by searching for a maximum absolute value, alternating through the dimensions. If no starting point is given, `[1, 1, ...]` is used.
119119

120+
## Combing TCI2 and global pivot search
121+
The main algorithm for adding new pivots in TCI2 is the 2-site algorithm, which is local.
122+
The 2-site algorithm alone may miss some regions with high interpolation error.
123+
124+
The current TCI2 implementation provides the combination of the 2-site algorithm and a global search algorithm to find such regions.
125+
This functionality is activated by default.
126+
In the function [`crossinterpolate2`](@ref), we alternate between a 2-site-update sweep and a global pivot insertion.
127+
After a 2-site-update sweep, we search for index sets with high interpolation errors (> the given tolerance multiplied by the parameter `tolmarginglobalsearch`) and add them to the TCI2 object, and then we continue with a 2-site-update sweep.
128+
The number of initial points used in one global search is controlled by the parameter `nsearchglobalpivot`.
129+
You may consider increasing this number if the global search is not effective (check the number of pivots found and timings of the global search by setting `verbosity` to a higher value!).
130+
The maximum number of global pivots inserted at once is controlled by the parameter `maxnglobalpivot`.
131+
132+
133+
120134
## Estiamte true interpolation error by random global search
121-
Since the TCI update algorithms are local, the true interpolation error is not known. However, the error can be estimated by global searches. This is implemented in the function `estimatetrueerror`:
135+
Since most of the TCI update algorithms are local, the true interpolation error is not known. However, the error can be estimated by global searches. This is implemented in the function [`estimatetrueerror`](@ref):
122136

123137
```julia
124138
pivoterrors = TCI.estimatetrueerror(TCI.TensorTrain(tci), f)

src/tensorci2.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function addglobalpivots2sitesweep!(
214214
pivotsearch::Symbol=:full,
215215
verbosity::Int=0,
216216
ntry::Int=10,
217-
strictlynested::Bool=true
217+
strictlynested::Bool=false
218218
)::Int where {F,ValueType}
219219
if any(length(tci) .!= length.(pivots))
220220
throw(DimensionMismatch("Please specify a pivot as one index per leg of the MPS."))
@@ -604,9 +604,9 @@ end
604604
normalizeerror::Bool=true,
605605
ncheckhistory=3,
606606
maxnglobalpivot::Int=5,
607-
nsearchglobalpivot::Int=0,
607+
nsearchglobalpivot::Int=5,
608608
tolmarginglobalsearch::Float64=10.0,
609-
strictlynested::Bool=true
609+
strictlynested::Bool=false
610610
) where {ValueType}
611611
612612
Perform optimization sweeps using the TCI2 algorithm. This will sucessively improve the TCI approximation of a function until it fits `f` with an error smaller than `tolerance`, or until the maximum bond dimension (`maxbonddim`) is reached.
@@ -627,7 +627,7 @@ Arguments:
627627
- `normalizeerror::Bool` determines whether to scale the error by the maximum absolute value of `f` found during sampling. If set to `false`, the algorithm continues until the *absolute* error is below `tolerance`. If set to `true`, the algorithm uses the absolute error divided by the maximum sample instead. This is helpful if the magnitude of the function is not known in advance. Default: `true`.
628628
- `ncheckhistory::Int` is the number of history points to use for convergence checks. Default: `3`.
629629
- `maxnglobalpivot::Int` can be set to `>= 0`. Default: `5`.
630-
- `nsearchglobalpivot::Int` can be set to `>= 0`. Default: `0`.
630+
- `nsearchglobalpivot::Int` can be set to `>= 0`. Default: `5`.
631631
- `tolmarginglobalsearch` can be set to `>= 1.0`. Seach global pivots where the interpolation error is larger than the tolerance by `tolmarginglobalsearch`. Default: `10.0`.
632632
- `strictlynested::Bool` determines whether to preserve partial nesting in the TCI algorithm. Default: `false`.
633633
- `checkbatchevaluatable::Bool` Check if the function `f` is batch evaluatable. Default: `false`.
@@ -653,7 +653,7 @@ function optimize!(
653653
normalizeerror::Bool=true,
654654
ncheckhistory::Int=3,
655655
maxnglobalpivot::Int=5,
656-
nsearchglobalpivot::Int=0,
656+
nsearchglobalpivot::Int=5,
657657
tolmarginglobalsearch::Float64=10.0,
658658
strictlynested::Bool=false,
659659
checkbatchevaluatable::Bool=false
@@ -776,7 +776,7 @@ function sweep2site!(
776776
sweepstrategy::Symbol=:backandforth,
777777
pivotsearch::Symbol=:full,
778778
verbosity::Int=0,
779-
strictlynested::Bool=true,
779+
strictlynested::Bool=false,
780780
fillsitetensors::Bool=true
781781
) where {ValueType}
782782
invalidatesitetensors!(tci)
@@ -850,9 +850,9 @@ end
850850
normalizeerror::Bool=true,
851851
ncheckhistory=3,
852852
maxnglobalpivot::Int=5,
853-
nsearchglobalpivot::Int=0,
853+
nsearchglobalpivot::Int=5,
854854
tolmarginglobalsearch::Float64=10.0,
855-
strictlynested::Bool=true
855+
strictlynested::Bool=false
856856
) where {ValueType,N}
857857
858858
Cross interpolate a function ``f(\mathbf{u})`` using the TCI2 algorithm. Here, the domain of ``f`` is ``\mathbf{u} \in [1, \ldots, d_1] \times [1, \ldots, d_2] \times \ldots \times [1, \ldots, d_{\mathscr{L}}]`` and ``d_1 \ldots d_{\mathscr{L}}`` are the local dimensions.
@@ -873,9 +873,9 @@ Arguments:
873873
- `normalizeerror::Bool` determines whether to scale the error by the maximum absolute value of `f` found during sampling. If set to `false`, the algorithm continues until the *absolute* error is below `tolerance`. If set to `true`, the algorithm uses the absolute error divided by the maximum sample instead. This is helpful if the magnitude of the function is not known in advance. Default: `true`.
874874
- `ncheckhistory::Int` is the number of history points to use for convergence checks. Default: `3`.
875875
- `maxnglobalpivot::Int` can be set to `>= 0`. Default: `5`.
876-
- `nsearchglobalpivot::Int` can be set to `>= 0`. Default: `0`.
876+
- `nsearchglobalpivot::Int` can be set to `>= 0`. Default: `5`.
877877
- `tolmarginglobalsearch` can be set to `>= 1.0`. Seach global pivots where the interpolation error is larger than the tolerance by `tolmarginglobalsearch`. Default: `10.0`.
878-
- `strictlynested::Bool=true` determines whether to preserve partial nesting in the TCI algorithm. Default: `true`.
878+
- `strictlynested::Bool=false` determines whether to preserve partial nesting in the TCI algorithm. Default: `true`.
879879
- `checkbatchevaluatable::Bool` Check if the function `f` is batch evaluatable. Default: `false`.
880880
881881
Notes:

test/runtests.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import TensorCrossInterpolation as TCI
22
using Test
33
using LinearAlgebra
44

5-
#==
65
include("test_with_aqua.jl")
76
include("test_with_jet.jl")
87
include("test_util.jl")
@@ -20,5 +19,4 @@ include("test_tensortrain.jl")
2019
include("test_conversion.jl")
2120
include("test_contraction.jl")
2221
include("test_integration.jl")
23-
==#
2422
include("test_globalsearch.jl")

0 commit comments

Comments
 (0)