Skip to content

Instantly share code, notes, and snippets.

@jsmpereira
Created March 15, 2013 14:56
Show Gist options
  • Save jsmpereira/5170420 to your computer and use it in GitHub Desktop.
Save jsmpereira/5170420 to your computer and use it in GitHub Desktop.
Hi,
After trying out GSLL, Clem, also FemLisp, Lisplab managed to get me
the functionality I needed with the least trouble.
I'm trying to get the connectivity of a graph (second smallest eigen value) from eigenvalues.
Given the fully connected 4x4 adjacency matrix:
#md(( 0.000 1.000 1.000 1.000 )
( 1.000 0.000 1.000 1.000 )
( 1.000 1.000 0.000 1.000 )
( 1.000 1.000 1.000 0.000 ))
I compute the diagonal matrix of the vector sum of the adjacency matrix and then
subtract the adjacency matrix from it to get the laplacian matrix.
I'm unable to call (lisplab:eigenvalues) on that matrix, despite being a #md matrix.
I can see that the function calls for LISPLAB::MATRIX-FOREIGN-DGE. However other functions
that call for the same type seem to work when called with #md, namely FFT1.
As a workaround, I'm using this call to get the eigenvalues:
(lisplab::dgeev (laplacian-matrix *adj-matrix* *diag-matrix*) nil nil) and I get:
(
#md(( 4.000 )
(-1.1102d-16)
( 4.000 )
( 4.000 ))
NIL NIL)
Is this appropriate?
I'm curious however about different results I get from Matlab.
I get the same results up until the call to
>> eig(diag(sum(A)) - A)
which gives me
ans =
0.0000
4.0000
4.0000
4.0000
Any comment I can get on this would be awsome. Am I going about this right?
What might I be missing?
Sorry about the lengthy email.
Thanks!
@jsmpereira
Copy link
Author

Am I missing something?

CL-USER> (type-of (lisplab:make-matrix-instance 'lisplab::matrix-foreign-dge '(4 4) 0))
LISPLAB::MATRIX-FOREIGN-DGE
CL-USER> (lisplab:eigenvalues (lisplab:make-matrix-instance 'lisplab::matrix-foreign-dge '(4 4) 0))

There is no next method for the generic function
  #<STANDARD-GENERIC-FUNCTION LISPLAB:EIGENVALUES (2)>
when called from method
  #<STANDARD-METHOD
    LISPLAB:EIGENVALUES (LISPLAB::MATRIX-FOREIGN-DGE)
    {1006532CF3}>
with arguments
  (
#md(#1=( 0.000    #2=  0.000    #2# 0.000    #2# 0.000    #3=)
    #1# 0.000    #2# 0.000    #2# 0.000    #2# 0.000    #3#
    #1# 0.000    #2# 0.000    #2# 0.000    #2# 0.000    #3#
    #1# 0.000    #2# 0.000    #2# 0.000    #2# 0.000    #3#)).
   [Condition of type SIMPLE-ERROR]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [REMOVE-FD-HANDLER] Remove #<SB-IMPL::HANDLER INPUT on descriptor 8: #<CLOSURE (LABELS SWANK-BACKEND::RUN :IN SWANK-BACKEND:ADD-FD-HANDLER) {100301C57B}>>
 3: [ABORT] Exit debugger, returning to top level.

Backtrace:
  0: ((SB-PCL::FAST-METHOD NO-NEXT-METHOD (STANDARD-GENERIC-FUNCTION STANDARD-METHOD)) ..)
  1: (SB-INT:SIMPLE-EVAL-IN-LEXENV (LISPLAB:EIGENVALUES (LISPLAB:MAKE-MATRIX-INSTANCE 'LISPLAB::MATRIX-FOREIGN-DGE '(4 4) 0)) #<NULL-LEXENV>)
  2: (EVAL (LISPLAB:EIGENVALUES (LISPLAB:MAKE-MATRIX-INSTANCE 'LISPLAB::MATRIX-FOREIGN-DGE '(4 4) 0)))
  3: (SWANK::EVAL-REGION "(lisplab:eigenvalues (lisplab:make-matrix-instance 'lisplab::matrix-foreign-dge '(4 4) 0))\n")
  4: ((LAMBDA () :IN SWANK::REPL-EVAL))
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment