Esempio n. 1
0
def mapLoadData(dataSetName, seedVal=100000):
    """This is for loading in data sets for processing using machine
    learning algorithms, particularly mapping models (classification,
    regression) latent variable models.

    Options for dataSetName include 'spgp1d', 'gp1d' """

    numpy.random.seed(seed=seedVal)
    if dataSetName == 'spgp1d':
        numIn = 1
        N = 500
        X = numpy.random.uniform(low=-1.0, high=1.0, size=(N, numIn))
        X.sort(axis=0)
        Xn = ndlml.matrix(X)
        kern1 = ndlml.rbfKern(Xn)
        kern1.setVariance(1)
        kern1.setInverseWidth(20)
        kern2 = ndlml.whiteKern(Xn)
        kern2.setVariance(0.01)
        kern = ndlml.cmpndKern(Xn)
        kern.addKern(kern1)
        kern.addKern(kern2)
        K = ndlml.matrix(numpy.empty((N, N)))
        kern.compute(K, Xn)
        Kmat = K.toarray()
        y = numpy.reshape(
            numpy.random.multivariate_normal(numpy.zeros(N), Kmat), (N, 1))
        return X, y

    elif dataSetName == 'gp1d':
        numIn = 1
        N = 50
        X = numpy.random.uniform(low=-1.0, high=1.0, size=(N, numIn))
        X.sort(axis=0)
        Xn = ndlml.matrix(X)
        kern1 = ndlml.rbfKern(Xn)
        kern1.setVariance(1)
        kern1.setInverseWidth(20)
        kern2 = ndlml.whiteKern(Xn)
        kern2.setVariance(0.0001)
        kern = ndlml.cmpndKern(Xn)
        kern.addKern(kern1)
        kern.addKern(kern2)
        K = ndlml.matrix(numpy.empty((N, N)))
        kern.compute(K, Xn)
        Kmat = K.toarray()
        y = numpy.reshape(
            numpy.random.multivariate_normal(numpy.zeros(N), Kmat), (N, 1))
        return X, y

    else:
        raise NameError, "Unknown data set"
Esempio n. 2
0
def mapLoadData(dataSetName, seedVal=100000):

    """This is for loading in data sets for processing using machine
    learning algorithms, particularly mapping models (classification,
    regression) latent variable models.

    Options for dataSetName include 'spgp1d', 'gp1d' """

    numpy.random.seed(seed=seedVal)
    if dataSetName == 'spgp1d':
        numIn = 1
	N = 500
	X = numpy.random.uniform(low=-1.0, high=1.0, size=(N, numIn))
	X.sort(axis=0)
	Xn = ndlml.matrix(X)
	kern1 = ndlml.rbfKern(Xn)
	kern1.setVariance(1)
	kern1.setInverseWidth(20)
	kern2 = ndlml.whiteKern(Xn)
	kern2.setVariance(0.01)
	kern = ndlml.cmpndKern(Xn)
	kern.addKern(kern1)
	kern.addKern(kern2)
	K = ndlml.matrix(numpy.empty((N, N)))
	kern.compute(K, Xn)
	Kmat = K.toarray()
	y = numpy.reshape(numpy.random.multivariate_normal(numpy.zeros(N), Kmat), (N,1))
	return X,y

    elif dataSetName == 'gp1d':
        numIn = 1
	N = 50
	X = numpy.random.uniform(low=-1.0, high=1.0, size=(N, numIn))
	X.sort(axis=0)
	Xn = ndlml.matrix(X)
	kern1 = ndlml.rbfKern(Xn)
	kern1.setVariance(1)
	kern1.setInverseWidth(20)
	kern2 = ndlml.whiteKern(Xn)
	kern2.setVariance(0.0001)
	kern = ndlml.cmpndKern(Xn)
	kern.addKern(kern1)
	kern.addKern(kern2)
	K = ndlml.matrix(numpy.empty((N, N)))
	kern.compute(K, Xn)
	Kmat = K.toarray()
	y = numpy.reshape(numpy.random.multivariate_normal(numpy.zeros(N), Kmat), (N,1))
	return X,y

    else:
        raise NameError, "Unknown data set"
