Skip to content

Commit

Permalink
Merge pull request #50 from kahaaga/kah/plotrecipes
Browse files Browse the repository at this point in the history
Plot recipes
  • Loading branch information
kahaaga committed Nov 29, 2018
2 parents 7508727 + 594aac8 commit 02ea6a3
Show file tree
Hide file tree
Showing 20 changed files with 771 additions and 371 deletions.
42 changes: 24 additions & 18 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ version = "0.3.2"

[[DiffEqBase]]
deps = ["Compat", "IteratorInterfaceExtensions", "LinearAlgebra", "RecipesBase", "RecursiveArrayTools", "Requires", "Roots", "SparseArrays", "StaticArrays", "Statistics", "SuiteSparse", "TableTraits", "Test", "TreeViews"]
git-tree-sha1 = "a79e0d74bdc91d4dfc501fe03af762b48cbc3764"
git-tree-sha1 = "b8c9c5a296e426d0ad978e6e7ad699dde444d3a1"
uuid = "2b5f629d-d688-5b77-993f-72d75c75574e"
version = "4.31.0"
version = "4.31.1"

[[DiffEqBiological]]
deps = ["Compat", "DataStructures", "DiffEqBase", "DiffEqJump", "MacroTools", "Random", "Reexport", "Statistics", "SymEngine", "Test"]
Expand Down Expand Up @@ -232,10 +232,10 @@ uuid = "055956cb-9e8b-5191-98cc-73ae4a59e68a"
version = "3.1.0"

[[DiffEqSensitivity]]
deps = ["Compat", "DiffEqBase", "DiffEqCallbacks", "DiffEqDiffTools", "ForwardDiff", "LinearAlgebra", "QuadGK", "RecursiveArrayTools", "Statistics", "Test"]
git-tree-sha1 = "cc4716516bd4a60e092e8a909efcbd26170cd358"
deps = ["Compat", "DiffEqBase", "DiffEqCallbacks", "DiffEqDiffTools", "ForwardDiff", "LinearAlgebra", "QuadGK", "RecursiveArrayTools", "ReverseDiff", "Statistics", "Test"]
git-tree-sha1 = "76f33416ee523314b7fcdc08696408861489c427"
uuid = "41bf760c-e81c-5289-8e54-58b1f1f8abe2"
version = "2.2.0"
version = "2.3.0"

[[DiffEqUncertainty]]
deps = ["DiffEqBase", "Test"]
Expand Down Expand Up @@ -378,9 +378,9 @@ uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[Interpolations]]
deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"]
git-tree-sha1 = "2a3b97b4f4cd6f6be5c73f07b15a30e9eaba465d"
git-tree-sha1 = "3493536a64dae5a21c0cc8aecf680647f3e12313"
uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
version = "0.10.6"
version = "0.11.0"

[[IteratorInterfaceExtensions]]
deps = ["Test"]
Expand Down Expand Up @@ -518,9 +518,9 @@ version = "1.0.2"

[[OrdinaryDiffEq]]
deps = ["DataStructures", "DiffEqBase", "DiffEqDiffTools", "DiffEqOperators", "ExponentialUtilities", "ForwardDiff", "GenericSVD", "InteractiveUtils", "LinearAlgebra", "Logging", "MuladdMacro", "NLsolve", "Parameters", "Printf", "Random", "RecursiveArrayTools", "Reexport", "SparseArrays", "StaticArrays", "Statistics", "Test"]
git-tree-sha1 = "44b786ca14842e30eba2656d83c7055f8a20b74d"
git-tree-sha1 = "06b6488f3f17f816de2c96fc071a8115b84ca736"
uuid = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
version = "4.17.2"
version = "4.18.0"

[[PDMats]]
deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"]
Expand Down Expand Up @@ -548,9 +548,9 @@ version = "0.1.2"

[[PerronFrobenius]]
deps = ["Conda", "Distributed", "Documenter", "InplaceOps", "LinearAlgebra", "Parameters", "Printf", "PyCall", "RecipesBase", "Reexport", "SharedArrays", "Simplices", "SparseArrays", "StateSpaceReconstruction", "StaticArrays", "Test"]
git-tree-sha1 = "6c1471a5c3c36859c62e48d8b4c793ac16fae4d8"
git-tree-sha1 = "7695c740e987c4d8902dfc6375810a128654393a"
uuid = "260eed61-d0e8-5f1e-b040-a9756a401c97"
version = "0.2.0"
version = "0.2.2"

