旋转门 mysql_数据压缩算法:旋转门算法(SDT)的C#实现

旋转门算法是用于实时数据库数据压缩的高效线性拟合算法,尤其适用于数据采集量大且数据临近度高的场景。本文介绍了C# 结构体实现旋转门算法的详细步骤,通过比较当前数据与上一保存数据的斜率来决定是否保存当前点,从而达到数据压缩的目的。
摘要由CSDN通过智能技术生成

旋转门算法是一种比较快速的线性拟合算法,常常用于实时数据库中对数据进行压缩,使存储容量大大的减少。在实时数据库中,数据通常具有如下特点:

数据采集量大。

数据临近度高。如果不能对这些数据进行压缩,将对资源造成巨大的浪费。旋转门算法作为线性拟合的一种简便算法,具有效率高、压缩比高、实现简单、误差可控制的优点,现在已成为一种专门算法。

9778473da30edd86ae133fd9b87c742d.png

public struct point

{

public point(double pointx, double pointy)

{

this.x = pointx;

this.y = pointy;

}

private double x;

private double y;

public double X

{

get

{

return x;

}

set

{

x = value;

}

}

public double Y

{

get

{

return y;

}

set

{

y = value;

}

}

}

public struct SDTPoints

{

private point currentData;//当前读取数据

private point lastReadData;//上一个读取数据

private point lastStoredData;//上一个保存数据

public point CurrentData

{

get

{

return currentData;

}

set

{

currentData = value;

}

}

public point LastReadData

{

get

{

return lastReadData;

}

set

{

lastReadData = value;

}

}

public point LastStoredData

{

get

{

return lastStoredData;

}

set

{

lastStoredData = value;

}

}

}

public List SDTcompress(List originData, double AccuracyE,IProgress progress,CancellationToken cancel)//后两个参数为其异步编程使用

{

List listSDT=new List();

double upGate = -double.MaxValue;

double downGate = double.MaxValue;

double nowUp, nowDown;//当前数据的上下斜率

SDTPoints status=new SDTPoints();

if (originData.Count <= 0)

return null;

status.LastReadData = originData[0];

status.LastStoredData = status.LastReadData;

listSDT.Add(status.LastReadData);

int i = 0;

foreach (var p in originData)

{

status.CurrentData = p;

nowUp = (p.Y - status.LastStoredData.Y - AccuracyE)/(p.X - status.LastStoredData.X);

if (nowUp > upGate)

upGate = nowUp;

nowDown = (p.Y - status.LastStoredData.Y + AccuracyE)/(p.X - status.LastStoredData.X);

if (nowDown < downGate)

downGate = nowDown;

if (upGate >= downGate)

{

listSDT.Add(status.LastReadData);//保存前一个点

status.LastStoredData = status.LastReadData;//修改最近保存的点

upGate=(p.Y-status.LastStoredData.Y-AccuracyE)/ (p.X - status.LastStoredData.X);

downGate = (p.Y - status.LastStoredData.Y + AccuracyE) / (p.X - status.LastStoredData.X);

}

status.LastReadData = p;

i++;

cancel.ThrowIfCancellationRequested();

progress?.Report(i * 100 / originData.Count );

}

if (listSDT.Count == 1)

{

listSDT.Add(originData[originData.Count-1]);

}

return listSDT;

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值