Changes:迭代方差计算
This commit is contained in:
32
variance_x.py
Normal file
32
variance_x.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
from algorithm import algorithm
|
||||||
|
import json
|
||||||
|
import ray
|
||||||
|
|
||||||
|
@ray.remote
|
||||||
|
class variance_x(algorithm):
|
||||||
|
def __init__(self):
|
||||||
|
self.config_dict_ = None
|
||||||
|
self.config_ = None
|
||||||
|
self.window_length_ = 10
|
||||||
|
self.avg_ = 0
|
||||||
|
self.var_ = 0
|
||||||
|
|
||||||
|
def set_config(self, config):
|
||||||
|
self.config_ = config
|
||||||
|
self.config_dict_ = json.loads(self.config_)
|
||||||
|
self.window_length_ = self.config_dict_["WINDOW_LENGTH"]
|
||||||
|
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
|
||||||
|
self.var_ = 0
|
||||||
|
else:
|
||||||
|
present_avg_ = self.avg_ * (self.window_length_ - 1)/self.window_length_ + value / self.window_length_
|
||||||
|
self.var_ = self.var_ +(value - present_avg_) * (value-self.avg_)
|
||||||
|
self.avg_ = present_avg_
|
||||||
|
return self.var_
|
||||||
31
variance_x_test_csv.py
Normal file
31
variance_x_test_csv.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import pandas as pd
|
||||||
|
from variance_x import variance_x
|
||||||
|
import ray
|
||||||
|
|
||||||
|
ray.init()
|
||||||
|
|
||||||
|
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]
|
||||||
|
variance_data = origin_data
|
||||||
|
algorithm_variance_x = variance_x.remote()
|
||||||
|
|
||||||
|
cow_name = "G1.TTXD1_3"
|
||||||
|
contrast_data = pd.DataFrame()
|
||||||
|
contrast_data[cow_name+'_origin'] = origin_data[cow_name]
|
||||||
|
algorithm_variance_x.set_config.remote('{"WINDOW_LENGTH": 5 }')
|
||||||
|
# algorithm_step.set_config('{"CYCLE_TIME_BASE": 5 }')
|
||||||
|
for i in range(0,row_len):
|
||||||
|
futures=algorithm_variance_x.eval.remote(origin_data.loc[i,cow_name])
|
||||||
|
variance_data.loc[i, cow_name]=ray.get(futures)
|
||||||
|
|
||||||
|
print(variance_data.loc[:, cow_name])
|
||||||
|
contrast_data[cow_name+'_variance_x'] = variance_data[cow_name]
|
||||||
|
# average_data.to_csv("D:/python_project_data/1_disturb.csv", index=False)
|
||||||
|
contrast_data.to_csv("D:/python_project_data/variance_data_x.csv", index=False)
|
||||||
|
|
||||||
|
|
||||||
|
# 以下均为测试性能用
|
||||||
|
# print(algorithm_step.config_)
|
||||||
Reference in New Issue
Block a user