[[Pkg]]
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
Expand Down Expand Up @@ -658,6 +658,12 @@ git-tree-sha1 = "263fe0a06007bf5ba8f72c55475f58fc9bf81834"
uuid = "ae5879a3-cd67-5da8-be7f-38c6eb64a37b"
version = "0.5.0"

[[ReverseDiff]]
deps = ["DiffResults", "DiffRules", "ForwardDiff", "FunctionWrappers", "LinearAlgebra", "NaNMath", "Random", "SpecialFunctions", "StaticArrays", "Statistics", "Test"]
git-tree-sha1 = "d44e80d815a1a5abaf1ff1def21bb629cabaffec"
uuid = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
version = "0.3.1"

[[Rmath]]
deps = ["BinaryProvider", "Libdl", "Random", "Statistics", "Test"]
git-tree-sha1 = "9a6c758cdf73036c3239b0afbea790def1dabff9"
Expand Down Expand Up @@ -694,9 +700,9 @@ version = "0.8.0"

[[Simplices]]
deps = ["Conda", "Distributions", "Documenter", "LinearAlgebra", "Parameters", "Printf", "PyCall", "StaticArrays", "Test"]
git-tree-sha1 = "4e96805d9ab3413ab3b82883b61fdea14dfcc33e"
git-tree-sha1 = "36b8816dc8297a39d3ad56b32e0cf61e333121fc"
uuid = "d5428e67-3037-59ba-9ab1-57a04f0a3b6a"
version = "0.2.1"
version = "0.2.2"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
Expand All @@ -718,10 +724,10 @@ uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "0.7.2"

[[StateSpaceReconstruction]]
deps = ["Conda", "Distributions", "LinearAlgebra", "PyCall", "Reexport", "Simplices", "StaticArrays", "Statistics", "Test"]
git-tree-sha1 = "1137310fbd695e00b5bcdaf68677b6383e6e1151"
deps = ["Conda", "Distances", "Distributions", "LinearAlgebra", "NearestNeighbors", "PyCall", "Reexport", "Simplices", "StaticArrays", "Statistics", "Test"]
git-tree-sha1 = "211298d65326fd109bb00c92ce0adca0f4c09435"
uuid = "1441a9f6-6a74-5418-a591-cdf1d78a07f0"
version = "0.3.0"
version = "0.3.1"

[[StaticArrays]]
deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"]
Expand All @@ -735,9 +741,9 @@ uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[StatsBase]]
deps = ["DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"]
git-tree-sha1 = "723193a13e8078cec6dcd0b8fe245c8bfd81690e"
git-tree-sha1 = "2722397d88f8ffef551948f6c20e1d74a743298c"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.25.0"
version = "0.26.0"

[[StatsFuns]]
deps = ["Rmath", "SpecialFunctions", "Test"]
Expand Down
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ DocumenterMarkdown = "997ab1e6-3595-5248-9280-8efb232c3433"
DynamicalSystems = "61744808-ddfa-5f27-97ff-6e42cc95d634"
DynamicalSystemsBase = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
PerronFrobenius = "260eed61-d0e8-5f1e-b040-a9756a401c97"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Expand All @@ -24,6 +26,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Simplices = "d5428e67-3037-59ba-9ab1-57a04f0a3b6a"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StateSpaceReconstruction = "1441a9f6-6a74-5418-a591-cdf1d78a07f0"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimeseriesSurrogates = "c804724b-8c18-5caa-8579-6025a0767c70"
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ Check out the documentation (coming) for more information!

