WINCC 聚类算法 clustering algorithm

//聚类算法
//RANGE:离散阈值
double  ShowMost(double Data[], int Count, double RANGE)
{
    double cluster;

    double nSum = 0;
    int nCount = 0;
    int nSection = 0;
    double nAvg;

    int nMaxSection = 0;  //最密集的段的ID
    int nMaxSectionCount = 0;  //最密集的段的元素个数
    double nResult = 0;  //计算后得出的平均值
    int nIndex = -1;  //段结束的下标
    int i;
    //double RANGE  =   0.02 ;
    for (i=0; i<Count; i++)
    {
        nSum += Data[i];
        nCount++;
        nAvg = nSum/nCount;
        if (!(nAvg+RANGE>=Data[i] && nAvg-RANGE<=Data[i]))
        {
            if (nCount-1>nMaxSectionCount)  //如果当前段比上一个段还大,则当前段设置成最大段
            //如果存在多个数量相同的最大段,则使用大于取最后一个最大段,使用大于等于取第一个最大段
            {
                nMaxSectionCount = nCount -1;
                nMaxSection = nSection;
                nResult = (nSum - Data[i])/nMaxSectionCount;
                nIndex = i - 1;
            }
            nSum = Data[i];
            nCount = 1;
            nSection++;
        }
    }
    //打印和验证结果
    printf("nMaxSectionCount=%d ", nMaxSectionCount);
    printf("nMaxSection=%d ", nMaxSection);
    printf("nResult=%4.4f ", nResult);
    printf("\r\n");
    nSum = 0;
    for (i=nIndex-nMaxSectionCount+1; i<=nIndex; i++)
    {
        printf("data[%d]=%4.4f ", i, Data[i]);
        nSum += Data[i];
    }
    printf("\r\n");
    printf("sum=%4.4f, avg=%4.4f ", nSum, nSum/nMaxSectionCount);
    printf("\r\n");
cluster = nSum/nMaxSectionCount;

return cluster;
}
double almnLB[601];
double* almnarray(double AI_IN,int LB_CS)
{
	
	int almnN = 0;
	for(almnN = LB_CS - 1;almnN>=1;almnN--)
	{
		almnLB[almnN] = almnLB[almnN-1];
	}
	almnLB[0] = AI_IN;

	return almnLB;
}
稳定 =  2 //卡涩
递减 =  1
无序 =  0 //震荡
递 增= -1
alarray = almnarray(OKQ1/OMQ1,inum);
printf("tr=%d ", tr);
printf("\r\n");
//for (i=0; i<inum; i++)
//{
//	printf("alarray[%d]=%4.4f ", i, alarray[i]);
//	printf("\r\n");
//}			
//clustering algorithm 
almn = ShowMost(alarray, inum, th);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杨铮...

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值