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 numpy as np | |
from scipy.sparse import csc_matrix | |
def pageRank(G, s = .85, maxerr = .001): | |
""" | |
Computes the pagerank for each of the n states. | |
Used in webpage ranking and text summarization using unweighted | |
or weighted transitions respectively. |
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 numpy as np | |
def powerLaw(y, x): | |
""" | |
'When the frequency of an event varies as power of some attribute of that | |
event the frequency is said to follow a power law.' (wikipedia) | |
This is represented by the following equation, where c and alpha are | |
constants: | |
y = c . x ^ alpha |
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/python | |
# -*- coding: utf-8 -*- | |
import numpy as np | |
import matplotlib.pyplot as plt | |
class RidgeRegressor(object): | |
""" | |
Linear Least Squares Regression with Tikhonov regularization. |
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 numpy as np | |
from scipy.optimize import fmin_cg | |
def cost(p, Y, R, alpha): | |
""" | |
Calculates collaborative filtering cost function. | |
Arguments |
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 numpy as np | |
import matplotlib.pyplot as plt | |
def params(X): | |
""" | |
Calculates the mean vector and covariance matrix for the given data. | |
Arguments | |
--------- |
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/python | |
def combinations(S): | |
""" | |
Generates every possible combination from a set of discrete variables | |
Arguments | |
--------- | |
S: Cardinality of variable space. When S = [2, 3, 4] variables 1, 2 and |