Skip to content

Commit

Permalink
Merge pull request #41 from tensor4all/40-estimatetrueerror-does-not-…
Browse files Browse the repository at this point in the history
…stop-if-the-error-is-close-to-machine-precision

Fixed possible infinite loop in estimatetrueerror
  • Loading branch information
shinaoka authored Sep 4, 2024
2 parents 99c552a + 361dc1a commit 8383afd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/globalsearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ function _floatingzone(
)
err = vec(abs.(exactdata .- prediction))
pivot[ipos] = argmax(err)
maxerror = maximum(err)
# In RHS, we compare the maximum of the error vector with the current maxerror
# to make sure that the error does not decrease even if maxerror is close to machine precision.
maxerror = max(maximum(err), maxerror)
end

if maxerror == prev_maxerror || maxerror > earlystoptol # early stop
Expand Down
2 changes: 1 addition & 1 deletion test/test_globalsearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ import QuanticsGrids as QD
pivoterrors = TCI.estimatetrueerror(TCI.TensorTrain(tci), f)

errors = [e for (_, e) in pivoterrors]
@test all([abs(f(p) - tci(p)) for (p, _) in pivoterrors] .== errors)
@test [abs(f(p) - tci(p)) for (p, _) in pivoterrors] errors
@test all(errors[1:end-1] .>= errors[2:end]) # check if errors are sorted in descending order
end

0 comments on commit 8383afd

Please sign in to comment.