示例#1
0
    def test_mreg_interpolation_multi(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 3, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:350]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        neighbors = windpark.get_turbines()[:-1]
        count_neighbors = len(neighbors)
        reg = 'knn' # KNeighborsRegressor(10, 'uniform')
        regargs = {'n' : 10, 'variant' : 'uniform'}

        processed = 0
        missed = {k : count_neighbors for k in indices}
        exclude = []
        damaged_nseries = []

        for neighbor in neighbors:
            nseries = neighbor.get_measurements()[300:350]
            damaged, indices = MARDestroyer().destroy(nseries, percentage=.50, exclude=exclude)

            for index in indices:
                if(index not in missed.keys()):
                    missed[index] = count_neighbors
                missed[index] -= 1
                if(missed[index] == 1):
                    exclude.append(index) # exclude in next iterations
            damaged_nseries.append(damaged)

        t_hat = MRegInterpolation().interpolate(damaged, timestep=timestep,\
            neighbor_series=damaged_nseries, reg=reg, regargs=regargs)

        after_misses = MissingDataFinder().find(t_hat, timestep)
        assert(len(after_misses) < 1)
示例#2
0
    def test_mreg_interpolation_multi(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 3, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:350]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        neighbors = windpark.get_turbines()[:-1]
        count_neighbors = len(neighbors)
        reg = 'knn' # KNeighborsRegressor(10, 'uniform')
        regargs = {'n' : 8, 'variant' : 'uniform'}

        processed = 0
        missed = {k : count_neighbors for k in indices}
        exclude = []
        damaged_nseries = []

        for neighbor in neighbors:
            nseries = neighbor.get_measurements()[300:350]
            damaged, indices = MARDestroyer().destroy(nseries, percentage=.50, exclude=exclude)

            for index in indices:
                if(index not in missed.keys()):
                    missed[index] = count_neighbors
                missed[index] -= 1
                if(missed[index] == 1):
                    exclude.append(index) # exclude in next iterations
            damaged_nseries.append(damaged)

        t_hat = MRegInterpolation().interpolate(damaged, timestep=timestep,\
            neighbor_series=damaged_nseries, reg=reg, regargs=regargs)

        after_misses = MissingDataFinder().find(t_hat, timestep)
        assert(len(after_misses) < 1)
示例#3
0
    def test_mreg_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 3, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        neighbors = windpark.get_turbines()[:-1]

        reg = 'knn' # KNeighborsRegressor(10, 'uniform')
        regargs = {'n' : 10, 'variant' : 'uniform'}

        nseries = [t.get_measurements()[300:500] for t in neighbors]
        t_hat = MRegInterpolation().interpolate(damaged, timestep=timestep,\
            neighbor_series=nseries, reg=reg, regargs=regargs)
        after_misses = MissingDataFinder().find(t_hat, timestep)
        assert(len(after_misses) < 1)
示例#4
0
    def test_mreg_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 3, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        neighbors = windpark.get_turbines()[:-1]

        reg = 'knn' # KNeighborsRegressor(10, 'uniform')
        regargs = {'n' : 8, 'variant' : 'uniform'}

        nseries = [t.get_measurements()[300:500] for t in neighbors]
        t_hat = MRegInterpolation().interpolate(damaged, timestep=timestep,\
            neighbor_series=nseries, reg=reg, regargs=regargs)
        after_misses = MissingDataFinder().find(t_hat, timestep)
        assert(len(after_misses) < 1)
示例#5
0
def fun(citynum,methodnum,K):
    park_id = NREL.park_id[cityname[citynum]]
    windpark = NREL().get_windpark(park_id, 10, 2004,2006)
    pla=[]
    kk=windpark.get_turbines()
    for i in range(len(kk)):
        pla.append(kk[i].idx)
        
    
    feature_window, horizon = 3, 3
    mapping = PowerMapping()   
    data_1 = np.array(mapping.get_features_park(windpark, feature_window, horizon)) 
     
    data_train = np.array(mapping.get_features_park(windpark, 1, 1))
    
    lendata=len(data_1)
    data1 = data_1[:lendata:3]
    l1=len(data_train)
    data_train1=data_train[:l1:3]
    half=int(math.floor(len(data1) * 0.5))
    
    traindata_1=data_train1[0:half,:]
    traindata1=np.transpose(traindata_1)
    traindata1=preprocessing.scale(np.array(traindata1),with_mean=True,with_std=True)
    if methodnum==0:
        ans = KMeans(n_clusters=K, random_state=0).fit(traindata1).predict(traindata1)
    if methodnum==1:
        ans = SpectralClustering(n_clusters=K, random_state=0).fit_predict(traindata1)
    if methodnum==2:
        ans = AgglomerativeClustering(n_clusters=K).fit_predict(traindata1)
    if methodnum==3:
        ans = Birch(n_clusters=K).fit_predict(traindata1)
    if methodnum==4:
        ans = DBSCAN(eps = 0.1).fit_predict(traindata1)
    fo = open('cluster10/'+cityname[citynum]+method[methodnum]+str(K)+'.csv','w', newline='')
    csv_write = csv.writer(fo,dialect='excel')
    for i in range(len(ans)):
        cc=[];
        cc.append(pla[i])
        cc.append(ans[i])
        csv_write.writerow(cc)
    fo.close()
