Commit ad26ac05 authored by Alberto Ramos's avatar Alberto Ramos

Fully functional version, but unfortunately slow

Still some work required to avoid allocations in functions:
- uwerr
- basic Math operations
- addobs
parent 3999094f
...@@ -6,25 +6,118 @@ git-tree-sha1 = "051c95d6836228d120f5f4b984dd5aba1624f716" ...@@ -6,25 +6,118 @@ git-tree-sha1 = "051c95d6836228d120f5f4b984dd5aba1624f716"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "0.5.0" version = "0.5.0"
[[Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "0fac443759fa829ed8066db6cf1077d888bb6573"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "2.0.2"
[[ArgCheck]]
git-tree-sha1 = "59c256cf71c3982484ae4486ee86a3d7da891dea"
uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197"
version = "2.0.0"
[[BDIO]]
deps = ["Documenter", "Nettle"]
git-tree-sha1 = "60af425a7baf34c51f96dc5169f6fbf66169a58a"
repo-rev = "master"
repo-url = "https://gitlab.ift.uam-csic.es/alberto/bdio.jl.git"
uuid = "375f315e-f2c4-11e9-2ef9-134f02f79e27"
version = "0.1.0"
[[Base64]] [[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[BinDeps]]
deps = ["Compat", "Libdl", "SHA", "URIParser"]
git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9"
uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee"
version = "0.8.10"
[[BinaryProvider]]
deps = ["Libdl", "Logging", "SHA"]
git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.10"
[[Bzip2_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "3663bfffede2ef41358b6fc2e1d8a6d50b3c3904"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.6+2"
[[ColorSchemes]]
deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random", "StaticArrays"]
git-tree-sha1 = "7a15e3690529fd1042f0ab954dff7445b1efc8a5"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.9.0"
[[ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "27eb374570946a02aa184ef5b403dabaa7380693"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.10.4"
[[Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Reexport"]
git-tree-sha1 = "1e9bba7984e78aa8cdeea7f9f7cc984ad4e4b1c7"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.2"
[[CommonSubexpressions]] [[CommonSubexpressions]]
deps = ["Test"] deps = ["Test"]
git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0"
uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
version = "0.2.0" version = "0.2.0"
[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "ed2c4abadf84c53d9e58510b5fc48912c2336fbb"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "2.2.0"
[[CompilerSupportLibraries_jll]] [[CompilerSupportLibraries_jll]]
deps = ["Libdl", "Pkg"] deps = ["Libdl", "Pkg"]
git-tree-sha1 = "7c4f882c41faa72118841185afc58a2eb00ef612" git-tree-sha1 = "7c4f882c41faa72118841185afc58a2eb00ef612"
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "0.3.3+0" version = "0.3.3+0"
[[Contour]]
deps = ["StaticArrays"]
git-tree-sha1 = "0b17db36e7e03f8437e0d1f55aea3e4a60c74353"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.5.3"
[[DataAPI]]
git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.3.0"
[[DataStructures]]
deps = ["InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "edad9434967fdc0a2631a65d902228400642120c"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.17.19"
[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"
[[Dates]] [[Dates]]
deps = ["Printf"] deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
[[DefaultApplication]]
deps = ["InteractiveUtils"]
git-tree-sha1 = "fc2b7122761b22c87fec8bf2ea4dc4563d9f8c24"
uuid = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85"
version = "1.0.0"
[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
[[DiffResults]] [[DiffResults]]
deps = ["StaticArrays"] deps = ["StaticArrays"]
git-tree-sha1 = "da24935df8e0c6cf28de340b958f6aac88eaa0cc" git-tree-sha1 = "da24935df8e0c6cf28de340b958f6aac88eaa0cc"
...@@ -41,6 +134,30 @@ version = "1.0.1" ...@@ -41,6 +134,30 @@ version = "1.0.1"
deps = ["Random", "Serialization", "Sockets"] deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
[[DocStringExtensions]]
deps = ["LibGit2", "Markdown", "Pkg", "Test"]
git-tree-sha1 = "c5714d9bcdba66389612dc4c47ed827c64112997"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.2"
[[Documenter]]
deps = ["Base64", "Dates", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
git-tree-sha1 = "395fa1554c69735802bba37d9e7d9586fd44326c"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.24.11"
[[FFMPEG]]
deps = ["FFMPEG_jll"]
git-tree-sha1 = "c82bef6fc01e30d500f588cd01d29bdd44f1924e"
uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
version = "0.3.0"
[[FFMPEG_jll]]
deps = ["Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "LAME_jll", "LibVPX_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"]
git-tree-sha1 = "0fa07f43e5609ea54848b82b4bb330b250e9645b"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.1.0+3"
[[FFTW]] [[FFTW]]
deps = ["AbstractFFTs", "FFTW_jll", "IntelOpenMP_jll", "Libdl", "LinearAlgebra", "MKL_jll", "Reexport"] deps = ["AbstractFFTs", "FFTW_jll", "IntelOpenMP_jll", "Libdl", "LinearAlgebra", "MKL_jll", "Reexport"]
git-tree-sha1 = "14536c95939aadcee44014728a459d2fe3ca9acf" git-tree-sha1 = "14536c95939aadcee44014728a459d2fe3ca9acf"
...@@ -53,12 +170,71 @@ git-tree-sha1 = "6c975cd606128d45d1df432fb812d6eb10fee00b" ...@@ -53,12 +170,71 @@ git-tree-sha1 = "6c975cd606128d45d1df432fb812d6eb10fee00b"
uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a" uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a"
version = "3.3.9+5" version = "3.3.9+5"
[[FastGaussQuadrature]]
deps = ["LinearAlgebra", "SpecialFunctions"]
git-tree-sha1 = "c139e3f4c75dc489a493627c7ee44befc177420f"
uuid = "442a2c76-b920-505d-bb47-c5924d526838"
version = "0.4.2"
[[FixedPointNumbers]]
git-tree-sha1 = "8fb797c37a3b7ced4327a05ac4ca0dd6a4f1ba92"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.1"
[[ForwardDiff]] [[ForwardDiff]]
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "NaNMath", "Random", "SpecialFunctions", "StaticArrays"] deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "NaNMath", "Random", "SpecialFunctions", "StaticArrays"]
git-tree-sha1 = "869540e4367122fbffaace383a5bdc34d6e5e5ac" git-tree-sha1 = "869540e4367122fbffaace383a5bdc34d6e5e5ac"
uuid = "f6369f11-7733-5829-9624-2563aa707210" uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "0.10.10" version = "0.10.10"
[[FreeType2_jll]]
deps = ["Bzip2_jll", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "7d900f32a3788d4eacac2bfa3bf5c770179c8afd"
uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7"
version = "2.10.1+2"
[[FriBidi_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "2f56bee16bd0151de7b6a1eeea2ced190a2ad8d4"
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
version = "1.0.5+3"
[[GMP_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "4dd9301d3a027c05ec403e756ee7a60e3c367e5d"
uuid = "781609d7-10c4-51f6-84f2-b8444358ff6d"
version = "6.1.2+5"
[[GR]]
deps = ["Base64", "DelimitedFiles", "HTTP", "JSON", "LinearAlgebra", "Printf", "Random", "Serialization", "Sockets", "Test", "UUIDs"]
git-tree-sha1 = "247adbd2b33c0c4b42efa20d1e807acf6312145f"
uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
version = "0.50.1"
[[GeometryBasics]]
deps = ["IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"]
git-tree-sha1 = "c1a5a41f28a301d1bf7c393671accee56b02d207"
uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
version = "0.2.13"
[[GeometryTypes]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "StaticArrays"]
git-tree-sha1 = "34bfa994967e893ab2f17b864eec221b3521ba4d"
uuid = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
version = "0.8.3"
[[HTTP]]
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"]
git-tree-sha1 = "ec87d5e2acbe1693789efbbe14f5ea7525758f71"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.8.15"
[[IniFile]]
deps = ["Test"]
git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8"
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f"
version = "0.5.0"
[[IntelOpenMP_jll]] [[IntelOpenMP_jll]]
deps = ["Libdl", "Pkg"] deps = ["Libdl", "Pkg"]
git-tree-sha1 = "fb8e1c7a5594ba56f9011310790e03b5384998d6" git-tree-sha1 = "fb8e1c7a5594ba56f9011310790e03b5384998d6"
...@@ -69,10 +245,43 @@ version = "2018.0.3+0" ...@@ -69,10 +245,43 @@ version = "2018.0.3+0"
deps = ["Markdown"] deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
[[IterTools]]
git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
version = "1.3.0"
[[IteratorInterfaceExtensions]]
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
uuid = "82899510-4779-5014-852e-03e436cf321d"
version = "1.0.0"
[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.0"
[[LAME_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "221cc8998b9060677448cbb6375f00032554c4fd"
uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d"
version = "3.100.0+1"
[[LaTeXStrings]]
git-tree-sha1 = "de44b395389b84fd681394d4e8d39ef14e3a2ea8"
uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
version = "1.1.0"
[[LibGit2]] [[LibGit2]]
deps = ["Printf"] deps = ["Printf"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
[[LibVPX_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "e3549ca9bf35feb9d9d954f4c6a9032e92f46e7c"
uuid = "dd192d2f-8180-539f-9fb4-cc70b1dcf69a"
version = "1.8.1+1"
[[Libdl]] [[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
...@@ -89,29 +298,138 @@ git-tree-sha1 = "0ce9a7fa68c70cf83c49d05d2c04d91b47404b08" ...@@ -89,29 +298,138 @@ git-tree-sha1 = "0ce9a7fa68c70cf83c49d05d2c04d91b47404b08"
uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7" uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
version = "2020.1.216+0" version = "2020.1.216+0"
[[MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "f7d2e3f654af75f01ec49be82c231c382214223a"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.5"
[[Markdown]] [[Markdown]]
deps = ["Base64"] deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"]
git-tree-sha1 = "426a6978b03a97ceb7ead77775a1da066343ec6e"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "1.0.2"
[[MbedTLS_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "f85473aeb7a2561a5c58c06c4868971ebe2bcbff"
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.16.6+0"
[[Measures]]
git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f"
uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
version = "0.3.1"
[[Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "de0a5ce9e5289f27df672ffabef4d1e5861247d5"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "0.4.3"
[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
[[NaNMath]] [[NaNMath]]
git-tree-sha1 = "928b8ca9b2791081dc71a51c55347c27c618760f" git-tree-sha1 = "928b8ca9b2791081dc71a51c55347c27c618760f"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.3" version = "0.3.3"
[[Nettle]]
deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"]
git-tree-sha1 = "f57e8e907faab4f55f9f164313a633509ac83e2c"
uuid = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9"
version = "0.4.0"
[[Nettle_jll]]
deps = ["GMP_jll", "Libdl", "Pkg"]
git-tree-sha1 = "d69f99a48b9f5722bff9f0fa031f1c916b657017"
uuid = "4c82536e-c426-54e4-b420-14f461c4ed8b"
version = "3.4.1+1"
[[Ogg_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "59cf7a95bf5ac39feac80b796e0f39f9d69dc887"
uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051"
version = "1.3.4+0"
[[OpenSSL_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "7aaaded15bf393b5f34c2aad5b765c18d26cb495"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "1.1.1+4"
[[OpenSpecFun_jll]] [[OpenSpecFun_jll]]
deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"]
git-tree-sha1 = "d51c416559217d974a1113522d5919235ae67a87" git-tree-sha1 = "d51c416559217d974a1113522d5919235ae67a87"
uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e"
version = "0.5.3+3" version = "0.5.3+3"
[[Opus_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "002c18f222a542907e16c83c64a1338992da7e2c"
uuid = "91d4177d-7536-5919-b921-800302f37372"
version = "1.3.1+1"
[[OrderedCollections]]
git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.2.0"
[[PGFPlotsX]]
deps = ["ArgCheck", "DataStructures", "Dates", "DefaultApplication", "DocStringExtensions", "MacroTools", "Parameters", "Requires", "StatsBase"]
git-tree-sha1 = "0138f33baf8f19e7ada1184df8bf458a74388fa6"
uuid = "8314cec4-20b6-5062-9cdb-752b83310925"
version = "1.2.8"
[[Parameters]]
deps = ["OrderedCollections", "UnPack"]
git-tree-sha1 = "38b2e970043613c187bd56a995fe2e551821eb4a"
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a"
version = "0.12.1"
[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "20ef902ea02f7000756a4bc19f7b9c24867c6211"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.6"
[[Pkg]] [[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
[[PlotThemes]]
deps = ["PlotUtils", "Requires", "Statistics"]
git-tree-sha1 = "c6f5ea535551b3b16835134697f0c65d06c94b91"
uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
version = "2.0.0"
[[PlotUtils]]
deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"]
git-tree-sha1 = "e18e0e51ff07bf92bb7e06dcb9c082a4e125e20c"
uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043"
version = "1.0.5"
[[Plots]]
deps = ["Base64", "Contour", "Dates", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "GeometryTypes", "JSON", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"]
git-tree-sha1 = "943b56316b010e37c6872de9f8c6f9ff748b482d"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
version = "1.4.4"
[[Printf]] [[Printf]]
deps = ["Unicode"] deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
[[QuadGK]]
deps = ["DataStructures", "LinearAlgebra"]
git-tree-sha1 = "dc84e810393cfc6294248c9032a9cdacc14a3db4"
uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
version = "2.3.1"
[[REPL]] [[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"] deps = ["InteractiveUtils", "Markdown", "Sockets"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
...@@ -120,21 +438,60 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" ...@@ -120,21 +438,60 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
deps = ["Serialization"] deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
[[RecipesBase]]
git-tree-sha1 = "54f8ceb165a0f6d083f0d12cb4996f5367c6edbc"
uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
version = "1.0.1"
[[RecipesPipeline]]
deps = ["Dates", "PlotUtils", "RecipesBase"]
git-tree-sha1 = "d2a58b8291d1c0abae6a91489973f8a92bf5c04a"
uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c"
version = "0.1.11"
[[Reexport]] [[Reexport]]
deps = ["Pkg"] deps = ["Pkg"]
git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0"
uuid = "189a3867-3050-52da-a836-e630ba90ab69" uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "0.2.0" version = "0.2.0"
[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "d37400976e98018ee840e0ca4f9d20baa231dc6b"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.0.1"
[[Roots]]
deps = ["Printf"]
git-tree-sha1 = "c2f7348c55d1433d1cab0159b4d2c6d27af36fc4"
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
version = "1.0.2"
[[SHA]] [[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
[[Serialization]] [[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
[[Showoff]]
deps = ["Dates"]
git-tree-sha1 = "e032c9df551fb23c9f98ae1064de074111b7bc39"
uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
version = "0.3.1"
[[Sockets]] [[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc" uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
[[SortingAlgorithms]]
deps = ["DataStructures", "Random", "Test"]
git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "0.3.1"
[[SparseArrays]] [[SparseArrays]]
deps = ["LinearAlgebra", "Random"] deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
...@@ -155,13 +512,90 @@ version = "0.12.3" ...@@ -155,13 +512,90 @@ version = "0.12.3"
deps = ["LinearAlgebra", "SparseArrays"] deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[[StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics"]
git-tree-sha1 = "a6102b1f364befdb05746f386b67c6b7e3262c45"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.33.0"
[[StructArrays]]
deps = ["Adapt", "DataAPI", "Tables"]
git-tree-sha1 = "8099ed9fb90b6e754d6ba8c6ed8670f010eadca0"
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
version = "0.4.4"
[[TableTraits]]
deps = ["IteratorInterfaceExtensions"]
git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e"
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
version = "1.0.0"
[[Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "c45dcc27331febabc20d86cb3974ef095257dcf3"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "1.0.4"
[[Test]] [[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[[URIParser]]
deps = ["Unicode"]
git-tree-sha1 = "53a9f49546b8d2dd2e688d216421d050c9a31d0d"
uuid = "30578b45-9adc-5946-b283-645ec420af67"
version = "0.4.1"
[[UUIDs]] [[UUIDs]]
deps = ["Random", "SHA"] deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[[UnPack]]
git-tree-sha1 = "d4bfa022cd30df012700cf380af2141961bb3bfb"
uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
version = "1.0.1"
[[Unicode]] [[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[[UnicodePlots]]
deps = ["Dates", "Random", "SparseArrays", "StatsBase", "Test"]
git-tree-sha1 = "b8e58d4390ccebfa4f3bf502a45e08066eec3bf9"
uuid = "b8865327-cd53-5732-bb35-84acbb429228"
version = "1.1.0"
[[Zlib_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "622d8b6dc0c7e8029f17127703de9819134d1b71"
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.11+14"
[[libass_jll]]
deps = ["Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "027a304b2a90de84f690949a21f94e5ae0f92c73"
uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0"
version = "0.14.0+2"
[[libfdk_aac_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "480c7ed04f68ea3edd4c757f5db5b6a0a4e0bd99"
uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280"
version = "0.1.6+2"
[[libvorbis_jll]]
deps = ["Libdl", "Ogg_jll", "Pkg"]
git-tree-sha1 = "6a66f65b5275dfa799036c8a3a26616a0a271c4a"
uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a"
version = "1.3.6+4"
[[x264_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "d89346fe63a6465a9f44e958ac0e3d366af90b74"
uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a"
version = "2019.5.25+2"
[[x265_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "61324ad346b00a6e541896b94201c9426591e43a"
uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76"
version = "3.0.0+1"
...@@ -4,7 +4,18 @@ authors = ["Alberto Ramos <alberto.ramos@ific.uv.es>"] ...@@ -4,7 +4,18 @@ authors = ["Alberto Ramos <alberto.ramos@ific.uv.es>"]
version = "0.1.0" version = "0.1.0"
[deps] [deps]
BDIO = "375f315e-f2c4-11e9-2ef9-134f02f79e27"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Nettle = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9"
PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
module ADerrors module ADerrors
import ForwardDiff, Statistics, FFTW#, BDIO import ForwardDiff, Statistics, FFTW, LinearAlgebra, QuadGK, BDIO, Printf
# Include data types # Include data types
include("ADerrorsTypes.jl") include("ADerrorsTypes.jl")
...@@ -24,7 +24,18 @@ include("ADerrorsMath.jl") ...@@ -24,7 +24,18 @@ include("ADerrorsMath.jl")
# I/O # I/O
include("ADerrorsIO.jl") include("ADerrorsIO.jl")
export err, value, derror, taui, dtaui, window
# Basic tools
include("ADerrorsTools.jl")
# Root, fit, integral error propagation
include("ADerrorsUtils.jl")
export err, value, derror, taui, dtaui, window, rho, drho, details
export uwreal, uwerr export uwreal, uwerr
export cov, trcov, trcorr, neid
export read_uwreal, write_uwreal
export addobs, cobs
export root_error, chiexp, fit_error, int_error
end # module end # module
...@@ -56,28 +56,23 @@ function bin_data(vin::Array{Float64, 1}, nbin::Int64) ...@@ -56,28 +56,23 @@ function bin_data(vin::Array{Float64, 1}, nbin::Int64)
return vout return vout
end end
function uwcls(data::Vector{Float64}, id::Int64, ws::wspace, iv::Vector{Int64}) function add_DB(delta::Vector{Float64}, id::Int64, iv::Vector{Int64}, ws::wspace)
if (length(data) == 2)
nd = length(delta)
if (nd == 1)
ws.nob += 1 ws.nob += 1
new = fbd(1, 1, [data[2]], [1], Dict{Int64,Vector{Complex{Float64}}}()) new = fbd(1, 1, delta, [1], Dict{Int64,Vector{Complex{Float64}}}())
push!(ws.fluc, new) push!(ws.fluc, new)
push!(ws.map_nob, id) push!(ws.map_nob, id)
if (!haskey(ws.map_ids, id)) if (!haskey(ws.map_ids, id))
ws.map_ids[id] = ws.nob ws.map_ids[id] = ws.nob
end end
p = [false for n in 1:ws.nob]
p[end] = true
d = [0.0 for n in 1:ws.nob]
d[end] = 1.0
return uwreal(data[1], 0.0, 0.0,
p, d, Vector{Int64}(), Vector{cfdata}())
else else
if (sum(iv) != length(data)) if (sum(iv) != length(delta))
ArgumentError("Sum of replica length does not match number of measurements") ArgumentError("Sum of replica length does not match number of measurements")
end end
ws.nob += 1 ws.nob += 1
avg = Statistics.mean(data)
push!(ws.map_nob, id) push!(ws.map_nob, id)
if (!haskey(ws.map_ids, id)) if (!haskey(ws.map_ids, id))
ws.map_ids[id] = ws.nob ws.map_ids[id] = ws.nob
...@@ -89,18 +84,36 @@ function uwcls(data::Vector{Float64}, id::Int64, ws::wspace, iv::Vector{Int64}) ...@@ -89,18 +84,36 @@ function uwcls(data::Vector{Float64}, id::Int64, ws::wspace, iv::Vector{Int64})
for i in 1:length(iv) for i in 1:length(iv)
ie = is + iv[i] - 1 ie = is + iv[i] - 1
nbdt = div(iv[i], nbin) nbdt = div(iv[i], nbin)
datapad = [bin_data(data[is:ie] .- avg, nbin); datapad = [bin_data(delta[is:ie], nbin);
zeros(Float64, nextpow(2,2*nbdt+1)-nbdt) ] zeros(Float64, nextpow(2,2*nbdt+1)-nbdt) ]
fseries[i] = FFTW.fft(datapad) fseries[i] = FFTW.fft(datapad)
is = ie + 1 is = ie + 1
end end
new = fbd(length(data), nbin, new = fbd(length(delta), nbin,
data .- avg, delta,
iv, iv,
fseries) fseries)
push!(ws.fluc, new) push!(ws.fluc, new)
end
end
function uwcls(data::Vector{Float64}, id::Int64, ws::wspace, iv::Vector{Int64})
if (length(data) == 2)
add_DB([data[2]], id, Vector{Int64}(), ws)
p = [false for n in 1:ws.nob]
p[end] = true
d = [0.0 for n in 1:ws.nob]
d[end] = 1.0
return uwreal(data[1], 0.0, 0.0,
p, d, Vector{Int64}(), Vector{cfdata}())
else
avg = Statistics.mean(data)
add_DB(data .- avg, id, iv, ws)
p = [false for n in 1:ws.nob] p = [false for n in 1:ws.nob]
p[end] = true p[end] = true
d = [0.0 for n in 1:ws.nob] d = [0.0 for n in 1:ws.nob]
...@@ -119,37 +132,18 @@ function uwcls_gaps(data::Vector{Float64}, ...@@ -119,37 +132,18 @@ function uwcls_gaps(data::Vector{Float64},
if (nms < 4) if (nms < 4)
ArgumentError("MC data length has to be larger than 4") ArgumentError("MC data length has to be larger than 4")
end end
if (sum(iv) != nms)
ArgumentError("Sum of replica length does not match number of measurements")
end
avg = Statistics.mean(data) avg = Statistics.mean(data)
dt = fill(avg, nms) dt = zeros(Float64, nms)
for n in 1:length(idm) for n in 1:length(idm)
dt[idm[n]] = data[n] - avg dt[idm[n]] = data[n] - avg
end end
dt .= (nms/length(idm)) .* dt dt .= (nms/length(idm)) .* dt
ws.nob += 1 add_DB(dt, id, iv, ws)
push!(ws.map_nob, id)
if (!haskey(ws.map_ids, id))
ws.map_ids[id] = ws.nob
end
fseries = Dict{Int64,Vector{Complex{Float64}}}()
nbin = get_nbin_vec(iv)
is = 1
for i in 1:length(iv)
ie = is + iv[i] - 1
nbdt = div(iv[i], nbin)
datapad = [bin_data(dt[is:ie], nbin);
zeros(Float64, nextpow(2,2*nbdt+1)-nbdt) ]
fseries[i] = FFTW.fft(datapad)
is = ie + 1
end
new = fbd(nms, nbin,
dt,
iv,
fseries)
push!(ws.fluc, new)
p = [false for n in 1:ws.nob] p = [false for n in 1:ws.nob]
p[end] = true p[end] = true
...@@ -164,7 +158,7 @@ function unique_ids!(a::uwreal, ws::wspace) ...@@ -164,7 +158,7 @@ function unique_ids!(a::uwreal, ws::wspace)
if (length(a.ids) == 0) if (length(a.ids) == 0)
for i in 1:length(a.prop) for i in 1:length(a.prop)
if (a.prop[i]) if (a.prop[i])
if (any(a.ids[1:end] == ws.map_nob[i])) if (any(a.ids[1:end] .== ws.map_nob[i]))
continue continue
end end
push!(a.ids, ws.map_nob[i]) push!(a.ids, ws.map_nob[i])
...@@ -242,7 +236,7 @@ function uwerror(a::uwreal, ws::wspace, wpm::Dict{Int64,Vector{Float64}}) ...@@ -242,7 +236,7 @@ function uwerror(a::uwreal, ws::wspace, wpm::Dict{Int64,Vector{Float64}})
new.gamm[ig] = new.gamm[ig] + real(ftemp[k][ig]) new.gamm[ig] = new.gamm[ig] + real(ftemp[k][ig])
end end
end end
for ig in 1:nt for ig in 1:nt
nrcnt = count(map(x -> div(x, 2*ws.fluc[idx].ibn), ws.fluc[idx].ivrep) .> ig-1) nrcnt = count(map(x -> div(x, 2*ws.fluc[idx].ibn), ws.fluc[idx].ivrep) .> ig-1)
new.gamm[ig] = new.gamm[ig] / (nd_eff - nrcnt*(ig-1)) new.gamm[ig] = new.gamm[ig] / (nd_eff - nrcnt*(ig-1))
end end
...@@ -345,13 +339,15 @@ function uwerror(a::uwreal, ws::wspace, wpm::Dict{Int64,Vector{Float64}}) ...@@ -345,13 +339,15 @@ function uwerror(a::uwreal, ws::wspace, wpm::Dict{Int64,Vector{Float64}})
a.err = sqrt(a.err) a.err = sqrt(a.err)
a.derr = sqrt(a.derr) a.derr = sqrt(a.derr)
return a.err
end end
function unique_ids_multi(a::Vector{uwreal}) function unique_ids_multi(a::Vector{uwreal}, ws::wspace)
is = 0 is = 0
for i in 1:length(a) for i in 1:length(a)
is = is + unique_ids!(a) is = is + unique_ids!(a[i], ws)
end end
n = 0 n = 0
...@@ -359,11 +355,11 @@ function unique_ids_multi(a::Vector{uwreal}) ...@@ -359,11 +355,11 @@ function unique_ids_multi(a::Vector{uwreal})
for k in 1:length(a) for k in 1:length(a)
for i in 1:length(a[k].prop) for i in 1:length(a[k].prop)
if (a[k].prop[i]) if (a[k].prop[i])
if (any(a.ids[1:end] == ws.map_nob[i])) if (any(ids[1:end] .== ws.map_nob[i]))
continue continue
end end
n = n + 1 n = n + 1
push!(ids, map_nob[i]) push!(ids, ws.map_nob[i])
end end
end end
end end
...@@ -375,9 +371,9 @@ end ...@@ -375,9 +371,9 @@ end
function cov(a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}}) function cov(a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}})
for i in 1:length(a) for i in 1:length(a)
uwerr(a, wpm) ADerrors.uwerror(a[i], ws, wpm)
end end
ids = unique_ids_multi(a) ids = unique_ids_multi(a, ws)
nid = length(ids) nid = length(ids)
iw = zeros(Int64, nid) iw = zeros(Int64, nid)
...@@ -393,19 +389,34 @@ function cov(a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}}) ...@@ -393,19 +389,34 @@ function cov(a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}})
wopt = Dict{Int64,Vector{Float64}}() wopt = Dict{Int64,Vector{Float64}}()
for i in 1:nid for i in 1:nid
wopt[ids[i]] = [convert(Float64, iw[i]), -1.0, -1.0, -1.0] wopt[ids[i]] = [Base.convert(Float64, iw[i]), -1.0, -1.0, -1.0]
end end
cov = zeros(Float64, length(a), length(a)) cov = zeros(Float64, length(a), length(a))
for k in 1:length(a) for k in 1:length(a)
uwerr(a[k], wopt) ADerrors.uwerror(a[k], ws, wopt)
cov[k,k] = a[k].err^2 cov[k,k] = a[k].err^2
end end
for j in 1:nid for j in 1:nid
idx = ws.map_ids[a.ids[j]] idx = ws.map_ids[ids[j]]
nd = ws.fluc[idx].nd nd = ws.fluc[idx].nd
nrep = length(ws.fluc[idx].ivrep) if (nd != 1)
nd_eff = div(nd, ws.fluc[idx].ibn)
(nt,ip) = findmax(ws.fluc[idx].ivrep)
nt = div(nt, 2*ws.fluc[idx].ibn)
nrep = length(ws.fluc[idx].ivrep)
ftemp1 = Dict{Int64,Vector{Complex{Float64}}}()
ftemp2 = Dict{Int64,Vector{Complex{Float64}}}()
for i in 1:nrep
ns = length(ws.fluc[idx].fourier[i])
ftemp1[i] = zeros(Complex{Float64}, ns)
ftemp2[i] = zeros(Complex{Float64}, ns)
end
gamm = zeros(Float64, nt)
end
for k1 in 1:length(a)-1 for k1 in 1:length(a)-1
v1 = 0.0 v1 = 0.0
for i in 1:length(a[k1].prop) for i in 1:length(a[k1].prop)
...@@ -413,7 +424,9 @@ function cov(a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}}) ...@@ -413,7 +424,9 @@ function cov(a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}})
if (nd == 1) if (nd == 1)
v1 = v1 + a[k1].der[i]*ws.fluc[i].delta[1] v1 = v1 + a[k1].der[i]*ws.fluc[i].delta[1]
else else
# AQUI for k in 1:nrep
ftemp1[k] = ftemp1[k] + a[k1].der[i]*ws.fluc[i].fourier[k]
end
end end
end end
end end
...@@ -423,20 +436,155 @@ function cov(a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}}) ...@@ -423,20 +436,155 @@ function cov(a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}})
if (a[k2].prop[i] && (ws.map_nob[i] == ids[j])) if (a[k2].prop[i] && (ws.map_nob[i] == ids[j]))
if (nd == 1) if (nd == 1)
v2 = v2 + a[k2].der[i]*ws.fluc[i].delta[1] v2 = v2 + a[k2].der[i]*ws.fluc[i].delta[1]
else
for k in 1:nrep
ftemp2[k] = ftemp2[k] + a[k2].der[i]*ws.fluc[i].fourier[k]
end
end end
end end
end end
end
if (nd == 1) if (nd == 1)
cov[k1,k2] = cov[k1,k2] + v1*v2 cov[k1,k2] = cov[k1,k2] + v1*v2
else
for k in 1:nrep
ftemp2[k] .= ftemp1[k].*conj(ftemp2[k])
FFTW.ifft!(ftemp2[k])
for ig in 1:min(nt,length(ftemp2[k]))
gamm[ig] = gamm[ig] + real(ftemp2[k][ig])
end
end
for ig in 1:nt
nrcnt = count(map(x -> div(x, 2*ws.fluc[idx].ibn), ws.fluc[idx].ivrep) .> ig-1)
gamm[ig] = gamm[ig] / (nd_eff - nrcnt*(ig-1))
end
dbias = gamm[1] + 2.0*sum(gamm[2:iw[j]])
gamm .= gamm .+ dbias/nd_eff
cov[k1,k2] = cov[k1, k2] + ( gamm[1] + 2.0*sum(gamm[2:iw[j]]) )/nd_eff
for i in 1:nrep
for l in 1:length(ws.fluc[idx].fourier[i])
ftemp2[i][l] = Base.convert(Complex{Float64}, 0.0)
end
end
for i in 1:nt
gamm[i] = 0.0
end
end
end
if (nd > 1)
for i in 1:nrep
for l in 1:length(ws.fluc[idx].fourier[i])
ftemp1[i][l] = Base.convert(Complex{Float64}, 0.0)
end
end
end end
end end
end end
for k1 in 1:length(a)-1
for k2 in k1+1:length(a)
cov[k2,k1] = cov[k1,k2]
end
end
return cov
end
function trcov(M, a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}})
usvt = LinearAlgebra.svd(M)
n = length(a)
p = similar(a)
for i in 1:n
p[i] = a[1]*usvt.U[1,i]
for j in 2:n
p[i] = p[i] + a[j]*usvt.U[j,i]
end
ADerrors.uwerror(p[i], ws, wpm)
end
ids = unique_ids_multi(a, ws)
iw = zeros(Int64, length(ids))
for k in 1:n
for j in 1:length(p[k].ids)
for i in 1:length(ids)
if (p[k].ids[j] == ids[i])
iw[i] = max(iw[i], p[k].cfd[j].iw)
end
end
end
end
wopt = Dict{Int64,Vector{Float64}}()
for i in 1:length(ids)
wopt[ids[i]] = [Base.convert(Float64, iw[i]), -1.0, -1.0, -1.0]
end
tr = 0.0
for k in 1:n
ADerrors.uwerror(p[k], ws, wopt)
tr = tr + usvt.S[k]*p[k].err^2
end
return tr
end end
function trcorr(M, a::Vector{uwreal}, ws::wspace, wpm::Dict{Int64,Vector{Float64}}, W::Vector{Float64})
usvt = LinearAlgebra.svd(M)
n = length(a)
Ww = zeros(Float64, length(a))
if (length(W) == 0)
for i in 1:length(a)
ADerrors.uwerror(a[i], ws, wpm)
Ww[i] = a[i].err
end
else
Ww .= W
end
p = similar(a)
for i in 1:n
p[i] = a[1]*usvt.U[1,i]/Ww[1]
for j in 2:n
p[i] = p[i] + a[j]*usvt.U[j,i]/Ww[j]
end
ADerrors.uwerror(p[i], ws, wpm)
end
ids = unique_ids_multi(a, ws)
iw = zeros(Int64, length(ids))
for k in 1:n
for j in 1:length(p[k].ids)
for i in 1:length(ids)
if (p[k].ids[j] == ids[i])
iw[i] = max(iw[i], p[k].cfd[j].iw)
end
end
end
end
wopt = Dict{Int64,Vector{Float64}}()
for i in 1:length(ids)
wopt[ids[i]] = [Base.convert(Float64, iw[i]), -1.0, -1.0, -1.0]
end
tr = 0.0
for k in 1:n
ADerrors.uwerror(p[k], ws, wopt)
tr = tr + usvt.S[k]*p[k].err^2
end
return tr
end
## ## ## ##
# Module workspace and function definitions # # Module workspace and function definitions #
...@@ -450,10 +598,169 @@ wsg = ADerrors.wspace(similar(Vector{ADerrors.fbd}, 0), ...@@ -450,10 +598,169 @@ wsg = ADerrors.wspace(similar(Vector{ADerrors.fbd}, 0),
empt = Dict{Int64,Vector{Float64}}() empt = Dict{Int64,Vector{Float64}}()
"""
uwreal(x::Float64)
uwreal([value::Float64, error::Float64], mcid)
uwreal(data::Vector{Float64}, mcid::Int64[, replica::Vector{Int64}])
uwreal(data::Vector{Float64}, mcid::Int64[, replica::Vector{Int64}], idm::Vector{Int64}, nms::Int64)
Returns an `uwreal` data type. Depending on the first argument, the `uwreal` stores the following information:
- A single `Float64`. In this case the variable acts in exactly the same way as a real number. This is understood as a quantity with zero error.
- A 2 element Vector of `Float64` `[value, error]`. In this case the data is understood as `value +/- error`.
- A Vector of `Float64` of length larger than 2. In this case the data is understood as consecutive measurements of an observable in a Monte Carlo (MC) simulation.
In the last two cases, an ensemble `ID` is required as input. Data with the same `ID` are considered as correlated (i.e. fully correlated for the case of a `value +/- error` observables measured on the same sample for the case of data from a MC simulation). For example:
```@example
using ADerrors # hide
a = uwreal([1.2, 0.2], 12) # a = 1.2 +/- 0.2
b = uwreal([1.2, 0.2], 12) # b = 1.2 +/- 0.2
c = uwreal([1.2, 0.2], 2000) # c = 1.2 +/- 0.2
d = a-b
uwerr(d)
println("d has zero error because a and b are correlated", d)
e = a-c
uwerr(e)
println("e has non zero error because a and c are independent", e)
```
### Replica
`data` can contain measurements in several replica (i.e. independent simulations with the same physical and algorithmic parameters). How many measurements correspond to each replica are specified by an optional replica vector argument `replica`. Note that `length(replica)` is the number of replica (i.e. independent simulations), and that `sum(replica)` must match `length(data)`
```@example
using ADerrors # hide
# 1000 measurements in three replica of lengths
# 500, 100 and 400
a = uwreal(rand(1000), 12, [500, 100, 400])
```
### Gaps in the measurements
In some situations an observable is not measured in every configuration. In this case two additional arguments aree needed to define the observable
- `idm`. Type `Vector{Int64}`. `idm[n]` labels the configuration where data[n] is measured.
- `nms`. Type `Int64`. The total number of measurements in the ensemble
```@example
using ADerrors # hide
# Observable measured on the odd configurations
# 1, 3, 5, ..., 999 on an emsemble of length 1000
a = uwreal(rand(500), 12, collect(1:2:999), 1000)
# Observable measured on the first 900 configurations
# on the same emsemble
b = uwreal(rand(900), 12, collect(1:900), 1000)
```
Note that in this case, if the ensemble has different replica, `sum(replica)` must match `nms`
```@example
using ADerrors # hide
# Observable measured on the even configurations
# 2, 4, 6, ..., 200 on an emsemble of length 200
# with two replica of lengths 75, 125
a = uwreal(data_a[1:500], 123, [75, 125], collect(2:2:200), 200)
```
"""
uwreal(x::Float64) = ADerrors.uwreal(x, 0.0, 0.0,
Vector{Bool}(), Vector{Float64}(),
Vector{Int64}(), Vector{cfdata}())
uwreal(data::Vector{Float64}, id::Int64) = ADerrors.uwcls(data::Vector{Float64}, id::Int64, wsg, [length(data)]) uwreal(data::Vector{Float64}, id::Int64) = ADerrors.uwcls(data::Vector{Float64}, id::Int64, wsg, [length(data)])
uwreal(data::Vector{Float64}, id::Int64, iv::Vector{Int64}) = ADerrors.uwcls(data::Vector{Float64}, id::Int64, wsg, iv) uwreal(data::Vector{Float64}, id::Int64, iv::Vector{Int64}) = ADerrors.uwcls(data::Vector{Float64}, id::Int64, wsg, iv)
uwreal(data::Vector{Float64}, id::Int64, idm::Vector{Int64}, nms::Int64) = ADerrors.uwcls_gaps(data::Vector{Float64},
id::Int64, ws::wspace,
[nms],
idm::Vector{Int64},
nms::Int64)
uwreal(data::Vector{Float64}, id::Int64, iv::Vector{Int64}, idm::Vector{Int64}, nms::Int64) = ADerrors.uwcls_gaps(data::Vector{Float64},
id::Int64, ws::wspace,
iv::Vector{Int64},
idm::Vector{Int64},
nms::Int64)
@doc raw"""
uwerr(a::uwreal[, wpm::Dict{Int64,Vector{Float64}}])
Performs error analysis on the observable `a`.
```@example
using ADerrors # hide
a = uwreal([1.3, 0.01], 1) # 1.3 +/- 0.01
b = sin(2.0*a)
uwerr(b)
println("Look how I propagate errors: ", b)
c = 1.0 + b - 2.0*sin(a)*cos(a)
uwerr(b)
println("Look how good I am at this (zero error!): ", c)
```
### Optimal window
Error in data coming from a Monte Carlo ensemble is performed by summing the autocorrelation function ``\Gamma_{\rm ID}(t)`` of the data for each ensemble ID. In practice this sum is truncated up to a window ``W_{\rm ID}``.
By default, the summation window is determined as [proposed by U. Wolff](https://inspirehep.net/literature/621085) with a parameter ``S_{\tau} = 4``, but other methods are avilable via the optional argument `wpm`.
For each ensemble `ID` one has to pass a vector of `Float64` of length 4. The first three components of the vector specify the criteria to determine the summation window:
- `vp[1]`: The autocorrelation function is summed up to `t = round(vp[1])`.
- `vp[2]`: The sumation window is determined [using U. Wolff poposal](https://inspirehep.net/literature/621085) with ``S_{\tau} = {\rm vp[2]}``.
- `vp[3]`: The autocorrelation function ``\Gamma(t)`` is summed up a point where its error ``\delta\Gamma(t)`` is a factor `vp[3]` times larger than the signal.
An additional fourth parameter `vp[4]`, tells `ADerrors` to add a tail to the error with ``\tau_{\rm exp} = {\rm vp[4]}``. See [the reference](https://inspirehep.net/literature/871175) for an explanation of the procedure.
Note that:
- Negative values of `vp[1:4]` are ignored.
- One, and only one, of the components `vp[1:3]` has to be positive. This chooses your criteria to determine the summation window.
```@example
using ADerrors # hide
a = uwreal(rand(2000), 1233)
wpm = Dict{Int64,Vector{Float64}}()
# Use default analysis (stau = 4.0)
uwerr(a)
println(a)
# This will still do default analysis because
# a does not depend on emsemble 300
wpm[300] = [-1.0, 8.0, -1.0, 145.0]
uwerr(a, wpm)
println(a)
# Fix the summation window to 1 (i.e. uncorrelated data)
wpm[1233] = [1.0, -1.0, -1.0, -1.0]
uwerr(a, wpm)
println(a)
# Use stau = 1.5
wpm[1233] = [-1.0, 1.5, -1.0, -1.0]
uwerr(a, wpm)
println(a)
# Use fixed window 15 and add tail with texp = 100.0
wpm[1233] = [15.0, -1.0, -1.0, 100.0]
uwerr(a, wpm)
println(a)
# Sum up to the point that the signal in Gamma is
# 1.5 times the error and add a tail with texp = 30.0
wpm[1233] = [-1.0, -1.0, 1.5, 30.0]
uwerr(a, wpm)
println(a)
```
"""
uwerr(a::uwreal, wpm::Dict{Int64,Vector{Float64}}) = ADerrors.uwerror(a::uwreal, wsg, wpm)
uwerr(a::uwreal) = ADerrors.uwerror(a::uwreal, wsg, empt) uwerr(a::uwreal) = ADerrors.uwerror(a::uwreal, wsg, empt)
uwerr(a::uwreal, wpm::Dict{Int64,Vector{Float64}}) = ADerrors.uwerror(a::uwreal, wsg, wpm::Dict{Int64,Vector{Float64}})
cov(a::Vector{uwreal}) = cov(a::Vector{uwreal}, wsg, empt)
cov(a::Vector{uwreal}, wpm::Dict{Int64,Vector{Float64}}) = cov(a::Vector{uwreal}, wsg, wpm::Dict{Int64,Vector{Float64}})
trcov(M, a::Vector{uwreal}) = trcov(M, a::Vector{uwreal}, wsg, empt)
trcov(M, a::Vector{uwreal}, wpm::Dict{Int64,Vector{Float64}}) = trcov(M, a::Vector{uwreal}, wsg, wpm::Dict{Int64,Vector{Float64}})
trcorr(M, a::Vector{uwreal},
W::Vector{Float64}=Vector{Float64}()) = trcorr(M, a::Vector{uwreal}, wsg, empt, W)
trcorr(M, a::Vector{uwreal},
W::Vector{Float64}, wpm::Dict{Int64,Vector{Float64}}) = trcorr(M, a::Vector{uwreal}, wsg, wpm::Dict{Int64,Vector{Float64}}, W)
trcorr(M, a::Vector{uwreal},
wpm::Dict{Int64,Vector{Float64}}) = trcorr(M, a::Vector{uwreal}, wsg, wpm::Dict{Int64,Vector{Float64}}, Vector{Float64}())
neid(a::uwreal) = ADerrors.unique_ids!(a::uwreal, wsg) neid(a::uwreal) = ADerrors.unique_ids!(a::uwreal, wsg)
function find_mcid(a::uwreal, mcid::Int64)
if (length(a.cfd) == 0)
return 0
else
for i in 1:length(a.ids)
if (a.ids[i] == mcid)
return i
end
end
end
return 0
end
err(a::uwreal) = a.err err(a::uwreal) = a.err
value(a::uwreal) = a.mean value(a::uwreal) = a.mean
derror(a::uwreal) = a.derr derror(a::uwreal) = a.derr
taui(a::uwreal, i::Int64) = a.cfd[i].taui
dtaui(a::uwreal, i::Int64) = a.cfd[i].taui function taui(a::uwreal, mcid::Int64)
window(a::uwreal, i::Int64) = a.cfd[i].iw idx = find_mcid(a, mcid)
if (idx == 0)
return 0.5
else
return a.cfd[idx].taui
end
end
function dtaui(a::uwreal, mcid::Int64)
idx = find_mcid(a, mcid)
if (idx == 0)
return 0.0
else
return a.cfd[idx].dtaui
end
end
function window(a::uwreal, mcid::Int64)
idx = find_mcid(a, mcid)
if (idx == 0)
return 0
else
return a.cfd[idx].iw
end
end
function rho(a::uwreal, mcid::Int64)
idx = find_mcid(a, mcid)
if (idx == 0)
return [1.0]
else
return a.cfd[idx].gamm ./ a.cfd[idx].gamm[1]
end
end
function drho(a::uwreal, mcid::Int64)
idx = find_mcid(a, mcid)
if (idx == 0)
return [0.0]
else
return a.cfd[idx].drho
end
end
function read_bdio(fb, ws::wspace)
dfoo = zeros(Float64, 1)
ifoo = zeros(Int32, 1)
BDIO.BDIO_read(fb, dfoo)
BDIO.BDIO_read(fb, ifoo)
nid::Int32 = ifoo[1]
p = [false for i in 1:ws.nob+nid]
d = zeros(Float64, ws.nob+nid)
p[ws.nob+1:end] .= true
d[ws.nob+1:end] .= 1.0
nds = zeros(Int32, nid)
nrep = zeros(Int32, nid)
ids = zeros(Int32, nid)
itmp = zeros(Int32, nid)
BDIO.BDIO_read(fb, nds)
BDIO.BDIO_read(fb, nrep)
ivrep = zeros(Int32, sum(nrep))
BDIO.BDIO_read(fb, ivrep)
BDIO.BDIO_read(fb, ids)
dfl = zeros(Float64, nid)
BDIO.BDIO_read(fb, itmp)
for i in 1:2
BDIO.BDIO_read(fb, dfl)
end
is = 1
for i in 1:nid
ie = is + nrep[i] - 1
if (sum(ivrep[is:ie]) != nds[i])
throw("Replica sum does not match number of measurements")
end
dfl = zeros(Float64, nds[i])
BDIO.BDIO_read(fb, dfl)
add_DB(dfl, convert(Int64, ids[i]), convert(Vector{Int64}, ivrep[is:ie]), ws)
is = ie + 1
end
return uwreal(dfoo[1], p, d)
end
function write_bdio(p::uwreal, fb, iu::Int, ws::wspace)
BDIO.BDIO_start_record!(fb, BDIO.BDIO_BIN_GENERIC, convert(Int32, iu), true)
nid = convert(Int32, unique_ids!(p, ws))
BDIO.BDIO_write!(fb, [p.mean], true)
BDIO.BDIO_write!(fb, [nid], true)
for j in 1:nid
nd = convert(Int32, ws.fluc[ws.map_ids[p.ids[j]]].nd)
BDIO.BDIO_write!(fb, [nd], true)
end
for j in 1:nid
nr = convert(Int32, length(ws.fluc[ws.map_ids[p.ids[j]]].ivrep))
BDIO.BDIO_write!(fb, [nr], true)
end
for j in 1:nid
BDIO.BDIO_write!(fb, convert(Vector{Int32}, ws.fluc[ws.map_ids[p.ids[j]]].ivrep), true)
end
BDIO.BDIO_write!(fb, convert(Vector{Int32}, p.ids), true)
for j in 1:nid
for i in 1:length(p.prop)
if (p.prop[i] && (ws.map_nob[i] == p.ids[j]))
(nt,ip) = findmax(ws.fluc[i].ivrep)
nt = convert(Int32, div(nt, 2*ws.fluc[i].ibn))
BDIO.BDIO_write!(fb, [nt], true)
continue
end
end
end
BDIO.BDIO_write!(fb, zeros(Float64, nid), true)
BDIO.BDIO_write!(fb, [DEFAULT_STAU for n in 1:nid], true)
for j in 1:nid
nd = ws.fluc[ws.map_ids[p.ids[j]]].nd
dt = zeros(Float64, nd)
for i in 1:length(p.prop)
if (p.prop[i] && (ws.map_nob[i] == p.ids[j]))
dt .= dt .+ p.der[i] .* ws.fluc[i].delta
end
end
BDIO.BDIO_write!(fb, dt, true)
end
BDIO.BDIO_write_hash!(fb)
return true
end
"""
details(a::uwreal; io::IO=stdout, names::Dict{Int64, String} = Dict{Int64, String}())
Write out a detailed information on the error of `a`.
## Arguments
Optionally one can pass as a keyword argument (`io`) the `IO` stream to write to and a dictionary (`names`) that translates ensemble `ID`s into more human friendly `Strings`
## Example
```@example
using ADerrors # hide
a = uwreal(rand(2000), 120)
b = uwreal([1.2, 0.023], 121)
c = uwreal([5.2, 0.03], 122)
d = a + b - c
uwerr(d)
bnm = Dict{Int64, String}()
bnm[120] = "Very important ensemble"
bnm[122] = "H12B K87"
details(d, bnm)
```
"""
function details(a::uwreal, ws::wspace, io::IO=stdout, names::Dict{Int64, String} = Dict{Int64, String}())
if (length(a.prop) == 0)
print(a.mean)
return
end
if (length(a.cfd) > 0)
println(a.mean, " +/- ", a.err)
println(" ## Number of error sources: ", length(a.ids))
n = 0
for i in 1:length(a.cfd)
if (length(a.cfd[i].gamm) > 0)
n = n + 1
end
end
println(" ## Number of MC ids : ", n)
println(" ## Contribution to error : Ensemble [%] [MC length]")
truncate_ascii(s::String,n::Int) = s[1:min(sizeof(s),n)]
ntrunc = 45
v = zeros(length(a.cfd))
for i in eachindex(v)
v[i] = a.cfd[i].var
end
ip = sortperm(v, rev=true)
for i in 1:length(a.cfd)
sid = truncate_ascii(get(names, a.ids[ip[i]], string(a.ids[ip[i]])), ntrunc)
if (length(a.cfd[ip[i]].gamm) > 0)
idx = ws.map_ids[a.ids[i]]
nd = ws.fluc[idx].nd
Printf.@printf(" # %45s %6.2f %10d\n",
sid, 100.0 .* a.cfd[ip[i]].var ./ a.err^2, nd)
else
Printf.@printf(" # %45s %6.2f -\n",
sid, 100.0 .* a.cfd[ip[i]].var ./ a.err^2)
end
end
else
print(a.mean, " (Error not available... maybe run uwerr)")
end
end
details(a::uwreal; io::IO=stdout, names::Dict{Int64, String} = Dict{Int64, String}()) = details(a, wsg, io, names)
read_uwreal(fb) = read_bdio(fb, ADerrors.wsg)
write_uwreal(p::uwreal, fb, iu::Int) = write_bdio(p::uwreal, fb, iu::Int, ADerrors.wsg)
###
### "THE BEER-WARE LICENSE":
### Alberto Ramos wrote this file. As long as you retain this
### notice you can do whatever you want with this stuff. If we meet some
### day, and you think this stuff is worth it, you can buy me a beer in
### return. <alberto.ramos@cern.ch>
###
### file: ADerrorsTools.jl
### created: Fri Jun 26 21:48:35 2020
###
function cobs(avgs::Vector{Float64}, cov::Array{Float64, 2}, ids::Vector{Int64})
ch = LinearAlgebra.cholesky(cov)
n = length(avgs)
p = Vector{uwreal}()
for j in 1:n
new = uwreal([avgs[j], ch.L[j, 1]], ids[1])
for i in 2:n
new = new + uwreal([0.0, ch.L[j,i]], ids[i])
end
push!(p, new)
end
return p
end
function addobs(a::Vector{uwreal}, der::Vector{Float64}, mvl::Float64)
n = 0
for i in 1:length(a)
n = max(n,length(a[i].der))
end
p = [false for i in 1:n]
d = zeros(Float64, n)
for k in 1:n
for j in 1:length(a)
if (k <= length(a[j].prop))
p[k] = p[k] || a[j].prop[k]
if (a[j].prop[k])
d[k] = d[k] + der[j]*a[j].der[k]
end
end
end
end
return uwreal(mvl, p, d)
end
function addobs(a::Vector{uwreal}, der::Array{Float64, 2}, mvl::Vector{Float64})
n = 0
for i in 1:length(a)
n = max(n,length(a[i].der))
end
x = Vector{uwreal}()
for i in 1:size(der, 1)
p = [false for i in 1:n]
d = zeros(Float64, n)
for k in 1:n
for j in 1:length(a)
if (k <= length(a[j].prop))
p[k] = p[k] || a[j].prop[k]
if (a[j].prop[k])
d[k] = d[k] + der[i,j]*a[j].der[k]
end
end
end
end
push!(x, uwreal(mvl[i], p, d))
end
return x
end
...@@ -32,6 +32,22 @@ mutable struct uwreal ...@@ -32,6 +32,22 @@ mutable struct uwreal
ids::Array{Int64, 1} ids::Array{Int64, 1}
cfd::Vector{cfdata} cfd::Vector{cfdata}
uwreal(a::Float64, b::Float64, c::Float64,
d::Array{Bool, 1}, e::Array{Float64, 1},
f::Array{Int64, 1}, g::Vector{cfdata}) = new(a, b, c, d, e, f, g)
function uwreal(n::Int64)
x = new()
x.mean = 0.0
x.err = 0.0
x.derr = 0.0
x.prop = Vector{Bool}(undef, n)
x.der = Vector{Float64}(undef, n)
x.prop .= false
x.der .= 0.0
return x
end
end end
mutable struct fbd mutable struct fbd
...@@ -52,6 +68,10 @@ mutable struct wspace ...@@ -52,6 +68,10 @@ mutable struct wspace
end end
Base.convert(::Type{uwreal}, x::Float64) = uwreal(x, 0.0, 0.0,
Vector{Bool}(), Vector{Float64}(),
Vector{Int64}(), Vector{cfdata}())
uwreal(v::Float64, n::Int) = uwreal(v, 0.0, 0.0, uwreal(v::Float64, n::Int) = uwreal(v, 0.0, 0.0,
[false for i in 1:n], [0.0 for i in 1:n], [false for i in 1:n], [0.0 for i in 1:n],
Vector{Int64}(), Vector{cfdata}()) Vector{Int64}(), Vector{cfdata}())
...@@ -60,6 +80,12 @@ uwreal(v::Float64, prop::Vector{Bool}, der::Vector{Float64}) = uwreal(v, 0.0, 0. ...@@ -60,6 +80,12 @@ uwreal(v::Float64, prop::Vector{Bool}, der::Vector{Float64}) = uwreal(v, 0.0, 0.
Vector{Int64}(), Vector{cfdata}()) Vector{Int64}(), Vector{cfdata}())
function Base.show(io::IO, a::uwreal) function Base.show(io::IO, a::uwreal)
if (length(a.prop) == 0)
print(a.mean)
return
end
if (length(a.cfd) > 0) if (length(a.cfd) > 0)
print(a.mean, " +/- ", a.err) print(a.mean, " +/- ", a.err)
else else
......
###
### "THE BEER-WARE LICENSE":
### Alberto Ramos wrote this file. As long as you retain this
### notice you can do whatever you want with this stuff. If we meet some
### day, and you think this stuff is worth it, you can buy me a beer in
### return. <alberto.ramos@cern.ch>
###
### file: ADerrorsUtils.jl
### created: Fri Jun 26 19:30:27 2020
###
function root_error(fnew::Function, x::Float64,
data::Vector{uwreal})
function fvec(x::Vector)
return fnew(x[1], x[2:end])
end
xv = zeros(Float64, length(data)+1)
xv[1] = x
for i in 1:length(data)
xv[i+1] = data[i].mean
end
grad = ForwardDiff.gradient(fvec, xv)
return addobs(data, -grad[2:end]./grad[1], x)
end
function chiexp(hess::Array{Float64, 2}, data::Vector{uwreal}, W::Vector{Float64})
m = length(data)
n = size(hess, 1) - m
hm = view(hess, 1:n, n+1:n+m)
sm = hm * LinearAlgebra.Diagonal(1.0 ./ sqrt.(W))
Px = LinearAlgebra.Symmetric(LinearAlgebra.Diagonal(W)) -
LinearAlgebra.Symmetric(hm' *
LinearAlgebra.inv(LinearAlgebra.Symmetric(sm * sm')) *
hm)
return trcov(Px, data)
end
function chiexp(hess::Array{Float64, 2}, data::Vector{uwreal}, W::Array{Float64, 2})
m = length(data)
n = size(hess, 1) - m
Lm = LinearAlgebra.cholesky(LinearAlgebra.Symmetric(W))
Li = LinearAlgebra.inv(Lm.L)
hm = view(hess, 1:n, n+1:n+m)
sm = hm * Li'
Px = LinearAlgebra.Symmetric(W) -
LinearAlgebra.Symmetric(hm' *
LinearAlgebra.inv(LinearAlgebra.Symmetric(sm * sm')) *
hm)
return trcov(Px, data)
end
function chiexp(chisq::Function,
xp::Vector{Float64},
data::Vector{uwreal};
W = Vector{Float64}())
n = length(xp) # Number of fit parameters
m = length(data) # Number of data
ccsq(x::Vector) = chisq(x[1:n], x[n+1:end])
xav = zeros(Float64, n+m)
for i in 1:n
xav[i] = xp[i]
end
for i in n+1:n+m
xav[i] = data[i-n].mean
end
hess = ForwardDiff.hessian(ccsq, xav)
cse = 0.0
if (m-n > 0)
if (length(W) == 0)
Ww = zeros(Float64, m)
for i in 1:m
if (data[i].err == 0.0)
uwerr(data[i])
if (data[i].err == 0.0)
error("Zero error in fit data")
end
end
Ww[i] = 1.0 / data[i].err^2
end
else
Ww = W
end
cse = chiexp(hess, data, Ww)
end
return cse
end
function fit_error(chisq::Function,
xp::Vector{Float64},
data::Vector{uwreal};
W = Vector{Float64}(), chi_exp = true)
n = length(xp) # Number of fit parameters
m = length(data) # Number of data
ccsq(x::Vector) = chisq(x[1:n], x[n+1:end])
xav = zeros(Float64, n+m)
for i in 1:n
xav[i] = xp[i]
end
for i in n+1:n+m
xav[i] = data[i-n].mean
end
hess = ForwardDiff.hessian(ccsq, xav)
hinv = LinearAlgebra.pinv(hess[1:n,1:n])
grad = - hinv[1:n,1:n] * hess[1:n,n+1:n+m]
param = addobs(data, grad, xp)
if (!chi_exp)
return param
end
cse = 0.0
if (m-n > 0)
if (length(W) == 0)
Ww = zeros(Float64, m)
for i in 1:m
if (data[i].err == 0.0)
uwerr(data[i])
if (data[i].err == 0.0)
error("Zero error in fit data")
end
end
Ww[i] = 1.0 / data[i].err^2
end
else
Ww = W
end
cse = chiexp(hess, data, Ww)
end
return param, cse
end
function int_error(fint::Function,
a,
b,
param::Vector{uwreal})
# First basic integral
xp = zeros(Float64, length(param))
for i in 1:length(xp)
xp[i] = param[i].mean
end
f(x) = fint(x, xp)
(val, foo) = QuadGK.quadgk(f, a, b)
# Functions that return the derivatives
# with respect to the parameters as functions
function fp(n::Int64)
function fd(x)
fax(pa) = fint(x,[xp[1:n-1];[pa];xp[n+1:end]])
return ForwardDiff.derivative(fax, xp[n])
end
return fd
end
grad = zeros(Float64, length(param))
for i in 1:length(param)
(grad[i], foo) = QuadGK.quadgk(fp(i), a, b)
end
return addobs(param, grad, val)
end
function int_error(fint::Function,
a::uwreal,
b::Float64,
param::Vector{uwreal})
# First basic integral
xp = zeros(Float64, length(param))
for i in 1:length(xp)
xp[i] = param[i].mean
end
f(x) = fint(x, xp)
(val, foo) = QuadGK.quadgk(f, a.mean, b)
# Functions that return the derivatives
# with respect to the parameters as functions
function fp(n::Int64)
function fd(x)
fax(pa) = fint(x,[xp[1:n-1];[pa];xp[n+1:end]])
return ForwardDiff.derivative(fax, xp[n])
end
return fd
end
grad = zeros(Float64, length(param)+1)
for i in 1:length(param)
(grad[i], foo) = QuadGK.quadgk(fp(i), a.mean, b)
end
grad[end] = fint(a.mean, xp)
return addobs([param; a], grad, val)
end
function int_error(fint::Function,
a::uwreal,
b::uwreal,
param::Vector{uwreal})
# First basic integral
xp = zeros(Float64, length(param))
for i in 1:length(xp)
xp[i] = param[i].mean
end
f(x) = fint(x, xp)
(val, foo) = QuadGK.quadgk(f, a.mean, b.mean)
# Functions that return the derivatives
# with respect to the parameters as functions
function fp(n::Int64)
function fd(x)
fax(pa) = fint(x,[xp[1:n-1];[pa];xp[n+1:end]])
return ForwardDiff.derivative(fax, xp[n])
end
return fd
end
grad = zeros(Float64, length(param)+2)
for i in 1:length(param)
(grad[i], foo) = QuadGK.quadgk(fp(i), a.mean, b.mean)
end
grad[end-1] = fint(a.mean, xp)
grad[end] = fint(b.mean, xp)
return addobs([param; a; b], grad, val)
end
function int_error(fint::Function,
a::Float64,
b::uwreal,
param::Vector{uwreal})
# First basic integral
xp = zeros(Float64, length(param))
for i in 1:length(xp)
xp[i] = param[i].mean
end
f(x) = fint(x, xp)
(val, foo) = QuadGK.quadgk(f, a, b.mean)
# Functions that return the derivatives
# with respect to the parameters as functions
function fp(n::Int64)
function fd(x)
fax(pa) = fint(x,[xp[1:n-1];[pa];xp[n+1:end]])
return ForwardDiff.derivative(fax, xp[n])
end
return fd
end
grad = zeros(Float64, length(param)+1)
for i in 1:length(param)
(grad[i], foo) = QuadGK.quadgk(fp(i), a, b.mean)
end
grad[end] = fint(b.mean, xp)
return addobs([param; b], grad, val)
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment