midas.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:scikit-discovery 作者: MITHaystack 项目源码 文件源码
def process(self, obj_data):
        '''
        Apply the MIDAS estimator to generate velocity estimates

        Adds the result to the data wrapper

        @param obj_data: Data wrapper
        '''

        if self.column_names == None:
            column_names = obj_data.getDefaultColumns()
        else:
            column_names = self.column_names

        time_diff = pd.to_timedelta('365d')
        results = dict()
        for label, data in obj_data.getIterator():
            start_date = data.index[0]
            end_date = data.index[-1]
            for column in column_names:
                start_data = data.loc[start_date:(end_date-time_diff), column]
                end_data = data.loc[start_date+time_diff:end_date, column]

                offsets = end_data.values - start_data.values
                offsets = offsets[~np.isnan(offsets)]
                med_off = np.median(offsets)
                mad_off = mad(offsets)

                cut_offsets = offsets[np.logical_and(offsets < med_off + 2*mad_off, 
                                                     offsets > med_off - 2*mad_off)]
                final_vel = np.median(cut_offsets)
                final_unc = np.sqrt(np.pi/2) * mad(cut_offsets) / np.sqrt(len(cut_offsets))

                results[label] = pd.DataFrame([final_vel,final_unc], ['velocity', 'uncertainty'] ,[column])

        obj_data.addResult(self.str_description, pd.Panel.fromDict(results,orient='minor'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号