Giter VIP home page Giter VIP logo

convergenceplots.jl's Introduction

ConvergencePlots

This is a Julia package that makes it easy to do live tracking of the convergence of your algorithm. All the plotting is done using PyPlot.jl.

Installation

To install ConvergencePlots.jl, run the following Julia code.

using Pkg
pkg"add https://github.com/mohamed82008/ConvergencePlots.jl"

Usage

First create an empty plot:

plot = ConvergencePlot()

This will create an empty convergence plot that plots up to 100000 history points. Older points are overwritten. To specify how many history points to plot, use the constructor:

plot = ConvergencePlot(n)

where n is the number of points.

The keyword arguments you can pass to the ConvergencePlot constructor are:

  • names: a Vector{String} that has all the names of the convergence metrics to be plotted. The default value of names is ["Residual"].
  • options: a dictionary mapping each name in names to a NamedTuple. Each named tuple has the plotting options to pass to PyPlot, e.g. (label = "KKT residual", ls = "--", marker = "+"). If label is not passed, it defaults to the corresponding name in names. You can also pass a single NamedTuple of options without the label option, and it will be used for all the names.
  • show: if true the empty figure will be displayed. This is false by default.

After creating an empty plot, you can add points to it as follows:

addpoint!(plot, Dict("Residual" => 1.0))

where the second argument can contain one value for each name in names. If only a single name exists, you can also use:

addpoint!(plot, 1.0)

Adding a point will display the plot by default. To stop the plot from displaying, set the show keyword argument to false.

To close the plot, call:

closeplot!(plot)

Example

using ConvergencePlots

plot = ConvergencePlot(
    names = ["KKT residual", "|Δx|", "|Δf|"],
    options = Dict(
        "KKT residual" => (color = "red",),
        "|Δx|" => (color = "blue",),
        "|Δf|" => (color = "black",),
    ),
)
kkt = 1 ./ (1:50)
Δx = 0.1 .* sqrt.(kkt)
Δf = 10 .* kkt .^ 2
for i in 1:50
    sleep(1e-4)
    addpoint!(
        plot,
        Dict(
            "KKT residual" => kkt[i],
            "|Δx|" => Δx[i],
            "|Δf|" => Δf[i],
        ),
    )
end

Figure

convergenceplots.jl's People

Contributors

mohamed82008 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.