Skip to content

Instantly share code, notes, and snippets.

View giuseppebonaccorso's full-sized avatar
🎯
Focusing

Giuseppe Bonaccorso giuseppebonaccorso

🎯
Focusing
View GitHub Profile
@giuseppebonaccorso
giuseppebonaccorso / hetero-encoder.py
Created December 31, 2017 09:13
Stories with Convolutional Hetero-Encoders
import matplotlib.pyplot as plt
import multiprocessing
import numpy as np
import tensorflow as tf
from keras.datasets import cifar10
# Set random seed (for reproducibility)
np.random.seed(1000)
tf.set_random_seed(1000)
@giuseppebonaccorso
giuseppebonaccorso / som-olivetti-cupy.py
Last active October 22, 2017 16:16
Example of Self-Organizing Map (Kohonen Network) based on the Olivetti faces dataset (Cupy-based)
import cupy as cp
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import fetch_olivetti_faces
# Set random seed for reproducibility
np.random.seed(1000)
cp.random.seed(1000)
@giuseppebonaccorso
giuseppebonaccorso / passive_aggressive_regression.py
Created October 6, 2017 10:21
Passive Aggressive Regression
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import make_regression
# Set random seed (for reproducibility)
np.random.seed(1000)
nb_samples = 500
nb_features = 4
@giuseppebonaccorso
giuseppebonaccorso / passive_aggressive_classification.py
Last active November 13, 2017 01:07
Passive Aggressive Classification
import numpy as np
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
# Set random seed (for reproducibility)
np.random.seed(1000)
nb_samples = 5000
@giuseppebonaccorso
giuseppebonaccorso / rubner-tavan-pca-network.py
Last active December 4, 2017 15:58
PCA with Rubner-Tavan Networks
from sklearn.datasets import load_digits
import numpy as np
# Set random seed for reproducibility
np.random.seed(1000)
# Load MNIST dataset
X, Y = load_digits(return_X_y=True)
X /= 255.0
@giuseppebonaccorso
giuseppebonaccorso / brain-state-in-a-box.py
Created September 22, 2017 09:27
Brain-State-in-a-Box Network
import matplotlib.pyplot as plt
import numpy as np
# Set random seed for reproducibility
np.random.seed(1000)
nb_patterns = 4
pattern_width = 4
pattern_height = 4
max_iterations = 100
@giuseppebonaccorso
giuseppebonaccorso / hopfield.py
Created September 20, 2017 12:33
Hopfield Network
import matplotlib.pyplot as plt
import numpy as np
# Set random seed for reproducibility
np.random.seed(1000)
nb_patterns = 4
pattern_width = 4
pattern_height = 4
max_iterations = 10
@giuseppebonaccorso
giuseppebonaccorso / quickprop.py
Created September 15, 2017 11:43
Quickprop example
from sklearn.datasets import make_classification
import numpy as np
# Set random seed (for reproducibility)
np.random.seed(1000)
def sigmoid(arg):
return 1.0 / (1.0 + np.exp(-arg))
@giuseppebonaccorso
giuseppebonaccorso / model_free_collaborative_filtering.py
Last active April 17, 2018 22:14
A model-free collaborative recommendation system in 20 lines of Python
from scipy.sparse import dok_matrix
from sklearn.metrics.pairwise import pairwise_distances
import numpy as np
# Set random seed (for reproducibility)
np.random.seed(1000)
# Create a dummy user-item dataset
nb_users = 1000
@giuseppebonaccorso
giuseppebonaccorso / fim.py
Created September 2, 2017 15:02
Fisher Information Matrix
import numpy as np
import tensorflow as tf
from sklearn.datasets import make_blobs
# Set random seed (for reproducibility)
np.random.seed(1000)
# Create dataset
nb_samples=2000