Esempio n. 3
0
q = 2
Y, lbls = datasets.lvmLoadData('oil')
#Y = Y[0:10, :]
numData = Y.shape[0]
d = Y.shape[1]
#v, X = netlab.pca(Y.transpose(), q)
X = numpy.random.normal(0.0, 1e-1, (numData, 2))
Xstore = X;
Xstor = numpy.empty(Xstore.shape)
Ystore = Y;
Y = ndlwrap.fromarray(Y)
X = ndlwrap.fromarray(X)

# Set up kernel function
kern = nl.cmpndKern()

kern1 = nl.rbfKern(X)
kern2 = nl.biasKern(X)
kern3 = nl.whiteKern(X)
kern3.setVariance(1e-3)

kern.addKern(kern1)
kern.addKern(kern2)
kern.addKern(kern3)


noise = nl.gaussianNoise(Y)

# Create a GP model.
model = nl.gp(q, d, X, Y, kern, noise, nl.gp.DTCVAR, 100, 3)
Esempio n. 4
0
import datasets
import matplotlib.pyplot as plt
import math

X, y = datasets.mapLoadData('spgp1d')

numActive = 9

Xstore = np.array(X)
ystore = np.array(y)

X = nl.matrix(X)
y = nl.matrix(y)

# Set up kernel function
kern = nl.cmpndKern()

kern1 = nl.rbfKern(X)
kern2 = nl.biasKern(X)
kern3 = nl.whiteKern(X)
kern3.setVariance(1e-4)

kern.addKern(kern1)
kern.addKern(kern2)
kern.addKern(kern3)

noise = nl.gaussianNoise(y)

# Create a GP model.
model = nl.gp(1, 1, X, y, kern, noise, nl.gp.DTC, numActive, 3)
model.setBetaVal(math.exp(2))

q = 2
Y, lbls = datasets.lvmLoadData('oil100')
d = Y.shape[0]
numData = Y.shape[1]
v, X = netlab.pca(Y.transpose(), q)
X = numpy.random.normal(0.0, 1e-6, (Y.shape[0], 2))
Xstore = X;
Xstor = numpy.empty(Xstore.shape)
Ystore = Y;
Y = ndlwrap.fromarray(Y)
X = ndlwrap.fromarray(X)

# Set up kernel function
kern = ndlml.cmpndKern()

kern1 = ndlml.rbfKern(X)
kern2 = ndlml.biasKern(X)
kern3 = ndlml.whiteKern(X)

kern.addKern(kern1)
kern.addKern(kern2)
kern.addKern(kern3)


noise = ndlml.gaussianNoise(Y)

# Create an GP model.
model = ndlml.gp(2, 12, X, Y, kern, noise, ndlml.gp.FTC, 100, 3)
Esempio n. 6
0
resultsDir = os.path.join(".", dataSetName + str(experimentNo))
if not os.path.exists(resultsDir):
    os.mkdir(resultsDir)


# set initial values to small random numbers.
X = np.random.normal(0.0, 1e-6, (len(tr.movieIDs()), q))
X_u = np.random.normal(0.0, 1e-6, (numActive, q))

lnsigma2 = math.log(startVar)
lnbeta = -math.log(startVar)


# Set up kernel functions
kernFtc = nl.cmpndKern(q)
kernSp = nl.cmpndKern(q)

kern1 = nl.rbfKern(q)
kern2 = nl.biasKern(q)
kern3 = nl.whiteKern(q)
kern4 = nl.whitefixedKern(q)

kern2.setVariance(0.11)
kern3.setVariance(math.exp(lnsigma2))
kern4.setVariance(1e-2)

kernFtc.addKern(kern1)
kernFtc.addKern(kern2)
kernFtc.addKern(kern3)