示例#6
0
    def test_topological_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 10, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = NMARDestroyer().destroy(measurements, percentage=.80,\
                min_length=10, max_length=100)

        tloc = (target.longitude, target.latitude)
        neighbors = windpark.get_turbines()[:-1]

        nseries = [t.get_measurements()[300:500] for t in neighbors]
        nlocs = [(t.longitude, t.latitude) for t in neighbors]

        t_hat = TopologicInterpolation().interpolate(\
                                    damaged, method="topologic",\
                                    timestep=timestep, location=tloc,\
                                    neighbor_series = nseries,\
                                    neighbor_locations = nlocs)
        misses = MissingDataFinder().find(t_hat, timestep)

        assert(measurements.shape[0] == t_hat.shape[0])
        assert(len(misses) < 1)
示例#7
0
    def test_topological_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 10, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = NMARDestroyer().destroy(measurements, percentage=.80,\
                min_length=10, max_length=100)

        tloc = (target.longitude, target.latitude)
        neighbors = windpark.get_turbines()[:-1]

        nseries = [t.get_measurements()[300:500] for t in neighbors]
        nlocs = [(t.longitude, t.latitude) for t in neighbors]

        t_hat = TopologicInterpolation().interpolate(\
                                    damaged, method="topologic",\
                                    timestep=timestep, location=tloc,\
                                    neighbor_series = nseries,\
                                    neighbor_locations = nlocs)
        misses = MissingDataFinder().find(t_hat, timestep)

        assert(measurements.shape[0] == t_hat.shape[0])
        assert(len(misses) < 1)
示例#8
0
import matplotlib.pyplot as plt
import matplotlib.dates as md
from pylab import *

from numpy import array, zeros, float32, int32

# get windpark and corresponding target. forecast is for the target turbine
park_id = NREL.park_id['tehachapi']
windpark = NREL().get_windpark(park_id, 3, 2004)
target = windpark.get_target()

measurements = target.get_measurements()[300:1000]
damaged, indices = destroy(measurements, method="nmar", percentage=.80,\
        min_length=10, max_length=100)

neighbors = windpark.get_turbines()[:-1]
nseries = [t.get_measurements()[300:1000] for t in neighbors]

tinterpolated = interpolate(damaged, method='mreg',\
                            timestep=600,\
                            neighbor_series = nseries,\
                            reg = 'linear_model')

d = array([m[0] for m in tinterpolated])
y1 = array([m[1] for m in tinterpolated]) #score
y2 = array([m[2] for m in tinterpolated]) #speed

d_hat = array([m[0] for m in damaged])
y1_hat = array([m[1] for m in damaged])
y2_hat = array([m[2] for m in damaged])
import matplotlib.pyplot as plt
import matplotlib.dates as md
from pylab import *

from numpy import array, zeros, float32, int32

# get windpark and corresponding target. forecast is for the target turbine
park_id = NREL.park_id['tehachapi']
windpark = NREL().get_windpark(park_id, 5, 2004)
target = windpark.get_target()

measurements = target.get_measurements()[300:1000]
damaged, indices = destroy(measurements, method='nmar', percentage=.80,\
        min_length=10, max_length=100)

neighbors = windpark.get_turbines()[:-1]
nseries = [t.get_measurements()[300:1000] for t in neighbors]

gamma_range = [0.0001, 0.000001]
C_range = [2**i for i in range(-3, 5, 1)]
regargs = {
    "epsilon": 0.1,
    "cv_method": "kfold",
    "cv_args": {
        "k_folds": 10
    },
    "kernel": 'rbf',
    "tuned_parameters": [{
        'kernel': ['rbf'],
        'C': C_range,
        'gamma': gamma_range