我目前正在实现一个软件,可以随着时间的推移测量某些值。用户可以选择在 28 天内测量该值 100 次。 (仅举个例子)
线性分布不是问题,但我目前正在尝试获得时间跨度内点的对数分布。
直接的实现是迭代这些点,因此我需要一个指数函数。 (我已经走到这一步了!)
我当前的算法(C#)如下:
long tRelativeLocation = 0;
double tValue;
double tBase = PhaseTimeSpan.Ticks;
int tLastPointMinute = 0;
TimeSpan tSpan;
for (int i = 0; i < NumberOfPoints; i++)
{
tValue = Math.Log(i + 1, NumberOfPoints);
tValue = Math.Pow(tBase, tValue);
tRelativeLocation = (long)tValue;
tSpan = new TimeSpan(tRelativeLocation);
tCurrentPoint = new DefaultMeasuringPointTemplate(tRelativeLocation);
tPoints.Add(tCurrentPoint);
}
这给了我 28 天和 100 分的相当“好的”结果。
前11个点都在0秒,
1 秒第 12 点,
20 号 50 秒,
第 50 场,390 分钟,
第 95 场,28605 分钟
第 99 次,37697 分钟(距离最后一点还有 43 小时)
我的问题是: 有人知道如何让前 20-30 点彼此距离更远,也许让最后 20-30 点更接近一点吗?
我知道我最终必须添加一些算法,将第一个点分开至少一分钟左右,因为我无法将这种行为纳入严格的数学算法中。
类似这样的事情:
if (((int)tSpan.TotalMinutes) <= tLastPointMinute)
{
tSpan = new TimeSpan((tLastPointMinute +1) * 600000000L);
tRelativeLocation = tSpan.Ticks;
tLastPointMinute = (int)tSpan.TotalMinutes;
}
但是,我希望总体上得到稍微更好的分布。
任何来自数学高手的酷想法都将不胜感激!
最佳答案
从实用的角度来看,对数函数已经将您的时间点压缩到原点附近。幂函数对它们的挤压更大。简单的乘法怎么样?
tValue = Math.Log(i + 1, NumberOfPoints);
tValue = tBase * tValue;
使曲线变平的另一种方法是从距离原点更远的地方开始。
for (int i = 0; i < NumberOfPoints; i++)
{
tValue = Math.Log(i + 10, NumberOfPoints + 9);
tvalue的范围仍然是0到1。
开头的最小间隔为 1 秒怎么样?
double nextTick = 0;
for (int i = 0; i < NumberOfPoints; i++)
{
tValue = Math.Log(i + 1, NumberOfPoints);
tValue = Math.Pow(tBase, tValue);
if (tValue < nextTick) tValue = nextTick;
nextTick++;
关于c# - 使用方法 : Find a good mathematical algorithm to distribute measuring points over time?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3361890/