Changes:递归均值计算以及测试代码完成
This commit is contained in:
29
average_x.py
Normal file
29
average_x.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from algorithm import algorithm
|
||||||
|
import json
|
||||||
|
import ray
|
||||||
|
|
||||||
|
@ray.remote
|
||||||
|
class average_x(algorithm):
|
||||||
|
def __init__(self):
|
||||||
|
self.config_dict_ = None
|
||||||
|
self.config_ = None
|
||||||
|
self.average_number_ = 10
|
||||||
|
self.present_number_ = 0
|
||||||
|
self.avg_ = 0
|
||||||
|
|
||||||
|
def set_config(self, config):
|
||||||
|
self.config_ = config
|
||||||
|
self.config_dict_ = json.loads(self.config_)
|
||||||
|
self.average_number_ = self.config_dict_["AVERAGE_NUMBER"]
|
||||||
|
self.init_flag_ = False
|
||||||
|
|
||||||
|
def config(self):
|
||||||
|
return self.config_
|
||||||
|
|
||||||
|
def eval(self, value):
|
||||||
|
if self.init_flag_ == False:
|
||||||
|
self.init_flag_ = True
|
||||||
|
self.avg_ = value
|
||||||
|
else:
|
||||||
|
self.avg_ = self.avg_ * (self.average_number_ - 1)/self.average_number_ + value / self.average_number_
|
||||||
|
return self.avg_
|
||||||
31
average_x_test_csv.py
Normal file
31
average_x_test_csv.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import pandas as pd
|
||||||
|
from average_x import average_x
|
||||||
|
import ray
|
||||||
|
|
||||||
|
ray.init()
|
||||||
|
|
||||||
|
ray.RAY_DISABLE_MEMORY_MONITOR=1
|
||||||
|
filepath = "D:/python_project_data/1.csv"
|
||||||
|
origin_data = pd.read_csv(filepath)
|
||||||
|
row_len = origin_data.shape[0]
|
||||||
|
cow_len = origin_data.shape[1]
|
||||||
|
average_data = origin_data
|
||||||
|
algorithm_average = average_x.remote()
|
||||||
|
|
||||||
|
cow_name = "G1.TTXD1_3"
|
||||||
|
contrast_data = pd.DataFrame()
|
||||||
|
contrast_data[cow_name+'_origin'] = origin_data[cow_name]
|
||||||
|
algorithm_average.set_config.remote('{"AVERAGE_NUMBER": 5 }')
|
||||||
|
# algorithm_step.set_config('{"CYCLE_TIME_BASE": 5 }')
|
||||||
|
for i in range(0,row_len):
|
||||||
|
futures=algorithm_average.eval.remote(origin_data.loc[i,cow_name])
|
||||||
|
average_data.loc[i, cow_name]=ray.get(futures)
|
||||||
|
|
||||||
|
print(average_data.loc[:, cow_name])
|
||||||
|
contrast_data[cow_name+'_average_x'] = average_data[cow_name]
|
||||||
|
# average_data.to_csv("D:/python_project_data/1_disturb.csv", index=False)
|
||||||
|
contrast_data.to_csv("D:/python_project_data/average_x_data.csv", index=False)
|
||||||
|
|
||||||
|
|
||||||
|
# 以下均为测试性能用
|
||||||
|
# print(algorithm_step.config_)
|
||||||
Reference in New Issue
Block a user