andergray / intervalunionarithmetic.jl Goto Github PK
View Code? Open in Web Editor NEWAn implementation of interval union arithmetic in Julia
License: MIT License
An implementation of interval union arithmetic in Julia
License: MIT License
julia> a = interval(0,360)
julia> b = intervalUnion([interval(x...) for x in [[2.79673, 8.91372], [39.2939, 56.4471], [67.1466, 70.1468], [80.2861, 93.2176], [110.055, 130.796], [139.832, 142.835], [151.597, 154.8], [175.313, 178.315], [188.508, 200.028], [234.445, 246.861], [272.586, 275.589], [286.656, 298.892], [315.723, 318.724], [333.795, 343.149], [362.617, 372.152], [388.38, 398.013], [420.947, 438.171], [448.538, 451.541], [470.079, 478.298], [494.766, 505.138], [515.836, 521.239], [539.73, 564.545], [582.778, 595.462], [617.058, 621.725], [631.357, 634.36], [644.533, 647.535], [666.469, 670.569], [688.826, 704.525], [713.249, 716.25], [740.816, 745.865], [764.322, 785.23], [794.686, 797.688], [809.239, 812.241], [821.892, 829.197], [845.522, 848.524], [860.125, 881.507], [896.821, 902.851], [913.554, 916.557], [925.626, 928.629] , [937.907, 940.909] , [953.773, 966.779] , [979.707, 982.709] , [992.479, 995.481] , [1004.19, 1007.21] , [1018.72, 1042.07] , [1055.94, 1071.58] , [1091.95, 1105.8] , [1125.04, 1129.45] , [1140.79, 1151.73] , [1160.92, 1172.92] , [1183.24, 1207.91] , [1224.19, 1233.81] , [1252.02, 1255.77] , [1273.52, 1276.54] , [1291.92, 1294.94] , [1307.19, 1319.72] , [1331.31, 1342.02] , [1354.02, 1361.17] , [1371.06, 1379.12] , [1395.09, 1398.11] , [1408.4, 1411.42] , [1421.66, 1430.58] , [1447.54, 1450.56] , [1462.94, 1480.01] , [1507.29, 1515.55] , [1526.6, 1529.62] , [1542.84, 1545.86] , [1559.41, 1562.43] , [1573.36, 1577.9] , [1597.89, 1603.73] , [1623.08, 1646.25] , [1669.9, 1685.05] , [1697.35, 1700.37] , [1722.14, 1748.25] , [1764.96, 1791.44] , [1804.68, 1808.32] , [1840.8, 1853.31] , [1865.21, 1868.23] , [1878.51, 1884.73] , [1901.24, 1904.97] , [1927.78, 1932.05] , [1949.6, 1954.92] , [1972, 1984.02] , [1997.24, 2000.25] , [2013.48, 2043.86] , [2056.4, 2059.43] , [2074.69, 2077.72] , [2086.82, 2089.85] , [2101.82, 2106.68] , [2116.44, 2119.47] , [2135.3, 2148.33] , [2162.94, 2173.99] , [2193.26, 2196.29] , [2206.51, 2225.08] , [2242.53, 2245.54] , [2254.69, 2257.7] , [2274.09, 2289.49] , [2312.13, 2336.16] , [2356.9, 2367.83] , [2376.17, 2383.41]]
])
julia> a∩b
BoundsError: attempt to access 100-element Vector{Interval{Float64}} at index [0]
Stacktrace:
[1] getindex
@ ./array.jl:861 [inlined]
[2] partition!(v::Vector{Interval{Float64}}, lo::Int64, hi::Int64, o::Base.Order.ForwardOrdering)
@ Base.Sort ./sort.jl:564
[3] sort!(v::Vector{Interval{Float64}}, lo::Int64, hi::Int64, a::Base.Sort.QuickSortAlg, o::Base.Order.ForwardOrdering)
@ Base.Sort ./sort.jl:575
[4] sort!(v::Vector{Interval{Float64}}, lo::Int64, hi::Int64, a::Base.Sort.QuickSortAlg, o::Base.Order.ForwardOrdering)
@ Base.Sort ./sort.jl:580
[5] sort!
@ ./sort.jl:662 [inlined]
[6] #sort!#8
@ ./sort.jl:723 [inlined]
[7] sort!
@ ./sort.jl:711 [inlined]
[8] intervalUnion
@ ~/.julia/packages/IntervalUnionArithmetic/uttGJ/src/interval_unions.jl:37 [inlined]
[9] intersect(x::Interval{Float64}, y::IntervalUnion{Float64})
@ IntervalUnionArithmetic ~/.julia/packages/IntervalUnionArithmetic/uttGJ/src/set_operations.jl:68
[10] top-level scope
@ In[232]:4
[11] eval
@ ./boot.jl:373 [inlined]
[12] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1196```
julia> using IntervalUnionArithmetic
julia> union(Interval(0,1))\union(Interval(0.1,0.8))
[0, 0.100001] ∪ [0.8, 1]
julia> union(Interval(0,1))\Interval(0.1,0.8)
[0.1, ∞]ᵤ
Is it possible to get the size of the union? e.g. [0,10] ∪ [30,40] |> diam
to 20
?
julia> x = intervalUnion([Interval(i,i+0.5) for i=1:200])
[1, 101.5] ∪ [102, 102.5] ∪ [103, 103.5] ∪ [104, 104.5] ∪ [105, 105.5] ∪ [106, 106.5] ∪ [107, 107.5] ∪ [108, 108.5] ∪ [109, 109.5] ∪ [110, 110.5] ∪ [111, 111.5] ∪ [112, 112.5] ∪ [113, 113.5] ∪ [114, 114.5] ∪ [115, 115.5] ∪ [116, 116.5] ∪ [117, 117.5] ∪ [118, 118.5] ∪ [119, 119.5] ∪ [120, 120.5] ∪ [121, 121.5] ∪ [122, 122.5] ∪ [123, 123.5] ∪ [124, 124.5] ∪ [125, 125.5] ∪ [126, 126.5] ∪ [127, 127.5] ∪ [128, 128.5] ∪ [129, 129.5] ∪ [130, 130.5] ∪ [131, 131.5] ∪ [132, 132.5] ∪ [133, 133.5] ∪ [134, 134.5] ∪ [135, 135.5] ∪ [136, 136.5] ∪ [137, 137.5] ∪ [138, 138.5] ∪ [139, 139.5] ∪ [140, 140.5] ∪ [141, 141.5] ∪ [142, 142.5] ∪ [143, 143.5] ∪ [144, 144.5] ∪ [145, 145.5] ∪ [146, 146.5] ∪ [147, 147.5] ∪ [148, 148.5] ∪ [149, 149.5] ∪ [150, 150.5] ∪ [151, 151.5] ∪ [152, 152.5] ∪ [153, 153.5] ∪ [154, 154.5] ∪ [155, 155.5] ∪ [156, 156.5] ∪ [157, 157.5] ∪ [158, 158.5] ∪ [159, 159.5] ∪ [160, 160.5] ∪ [161, 161.5] ∪ [162, 162.5] ∪ [163, 163.5] ∪ [164, 164.5] ∪ [165, 165.5] ∪ [166, 166.5] ∪ [167, 167.5] ∪ [168, 168.5] ∪ [169, 169.5] ∪ [170, 170.5] ∪ [171, 171.5] ∪ [172, 172.5] ∪ [173, 173.5] ∪ [174, 174.5] ∪ [175, 175.5] ∪ [176, 176.5] ∪ [177, 177.5] ∪ [178, 178.5] ∪ [179, 179.5] ∪ [180, 180.5] ∪ [181, 181.5] ∪ [182, 182.5] ∪ [183, 183.5] ∪ [184, 184.5] ∪ [185, 185.5] ∪ [186, 186.5] ∪ [187, 187.5] ∪ [188, 188.5] ∪ [189, 189.5] ∪ [190, 190.5] ∪ [191, 191.5] ∪ [192, 192.5] ∪ [193, 193.5] ∪ [194, 194.5] ∪ [195, 195.5] ∪ [196, 196.5] ∪ [197, 197.5] ∪ [198, 198.5] ∪ [199, 199.5] ∪ [200, 200.5]
This is done on purpose in the function closeGaps!
... why is this needed?
I suggest renaming IntervalU
to IntervalUnion
for better readability.
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
julia> x = 1..2
[1, 2]
julia> IntervalU(x)
ERROR: MethodError: no method matching IntervalU(::Interval{Float64})
IntervalUnion{T<:Real} <: AbstractInterval{T}
but I don't see why it is a subtype of AbstractInterval{T}
. Isn't the point of this library that a union of intervals isn't necessarily an interval?
Loading this package pirates the union
operator from IntervalArithmetic.
I guess this is OK but it should be documented.
Currently there is no way to visually distinguish a single interval from an interval union containing a single interval.
julia> x = 1..2
[1, 2]
julia> IntervalU([x])
[1, 2]
The empty union could be represented by a vector of Intervals
of length == 0 (i.e. a union of no intervals) instead of a vector of length
== 1 with a single empty set (i.e. a union of a single empty set). This could simplify the code a bit, because there will be no need to keep always an empty Interval
in the stored vector.
Originally posted by @abraunst in #18 (comment)
julia> using IntervalUnionArithmetic
julia> intervalUnion(1,2) == Interval(1,2) ∪ ∅
false
julia> intervalUnion(1,2) == ∅
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Vector{Interval{Float64}}
Closest candidates are:
convert(::Type{T}, ::LinearAlgebra.Factorization) where T<:AbstractArray at ~/src/julia/build1.7/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/factorization.jl:58
...
I was expecting the output of this union to just have two elements, but it has 51.
using IntervalUnionArithmetic, IntervalArithmetic
f(x) = x > 1 ? x-1 : x;
X = 0.9..1.1
outU = intervalUnion( f.( mince(X, 100) ) )
[0.002, 0.00600001] ∪ [0.006, 0.0100001] ∪ [0.01, 0.0140001] ∪ [0.014, 0.0180001] ∪ [0.018, 0.0220001] ∪ [0.022, 0.0260001] ∪ [0.026, 0.0300001] ∪ [0.03, 0.0340001] ∪ [0.034, 0.0380001] ∪ [0.038, 0.0420001] ∪ [0.042, 0.0460001] ∪ [0.046, 0.0500001] ∪ [0.05, 0.0540001] ∪ [0.054, 0.0580001] ∪ [0.058, 0.0620001] ∪ [0.062, 0.0660001] ∪ [0.066, 0.0700001] ∪ [0.07, 0.0740001] ∪ [0.074, 0.0780001] ∪ [0.078, 0.0820001] ∪ [0.082, 0.0860001] ∪ [0.086, 0.0900001] ∪ [0.09, 0.0940001] ∪ [0.094, 0.0980001] ∪ [0.098, 0.100001] ∪ [0.899999, 0.904] ∪ [0.903999, 0.908] ∪ [0.907999, 0.912] ∪ [0.911999, 0.916] ∪ [0.915999, 0.92] ∪ [0.919999, 0.924] ∪ [0.923999, 0.928] ∪ [0.927999, 0.932] ∪ [0.931999, 0.936] ∪ [0.935999, 0.94] ∪ [0.939999, 0.944] ∪ [0.943999, 0.948] ∪ [0.947999, 0.952] ∪ [0.951999, 0.956] ∪ [0.955999, 0.96] ∪ [0.959999, 0.964] ∪ [0.963999, 0.968] ∪ [0.967999, 0.972] ∪ [0.971999, 0.976] ∪ [0.975999, 0.98] ∪ [0.979999, 0.984] ∪ [0.983999, 0.988] ∪ [0.987999, 0.992] ∪ [0.991999, 0.996] ∪ [0.995999, 1] ∪ [1, 1.00201]
On inspection
julia> outU[1].hi == outU[2].lo
true
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.