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 matplotlib.pyplot as plt | |
import numpy as np | |
from scipy import stats | |
def generate_template(n, width, height, random_state=1, max_random_state=10000, offset=0): | |
L = [np.array([offset, offset, width-offset, height-offset])] | |
random_state_lists = stats.randint.rvs(0, max_random_state, size=(n-1, 4), random_state=random_state) | |
for random_state_list in random_state_lists: | |
n_areas = len(L) |
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 | |
from scipy import stats | |
from sklearn.model_selection import GridSearchCV | |
from sklearn.neighbors import KernelDensity | |
from sklearn import datasets | |
from sklearn.preprocessing import StandardScaler | |
random_state = 1 | |
n_samples = 200 |
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 | |
from scipy import stats | |
def generate_samples(n, n_states, p, lam): | |
A = generate_transition_matrix(n_states, p) | |
x = [] | |
y = [] | |
state = 0 |
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
def viterbi(P, A): | |
""" | |
P: log probability matrix (n_samples by n_states) | |
A: log transition probability matrix (n_states by n_states) | |
""" | |
n_samples = P.shape[0] | |
states = np.arange(P.shape[1]) | |
V = np.zeros((n_samples, 2)) | |
S = np.zeros((n_samples, 2), dtype=int) | |
V[0] = P[0] |
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 | |
class GaussianTransformer(object): | |
def __init__(self, sigma=1.0, b=100, random_state=1): | |
self.sigma = sigma | |
self.b = 100 | |
self.random_state = random_state | |
def fit(self, X): | |
b = np.min([X.shape[0], self.b]) |
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 tensorflow as tf | |
import numpy as np | |
class SimpleClassifier(object): | |
def __init__(self, m=None, random_state=1, n_epochs=20): | |
self.m = m | |
self.random_state = random_state | |
self.n_epochs = n_epochs | |
def fit(self, X, y): |
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 sklearn import preprocessing, base | |
class SimpleBinaryClassifier(base.BaseEstimator): | |
def fit(self, X, y): | |
""" | |
Requirement: y \in \{0, 1\} | |
""" | |
self.scaler = preprocessing.StandardScaler() | |
X = self.scaler.fit_transform(X) |
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 scipy.sparse.linalg as sla | |
def KITML_lr(K0, constraints, dm=None, dc=None, gamma=1., max_iter=1000, stop_threshold=1e-3, max_k=None): | |
# check if K0 is symmetric | |
if max_k is None: | |
max_k = K0.shape[0]-1 | |
S, U = sla.eigsh(K0, k=max_k) | |
U = U[:,::-1] | |
S = S[::-1] |
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 import sparse | |
class SingleTopicUnigramGenerator(object): | |
def __init__(self, n_topics=3, n_features=1000, alpha=1.0, beta=1.0): | |
self.n_topics = n_topics | |
self.n_features = n_features | |
self.alpha = alpha | |
self.beta = beta |
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 sklearn.linear_model import SGDClassifier | |
from sklearn.cross_validation import StratifiedKFold | |
from sklearn.grid_search import GridSearchCV | |
class PUClassifier(object): | |
def __init__(self, trad_clf=None, n_folds=2): | |
self.trad_clf = trad_clf | |
self.n_folds = n_folds |
NewerOlder