duanqiang2617 2019-05-15 09:35
浏览 64

如何计算给定的整数是否接近它所属的数组的平均值

I have a set of numbers in an Array in PHP. I.e. [1,2,3,4,5,6,7,999,9999,10000,-20,-800,25,26,27,28].

I want to foreach over each element, calculate the Standard Deviation and the Average for this array and then figure out if one of the numbers is close to my Average Value.

I want to know on a scale from 1 to 0 if the number is close to my average (0.99xx.. result) or if its more far away (0.0xx.. result). This way I could determine wheter or not the given integer is close to the Average.

This should be used for a score mechanism that should get a "closer to average == better" logic.

If I do checks on MIN() and MAX(), numbers far away from respective numbers will always score as good, so this is polluting the actual result.

One more close to reality example is a set of the following data:

[0.2000, 0.3000, 0.3000, 0.9000, 0.8000, 0.7500, 0.1500, 0.4000, 0.3000, 0.6500, 0.8000]

Technically speaking I want to know whether or not the current iteration value is close to my average value, or not. If its close, the result number should be closer to 1. If its far away from my average it should be closer to 0. The further away, the closer to 0. The closer to the average, the closer to 1.

How could I do this in PHP? Note, this question is not about calculating averages.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 mmocr的训练错误,结果全为0
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