| package | functionality | version | build |
| :--- | :--- | :---: | ---: |
| [`StateSpaceReconstruction.jl`](https://github.com/kahaaga/StateSpaceReconstruction.jl/) | Fully flexible state space reconstructions (embeddings), partitioning routines (variable-width rectangular, and triangulations), and partition refinement (equal-volume splitting of simplices). | `0.2.3` | [![Build Status](https://travis-ci.org/kahaaga/StateSpaceReconstruction.jl.svg?branch=master)](https://travis-ci.org/kahaaga/StateSpaceReconstruction.jl) |
| [`StateSpaceReconstruction.jl`](https://github.com/kahaaga/StateSpaceReconstruction.jl/) | Fully flexible state space reconstructions (embeddings), partitioning routines (variable-width rectangular, and triangulations), and partition refinement (equal-volume splitting of simplices). | `0.3.1` | [![Build Status](https://travis-ci.org/kahaaga/StateSpaceReconstruction.jl.svg?branch=master)](https://travis-ci.org/kahaaga/StateSpaceReconstruction.jl) |
| [`TimeseriesSurrogates.jl`](https://github.com/kahaaga/TimeseriesSurrogates.jl/) | Generate surrogate data from time series. | `0.2.1` | [![Build Status](https://travis-ci.org/kahaaga/TimeseriesSurrogates.jl.svg?branch=master)](https://travis-ci.org/kahaaga/TimeseriesSurrogates.jl) |
| [`TransferEntropy.jl`](https://github.com/kahaaga/TransferEntropy.jl/) | Transfer entropy estimators. | `0.2.3` | [![Build Status](https://travis-ci.org/kahaaga/TransferEntropy.jl.svg?branch=master)](https://travis-ci.org/kahaaga/TransferEntropy.jl) | |
| [`PerronFrobenius.jl`](https://github.com/kahaaga/PerronFrobenius.jl/) | Transfer (Perron-Frobenius) operator estimators. | `0.1.3`  | [![Build Status](https://travis-ci.org/kahaaga/PerronFrobenius.jl.svg?branch=master)](https://travis-ci.org/kahaaga/PerronFrobenius.jl) |
| [`Simplices.jl`](https://github.com/kahaaga/Simplices.jl/) | Exact simplex intersections in N dimensions. | `0.2.1` | [![Build Status](https://travis-ci.org/kahaaga/Simplices.jl.svg?branch=master)](https://travis-ci.org/kahaaga/Simplices.jl) |
| [`TransferEntropy.jl`](https://github.com/kahaaga/TransferEntropy.jl/) | Transfer entropy estimators. | `0.3.1` | [![Build Status](https://travis-ci.org/kahaaga/TransferEntropy.jl.svg?branch=master)](https://travis-ci.org/kahaaga/TransferEntropy.jl) | |
| [`PerronFrobenius.jl`](https://github.com/kahaaga/PerronFrobenius.jl/) | Transfer (Perron-Frobenius) operator estimators. | `0.2.2`  | [![Build Status](https://travis-ci.org/kahaaga/PerronFrobenius.jl.svg?branch=master)](https://travis-ci.org/kahaaga/PerronFrobenius.jl) |
| [`Simplices.jl`](https://github.com/kahaaga/Simplices.jl/) | Exact simplex intersections in N dimensions. | `0.2.2` | [![Build Status](https://travis-ci.org/kahaaga/Simplices.jl.svg?branch=master)](https://travis-ci.org/kahaaga/Simplices.jl) |
| [`CrossMappings.jl`](https://github.com/kahaaga/CrossMappings.jl/) | Exact simplex intersections in N dimensions. | `0.2.0` | [![Build Status](https://travis-ci.org/kahaaga/CrossMappings.jl.svg?branch=master)](https://travis-ci.org/kahaaga/CrossMappings.jl) |


## Wrappers for common use cases
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ DynamicalSystems
NearestNeighbors
Interpolations
PerronFrobenius 0.2.0
Plots
PyCall
RecipesBase
Reexport
Simplices 0.2.1
StaticArrays
StateSpaceReconstruction 0.3.0
TimeseriesSurrogates 0.2.1
TransferEntropy 0.3.1
Measures
13 changes: 13 additions & 0 deletions install_dependencies.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if VERSION >= v"0.7.0-"
# Adding Pkg in test/REQUIRE would be an error in 0.6. Using
# Project.toml still has some gotchas. So:
Pkg = Base.require(Base.PkgId(Base.UUID(0x44cfe95a1eb252eab672e2afdf69b78f), "Pkg"))
end

# Let PyCall.jl use Python interpreter from Conda.jl
# See: https://github.com/JuliaPy/PyCall.jl
ENV["PYTHON"] = ""
Pkg.build("PyCall")

using Conda
Conda.add("scipy")
22 changes: 22 additions & 0 deletions runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if lowercase(get(ENV, "CI", "false")) == "true"
include("install_dependencies.jl")
end

using TransferEntropy
using Test
using Distances


n_realizations = 50

@testset "Visitation frequency estimator" begin
include("transferentropy/test_transferentropy_visitfreq.jl")
end

@testset "kNN (Kraskov) estimator" begin
include("transferentropy/test_transferentropy_kraskov.jl")
end

@testset "Transfer operator grid estimator" begin
include("transferentropy/test_transferentropy_transferoperator_grid.jl")
end
7 changes: 6 additions & 1 deletion src/CausalityTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ using Reexport
using AbstractFFTs
using Statistics
using RecipesBase
using Plots
using StaticArrays
using LinearAlgebra
using Measures


@reexport using TimeseriesSurrogates
Expand All @@ -31,6 +33,9 @@ include("surrogates/surrogates.jl")
# Wrappers of the different methods.
include("method_wrappers/highlevel_methods.jl")

# Plot recipes, also for all sub-packages
include("plot_recipes/recipes.jl")

export
Dataset,
DynamicalSystem,
Expand Down
112 changes: 112 additions & 0 deletions src/plot_recipes/helperfunctions_rectangulargrid.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#########################################################
# Helper functions to plot 3D rectangles.
#########################################################
"""
rectangle3dpts(x, y, z, ϵx, ϵy, ϵz)
Compute the coordinates of the vertices of a 3D rectangle, given the
coordinates of the origin (`x`, `y`, and `z`) and the corresponding edge lengths
(`ϵx`, `ϵy`, `ϵz`).
"""
function rectangle3dpts(x, y, z, ϵx, ϵy, ϵz)
v1b = [x, y, z]
v2b = [x+ϵx, y, z]
v3b = [x+ϵx, y+ϵy, z]
v4b = [x, y+ϵy, z]
v1t = [x, y, z+ϵz]
v2t = [x+ϵx, y, z+ϵz]
v3t = [x+ϵx, y+ϵy, z+ϵz]
v4t = [x, y+ϵy, z+ϵz]
(v1b, v2b, v3b, v4b, v1t, v2t, v3t, v4t)
end

"""
rectangle3dpts(o, ϵ)
Given the origin `o` (3-element vector) and edge lengths `ϵ` (also a
3-element vector) of a 3D rectangle, return the coordinates of its
vertices.
"""
function rectangle3dpts(o, ϵ)
x, y, z = (o...,)
ϵx, ϵy, ϵz =...,)
rectangle3dpts(x, y, z, ϵx, ϵy, ϵz)
end

"""
connectvertices(o, ϵ)
Given the origin `o` (3-element vector) and edge lengths `ϵ` (also a
3-element vector) of a 3D rectangle, return a vector of line segments
(each a dim-by-n_vertices array) that when plotted together yields
the entire rectangle.
"""
function connectvertices(o, ϵ)
# Get the vertices
v1b, v2b, v3b, v4b, v1t, v2t, v3t, v4t = rectangle3dpts(o, ϵ)

# Connect vertices in top and bottom planes
connect_top = zeros(3, 5)
connect_bottom = zeros(3, 5)

# Connect corners of the top and bottom planes
corner1 = zeros(3, 2)
corner2 = zeros(3, 2)
corner3 = zeros(3, 2)
corner4 = zeros(3, 2)
connect_bottom[:, 1:5] = [v1b v2b v3b v4b v1b]
connect_top[:, 1:5= [v1t v2t v3t v4t v1t]
corner1[:, 1:2] = [v1b v1t]
corner2[:, 1:2] = [v2b v2t]
corner3[:, 1:2] = [v3b v3t]
corner4[:, 1:2] = [v4b v4t]

return [connect_top, connect_bottom,
corner1, corner2, corner3, corner4]
end

"""
splitaxes(x)
Return a vector of the individual components of an array of points
provided as an array where each point is a column.
"""
splitaxes(x) = ([x[k, :] for k = 1:size(x, 1)]...,)

"""
plot_3D_rect!(p, origin, edgelengths;
lc = :black, lw = 1.0, ls = :solid)
Append a a 3D rectangle to an existing plot `p`, given the
origin `o` (3-element vector) and edge lengths
`ϵ` (3-element vector) of the rectangle.
"""
function plot_3D_rect!(p, o, ϵ;
lc = :black, lw = 1.0, ls = :solid, lα = 0.7)

linesegments = connectvertices(o, ϵ)
for segment in linesegments
plot!(p, splitaxes(segment),
lc = lc, lw = lw, ls = ls, lα = lα)
end
end

"""
Given the `origin` of a hyperrectangle and the `stepsizes` along each
coordinate axis, divide each axis into `N` stepsizes starting
from `origin[i] + (stepsizes[i]/N)/2`
"""
function fill_hyperrectangle_3D(origin, stepsizes, N = 10)
xs, ys, zs = ([LinRange(origin[i] + stepsizes[i]/N/2, origin[i] + stepsizes[i] - stepsizes[i]/N/2, N) for i = 1:length(origin)]...,)
pts = zeros(Float64, 3, length(xs)^3)
i = 0
for x in xs
for y in ys
for z in zs
i += 1
pts[:, i] = [x, y, z]
end
end
end
pts
end
Loading

0 comments on commit 02ea6a3

Please sign in to comment.