Ejemplo n.º 1
0
def snll(data, nums, means, covs, prior):
    return gmm.calcresps(data, nums, means, covs, True)[1] - np.log(prior)
Ejemplo n.º 2
0
    hard = False
    # Load data
    data, classes, labels = readData(os.path.join('..','data','wine.data'))
    
    lda = dimred.LDA(data, classes, labels, center=True, scale=True)
    projData = lda.transform(data)
    
    x = projData[0,:]
    y = projData[1,:]
    
    points = splitClasses(data,classes,labels)
    gaussians = [density.Gaussian(data=p) for p in points]
    means = np.array([g.mean() for g in gaussians]).T
    covs = np.array([g.cov() for g in gaussians])
    nums = np.array([ p.shape[1] for p in points ])
    weights,nll = gmm.calcresps(data, nums, means, covs, hard=hard)
    
    nums, means, covs, nll = gmm.gmm(data, weights, K=3, hard=hard, diagcov=False)
    numsd,meansd,covsd,nlld = gmm.gmm(data, weights, K=3, hard=hard, diagcov=True)
    
    print 'Question 2'
    print 'NLL for diagcov=False: ', nll
    print 'NLL for diagcov=True:  ', nlld
    print 'The diagcov=False seems to be the better choice.'
    print 'Because we have enough data per class we can use a full estimate '
    print 'of the covariance matrix without over-fitting. '
    print 'These extra parameters allow us to make a better model which is '
    print 'evident in the differance in negative-log-likelihood(NNL).\n'
    
    weights,nll = gmm.calcresps(data, nums, means, covs, hard=hard)
Ejemplo n.º 3
0
def snll(data, nums, means, covs, prior):
    return gmm.calcresps(data, nums, means, covs, True)[1] - np.log(prior)
Ejemplo n.º 4
0
    hard = False
    # Load data
    data, classes, labels = readData(os.path.join('..', 'data', 'wine.data'))

    lda = dimred.LDA(data, classes, labels, center=True, scale=True)
    projData = lda.transform(data)

    x = projData[0, :]
    y = projData[1, :]

    points = splitClasses(data, classes, labels)
    gaussians = [density.Gaussian(data=p) for p in points]
    means = np.array([g.mean() for g in gaussians]).T
    covs = np.array([g.cov() for g in gaussians])
    nums = np.array([p.shape[1] for p in points])
    weights, nll = gmm.calcresps(data, nums, means, covs, hard=hard)

    nums, means, covs, nll = gmm.gmm(data,
                                     weights,
                                     K=3,
                                     hard=hard,
                                     diagcov=False)
    numsd, meansd, covsd, nlld = gmm.gmm(data,
                                         weights,
                                         K=3,
                                         hard=hard,
                                         diagcov=True)

    print 'Question 2'
    print 'NLL for diagcov=False: ', nll
    print 'NLL for diagcov=True:  ', nlld