Ejemplo n.º 1
0
def returnXy(mode=0, pX=None, index=None, K = TRAINK):
	temp = returnDataA(1, 0)[3]
	L = len(temp)
	start = 0
	ed = int(L * K)
	X = []
	y = []
	for ci in range(0, CAN, 1):
		for xi in range(0, ed-start, 1):
			X.append([])
		for fi in range(TN):
			arr = returnDataA(ci, fi)[3][start:ed]
			for xi in range(0, ed-start, 1):
				X[(ci)*(ed-start)+xi].append(float(arr[xi]))	
		cop = []
		cop = returnDataA(ci, TCOP)[3][start:ed]
		for yi in range(0, ed-start, 1):
			y.append(cop[yi])  
	return X, y
Ejemplo n.º 2
0
def returnXy(mode=0, pX=None, index=None, K = TRAINK):
    #print '    K =', K, ' Mode =' , mode
    temp = returnDataA(1, 0)[3]
    
    #train index: 0 to L * K
    #predict index: L * K to L
    L = len(temp)

    
    if mode == 5: #single sample with index
        st = index
        ed = index + 1
    else:
        if mode == 0:
            st = 0 
            ed = int(L * K) 
        elif mode == 1:
            st = int(L * K) 
            ed = L
        elif mode == 2:
            st = 0
            ed = L
        elif mode == 3 or mode == 4 or mode == 6 or mode == 7:
            st = 0
            ed = int(L * K)
    
    #merely chiller 1
    X = []
    for xi in range(0, ed-st, 1):
        X.append([])
        
    for fi in range(TN):
        arr = returnDataA(1, fi)[3][st:ed]
        for xi in range(0, ed-st, 1):
            X[xi].append(arr[xi])
    
    y = []
    cop = []
    cop = returnDataA(1, TCOP)[3][st:ed]
    for yi in range(0, ed-st, 1):
        y.append(cop[yi])
    
    #clustered samples
    if mode == 3 or mode == 4 or mode == 6 or mode == 7: 
        X0 = []
        y0 = []
        X0 = deepcopy(X)
        y0 = deepcopy(y)
            
        #http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsRegressor.html
        if mode == 3: #single chiller clustering            
            #print 'clustered X, y' ###
            #print X[1:5], y[1:5] ###
            #print ###
            #from sklearn.neighbors import NearestNeighbors
            neigh = NearestNeighbors()
            neigh.fit(X0) 
            
            d, xis = neigh.kneighbors([pX])
            X = []
            y = []
            for i in range(len(xis)):
                for xi in xis[i]:
                    #print xi
                    #print X0[xi]
                    X.append(X0[xi])
                    y.append(y0[xi]) #share the common index
            
        elif mode == 4: #clustering chillers of the same type
            #CN = CSN #chillers of the same type
            
            X = []
            y = []
            Xt = []
            yt = []
            for ci in range(CSN):
                
                for xi in range(0, ed-st, 1):
                    Xt.append([])
                    
                for fi in range(TN):
                    arr = returnDataA(ci, fi)[3][st:ed]
                    for xi in range(0, ed-st, 1):
                        Xt[ci*(ed-st)+xi].append(arr[xi])
                
                
                cop = []
                cop = returnDataA(ci, TCOP)[3][st:ed]
                for yi in range(0, ed-st, 1):
                    yt.append(cop[yi])
                    
            #from sklearn.neighbors import NearestNeighbors
            neigh = NearestNeighbors()#
            neigh.fit(Xt) 
            X0 = []
            y0 = []
            X0 = deepcopy(Xt)
            y0 = deepcopy(yt)
            d, xis = neigh.kneighbors([pX])
            
            for i in range(len(xis)):
                for xi in xis[i]:
                    #print xi
                    #print X0[xi]
                    X.append(X0[xi])
                    y.append(y0[xi]) #share the common index
        elif mode == 6: #clustering chillers of all types
            
            X = []
            y = []
                                    
            for ci in range(0, CAN, 1):
                for xi in range(0, ed-st, 1):
                    X.append([])
                    
                for fi in range(TN):
                    arr = returnDataA(ci, fi)[3][st:ed]
                    for xi in range(0, ed-st, 1):
                        X[(ci)*(ed-st)+xi].append(arr[xi])
                
                cop = []
                cop = returnDataA(ci, TCOP)[3][st:ed]
                for yi in range(0, ed-st, 1):
                    y.append(cop[yi])
        elif mode == 7: #clustering all chillers 
            
            X = []
            y = []
                     
            Xt = []
            yt = []
            for ci in range(CAN):
                
                for xi in range(0, ed-st, 1):
                    Xt.append([])
                    
                for fi in range(TN):
                    arr = returnDataA(ci, fi)[3][st:ed]
                    for xi in range(0, ed-st, 1):
                        Xt[ci*(ed-st)+xi].append(arr[xi])
                
                
                cop = []
                cop = returnDataA(ci, TCOP)[3][st:ed]
                for yi in range(0, ed-st, 1):
                    yt.append(cop[yi])
                    
            kmeans = KMeans(n_clusters=5)#n_clusters=2, random_state=0
            XtCs = kmeans.fit_predict(Xt) 
            X0 = []
            y0 = []
            X0 = deepcopy(Xt)
            y0 = deepcopy(yt)
            pXCs = kmeans.predict([pX])
            pXC = pXCs[0] #which cluster is pX
            
            #print X0
            #print y0
            for xi in range(len(XtCs)):
                if XtCs[xi] == pXC: #take the samples from the same cluster
                #print xi
                #print X0[xi]
                    X.append(X0[xi])
                    y.append(y0[xi]) #share the common index
            #print 'Length', len(X), len(y)
            
    return X, y