This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Exercise 2.20 | |
(define (same-pair x . b) | |
(define (is-same-parity? x y) | |
(or (and (even? x) (even? y)) | |
(and (odd? x) (odd? y)))) | |
(define (same-pair-recur items) | |
(if (null? items) | |
'() | |
(if (is-same-parity? x (car items)) | |
(cons (car items) (same-pair-recur (cdr items))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Exercise 2.21 | |
(define (square x y) (* x y)) | |
(define (square-list-a items) | |
(if (null? items) | |
'() | |
(cons (* (car items) (car items)) | |
(square-list (cdr items))))) | |
(define (square-list-b items) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (tails,sort) | |
-- build suffix array | |
build :: Ord a => [a] -> [[a]] | |
build = sort.tails | |
-- binary search | |
bs [] str = False | |
bs [x] str = cmp str x | |
bs xs str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Posix.Unistd | |
import System.Posix.Signals | |
import System.Exit | |
main = do | |
let exit0 = exitWith ExitSuccess | |
let exit1 = exitWith (ExitFailure 1) | |
installHandler sigINT (Catch exit1) Nothing | |
sleep 1000000 | |
exit0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# HITS (on memory) | |
from numarray import * | |
from numarray.matrix import * | |
EPS = 1.0e-10 | |
class HITS(): | |
def __init__(self, adj_matrix): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# PageRank (on memory) | |
# using power method | |
from numarray import * | |
from numarray.matrix import * | |
EPS = 1.0e-10 | |
class PageRank(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# HITS (on memory) | |
# using co-citation matrix | |
from numpy import * | |
from numpy.linalg import * | |
class HITS(): | |
def __init__(self, adj_matrix): | |
self._adj = adj_matrix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# HITS (on memory) | |
# using co-citation matrix | |
from numpy import * | |
from numpy.linalg import * | |
class HITS(): | |
def __init__(self, adj_matrix): | |
self._adj = adj_matrix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# HITS (on memory) | |
# using von Neumann kernel | |
from numpy import * | |
from numpy import ones | |
from numpy.linalg import * | |
STEP = 500 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# HITS (on memory) | |
# von Neumann kernel vs. regularized Laplacian kernel | |
from numpy import * | |
from numpy.linalg import * | |
STEP = 500 | |
class Relatedness(): |
OlderNewer