Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edited warnings #144

Merged
merged 2 commits into from
Sep 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/compute_fp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ be an approximation to the fixed point of `T`.
* `v::TV`: The initial condition. An object of type `TV`
* `;err_tol(1e-3)`: Stopping tolerance for iterations
* `;max_iter(50)`: Maximum number of iterations
* `;verbose(true)`: Whether or not to print status updates to the user
* `;print_skip(10)` : if `verbose` is true, how many iterations to apply between
print messages
* `;verbose(2)`: Level of feedback (0 for no output, 1 for warnings only, 2
for warning and convergence messages during iteration)
* `;print_skip(10)` : if `verbose == 2`, how many iterations to apply between
print messages

##### Returns
---
Expand All @@ -47,26 +48,37 @@ x_star = compute_fixed_point(x->T(x, 0.3), 0.4) # (4μ - 1)/(4μ)
```

"""
function compute_fixed_point{TV}(T::Function, v::TV; err_tol=1e-3,
max_iter=50, verbose=true, print_skip=10)
function compute_fixed_point{TV}(T::Function,
v::TV;
err_tol=1e-4,
max_iter=100,
verbose=2,
print_skip=10)

if !(verbose in (0, 1, 2))
throw(ArgumentError("verbose should be 0, 1 or 2"))
end

iterate = 0
err = err_tol + 1
while iterate < max_iter && err > err_tol
new_v = T(v)::TV
iterate += 1
err = Base.maxabs(new_v - v)
if verbose
if verbose == 2
if iterate % print_skip == 0
println("Compute iterate $iterate with error $err")
end
end
v = new_v
end

if iterate < max_iter && verbose
println("Converged in $iterate steps")
elseif iterate == max_iter
warn("max_iter attained in compute_fixed_point")
if verbose >= 1
if iterate == max_iter
warn("max_iter attained in compute_fixed_point")
elseif verbose == 2
println("Converged in $iterate steps")
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

if verbose >= 1
    if iterate == max_iter
        warn("max_iter attained in compute_fixed_point")
    elseif verbose == 2
        println("Converged in $iterate steps")
    end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's much better ;-)

I'll make the change.


return v
Expand Down