Markov Cluster algorithm
Forum rules
This forum is for discussing APLrelated issues. If you think that the subject is offtopic, then the Chat forum is probably a better place for your thoughts !
This forum is for discussing APLrelated issues. If you think that the subject is offtopic, then the Chat forum is probably a better place for your thoughts !
8 posts
• Page 1 of 1
Markov Cluster algorithm
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
I'm still a beginner in APL, any advice is welcome.
https://github.com/koteth/MCL_APL
 koteth
 Posts: 3
 Joined: Wed Jan 17, 2018 5:58 pm
Re: Markov Cluster algorithm
Looks really cool. How did you generate the graphics? Would you be interested in automatically generating those from within APL?

AdamDyalog  Posts: 62
 Joined: Thu Jun 25, 2015 1:13 pm
Re: Markov Cluster algorithm
Code from https://github.com/koteth/MCL_APL/blob/master/MCL.dyalog:
"Improved" version of as follows.
• separate code to create the matrix and to do the Markov iteration
• trivial functions included inline and left unnamed
 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 inline 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
}
 RogerDyalog
 Posts: 139
 Joined: Thu Jul 28, 2011 10:53 am
Re: Markov Cluster algorithm
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 inline. Therefore:
MCL4 ← {⍺←2 ⋄ ⌽↑⍸(0<+/FP)⌿FP← ⍺ {⍺ *⍨ +.×⍨ ⍵÷⍤1+⌿⍵}⍣≡ ⍵+∘.=⍨⍳≢⍵}
 RogerDyalog
 Posts: 139
 Joined: Thu Jul 28, 2011 10:53 am
Re: Markov Cluster algorithm
Interesting rewriting. Now is more clear to me how to use the ⍨ operator , thanks.
RogerDyalog 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 inline. Therefore:
MCL4 ← {⍺←2 ⋄ ⌽↑⍸(0<+/FP)⌿FP← ⍺ {⍺ *⍨ +.×⍨ ⍵÷⍤1+⌿⍵}⍣≡ ⍵+∘.=⍨⍳≢⍵}
 koteth
 Posts: 3
 Joined: Wed Jan 17, 2018 5:58 pm
Re: Markov Cluster algorithm
AdamDyalog 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?
 koteth
 Posts: 3
 Joined: Wed Jan 17, 2018 5:58 pm
Re: Markov Cluster algorithm
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.
 RogerDyalog
 Posts: 139
 Joined: Thu Jul 28, 2011 10:53 am
Re: Markov Cluster algorithm
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.htm
If 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.
 NicolasDyalog
 Posts: 12
 Joined: Wed Sep 10, 2008 9:39 am
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group