Page 1 of 1
Markov Cluster algorithm
Posted: Sun Jun 10, 2018 12:15 pm
by koteth
An attempt to implement the MCL (Markov Cluster) algorithm in APL.
I'm still a beginner in APL, any advice is welcome.
https://github.com/koteth/MCL_APL
Re: Markov Cluster algorithm
Posted: Tue Jun 12, 2018 3:31 pm
by Adam|Dyalog
Looks really cool. How did you generate the graphics? Would you be interested in automatically generating those from within APL?
Re: Markov Cluster algorithm
Posted: Tue Jun 12, 2018 4:10 pm
by Roger|Dyalog
Code from
https://github.com/koteth/MCL_APL/blob/master/MCL.dyalog:
Code: Select all
matrix ← ⎕csv 'PATH TO MATRIX/matrix.csv'
InflateCoef ← 2
M ← ⍎¨ matrix
id←{⍵ ⍵⍴1,⍵⍴0}
Nor←{+⌿⍵}
Nmat ← {( ( ⍴ ⍵) ⍴ (Nor ⍵)) }
NormColumn ← {( ⍴ ⍵ ) ⍴ ((×/⍴⍵) ⍴⍵)÷((×/⍴⍵) ⍴ Nmat ⍵ )}
Expand ← {⍵ +.× ⍵}
Inflate ← NormColumn { (⍴⍺) ⍴ ( (×/⍴⍺) ⍴ ⍺) * ⍵ }
M2 ← NormColumn (M + id (≢ M))
Markov ← { ( Expand (NormColumn ⍵) ) Inflate InflateCoef }
FP ← (Markov ⍣ ≡ ⊢ M2)
R ← ((+/FP) >0) ⌿ FP
ClustMap ← ⌽↑⍸R
"Improved" version of as follows.
• separate code to create the matrix and to do the Markov iteration
• trivial functions included in-line and left unnamed
Code: Select all
MCL3←{
⍺←2 ⍝ inflation coefficient default
id←{(⍵,⍵)⍴1,⍵⍴0} ⍝ identity matrix of order ⍵
NormColumn←{⍵÷⍤1+⌿⍵}
Markov←{⍺ *⍨ +.×⍨ NormColumn ⍵} ⍝ one Markov iteration
FP←⍺ Markov⍣≡NormColumn ⍵+id≢⍵
⌽↑⍸(0<+/FP)⌿FP
}
Re: Markov Cluster algorithm
Posted: Wed Jun 13, 2018 12:41 am
by Roger|Dyalog
Since NormColumn is idempotent and is the first function to be applied in Markov, it is not necessary to apply it before launching the iteration. Whence NormColumn is used just once and can be inserted in-line. Therefore:
MCL4 ← {⍺←2 ⋄ ⌽↑⍸(0<+/FP)⌿FP← ⍺ {⍺ *⍨ +.×⍨ ⍵÷⍤1+⌿⍵}⍣≡ ⍵+∘.=⍨⍳≢⍵}
Re: Markov Cluster algorithm
Posted: Sun Jun 17, 2018 8:51 am
by koteth
Interesting rewriting. Now is more clear to me how to use the ⍨ operator , thanks.
Roger|Dyalog wrote:Since NormColumn is idempotent and is the first function to be applied in Markov, it is not necessary to apply it before launching the iteration. Whence NormColumn is used just once and can be inserted in-line. Therefore:
MCL4 ← {⍺←2 ⋄ ⌽↑⍸(0<+/FP)⌿FP← ⍺ {⍺ *⍨ +.×⍨ ⍵÷⍤1+⌿⍵}⍣≡ ⍵+∘.=⍨⍳≢⍵}
Re: Markov Cluster algorithm
Posted: Sun Jun 17, 2018 9:01 am
by koteth
Adam|Dyalog wrote:Looks really cool. How did you generate the graphics? Would you be interested in automatically generating those from within APL?
For the image I've used python with networkx. It would be nice to use APL, i've never tried to generate graphics. I'm currently using Dyalog 16 for linux, would you be able to suggest some starting point?
Re: Markov Cluster algorithm
Posted: Mon Jun 18, 2018 6:39 pm
by Roger|Dyalog
koteth wrote:Interesting rewriting. Now is more clear to me how to use the ⍨ operator , thanks.
There are illuminating parallels between dyadic f⍨ and the passive case and monadic f⍨ and the reflexive case for verbs in natural languages.
Re: Markov Cluster algorithm
Posted: Tue Jun 19, 2018 9:56 am
by Nicolas|Dyalog
koteth wrote:For the image I've used python with networkx. It would be nice to use APL, i've never tried to generate graphics. I'm currently using Dyalog 16 for linux, would you be able to suggest some starting point?
Network graphs are documented in
https://sharpplot.com/NetworkMap.htmIf you've never used SharpPlot, see
https://sharpplot.com/Languages.htm which should help you translate the C# samples of the rest of the documentation.