annotate Code/eda.py @ 15:2e3c57fba632

Convolutional Neural Network code Scratch for Estimation of Distribution Algorithm
author Paulo Chiliguano <p.e.chiilguano@se14.qmul.ac.uk>
date Sat, 25 Jul 2015 21:51:16 +0100
parents
children 68b8b088f50a
rev   line source
p@15 1 # -*- coding: utf-8 -*-
p@15 2 """
p@15 3 Created on Wed Jul 22 17:42:09 2015
p@15 4
p@15 5 @author: paulochiliguano
p@15 6 """
p@15 7
p@15 8 import numpy as np
p@15 9 from sklearn import mixture
p@15 10
p@15 11 #User-item dictionary
p@15 12 users = {"Angelica": {"SOAJJPC12AB017D63F": 3.5, "SOAKIXJ12AC3DF7152": 2.0,
p@15 13 "SOAKPFH12A8C13BA4A": 4.5, "SOAGTJW12A6701F1F5": 5.0,
p@15 14 "SOAKWCK12A8C139F81": 1.5, "SOAKNZI12A58A79CAC": 2.5,
p@15 15 "SOAJZEP12A8C14379B": 2.0},
p@15 16 "Bill":{"SOAJJPC12AB017D63F": 2.0, "SOAKIXJ12AC3DF7152": 3.5,
p@15 17 "SOAHQFM12A8C134B65": 4.0, "SOAGTJW12A6701F1F5": 2.0,
p@15 18 "SOAKWCK12A8C139F81": 3.5, "SOAJZEP12A8C14379B": 3.0},
p@15 19 "Chan": {"SOAJJPC12AB017D63F": 5.0, "SOAKIXJ12AC3DF7152": 1.0,
p@15 20 "SOAHQFM12A8C134B65": 1.0, "SOAKPFH12A8C13BA4A": 3.0,
p@15 21 "SOAGTJW12A6701F1F5": 5, "SOAKWCK12A8C139F81": 1.0},
p@15 22 "Dan": {"SOAJJPC12AB017D63F": 3.0, "SOAKIXJ12AC3DF7152": 4.0,
p@15 23 "SOAHQFM12A8C134B65": 4.5, "SOAGTJW12A6701F1F5": 3.0,
p@15 24 "SOAKWCK12A8C139F81": 4.5, "SOAKNZI12A58A79CAC": 4.0,
p@15 25 "SOAJZEP12A8C14379B": 2.0},
p@15 26 "Hailey": {"SOAKIXJ12AC3DF7152": 4.0, "SOAHQFM12A8C134B65": 1.0,
p@15 27 "SOAKPFH12A8C13BA4A": 4.0, "SOAKNZI12A58A79CAC": 4.0,
p@15 28 "SOAJZEP12A8C14379B": 1.0},
p@15 29 "Jordyn": {"SOAKIXJ12AC3DF7152": 4.5, "SOAHQFM12A8C134B65": 4.0,
p@15 30 "SOAKPFH12A8C13BA4A": 5.0, "SOAGTJW12A6701F1F5": 5.0,
p@15 31 "SOAKWCK12A8C139F81": 4.5, "SOAKNZI12A58A79CAC": 4.0,
p@15 32 "SOAJZEP12A8C14379B": 4.0},
p@15 33 "Sam": {"SOAJJPC12AB017D63F": 5.0, "SOAKIXJ12AC3DF7152": 2.0,
p@15 34 "SOAKPFH12A8C13BA4A": 3.0, "SOAGTJW12A6701F1F5": 5.0,
p@15 35 "SOAKWCK12A8C139F81": 4.0, "SOAKNZI12A58A79CAC": 5.0},
p@15 36 "Veronica": {"SOAJJPC12AB017D63F": 3.0, "SOAKPFH12A8C13BA4A": 5.0,
p@15 37 "SOAGTJW12A6701F1F5": 4.0, "SOAKWCK12A8C139F81": 2.5,
p@15 38 "SOAKNZI12A58A79CAC": 3.0}
p@15 39 }
p@15 40
p@15 41 items = {"SOAJJPC12AB017D63F": [2.5, 4, 3.5, 3, 5, 4, 1],
p@15 42 "SOAKIXJ12AC3DF7152": [2, 5, 5, 3, 2, 1, 1],
p@15 43 "SOAKPFH12A8C13BA4A": [1, 5, 4, 2, 4, 1, 1],
p@15 44 "SOAGTJW12A6701F1F5": [4, 5, 4, 4, 1, 5, 1],
p@15 45 "SOAKWCK12A8C139F81": [1, 4, 5, 3.5, 5, 1, 1],
p@15 46 "SOAKNZI12A58A79CAC": [1, 5, 3.5, 3, 4, 5, 1],
p@15 47 "SOAJZEP12A8C14379B": [5, 5, 4, 2, 1, 1, 1],
p@15 48 "SOAHQFM12A8C134B65": [2.5, 4, 4, 1, 1, 1, 1]}
p@15 49
p@15 50 profile = {"Profile0": [2.5, 4, 3.5, 3, 5, 4, 1],
p@15 51 "Profile1": [2.5, 4, 3.5, 3, 5, 4, 1],
p@15 52 "Profile2": [2.5, 4, 3.5, 3, 5, 4, 1],
p@15 53 "Profile3": [2.5, 4, 3.5, 3, 5, 4, 1],
p@15 54 "Profile4": [2.5, 4, 3.5, 3, 5, 4, 1],
p@15 55 "Profile5": [2.5, 4, 3.5, 3, 5, 4, 1],
p@15 56 "Profile6": [2.5, 4, 3.5, 3, 5, 4, 1],
p@15 57 "Profile7": [2.5, 4, 3.5, 3, 5, 4, 1]}
p@15 58
p@15 59
p@15 60
p@15 61
p@15 62 np.random.seed(1)
p@15 63 g = mixture.GMM(n_components=7)
p@15 64 # Generate random observations with two modes centered on 0
p@15 65 # and 10 to use for training.
p@15 66 obs = np.concatenate((np.random.randn(100, 1), 10 + np.random.randn(300, 1)))
p@15 67 g.fit(obs)
p@15 68 np.round(g.weights_, 2)
p@15 69 np.round(g.means_, 2)
p@15 70 np.round(g.covars_, 2)
p@15 71 g.predict([[0], [2], [9], [10]])
p@15 72 np.round(g.score([[0], [2], [9], [10]]), 2)
p@15 73 # Refit the model on new data (initial parameters remain the
p@15 74 # same), this time with an even split between the two modes.
p@15 75 g.fit(20 * [[0]] + 20 * [[10]])
p@15 76 np.round(g.weights_, 2)