Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

example for affinity propagation

  • Loading branch information...
commit 99d8400b044cf8117143e34545ae0cb55a8f23e9 1 parent f2d34c5
@pluskid pluskid authored
View
2  README.md
@@ -100,7 +100,7 @@ interpreted as the tendency of assigning point ``i`` to point ``j``
clusters. For example, if ``S[i,i]==max(S)`` for all ``i``, then
every point will be an exemplar itself.
-Usually, assigning the diagonal of ``S`` to be the *medium of all the
+Usually, assigning the diagonal of ``S`` to be the *median of all the
rest entries* could lead to reasonable results.
Interfaces:
View
2  src/Clustering.jl
@@ -13,5 +13,5 @@ module Clustering
export AffinityPropagationOpts
export affinity_propagation
- include("ap.jl")
+ include("affprop.jl")
end
View
8 src/ap.jl → src/affprop.jl
@@ -38,7 +38,7 @@ function affinity_propagation{T<:FloatingPoint}(S::Matrix{T}, opts::AffinityProp
IC = nothing
for n_iter = 1:opts.max_iter
- update_message!(psi, phi, S, n, opts)
+ affprop_update_message!(psi, phi, S, n, opts)
IC = diag(psi) + diag(phi) .> 0
exemplars[:, mod(n_iter-1, opts.n_stop_check)+1] = IC
@@ -61,7 +61,7 @@ function affinity_propagation{T<:FloatingPoint}(S::Matrix{T}, opts::AffinityProp
end
end
- assignment, exemplar_index = decide_assignment(phi, S, n, IC)
+ assignment, exemplar_index = affprop_decide_assignment(phi, S, n, IC)
if opts.display == :iter || opts.display == :final
if converged
println("affinity propagation converged with $n_iter iterations")
@@ -83,7 +83,7 @@ affinity_propagation(x::Matrix; opts...) = affinity_propagation(x, AffinityPropa
# as well as the order of message updating can affect the
# convergence behavior drastically.
############################################################
-function update_message!{T<:FloatingPoint}(psi::Matrix{T}, phi::Matrix{T}, S::Matrix{T}, n, opts::AffinityPropagationOpts)
+function affprop_update_message!{T<:FloatingPoint}(psi::Matrix{T}, phi::Matrix{T}, S::Matrix{T}, n, opts::AffinityPropagationOpts)
# update phi
for i = 1:n
SM = S[i,:] + psi[i,:]
@@ -107,7 +107,7 @@ function update_message!{T<:FloatingPoint}(psi::Matrix{T}, phi::Matrix{T}, S::Ma
end
end
-function decide_assignment{T<:FloatingPoint}(phi::Matrix{T}, S::Matrix{T}, n::Integer, exemplar::BitArray{1})
+function affprop_decide_assignment{T<:FloatingPoint}(phi::Matrix{T}, S::Matrix{T}, n::Integer, exemplar::BitArray{1})
assignment = zeros(Int, n)
Iexp = find(exemplar)
View
12 test/affprop_test.jl
@@ -0,0 +1,12 @@
+# simple program to test affinity propagation
+
+using Distance
+using Clustering
+
+x = rand(100, 500)
+S = -pairwise(Euclidean(), x, x)
+
+# set diagonal value to median value
+S = S - diagm(diag(S)) + median(S)*eye(size(S,1))
+
+result = affinity_propagation(S; max_iter=200, display=:iter)
Please sign in to comment.
Something went wrong with that request. Please try again.