Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-igraph
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-igraph
Commits
575555f5
Commit
575555f5
authored
Jun 06, 2015
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add findCommunity
parent
d868daf3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
29 deletions
+91
-29
Community.hs
src/IGraph/Community.hs
+53
-15
Community.chs
src/IGraph/Internal/Community.chs
+34
-14
Constants.chs
src/IGraph/Internal/Constants.chs
+4
-0
No files found.
src/IGraph/Community.hs
View file @
575555f5
module
IGraph.Community
(
communityLeadingEigenvector
(
CommunityOpt
(
..
)
,
CommunityMethod
(
..
)
,
findCommunity
)
where
import
Control.Monad
...
...
@@ -10,26 +12,62 @@ import System.IO.Unsafe (unsafePerformIO)
import
Data.List
import
Data.Ord
import
Data.Function
(
on
)
import
Data.Default.Class
import
IGraph
import
IGraph.Mutable
(
U
)
import
IGraph.Internal.Data
import
IGraph.Internal.Constants
import
IGraph.Internal.Community
import
IGraph.Internal.Arpack
communityLeadingEigenvector
::
LGraph
U
v
e
->
Maybe
[
Double
]
-- ^ extract weights
->
Int
-- ^ number of steps
->
[[
Int
]]
communityLeadingEigenvector
gr
ws
step
=
unsafePerformIO
$
do
ap
<-
igraphArpackNew
vptr
<-
igraphVectorNew
0
wptr
<-
case
ws
of
data
CommunityOpt
=
CommunityOpt
{
_method
::
CommunityMethod
,
_weights
::
Maybe
[
Double
]
,
_nIter
::
Int
-- ^ [LeadingEigenvector] number of iterations, default is 10000
,
_nSpins
::
Int
-- ^ [Spinglass] number of spins, default is 25
,
_startTemp
::
Double
-- ^ [Spinglass] the temperature at the start
,
_stopTemp
::
Double
-- ^ [Spinglass] the algorithm stops at this temperature
,
_coolFact
::
Double
-- ^ [Spinglass] the cooling factor for the simulated annealing
,
_gamma
::
Double
-- ^ [Spinglass] the gamma parameter of the algorithm.
}
data
CommunityMethod
=
LeadingEigenvector
|
Spinglass
instance
Default
CommunityOpt
where
def
=
CommunityOpt
{
_method
=
LeadingEigenvector
,
_weights
=
Nothing
,
_nIter
=
10000
,
_nSpins
=
25
,
_startTemp
=
1.0
,
_stopTemp
=
0.01
,
_coolFact
=
0.99
,
_gamma
=
1.0
}
findCommunity
::
LGraph
U
v
e
->
CommunityOpt
->
[[
Int
]]
findCommunity
gr
opt
=
unsafePerformIO
$
do
result
<-
igraphVectorNew
0
ws
<-
case
_weights
opt
of
Just
w
->
listToVector
w
_
->
liftM
VectorPtr
$
newForeignPtr_
$
castPtr
nullPtr
igraphCommunityLeadingEigenvector
(
_graph
gr
)
wptr
nullPtr
vptr
step
ap
nullPtr
False
nullPtr
nullPtr
nullPtr
nullFunPtr
nullPtr
xs
<-
vectorPtrToList
vptr
return
$
map
f
$
groupBy
((
==
)
`
on
`
snd
)
$
sortBy
(
comparing
snd
)
$
zip
[
0
..
]
xs
where
f
=
fst
.
unzip
case
_method
opt
of
LeadingEigenvector
->
do
ap
<-
igraphArpackNew
igraphCommunityLeadingEigenvector
(
_graph
gr
)
ws
nullPtr
result
(
_nIter
opt
)
ap
nullPtr
False
nullPtr
nullPtr
nullPtr
nullFunPtr
nullPtr
Spinglass
->
igraphCommunitySpinglass
(
_graph
gr
)
ws
nullPtr
nullPtr
result
nullPtr
(
_nSpins
opt
)
False
(
_startTemp
opt
)
(
_stopTemp
opt
)
(
_coolFact
opt
)
IgraphSpincommUpdateConfig
(
_gamma
opt
)
IgraphSpincommImpOrig
1.0
liftM
(
map
(
fst
.
unzip
)
.
groupBy
((
==
)
`
on
`
snd
)
.
sortBy
(
comparing
snd
)
.
zip
[
0
..
]
)
$
vectorPtrToList
result
src/IGraph/Internal/Community.chs
View file @
575555f5
...
...
@@ -7,23 +7,43 @@ import Foreign.C.Types
{#import IGraph.Internal.Arpack #}
{#import IGraph.Internal.Graph #}
{#import IGraph.Internal.Data #}
{#import IGraph.Internal.Constants #}
#include "cbits/haskelligraph.c"
{#fun igraph_community_leading_eigenvector as ^ { `IGraphPtr'
, `VectorPtr'
, id `Ptr MatrixPtr'
, `VectorPtr'
, `Int'
, `ArpackOptPtr'
, id `Ptr CDouble'
, `Bool'
, id `Ptr VectorPtr'
, id `Ptr VectorPPtr'
, id `Ptr VectorPtr'
, id `T'
, id `Ptr ()'
} -> `Int' #}
{#fun igraph_community_spinglass as ^
{ `IGraphPtr'
, `VectorPtr'
, id `Ptr CDouble'
, id `Ptr CDouble'
, `VectorPtr'
, id `Ptr VectorPtr'
, `Int'
, `Bool'
, `Double'
, `Double'
, `Double'
, `SpincommUpdate'
, `Double'
, `SpinglassImplementation'
, `Double'
} -> `Int' #}
{#fun igraph_community_leading_eigenvector as ^
{ `IGraphPtr'
, `VectorPtr'
, id `Ptr MatrixPtr'
, `VectorPtr'
, `Int'
, `ArpackOptPtr'
, id `Ptr CDouble'
, `Bool'
, id `Ptr VectorPtr'
, id `Ptr VectorPPtr'
, id `Ptr VectorPtr'
, id `T'
, id `Ptr ()'
} -> `Int' #}
type T = FunPtr ( Ptr VectorPtr
-> CLong
...
...
src/IGraph/Internal/Constants.chs
View file @
575555f5
...
...
@@ -8,3 +8,7 @@ import Foreign
{#enum igraph_neimode_t as Neimode {underscoreToCase} deriving (Show, Eq) #}
{#enum igraph_edgeorder_type_t as EdgeOrderType {underscoreToCase} deriving (Show, Eq) #}
{#enum igraph_spincomm_update_t as SpincommUpdate {underscoreToCase} deriving (Show, Eq) #}
{#enum igraph_spinglass_implementation_t as SpinglassImplementation {underscoreToCase} deriving (Show, Eq) #}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment