def disaggregate_chunk(self, mains,ep,n):
        '''In-memory disaggregation.

        Parameters
        ----------
        mains : pd.Series of aggregate data
        Returns
        -------
        appliance_powers : pd.DataFrame where each column represents a
            disaggregated appliance.  Column names are the integer index
            into `self.model` for the appliance in question.
        '''
        up_limit = len(mains)

        mains.fillna(0, inplace=True)

        X_batch = np.array(mains)
        #print(X_batch)
        #X = laplace(X_batch,ep,n)
        X_batch = np.reshape(X_batch, (X_batch.shape[0],1,1))
        #print(X_batch.shape)
        print(X_batch)
        X_batch_1 = copy.deepcopy(X_batch)
        X_batch = laplace_generator(X_batch_1,n,ep)
        #print(X_batch)
        pred = self.model.predict(X_batch, batch_size=128)
        pred = np.reshape(pred, (len(pred)))
        column = pd.Series(pred, index=mains.index[:len(X_batch)], name=0)

        appliance_powers_dict = {}
        appliance_powers_dict[0] = column
        appliance_powers = pd.DataFrame(appliance_powers_dict)
        return appliance_powers
def laplace(test_elec,ep):
    num = test_elec.shape[0]
    array = np.zeros(num)
    for i in range(num):
        array[i] = test_elec.iloc[i]
    print(array)
    n = 10
    test_fix = laplace_generator(array,n,ep)
    for i in range(num):
       test_elec.iloc[i] = test_fix[i]
    return test_elec
Exemplo n.º 3
0
    adapted_event = 0
    adapted_errors = 0
    multi_switches_count = 0

    print()
    ep = 0.009
    for (fold, priors, testing) in folds:
        del priors
        tm_start = time()

        sshmm = sshmms[fold]
        obs_id = list(testing)[0]
        obs1 = list(testing[obs_id])
        obs2 = copy.deepcopy(obs1)
        #print(obs1)
        obs = laplace_generator(obs2, n, ep)
        #print(obs)
        hidden = [i for i in testing[labels].to_records(index=False)]

        print()
        print(
            'Begin evaluation testing on observations, compare against ground truth...'
        )
        print()
        pbar = ''
        pbar_incro = len(testing) // 20
        """
        noise
        """
        for i in range(1, len(obs)):
            multi_switches_count += (sum(
 c = 0
 #ep = 100-j*0.8
 #ep = 100
 ep = 0.001 * (j + 1)
 k = 0
 for i in range(1):
     f1 = open(
         "D:/project/CS5/CS8/CS/Viterbi - 副本/synctic_data02" +
         str(sparsity) + ".txt", 'a')
     f = open(
         "D:/project/CS5/CS8/CS/Viterbi - 副本/synctic_data02_2" +
         str(sparsity) + ".txt", 'a')
     time_start = ti.time()
     #print(y_fix_use)
     #y_fix = y_fix_use
     y_fix = laplace_generator(y_fix_use, n, ep)
     #print(y_fix)
     delta_x, delta_y, _size, _app = data_preprocess(
         ground_truth, y_fix)
     error = []
     for j in range(delta_y.shape[0]):
         error.append(
             one_shot_compressed_sensing_decode(
                 delta_x[j], delta_y[j], p, delta))
     acc = 1 - perform_matrix(error, _size, _app)
     print("acc", acc)
     temp = k
     a += acc
     c += 1
     k = a / c
     if temp - k < 0.00001 and i > 10: