Skip to content

Commit

Permalink
Merge pull request #8 from JuliaML/tom
Browse files Browse the repository at this point in the history
name changes
  • Loading branch information
tbreloff committed Aug 19, 2016
2 parents b4ea936 + 43338a3 commit 12d3c0a
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 126 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ a label

This package provide two different concrete implementations

- `QueueUnivalueHistory`: Logs the values using a `Dequeue`
- `VectorUnivalueHistory`: Logs the values using a `Vector`
- `QHistory`: Logs the values using a `Dequeue`
- `History`: Logs the values using a `Vector`

Supported operations for univalue histories:

Expand All @@ -51,7 +51,7 @@ Here is a little example code showing the basic usage:

```Julia
# Specify the type of value you wish to track
history = QueueUnivalueHistory(Float64)
history = QHistory(Float64)

for i = 1:100
# Store some value of the specified type
Expand All @@ -75,7 +75,7 @@ history
```

```
QueueUnivalueHistory
QHistory
types: Int64, Float64
length: 25
```
Expand Down Expand Up @@ -110,7 +110,7 @@ Supported operations for multivalue histories:
Here is a little example code showing the basic usage:

```Julia
history = DynMultivalueHistory()
history = MVHistory()

for i=1:100
x = 0.1i
Expand Down Expand Up @@ -150,7 +150,7 @@ history
```

```
DynMultivalueHistory{ValueHistories.VectorUnivalueHistory{I,V}}
MVHistory{ValueHistories.History{I,V}}
:mysin => 100 elements {Float64,Float64}
:mystring => 100 elements {Int64,ASCIIString}
:mycos => 25 elements {Float32,Float64}
Expand All @@ -175,19 +175,19 @@ Compilation already taken into account. The code can be found [here](https://git
Baseline: 100000 loops that accumulates a Float64
0.000127 seconds (5 allocations: 176 bytes)
VectorUnivalueHistory: 100000 loops tracking accumulator as Float64
History: 100000 loops tracking accumulator as Float64
0.003651 seconds (33 allocations: 4.001 MB)
VectorUnivalueHistory: Converting result into arrays
History: Converting result into arrays
0.000010 seconds (3 allocations: 96 bytes)
QueueUnivalueHistory: 100000 loops tracking accumulator as Float64
QHistory: 100000 loops tracking accumulator as Float64
0.002141 seconds (195 allocations: 1.529 MB)
QueueUnivalueHistory: Converting result into arrays
QHistory: Converting result into arrays
0.217000 seconds (1.60 M allocations: 35.067 MB, 3.63% gc time)
DynMultivalueHistory: 100000 loops tracking accumulator as Float64 and String
MVHistory: 100000 loops tracking accumulator as Float64 and String
0.185134 seconds (1.70 M allocations: 62.937 MB, 31.24% gc time)
DynMultivalueHistory: Converting result into arrays
MVHistory: Converting result into arrays
0.194542 seconds (1.39 M allocations: 28.914 MB, 25.88% gc time)
```

Expand Down
18 changes: 11 additions & 7 deletions src/ValueHistories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ export

ValueHistory,
UnivalueHistory,
VectorUnivalueHistory,
QueueUnivalueHistory,
History,
QHistory,
MultivalueHistory,
DynMultivalueHistory,
MVHistory,
@trace

include("abstract_history.jl")
include("queue_uv_history.jl")
include("vector_uv_history.jl")
include("dyn_mv_history.jl")
include("abstract.jl")
include("history.jl")
include("qhistory.jl")
include("mvhistory.jl")
include("recipes.jl")

Base.@deprecate_binding VectorUnivalueHistory History
Base.@deprecate_binding QueueUnivalueHistory QHistory
Base.@deprecate_binding DynMultivalueHistory MVHistory


end # module
File renamed without changes.
50 changes: 50 additions & 0 deletions src/history.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
type History{I,V} <: UnivalueHistory{I}
lastiter::I
iterations::Vector{I}
values::Vector{V}

function History(::Type{V}, ::Type{I})
new(typemin(I), Array(I, 0), Array(V, 0))
end
end

function History{I,V}(v::Type{V}, i::Type{I} = Int)
History{I,V}(v, i)
end

