diff --git a/weightmatrices/algos/ica.py b/weightmatrices/algos/ica.py new file mode 100644 index 0000000..bf8c240 --- /dev/null +++ b/weightmatrices/algos/ica.py @@ -0,0 +1,16 @@ + +import time +from tqdm import tqdm + +from sklearn.decomposition import FastICA +from weightmatrices.utils import utils + +def get_ica_trafo_matrix(data_loader, n_h): + transformer = FastICA(n_components=n_h) + + +def get_weightmatrices_ica(data_loader, n_h): + print("Creating weigth matrix for ICA for "+str(n_h)+" hidden neurons...") + s = data_loader.dataset.data.shape + n_in_features = s[-1]*s[-2] + assert n_h <= n_in_features, "Number of requested independent components higher than input dimensionality!" diff --git a/weightmatrices/algos/sc.py b/weightmatrices/algos/sc.py new file mode 100644 index 0000000..3fa98bd --- /dev/null +++ b/weightmatrices/algos/sc.py @@ -0,0 +1,21 @@ + +import time +from tqdm import tqdm + +from sklearn.decomposition import dict_learning_online +from weightmatrices.utils import utils + + + +def get_weightmatrices_sc(data_loader): + X = ? + out_tuple = dict_learning_online(X, n_components=2, *, alpha=1, n_iter=100, + return_code=True, dict_init=None, callback=None, + batch_size=3, verbose=False, shuffle=True, + n_jobs=None, method='lars', iter_offset=0, + random_state=None, return_inner_stats=False, + inner_stats=None, return_n_iter=False, + positive_dict=False, positive_code=False, + method_max_iter=1000): + W = ? + return W diff --git a/weightmatrices/utils/utils.py b/weightmatrices/utils/utils.py index b726772..d145f9c 100644 --- a/weightmatrices/utils/utils.py +++ b/weightmatrices/utils/utils.py @@ -1,19 +1,24 @@ import torch from torchvision import datasets, transforms from sklearn.preprocessing import normalize def load_data(dataset='EMNIST', batch_size=100000): if dataset=='EMNIST': trans = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (1.0,))]) data = datasets.EMNIST('./datasets/', 'bymerge', transform=trans, download = True) data_loader = torch.utils.data.DataLoader( dataset=data, batch_size=batch_size, shuffle=False, drop_last=True) return data_loader +def getbigdatamatrix(data_loader): + # Needed for ICA and SC and stuff... + # loop over data_loader and concatenation + return X + def normalise_weightmatrix(W): return normalize(W)