diff --git a/Project.toml b/Project.toml index 7d338db..e6486ad 100644 --- a/Project.toml +++ b/Project.toml @@ -14,11 +14,11 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df" [compat] ADNLPModels = "^0.3, 0.4, 0.7" Distributions = "0.25" +MLDatasets = "^0.7.4" NLPModels = "0.16, 0.17, 0.18, 0.19, 0.20" Noise = "0.2" Requires = "1" julia = "^1.3.0" -MLDatasets = "^0.7.4" [extras] ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a" @@ -28,4 +28,3 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["ADNLPModels", "DifferentialEquations", "MLDatasets", "Test"] - diff --git a/docs/Project.toml b/docs/Project.toml index 5977598..1a69045 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -2,6 +2,7 @@ ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a" DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +MLDatasets = "eb30cadb-4394-5ae3-aed4-317e484a6458" RegularizedProblems = "ea076b23-609f-44d2-bb12-a4ae45328278" [compat] diff --git a/docs/make.jl b/docs/make.jl index 2275125..331cab7 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,5 +1,5 @@ using Documenter -using ADNLPModels, DifferentialEquations +using ADNLPModels, DifferentialEquations, MLDatasets using RegularizedProblems makedocs( diff --git a/src/nnmf.jl b/src/nnmf.jl index ca85762..a2f163f 100644 --- a/src/nnmf.jl +++ b/src/nnmf.jl @@ -15,14 +15,31 @@ function nnmf_data(m::Int, n::Int, k::Int, T::DataType = Float64) parameters[i][2][j, j] = parameters[i][1][j] > 0.0 ? 0.3 : ϵ # to avoid problems in Cholesky factorization when calling MixtureModel end end - # generate a mixture of gaussians + # generate a mixture of gaussians dist = MixtureModel(MvNormal, parameters) - # sample data + # sample data A = rand(dist, m)' A[A .< 0] .= 0 return A end + +""" + model, Av, selected = nnmf_model(m = 100, n = 50, k = 10, T = Float64) + +Return an instance of an `NLPModel` representing the non-negative matrix factorization +objective + + f(W, H) = ½ ‖A - WH‖₂², + +where A ∈ Rᵐˣⁿ has non-negative entries and can be separeted into k clusters, `Av = A[:]`. +The vector of indices `selected = k*m+1: k*(m+n)` is used to indicate the components of W ∈ Rᵐˣᵏ and H ∈ Rᵏˣⁿ to apply the regularizer to (so that the regularizer only applies to entries of H). + +## Arguments +* `m :: Int`: the number of rows of A +* `n :: Int`: the number of columns of A (with `n` ≥ `m`) +* `k :: Int`: the number of clusters +""" function nnmf_model(m::Int = 100, n::Int = 50, k::Int = 10, T::DataType = Float64) A = nnmf_data(m, n, k, T) r = similar(A, m * n)