Base.length(history::History) = length(history.iterations)
Base.enumerate(history::History) = zip(history.iterations, history.values)
Base.first(history::History) = history.iterations[1], history.values[1]
Base.last(history::History) = history.iterations[end], history.values[end]
Base.get(history::History) = history.iterations, history.values

function Base.push!{I,V}(
history::History{I,V},
iteration::I,
value::V)
lastiter = history.lastiter
iteration > lastiter || throw(ArgumentError("Iterations must increase over time"))
history.lastiter = iteration
push!(history.iterations, iteration)
push!(history.values, value)
value
end

function Base.push!{I,V}(
history::History{I,V},
value::V)
lastiter = history.lastiter == typemin(I) ? zero(I) : history.lastiter
iteration = lastiter + one(history.lastiter)
history.lastiter = iteration
push!(history.iterations, iteration)
push!(history.values, value)
value
end

Base.print{I,V}(io::IO, history::History{I,V}) = print(io, "$(length(history)) elements {$I,$V}")

function Base.show{I,V}(io::IO, history::History{I,V})
println(io, "History")
println(io, " * types: $I, $V")
print(io, " * length: $(length(history))")
end
32 changes: 16 additions & 16 deletions src/dyn_mv_history.jl → src/mvhistory.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
immutable DynMultivalueHistory{H<:UnivalueHistory} <: MultivalueHistory
immutable MVHistory{H<:UnivalueHistory} <: MultivalueHistory
storage::Dict{Symbol, H}
end

function DynMultivalueHistory{H<:UnivalueHistory}(::Type{H} = VectorUnivalueHistory)
DynMultivalueHistory{H}(Dict{Symbol, H}())
function MVHistory{H<:UnivalueHistory}(::Type{H} = History)
MVHistory{H}(Dict{Symbol, H}())
end

# ==========================================================================
# Functions

Base.length(history::DynMultivalueHistory, key::Symbol) = length(history.storage[key])
Base.enumerate(history::DynMultivalueHistory, key::Symbol) = enumerate(history.storage[key])
Base.first(history::DynMultivalueHistory, key::Symbol) = first(history.storage[key])
Base.last(history::DynMultivalueHistory, key::Symbol) = last(history.storage[key])
Base.length(history::MVHistory, key::Symbol) = length(history.storage[key])
Base.enumerate(history::MVHistory, key::Symbol) = enumerate(history.storage[key])
Base.first(history::MVHistory, key::Symbol) = first(history.storage[key])
Base.last(history::MVHistory, key::Symbol) = last(history.storage[key])

function Base.push!{I,H<:UnivalueHistory,V}(
history::DynMultivalueHistory{H},
history::MVHistory{H},
key::Symbol,
iteration::I,
value::V)
Expand All @@ -30,7 +30,7 @@ function Base.push!{I,H<:UnivalueHistory,V}(
end

function Base.push!{H<:UnivalueHistory,V}(
history::DynMultivalueHistory{H},
history::MVHistory{H},
key::Symbol,
value::V)
if !haskey(history.storage, key)
Expand All @@ -43,13 +43,13 @@ function Base.push!{H<:UnivalueHistory,V}(
value
end

function Base.getindex(history::DynMultivalueHistory, key::Symbol)
function Base.getindex(history::MVHistory, key::Symbol)
history.storage[key]
end

Base.haskey(history::DynMultivalueHistory, key::Symbol) = haskey(history.storage, key)
Base.haskey(history::MVHistory, key::Symbol) = haskey(history.storage, key)

function Base.get(history::DynMultivalueHistory, key::Symbol)
function Base.get(history::MVHistory, key::Symbol)
l = length(history, key)
k, v = first(history.storage[key])
karray = zeros(typeof(k), l)
Expand All @@ -63,8 +63,8 @@ function Base.get(history::DynMultivalueHistory, key::Symbol)
karray, varray
end

function Base.show{H}(io::IO, history::DynMultivalueHistory{H})
print(io, "DynMultivalueHistory{$H}")
function Base.show{H}(io::IO, history::MVHistory{H})
print(io, "MVHistory{$H}")
for (key, val) in history.storage
print(io, "\n", " :$(key) => $(val)")
end
Expand All @@ -73,14 +73,14 @@ end
using Base.Meta

"""
Easily add to a DynMultivalueHistory object `tr`.
Easily add to a MVHistory object `tr`.
Example:
```julia
using ValueHistories, OnlineStats
v = Variance(BoundedEqualWeight(30))
tr = DynMultivalueHistory()
tr = MVHistory()
for i=1:100
r = rand()
fit!(v,r)
Expand Down
28 changes: 14 additions & 14 deletions src/queue_uv_history.jl → src/qhistory.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
type QueueUnivalueHistory{I,V} <: UnivalueHistory{I}
type QHistory{I,V} <: UnivalueHistory{I}
lastiter::I
storage::Deque{Tuple{I,V}}

function QueueUnivalueHistory(::Type{V}, ::Type{I})
function QHistory(::Type{V}, ::Type{I})
new(typemin(I), Deque{Tuple{I,V}}())
end
end

function QueueUnivalueHistory{I,V}(v::Type{V}, i::Type{I} = Int)
QueueUnivalueHistory{I,V}(v, i)
function QHistory{I,V}(v::Type{V}, i::Type{I} = Int)
QHistory{I,V}(v, i)
end

# ==========================================================================
#

Base.length(history::QueueUnivalueHistory) = length(history.storage)
Base.enumerate(history::QueueUnivalueHistory) = history.storage
Base.first(history::QueueUnivalueHistory) = front(history.storage)
Base.last(history::QueueUnivalueHistory) = back(history.storage)
Base.length(history::QHistory) = length(history.storage)
Base.enumerate(history::QHistory) = history.storage
Base.first(history::QHistory) = front(history.storage)
Base.last(history::QHistory) = back(history.storage)

function Base.push!{I,V}(
history::QueueUnivalueHistory{I,V},
history::QHistory{I,V},
iteration::I,
value::V)
lastiter = history.lastiter
Expand All @@ -31,7 +31,7 @@ function Base.push!{I,V}(
end

function Base.push!{I,V}(
history::QueueUnivalueHistory{I,V},
history::QHistory{I,V},
value::V)
lastiter = history.lastiter == typemin(I) ? zero(I) : history.lastiter
iteration = lastiter + one(history.lastiter)
Expand All @@ -40,7 +40,7 @@ function Base.push!{I,V}(
value
end

function Base.get{I,V}(history::QueueUnivalueHistory{I,V})
function Base.get{I,V}(history::QHistory{I,V})
l = length(history)
k, v = front(history.storage)
karray = zeros(I, l)
Expand All @@ -54,10 +54,10 @@ function Base.get{I,V}(history::QueueUnivalueHistory{I,V})
karray, varray
end

Base.print{I,V}(io::IO, history::QueueUnivalueHistory{I,V}) = print(io, "$(length(history)) elements {$I,$V}")
Base.print{I,V}(io::IO, history::QHistory{I,V}) = print(io, "$(length(history)) elements {$I,$V}")

function Base.show{I,V}(io::IO, history::QueueUnivalueHistory{I,V})
println(io, "QueueUnivalueHistory")
function Base.show{I,V}(io::IO, history::QHistory{I,V})
println(io, "QHistory")
println(io, " types: $I, $V")
print(io, " length: $(length(history))")
end
10 changes: 5 additions & 5 deletions src/recipes.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
_is_plotable_history(::UnivalueHistory) = false
_is_plotable_history{I,V<:Real}(::QueueUnivalueHistory{I,V}) = true
_is_plotable_history{I,V<:Real}(::VectorUnivalueHistory{I,V}) = true
_is_plotable_history{I,V<:Real}(::QHistory{I,V}) = true
_is_plotable_history{I,V<:Real}(::History{I,V}) = true

_filter_plotable_histories(h::DynMultivalueHistory) =
_filter_plotable_histories(h::MVHistory) =
filter((k,v) -> _is_plotable_history(v), h.storage)

@recipe function plot(h::Union{VectorUnivalueHistory,QueueUnivalueHistory})
@recipe function plot(h::Union{History,QHistory})
markershape --> :ellipse
title --> "Value History"
get(h)
end

@recipe function plot(h::DynMultivalueHistory)
@recipe function plot(h::MVHistory)
filtered = _filter_plotable_histories(h)
k_vec = [k for (k, v) in filtered]
v_vec = [v for (k, v) in filtered]
Expand Down
50 changes: 0 additions & 50 deletions src/vector_uv_history.jl

This file was deleted.

Loading

0 comments on commit 12d3c0a

Please sign in to comment.