From 4e157d106aa3566545289737f592596ef735b806 Mon Sep 17 00:00:00 2001 From: florian oswald Date: Thu, 13 Sep 2018 23:12:35 +0200 Subject: [PATCH 1/4] first tests work --- src/MomentOpt.jl | 34 ++++++++++++++++------------------ src/mopt/Eval.jl | 4 ++-- src/mopt/ObjExamples.jl | 2 +- src/mopt/incmopt.jl | 1 - src/mopt/mprob.jl | 8 ++++---- test/include/test-include.jl | 2 +- test/runtests.jl | 10 +++++----- 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/MomentOpt.jl b/src/MomentOpt.jl index 985f80c..568f2b8 100644 --- a/src/MomentOpt.jl +++ b/src/MomentOpt.jl @@ -4,10 +4,11 @@ module MomentOpt # Dependencies # ############ +using Logging using Distributions -using MiniLogging using DataFrames, DataFramesMeta -import Base.show, Base.std +import Base.show +using Statistics: std, mean using DataStructures using PDMats using Documenter @@ -17,15 +18,11 @@ using JLD2 gr() -# setup MiniLogging -logger = get_logger() -# if isinteractive() -# basic_config(MiniLogging.DEBUG; date_format="%H:%M:%S") -# else - basic_config(MiniLogging.INFO; date_format="%H:%M:%S") -# end -import Base.get, Base.mean, Base.write, Base.start, Base.== +# set log level +LogLevel(Logging.Debug) + +import Base.get,Base.write, Base.start, Base.== # exports: Types export MProb, Eval,MAlgo, MAlgoBGP @@ -50,7 +47,8 @@ export addParam!, save, readMalgo, restartMOpt!, - extendBGPChain! + extendBGPChain!, + fitMirror @@ -58,17 +56,17 @@ export addParam!, # ############ include("mopt/mprob.jl") -include("mopt/incmopt.jl") +# include("mopt/incmopt.jl") include("mopt/Eval.jl") -include("mopt/slices.jl") -include("mopt/AlgoAbstract.jl") -include("mopt/AlgoBGP.jl") +# include("mopt/slices.jl") +# include("mopt/AlgoAbstract.jl") +# include("mopt/AlgoBGP.jl") include("mopt/ObjExamples.jl") -include("mopt/Examples.jl") -include("mopt/plotting.jl") +# include("mopt/Examples.jl") +# include("mopt/plotting.jl") -end # module +end # module diff --git a/src/mopt/Eval.jl b/src/mopt/Eval.jl index b8ddd85..0475168 100644 --- a/src/mopt/Eval.jl +++ b/src/mopt/Eval.jl @@ -17,7 +17,7 @@ * `options`: Dict of options and other info """ -type Eval +struct Eval value :: Float64 time :: Float64 @@ -70,7 +70,7 @@ type Eval for k in keys(p) kk = Symbol(k) if length(p[k]) > 3 - warn("you have a parameter with more tham 3 entries. we assume p = [val,lb,ub]") + @warn "you have a parameter with more tham 3 entries. we assume p = [val,lb,ub]" end this.params[kk] = p[k][1] # we take the first one, in case there are several values per param # not sure about that. diff --git a/src/mopt/ObjExamples.jl b/src/mopt/ObjExamples.jl index c68607e..ba98c36 100644 --- a/src/mopt/ObjExamples.jl +++ b/src/mopt/ObjExamples.jl @@ -106,7 +106,7 @@ function banana(ev::Eval) start(ev) p = paramd(ev) - model = 100 .* (p["b"] - p["a"].^2 ).^2 .+ (1.-p["a"])^2 + model = 100 .* (p["b"] - p["a"].^2 ).^2 .+ (1 .- p["a"])^2 data = 0.0 setValue(ev,model) diff --git a/src/mopt/incmopt.jl b/src/mopt/incmopt.jl index f8efc16..982ef15 100644 --- a/src/mopt/incmopt.jl +++ b/src/mopt/incmopt.jl @@ -1,4 +1,3 @@ -export fitMirror # transpose a 2-column dataframe to a one-row dataframe, so that diff --git a/src/mopt/mprob.jl b/src/mopt/mprob.jl index 48f546a..f50ac45 100644 --- a/src/mopt/mprob.jl +++ b/src/mopt/mprob.jl @@ -26,7 +26,7 @@ of datamoments `moments`. ``` """ -type MProb +mutable struct MProb # setup initial_value :: OrderedDict # initial parameter value as a dict @@ -41,7 +41,7 @@ type MProb this.initial_value = OrderedDict() this.params_to_sample = OrderedDict() function def(x) - info("default objfunc, returns input") + @info "default objfunc, returns input" x end this.objfunc = def @@ -145,7 +145,7 @@ function evaluateObjective(m::MProb,p::Union{Dict,OrderedDict}) # ev = eval(Expr(:call,m.objfunc,ev)) ev = m.objfunc(ev) catch ex - warn("caught exception $ex") + @warn "caught exception $ex" ev.status = -2 end gc() @@ -158,7 +158,7 @@ function evaluateObjective(m::MProb,ev) # ev = eval(Expr(:call,m.objfunc,ev)) ev = m.objfunc(ev) catch ex - warn("caught exception $ex") + @warn "caught exception $ex" ev.status = -2 end gc() diff --git a/test/include/test-include.jl b/test/include/test-include.jl index 53a14de..66a5b8f 100644 --- a/test/include/test-include.jl +++ b/test/include/test-include.jl @@ -18,7 +18,7 @@ function test_chain() end -type MyP +struct MyP a :: Float64 b :: Float64 diff --git a/test/runtests.jl b/test/runtests.jl index 656695f..93ae5d4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,7 @@ using MomentOpt -using Base.Test -using TestSetExtensions +using Test using DataFrames # If we want the test to pass, we need this @@ -16,10 +15,11 @@ using DataFrames # Did you start 'gksqt'?"" ENV["GKSwstype"] = "100" -include(joinpath(dirname(@__FILE__),"include","test-include.jl")) +dir = dirname(@__FILE__) +include(joinpath(dir,"include","test-include.jl")) -@testset ExtendedTestSet "Running MomentOpt tests" begin +@testset "Running MomentOpt tests" begin - @includetests ARGS + include(joinpath(dir,"test_MProb.jl")) end From c93a89d0c1a77986c1028bc57598bb820c6620bf Mon Sep 17 00:00:00 2001 From: Florian Oswald Date: Fri, 14 Sep 2018 15:26:25 +0200 Subject: [PATCH 2/4] small progress, at least its a valid project now. blocked by issue with JLD2 recreating the user type --- Manifest.toml | 358 +++++++++++++++++++++++++++++++++++ Project.toml | 19 ++ src/MomentOpt.jl | 4 +- src/mopt/Eval.jl | 2 +- src/mopt/econometrics.jl | 1 - src/mopt/slices.jl | 17 +- test/REQUIRE | 1 - test/include/test-include.jl | 2 +- test/runtests.jl | 2 + 9 files changed, 391 insertions(+), 15 deletions(-) create mode 100644 Manifest.toml create mode 100644 Project.toml diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 0000000..b262b8f --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,358 @@ +[[Arpack]] +deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "5b046410fb617d9cf2f8bc0edd5da05a2e5a2ad4" +uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" +version = "0.2.3" + +[[Base64]] +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", "Pkg", "SHA", "Test"] +git-tree-sha1 = "b530fbeb6f41ab5a83fbe3db1fcbe879334bcd2d" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.4.2" + +[[CategoricalArrays]] +deps = ["Compat", "Future", "JSON", "Missings", "Printf", "Reexport"] +git-tree-sha1 = "8009a507e2e3db040d6854a82ce959fb5971cb37" +uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597" +version = "0.3.13" + +[[CodecZlib]] +deps = ["BinaryProvider", "Libdl", "Pkg", "Test", "TranscodingStreams"] +git-tree-sha1 = "83cb3d65c37ea1364c2d5bf7bcea41843ba645dc" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.5.0" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "0e3209ba7418aed732e5c3818076b4400ee36c08" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.4" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Pkg", "Printf", "Reexport", "Test"] +git-tree-sha1 = "8c89e0a9a583954eae3efcf6a531e51c02b38cee" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.4" + +[[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 = "ae262fa91da6a74e8937add6b613f58cd56cdad4" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.1.0" + +[[Contour]] +deps = ["LinearAlgebra", "StaticArrays", "Test"] +git-tree-sha1 = "b974e164358fea753ef853ce7bad97afec15bb80" +uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" +version = "0.5.1" + +[[DataFrames]] +deps = ["CategoricalArrays", "CodecZlib", "Compat", "DataStreams", "Dates", "InteractiveUtils", "LinearAlgebra", "Missings", "Pkg", "Printf", "Random", "Reexport", "SortingAlgorithms", "Statistics", "StatsBase", "Test", "TranscodingStreams", "Unicode", "WeakRefStrings"] +git-tree-sha1 = "31cca86a48add8d5cdd9457c4f75ee5577ef3488" +uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +version = "0.13.1" + +[[DataFramesMeta]] +deps = ["DataFrames", "Random", "Statistics", "Test"] +git-tree-sha1 = "5463b876fb15d6ebae76835a2c832fb08e6da753" +uuid = "1313f7d8-7da2-5740-9ea0-a2ca25f37964" +version = "0.4.0" + +[[DataStreams]] +deps = ["Dates", "Missings", "Pkg", "Test", "WeakRefStrings"] +git-tree-sha1 = "69c72a1beb4fc79490c361635664e13c8e4a9548" +uuid = "9a8bc11e-79be-5b39-94d7-1ccc349a1a85" +version = "0.4.1" + +[[DataStructures]] +deps = ["InteractiveUtils", "REPL", "Random", "Serialization", "Test"] +git-tree-sha1 = "5162c360c52e9265e0bfafb71415c31f746f7e04" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.12.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[Distributed]] +deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[Distributions]] +deps = ["Distributed", "LinearAlgebra", "PDMats", "Pkg", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"] +git-tree-sha1 = "c24e9b6500c037673f0241a2783472b8c3d080c7" +uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" +version = "0.16.4" + +[[DocStringExtensions]] +deps = ["LibGit2", "Markdown", "Pkg", "Test"] +git-tree-sha1 = "a016e0bfe98a748c4488e2248c2ef4c67d6fdd35" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.5.0" + +[[Documenter]] +deps = ["Compat", "DocStringExtensions", "Logging", "REPL"] +git-tree-sha1 = "7534ff3c50333a69ae0778d4d869e6f5c9ec022a" +uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +version = "0.19.6" + +[[FileIO]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "b80161b7e679a1241f9441ebfa60b62d4239cf99" +uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +version = "1.0.1" + +[[FixedPointNumbers]] +deps = ["Pkg", "Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[Future]] +deps = ["Random"] +uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" + +[[GLM]] +deps = ["Distributions", "LinearAlgebra", "Pkg", "Printf", "Random", "Reexport", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "StatsModels"] +git-tree-sha1 = "174a81dfee47880cf4b67cc247868849a217df78" +uuid = "38e38edf-8417-5370-95a0-9cbb8c7f171a" +version = "1.0.1" + +[[GR]] +deps = ["Base64", "DelimitedFiles", "Pkg", "Random", "Serialization", "Sockets", "Test"] +git-tree-sha1 = "0437921cbf8ee555ab7a2a3115c1d0907289e816" +uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +version = "0.34.1" + +[[InteractiveUtils]] +deps = ["LinearAlgebra", "Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[JLD2]] +deps = ["CodecZlib", "DataStructures", "FileIO", "LinearAlgebra", "Mmap", "Printf", "Random", "Test"] +git-tree-sha1 = "3ba90ff93e1d5b9b2103588051c2d349fae54dac" +uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +version = "0.1.2" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Pkg", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "fec8e4d433072731466d37ed0061b3ba7f70eeb9" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.19.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Measures]] +deps = ["Pkg", "Test"] +git-tree-sha1 = "ddfd6d13e330beacdde2c80de27c1c671945e7d9" +uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" +version = "0.3.0" + +[[Missings]] +deps = ["Compat"] +git-tree-sha1 = "866fb034899be6055dcb6cb1a70fbda379bb0b55" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.2.10" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[PDMats]] +deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] +git-tree-sha1 = "9e3e7a5c9b8cfdba8c01a1bcae38fe0144936fda" +uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" +version = "0.9.5" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[PlotThemes]] +deps = ["PlotUtils", "Requires", "Test"] +git-tree-sha1 = "f3afd2d58e1f6ac9be2cea46e4a9083ccc1d990b" +uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" +version = "0.3.0" + +[[PlotUtils]] +deps = ["Colors", "Dates", "Printf", "Random", "Reexport", "Test"] +git-tree-sha1 = "78553a920c4869d20742ba66193e3692369086ec" +uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" +version = "0.5.4" + +[[Plots]] +deps = ["Base64", "Contour", "Dates", "FixedPointNumbers", "GR", "JSON", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "Printf", "REPL", "RecipesBase", "Reexport", "Requires", "Showoff", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "UUIDs"] +git-tree-sha1 = "935241178e80158451cc33f4af7c57f671b881b8" +uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +version = "0.19.3" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[QuadGK]] +deps = ["DataStructures", "LinearAlgebra", "Test"] +git-tree-sha1 = "7e8dff9c205f36eceaf6e62a43ff851637ca45fc" +uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +version = "2.0.2" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RecipesBase]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "b18c3d875ad6805e3db59c4e81f206f04df71d66" +uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" +version = "0.5.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[Rmath]] +deps = ["BinaryProvider", "Libdl", "Pkg", "Random", "Statistics", "Test"] +git-tree-sha1 = "9a6c758cdf73036c3239b0afbea790def1dabff9" +uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" +version = "0.5.0" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Showoff]] +deps = ["Compat", "Pkg"] +git-tree-sha1 = "276b24f3ace98bec911be7ff2928d497dc759085" +uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" +version = "0.2.1" + +[[Sockets]] +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]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Compat", "Libdl"] +git-tree-sha1 = "d12f8917be3782f4b800ba16003b8d0d4858c2e5" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.0" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "d432c79bef174a830304f8601427a4357dfdbfb7" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.8.3" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "723193a13e8078cec6dcd0b8fe245c8bfd81690e" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.25.0" + +[[StatsFuns]] +deps = ["Pkg", "Rmath", "SpecialFunctions", "Test"] +git-tree-sha1 = "d14bb7b03defd2deaa5675646f6783089e0556f0" +uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +version = "0.7.0" + +[[StatsModels]] +deps = ["Compat", "DataFrames", "Pkg", "StatsBase", "Test"] +git-tree-sha1 = "8af0d8dbcdee59daa386167ee0cf0278e5c44263" +uuid = "3eaba693-59b7-5ba5-a881-562e759f1c8d" +version = "0.3.1" + +[[SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[TranscodingStreams]] +deps = ["DelimitedFiles", "Pkg", "Random", "Test"] +git-tree-sha1 = "a34a2d588e2d2825602bf14a24216d5c8b0921ec" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.8.1" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[WeakRefStrings]] +deps = ["Missings", "Random", "Test"] +git-tree-sha1 = "1087e8be380f2c8b96434b02bb1150fc1c511135" +uuid = "ea10d353-3f73-51f8-a26c-33c1cb351aa5" +version = "0.5.3" diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..0b1f34d --- /dev/null +++ b/Project.toml @@ -0,0 +1,19 @@ +name = "MomentOpt" +uuid = "bc769cb7-f249-5bba-802a-79f18cb247ec" +authors = ["Florian Oswald "] +version = "0.1.0" + +[deps] +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964" +DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a" +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" +PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/src/MomentOpt.jl b/src/MomentOpt.jl index 568f2b8..7d8521e 100644 --- a/src/MomentOpt.jl +++ b/src/MomentOpt.jl @@ -15,6 +15,8 @@ using Documenter using Plots using FileIO using JLD2 +using GLM +using Distributed gr() @@ -58,7 +60,7 @@ export addParam!, include("mopt/mprob.jl") # include("mopt/incmopt.jl") include("mopt/Eval.jl") -# include("mopt/slices.jl") +include("mopt/slices.jl") # include("mopt/AlgoAbstract.jl") # include("mopt/AlgoBGP.jl") include("mopt/ObjExamples.jl") diff --git a/src/mopt/Eval.jl b/src/mopt/Eval.jl index 0475168..63131c5 100644 --- a/src/mopt/Eval.jl +++ b/src/mopt/Eval.jl @@ -17,7 +17,7 @@ * `options`: Dict of options and other info """ -struct Eval +mutable struct Eval value :: Float64 time :: Float64 diff --git a/src/mopt/econometrics.jl b/src/mopt/econometrics.jl index 7050c15..f196b1d 100644 --- a/src/mopt/econometrics.jl +++ b/src/mopt/econometrics.jl @@ -27,7 +27,6 @@ Computes an approximation to the simulated score of moments at the optimal param """ function score(MA::MAlgo) - using GLM p = parameters_ID(MA.MChains) inf = infos(MA.MChains) diff --git a/src/mopt/slices.jl b/src/mopt/slices.jl index dd3b0f2..57e8d37 100644 --- a/src/mopt/slices.jl +++ b/src/mopt/slices.jl @@ -1,7 +1,6 @@ -# TODO -# add plot slices -type MyT + +mutable struct MyT data :: Dict end @@ -20,7 +19,7 @@ export Slice,slices,add!,get """ Slice -A *slice* in dimension ``j`` of a function ``f \in \mathbb{R}^N`` is defined as ``f(p[1],...,p[j],...,p[N])``, where `p` is the initial parameter vector and `p[j] = linspace(lower[j],upper[j],npoints)`, where `lower[j],upper[j]` are the bounds of the parameter space in dimension ``j``. +A *slice* in dimension ``j`` of a function ``f ∈ \\mathbb{R}^N`` is defined as ``f(p[1],...,p[j],...,p[N])``, where `p` is the initial parameter vector and `p[j] = linspace(lower[j],upper[j],npoints)`, where `lower[j],upper[j]` are the bounds of the parameter space in dimension ``j``. ## Fields @@ -36,11 +35,9 @@ julia> m = MProb() julia> p = OrderedDict(:p1=>1.1,:p2=>pi) julia> m = OrderedDict(:m1=>rand(),:m2=>e) julia> Slice(p,m) - ``` - """ -type Slice +mutable struct Slice res :: Union{Dict,OrderedDict} # result p0 :: Union{Dict,OrderedDict} # initial param m0 :: Union{Dict,OrderedDict} # data moments @@ -118,7 +115,7 @@ function doSlices(m::MProb,npoints::Int,parallel=false,pad=0.1) # initialize eval ev = Eval(m,m.initial_value) - @info(logger,"slicing along $pp") + @info "slicing along $pp" if parallel vv = pmap( linspace(bb[:lb], bb[:ub], npoints) ) do pval @@ -138,14 +135,14 @@ function doSlices(m::MProb,npoints::Int,parallel=false,pad=0.1) for v in vv if (typeof(v) <: Exception) - warn("exception received. value not stored.") + @warn "exception received. value not stored." else add!( res, pp, v) end end end t1 = round((time()-t0)/60) - @info(logger,"done after $t1 minutes") + @info "done after $t1 minutes" return res end diff --git a/test/REQUIRE b/test/REQUIRE index 4e217d8..4eb7a3c 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,2 +1 @@ -TestSetExtensions DataFrames \ No newline at end of file diff --git a/test/include/test-include.jl b/test/include/test-include.jl index 66a5b8f..132cf0d 100644 --- a/test/include/test-include.jl +++ b/test/include/test-include.jl @@ -18,7 +18,7 @@ function test_chain() end -struct MyP +mutable struct MyP a :: Float64 b :: Float64 diff --git a/test/runtests.jl b/test/runtests.jl index 93ae5d4..afaa31f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -21,5 +21,7 @@ include(joinpath(dir,"include","test-include.jl")) @testset "Running MomentOpt tests" begin include(joinpath(dir,"test_MProb.jl")) + include(joinpath(dir,"test_Eval.jl")) + include(joinpath(dir,"test_slices.jl")) end From 5ab5c124c48a3b47f0c3e2caee5ad14723e2c5d8 Mon Sep 17 00:00:00 2001 From: Florian Oswald Date: Mon, 17 Sep 2018 16:28:48 +0200 Subject: [PATCH 3/4] turn off precompilation to avoid Plots.jl warnings --- src/MomentOpt.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MomentOpt.jl b/src/MomentOpt.jl index 7d8521e..45b5c35 100644 --- a/src/MomentOpt.jl +++ b/src/MomentOpt.jl @@ -1,6 +1,8 @@ module MomentOpt +__precompile__(false) + # Dependencies # ############ From 61f5aa8419c5fdaeae9505560065133ab77afbc2 Mon Sep 17 00:00:00 2001 From: Florian Oswald Date: Mon, 17 Sep 2018 17:52:56 +0200 Subject: [PATCH 4/4] most functionality back except: save and load. some tests still turned off because of that --- src/MomentOpt.jl | 13 +++--- src/mopt/AlgoAbstract.jl | 14 +++--- src/mopt/AlgoBGP.jl | 94 ++++++++++++++++++++-------------------- src/mopt/ObjExamples.jl | 2 +- src/mopt/incmopt.jl | 2 +- test/REQUIRE | 3 +- test/runtests.jl | 9 +++- test/test_Eval.jl | 24 +++++----- test/test_algoBGP.jl | 25 ++++------- 9 files changed, 94 insertions(+), 92 deletions(-) diff --git a/src/MomentOpt.jl b/src/MomentOpt.jl index 45b5c35..85df003 100644 --- a/src/MomentOpt.jl +++ b/src/MomentOpt.jl @@ -10,7 +10,7 @@ using Logging using Distributions using DataFrames, DataFramesMeta import Base.show -using Statistics: std, mean +using Statistics using DataStructures using PDMats using Documenter @@ -27,6 +27,7 @@ gr() LogLevel(Logging.Debug) import Base.get,Base.write, Base.start, Base.== +import Statistics: mean # exports: Types export MProb, Eval,MAlgo, MAlgoBGP @@ -60,14 +61,14 @@ export addParam!, # ############ include("mopt/mprob.jl") -# include("mopt/incmopt.jl") +include("mopt/incmopt.jl") include("mopt/Eval.jl") include("mopt/slices.jl") -# include("mopt/AlgoAbstract.jl") -# include("mopt/AlgoBGP.jl") +include("mopt/AlgoAbstract.jl") +include("mopt/AlgoBGP.jl") include("mopt/ObjExamples.jl") -# include("mopt/Examples.jl") -# include("mopt/plotting.jl") +include("mopt/Examples.jl") +include("mopt/plotting.jl") end # module diff --git a/src/mopt/AlgoAbstract.jl b/src/mopt/AlgoAbstract.jl index 80f2cc6..58dca20 100644 --- a/src/mopt/AlgoAbstract.jl +++ b/src/mopt/AlgoAbstract.jl @@ -24,7 +24,7 @@ function runMOpt!( algo::MAlgo ) # load data from file if set in algo.opts # setup cluster if required - @info(logger,"Starting estimation loop.") + @info "Starting estimation loop." t0 = time() # do iteration @@ -42,7 +42,7 @@ function runMOpt!( algo::MAlgo ) if haskey(algo.opts,"filename") == true if mod(i,algo.opts["save_frequency"]) == 0 save(algo,algo.opts["filename"]) - @info(logger,"saved data at iteration $i") + @info "saved data at iteration $i" end end end @@ -58,13 +58,13 @@ function runMOpt!( algo::MAlgo ) save(algo,algo.opts["filename"]) else # if no filename is provided, generated a random number - filename = string(rand(1:Int(1e8))) - @warn(logger,"could not find 'filename' in algo.opts") - @warn(logger,"generated a random name instead: $(filename)") - save(algo,filename) + filename,err = mktemp() + @warn "could not find 'filename' in algo.opts" + save(algo,filename) end - @info(logger,"Done with estimation after $t1 minutes") + + @info "Done with estimation after $t1 minutes" if get(algo.opts,"animate",false) gif(algo.anim,joinpath(dirname(@__FILE__),"../../proposals.gif"),fps=2) diff --git a/src/mopt/AlgoBGP.jl b/src/mopt/AlgoBGP.jl index 253f85a..cb8350d 100644 --- a/src/mopt/AlgoBGP.jl +++ b/src/mopt/AlgoBGP.jl @@ -46,7 +46,7 @@ MCMC Chain storage for BGP algorithm. * `maxdist`: what's the maximal function value you will accept when proposed a swap. i.e. if ev.value > maxdist, you don't want to swap with ev. """ -type BGPChain <: AbstractChain +mutable struct BGPChain <: AbstractChain evals :: Array{Eval} best_id :: Vector{Int} # index of best eval.value so far best_val :: Vector{Float64} # best eval.value so far @@ -68,7 +68,7 @@ type BGPChain <: AbstractChain function BGPChain(id::Int=1,n::Int=10,m::MProb=MProb(),sig::Vector{Float64}=Float64[],upd::Int64=10,upd_by::Float64=0.01,smpl_iters::Int=1000,maxdist::Float64=10.0,acc_tuner::Float64=2.0) @assert length(sig) == length(m.params_to_sample) this = new() - this.evals = Array{Eval}(n) + this.evals = Array{Eval}(undef, n) this.best_val = ones(n) * Inf this.best_id = -ones(Int,n) this.curr_val = ones(n) * Inf @@ -166,7 +166,7 @@ function lastAccepted(c::BGPChain) if c.iter==1 return 1 else - return find(c.accepted[1:(c.iter)])[end] + return findall(c.accepted[1:(c.iter)])[end] end end getIterEval(c::BGPChain,i::Int) = c.evals[i] @@ -216,7 +216,7 @@ function next_eval(c::BGPChain) # increment interation c.iter += 1 - @debug(logger,"iteration = $(c.iter)") + @debug "iteration = $(c.iter)" # returns an OrderedDict pp = proposal(c) @@ -237,8 +237,8 @@ end function doAcceptReject!(c::BGPChain,eval_new::Eval) - @debug(logger,"") - @debug(logger,"doAcceptReject!") + @debug "" + @debug "doAcceptReject!" if c.iter == 1 # accept everything. eval_new.prob =1.0 @@ -257,10 +257,10 @@ function doAcceptReject!(c::BGPChain,eval_new::Eval) # this forumulation: old - new # because we are MINIMIZING the value of the objective function eval_new.prob = minimum([1.0,exp( c.acc_tuner * ( eval_old.value - eval_new.value) )]) #* (eval_new.value < ) - @debug(logger,"eval_new.value = $(eval_new.value)") - @debug(logger,"eval_old.value = $(eval_old.value)") - @debug(logger,"eval_new.prob = $(round(eval_new.prob,2))") - @debug(logger,"c.probs_acc[c.iter] = $(round(c.probs_acc[c.iter],2))") + @debug "eval_new.value = $(eval_new.value)" + @debug "eval_old.value = $(eval_old.value)" + @debug "eval_new.prob = $(round(eval_new.prob,2))" + @debug "c.probs_acc[c.iter] = $(round(c.probs_acc[c.iter],2))" if !isfinite(eval_new.prob) eval_new.prob = 0.0 @@ -269,7 +269,7 @@ function doAcceptReject!(c::BGPChain,eval_new::Eval) elseif !isfinite(eval_old.value) # should never have gotten accepted - @debug(logger,"eval_old is not finite") + @debug "eval_old is not finite" eval_new.prob = 1.0 eval_new.accepted = true else @@ -281,9 +281,9 @@ function doAcceptReject!(c::BGPChain,eval_new::Eval) eval_new.accepted = false end end - @debug(logger,"eval_new.accepted = $(eval_new.accepted)") - @debug(logger,"") - @debug(logger,"") + @debug "eval_new.accepted = $(eval_new.accepted)" + @debug "" + @debug "" end @@ -301,10 +301,10 @@ function doAcceptReject!(c::BGPChain,eval_new::Eval) # if mod(c.iter,c.sigma_update_steps) == 0 # too_high = c.accept_rate > 0.234 # if too_high - # @debug(logger,"acceptance rate on BGPChain $(c.id) is too high at $(c.accept_rate). increasing variance of each param by $(100* c.sigma_adjust_by)%.") + # @debug "acceptance rate on BGPChain $(c.id) is too high at $(c.accept_rate). increasing variance of each param by $(100* c.sigma_adjust_by)%.") # set_sigma!(c,diag(c.sigma) .* (1.0+c.sigma_adjust_by) ) # else - # @debug(logger,"acceptance rate on BGPChain $(c.id) is too low at $(c.accept_rate). decreasing variance of each param by $(100* c.sigma_adjust_by)%.") + # @debug "acceptance rate on BGPChain $(c.id) is too low at $(c.accept_rate). decreasing variance of each param by $(100* c.sigma_adjust_by)%.") # set_sigma!(c,diag(c.sigma) .* (1.0-c.sigma_adjust_by) ) # end # end @@ -341,9 +341,9 @@ function proposal(c::BGPChain) # Transition Kernel is q(.|theta(t-1)) ~ TruncatedN(theta(t-1), Sigma,lb,ub) newp = OrderedDict(zip(collect(keys(mu)),mysample(MvNormal(collect(values(mu)),c.sigma),lb,ub,c.smpl_iters))) - # @debug(logger,"iteration $(c.iter)") - # @debug(logger,"old param: $(ev_old.params)") - # @debug(logger,"new param: $newp") + # @debug "iteration $(c.iter)") + # @debug "old param: $(ev_old.params)") + # @debug "new param: $newp") # flat kernel: random choice in each dimension. # newp = Dict(zip(collect(keys(mu)),rand(length(lb)) .* (ub .- lb))) @@ -372,7 +372,7 @@ mutable struct MAlgoBGP <: MAlgo init_sd = OrderedDict{Symbol,Float64}() if opts["N"] > 1 - temps = linspace(1.0,opts["maxtemp"],opts["N"]) + temps = range(1.0,opts["maxtemp"],opts["N"]) # initial std dev for each parameter to achieve at least bound_prob on the bounds # println("opts=$opts") # println("pars = $( m.params_to_sample)") @@ -469,9 +469,9 @@ function computeNextIteration!( algo::MAlgoBGP ) cs = pmap( x->next_eval(x), algo.chains ) # this does proposal, evaluateObjective, doAcceptRecject else # for i in algo.chains - # @debug(logger," ") - # @debug(logger," ") - # @debug(logger,"debugging chain id $(i.id)") + # @debug " ") + # @debug " ") + # @debug "debugging chain id $(i.id)") # next_eval!(i) # end cs = map( x->next_eval(x), algo.chains ) # this does proposal, evaluateObjective, doAcceptRecject @@ -511,9 +511,9 @@ function exchangeMoves!(algo::MAlgoBGP) samples = algo["N"] < 3 ? algo["N"]-1 : algo["N"] pairs = sample(props,samples,replace=false) - @debug(logger,"") - @debug(logger,"exchangeMoves: proposing pairs") - @debug(logger,"$pairs") + @debug "" + @debug "exchangeMoves: proposing pairs" + @debug "$pairs" for p in pairs i,j = p @@ -522,20 +522,20 @@ function exchangeMoves!(algo::MAlgoBGP) # my version # if rand() < algo["mixprob"] # if (evj.value < evi.value) # if j's value is better than i's - # @debug(logger,"$j better than $i") - # # @debug(logger,"$(abs(j.value)) < $(algo.chains[p[1]].maxdist)") + # @debug "$j better than $i") + # # @debug "$(abs(j.value)) < $(algo.chains[p[1]].maxdist)") # # swap_ev!(algo,p) # set_ev_i2j!(algo,i,j) # else - # @debug(logger,"$i better than $j") + # @debug "$i better than $j") # set_ev_i2j!(algo,j,i) # end # end # BGP version # exchange i with j if rho(S(z_j),S(data)) < epsilon_i - @debug(logger,"Exchanging $i with $j? Distance is $(algo.dist_fun(evj.value - evi.value))") - @debug(logger,"Exchange: $(algo.dist_fun(evj.value - evi.value) < algo["maxdists"][i])") + @debug "Exchanging $i with $j? Distance is $(algo.dist_fun(evj.value - evi.value))" + @debug "Exchange: $(algo.dist_fun(evj.value - evi.value) < algo["maxdists"][i])" if algo.dist_fun(evj.value - evi.value) < algo["maxdists"][i] swap_ev_ij!(algo,i,j) end @@ -551,7 +551,7 @@ function exchangeMoves!(algo::MAlgoBGP) # tmp = abs(e2.value - e1.value) / abs(e1.value) # # tmp = abs(evals(algo.chains[ch2],algo.chains[ch2].i)[1] - oldval) / abs(oldval) # percent deviation # if tmp < dtol - # @debug(logger,"perc dist $ch and $ch2 is $tmp. will label that `close`.") + # @debug "perc dist $ch and $ch2 is $tmp. will label that `close`.") # push!(close,ch2) # end # end @@ -559,7 +559,7 @@ function exchangeMoves!(algo::MAlgoBGP) # # 2) with y% probability exchange with a randomly chosen BGPChain from close # if length(close) > 0 # ex_with = rand(close) - # @debug(logger,"making an exchange move for BGPChain $ch with BGPChain $ex_with set: $close") + # @debug "making an exchange move for BGPChain $ch with BGPChain $ex_with set: $close") # swap_ev!(algo,Pair(ch,ex_with)) # end # end @@ -567,7 +567,7 @@ function exchangeMoves!(algo::MAlgoBGP) end function set_ev_i2j!(algo::MAlgoBGP,i::Int,j::Int) - @debug(logger,"setting ev of $i to ev of $j") + @debug "setting ev of $i to ev of $j" ci = algo.chains[i] cj = algo.chains[j] @@ -581,7 +581,7 @@ function set_ev_i2j!(algo::MAlgoBGP,i::Int,j::Int) set_exchanged!(ci,j) end function swap_ev_ij!(algo::MAlgoBGP,i::Int,j::Int) - @debug(logger,"swapping ev of $i with ev of $j") + @debug "swapping ev of $i with ev of $j" ci = algo.chains[i] cj = algo.chains[j] @@ -619,7 +619,7 @@ function extendBGPChain!(chain::BGPChain, algo::MAlgoBGP, extraIter::Int64) #--------------------------------------- # 1. Change the size: #-------------------- - chain.evals = Array{Eval}(finalIter) + chain.evals = Array{Eval}(undef,finalIter) chain.best_val = ones(finalIter) * Inf chain.best_id = -ones(Int, finalIter) chain.curr_val = ones(finalIter) * Inf @@ -652,8 +652,8 @@ stopeed. Add extraIter additional steps to the optimization process. """ function restartMOpt!(algo::MAlgoBGP, extraIter::Int64) - @info(logger,"Restarting estimation loop with $(extraIter) iterations.") - @info(logger,"Current best value on chain 1 before restarting $(MomentOpt.summary(algo)[:best_val][1])") + @info "Restarting estimation loop with $(extraIter) iterations." + @info "Current best value on chain 1 before restarting $(MomentOpt.summary(algo)[:best_val][1])" t0 = time() # Minus 1, to follow the MomentOpt convention @@ -675,13 +675,13 @@ function restartMOpt!(algo::MAlgoBGP, extraIter::Int64) #change maxiter in the dictionary storing options #------------------------------------------------ - @debug(logger, "Setting algo.opts[\"maxiter\"] = $(finalIter)") + @debug "Setting algo.opts[\"maxiter\"] = $(finalIter)" algo.opts["maxiter"] = finalIter # do iterations, starting at initialIter # and not at i=1, as in runMOpt! for i in initialIter:finalIter - @debug(logger,"iteration $(i)") + @debug "iteration $(i)" algo.i = i @@ -711,7 +711,7 @@ function restartMOpt!(algo::MAlgoBGP, extraIter::Int64) if haskey(algo.opts,"filename") == true if mod(i,algo.opts["save_frequency"]) == 0 save(algo,algo.opts["filename"]) - @info(logger,"saved data at iteration $i") + @info "saved data at iteration $i" end end end @@ -725,14 +725,14 @@ function restartMOpt!(algo::MAlgoBGP, extraIter::Int64) save(algo,algo.opts["filename"]) else # if no filename is provided, generated a random number - filename = string(rand(1:Int(1e8))) - @warn(logger,"could not find 'filename' in algo.opts") - @warn(logger,"generated a random name instead: $(filename)") - save(algo,filename) + filename = string(rand(1:Int(1e8))) + @warn "could not find 'filename' in algo.opts" + @warn "generated a random name instead: $(filename)" + save(algo,filename) end - @info(logger,"Done with estimation after $t1 minutes") - @info(logger,"New best value on chain 1 = $(MomentOpt.summary(algo)[:best_val][1])") + @info "Done with estimation after $t1 minutes" + @info "New best value on chain 1 = $(MomentOpt.summary(algo)[:best_val][1])" if get(algo.opts,"animate",false) gif(algo.anim,joinpath(dirname(@__FILE__),"../../proposals.gif"),fps=2) diff --git a/src/mopt/ObjExamples.jl b/src/mopt/ObjExamples.jl index ba98c36..3fdeb7d 100644 --- a/src/mopt/ObjExamples.jl +++ b/src/mopt/ObjExamples.jl @@ -67,7 +67,7 @@ function objfunc_norm(ev::Eval) ns = 10000 sigma = [1.0;1.0] randMultiNormal = MomentOpt.MvNormal(mu,MomentOpt.PDiagMat(sigma)) - simM = mean(rand(randMultiNormal,ns),2) + simM = mean(rand(randMultiNormal,ns),dims = 2) simMoments = Dict(:mu1 => simM[1], :mu2 => simM[2]) diff --git a/src/mopt/incmopt.jl b/src/mopt/incmopt.jl index 982ef15..fe3a7dd 100644 --- a/src/mopt/incmopt.jl +++ b/src/mopt/incmopt.jl @@ -158,7 +158,7 @@ function fitMirror!(x::DataFrame,b::Dict) end -function findInterval{T<:Number}(x::T,vec::Array{T}) +function findInterval(x::T, vec::Array{T}) where T <: Number out = zeros(Int,length(x)) sort!(vec) diff --git a/test/REQUIRE b/test/REQUIRE index 4eb7a3c..a46c011 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1 +1,2 @@ -DataFrames \ No newline at end of file +DataFrames +DataStructures diff --git a/test/runtests.jl b/test/runtests.jl index afaa31f..0dcab1a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,6 +3,11 @@ using MomentOpt using Test using DataFrames +using Distributed +using Random +using GLM +using DataStructures +using Statistics # If we want the test to pass, we need this # see https://github.com/JuliaPlots/Plots.jl/issues/1076 @@ -22,6 +27,8 @@ include(joinpath(dir,"include","test-include.jl")) include(joinpath(dir,"test_MProb.jl")) include(joinpath(dir,"test_Eval.jl")) - include(joinpath(dir,"test_slices.jl")) + # include(joinpath(dir,"test_slices.jl")) + # include(joinpath(dir,"test_AlgoAbstract.jl")) + include(joinpath(dir,"test_AlgoBGP.jl")) end diff --git a/test/test_Eval.jl b/test/test_Eval.jl index 0be72a8..ca447e2 100644 --- a/test/test_Eval.jl +++ b/test/test_Eval.jl @@ -63,18 +63,18 @@ @test ev.value == 4.2 end - @testset "testing saving/loading" begin - MomentOpt.FileIO.save("test5.jld2",Dict("ev"=>ev,"evs"=>[ev,ev2])) - sleep(1) - ev2_ = MomentOpt.FileIO.load("test5.jld2", "ev") - @test ev2_ == ev - - evs = MomentOpt.FileIO.load("test5.jld2","evs") - @test evs[1] == ev - @test evs[2] == ev2 - rm("test5.jld2") - - end + # @testset "testing saving/loading" begin + # MomentOpt.FileIO.save("test5.jld2",Dict("ev"=>ev,"evs"=>[ev,ev2])) + # sleep(1) + # ev2_ = MomentOpt.FileIO.load("test5.jld2", "ev") + # @test ev2_ == ev + + # evs = MomentOpt.FileIO.load("test5.jld2","evs") + # @test evs[1] == ev + # @test evs[2] == ev2 + # rm("test5.jld2") + + # end end diff --git a/test/test_algoBGP.jl b/test/test_algoBGP.jl index a554280..a1a49ed 100644 --- a/test/test_algoBGP.jl +++ b/test/test_algoBGP.jl @@ -62,12 +62,11 @@ addprocs(2) @everywhere using MomentOpt - using GLM - using DataStructures - using DataFrames - using Plots + @everywhere using Statistics + @everywhere using MomentOpt + - srand(1234) + Random.seed!(1234) #------------------------ # initialize the problem: @@ -115,7 +114,7 @@ # draw ns observations from N([mu], sigma): randMultiNormal = MomentOpt.MvNormal(mu,MomentOpt.PDiagMat(sigma)) # calculate the mean of the simulated data - simM = mean(rand(randMultiNormal,ns),2) + simM = mean(rand(randMultiNormal,ns),dims = 2) # store simulated moments in a dictionary simMoments = Dict(:mu1 => simM[1], :mu2 => simM[2]) @@ -248,12 +247,6 @@ # in the first place (keeping random shocks constant) @testset "Testing stopping and restarting" begin - using MomentOpt - using GLM - using DataStructures - using DataFrames - using Plots - #------------------------ # initialize the problem: #------------------------ @@ -292,10 +285,10 @@ #sigma is set to be the identity matrix sigma = [1.0 ;1.0] # draw ns observations from N([mu], sigma): - srand(1234) + Random.seed!(1234) randMultiNormal = MomentOpt.MvNormal(mu,MomentOpt.PDiagMat(sigma)) # calculate the mean of the simulated data - simM = mean(rand(randMultiNormal,ns),2) + simM = mean(rand(randMultiNormal,ns),dims = 2) # store simulated moments in a dictionary simMoments = Dict(:mu1 => simM[1], :mu2 => simM[2]) @@ -378,7 +371,7 @@ # set-up BGP algorithm: - srand(1234) + Random.seed!(1234) MA = MAlgoBGP(mprob,opts) # run the estimation @@ -430,7 +423,7 @@ # set-up BGP algorithm: - srand(1234) + Random.seed!(1234) MA2 = MAlgoBGP(mprob2,opts2) # run the estimation: