예제 #1
0
    def validation(self,
                   layout_validation_result_file_path,
                   record_num,
                   start_pos=0):
        res = self.generate()
        final_error = []
        for item in res:
            row = []
            selected_sensors, unselected_sensors = item[0], item[1]

            ok3d_linear = OrdinaryKriging(self.filtered_file_path,
                                          self.pos_file_path, selected_sensors,
                                          unselected_sensors, record_num,
                                          start_pos, 'linear')
            ok3d_linear_res = ok3d_linear.run()

            final_error.append(self.accuracy_calculate(ok3d_linear_res))

        csvfile = file(layout_validation_result_file_path, 'wb')
        writer = csv.writer(csvfile)

        tmp_rows = [item[0] for item in res]
        writer.writerows(tmp_rows)
        writer.writerow(final_error)
        csvfile.close()
    def energy(self):
        tac = PickTactics()
        selected_sensors, unselected_sensors = tac.fixed_tactic(self.state)
        ok3d = OrdinaryKriging(self.filtered_file_path, self.pos_file_path,
                               selected_sensors, unselected_sensors,
                               self.each_sensor_number, 0, 'linear')
        rmse = RMSE(ok3d.run())
        #print(self.state)

        res = rmse.temperature_error() + rmse.humidity_error()
        if res <= self.goal:
            super(LayoutOptimization, self).set_user_exit(0, 0)
        return res
예제 #3
0
    def validation(self, validation_result_file_path, record_num):
        res = self.generate()
        final_error = []

        for item in res:
            selected_sensors,unselected_sensors = item[0],item[1]
            #print selected_sensors
            #print unselected_sensors

            ok3d_linear = OrdinaryKriging(self.filtered_file_path,self.pos_file_path,selected_sensors,unselected_sensors, record_num, 0,'linear')
            ok3d_linear_res = ok3d_linear.run()
            #print ok3d_linear_res
            cal_res = self.accuracy_calculate(ok3d_linear_res)
            final_error.append(cal_res)


        #print final_error
        csvfile = file(validation_result_file_path, 'wb')
        writer = csv.writer(csvfile)
        writer.writerow(final_error)
        csvfile.close()
            average_prediction /= len(group)

            sum1 = 0.0
            sum2 = 0.0
            for item in group:
                sum1 += (float(item[6]) - average_real) * (float(item[7]) -
                                                           average_prediction)
                sum2 += (float(item[6])-average_real)*(float(item[6])-average_real)*\
                    (float(item[7])-average_prediction)*(float(item[7])-average_prediction)

            total += sum1 / math.sqrt(sum2)

        return total / len(self.data)


if __name__ == '__main__':
    tac = PickTactics()
    selected_sensors, unselected_sensors = tac.fixed_tactic(
        [1, 2, 3, 4, 5, 11])
    ok3d = OrdinaryKriging("../data/filter_data", "../data/pos/pos.csv",
                           selected_sensors, unselected_sensors, 2)
    pearson1 = Pearson(ok3d.run())
    idw = InverseDistanceWeighted("../data/filter_data", "../data/pos/pos.csv",
                                  "../data/pos/distance.csv", selected_sensors,
                                  unselected_sensors, 2)
    pearson2 = Pearson(idw.run())

    print pearson1.temperature_error()
    print pearson1.humidity_error()
    print pearson2.temperature_error()
    print pearson2.humidity_error()
예제 #5
0
    def temperature_error(self):
        total = 0.0
        for group in self.data:
            tmp = 0.0
            for item in group:
                tmp += (float(item[5])-float(item[4]))*(float(item[5])-float(item[4]))

            total += math.sqrt(tmp/len(group))

        return total/len(self.data)

    def humidity_error(self):
        total = 0.0
        for group in self.data:
            tmp = 0.0
            for item in group:
                tmp += (float(item[7])-float(item[6]))*(float(item[7])-float(item[6]))

            total += math.sqrt(tmp/len(group))

        return total/len(self.data)

if __name__ == '__main__':
    tac = PickTactics()
    selected_sensors,unselected_sensors = tac.fixed_tactic([0,1,2])
    ok3d = OrdinaryKriging("../data/filter_data","../data/pos/pos.csv",selected_sensors,unselected_sensors, 2,0,'linear')
    tmp = ok3d.run()
    print tmp
    rmse = RMSE(tmp)
    print rmse.temperature_error()
    print rmse.humidity_error()
    def validation(self, validation_result_file_path, record_num):
        res = self.generate()
        final_error = []
        average_error = [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                         [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                         [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]
        for item in res:
            row = []
            selected_sensors, unselected_sensors = item[0], item[1]
            idw = InverseDistanceWeighted(self.filtered_file_path,
                                          self.pos_file_path,
                                          self.dis_file_path, selected_sensors,
                                          unselected_sensors, record_num)
            idw_res = idw.run()

            ok3d_spherical = OrdinaryKriging(self.filtered_file_path,
                                             self.pos_file_path,
                                             selected_sensors,
                                             unselected_sensors, record_num,
                                             'spherical')
            ok3d_spherical_res = ok3d_spherical.run()

            ok3d_linear = OrdinaryKriging(self.filtered_file_path,
                                          self.pos_file_path, selected_sensors,
                                          unselected_sensors, record_num,
                                          'linear')
            ok3d_linear_res = ok3d_linear.run()

            ok3d_power = OrdinaryKriging(self.filtered_file_path,
                                         self.pos_file_path, selected_sensors,
                                         unselected_sensors, record_num,
                                         'power')
            ok3d_power_res = ok3d_power.run()

            #ok3d_gaussian = OrdinaryKriging(self.filtered_file_path,self.pos_file_path,selected_sensors,unselected_sensors, record_num, 'gaussian')
            #ok3d_gaussian_res = ok3d_gaussian.run()

            ok3d_exponential = OrdinaryKriging(self.filtered_file_path,
                                               self.pos_file_path,
                                               selected_sensors,
                                               unselected_sensors, record_num,
                                               'exponential')
            ok3d_exponential_res = ok3d_exponential.run()

            for i in range(3):
                cal_res = self.accuracy_calculate(i, idw_res,
                                                  ok3d_spherical_res,
                                                  ok3d_linear_res,
                                                  ok3d_power_res,
                                                  ok3d_exponential_res)
                row.append(cal_res)

            for j in range(len(average_error)):
                for k in range(len(average_error[0])):
                    average_error[j][k] += row[j][k]

            final_error.append(row)

        #print average_error
        average_error = [[j / len(res) for j in i] for i in average_error]
        #print average_error

        for i in range(3):
            csvfile = file(validation_result_file_path[i], 'wb')
            writer = csv.writer(csvfile)
            writer.writerow([
                'idw温度',
                'idw湿度',
                'kriging_spherical温度',
                'kriging_spherical湿度',
                'kriging_linear温度',
                'kriging_linear湿度',
                'kriging_power温度',
                'kriging_power湿度',
                #'kriging_gaussian温度','kriging_gaussian湿度',
                'kriging_exponential温度',
                'kriging_exponential湿度'
            ])
            tmp_rows = [item[i] for item in final_error]
            writer.writerows(tmp_rows)
            writer.writerow([
                '平均值', '平均值', '平均值', '平均值', '平均值', '平均值', '平均值', '平均值', '平均值',
                '平均值'
            ])
            writer.writerow(average_error[i])
            csvfile.close()
        total = 0.0
        for group in self.data:
            tmp = 0.0
            for item in group:
                tmp += (float(item[5]) - float(item[4]))

            total += tmp / len(group)

        return total / len(self.data)

    def humidity_error(self):
        total = 0.0
        for group in self.data:
            tmp = 0.0
            for item in group:
                tmp += (float(item[7]) - float(item[6]))

            total += tmp / len(group)

        return total / len(self.data)


if __name__ == '__main__':
    tac = PickTactics()
    selected_sensors, unselected_sensors = tac.fixed_tactic(
        [31, 32, 12, 7, 3, 11])
    ok3d = OrdinaryKriging("../data/filter_data", "../data/pos/pos.csv",
                           selected_sensors, unselected_sensors, 2)
    me = MeanError(ok3d.run())
    print me.temperature_error()
    print me.humidity_error()