重新缩放 0 到 1 之间的数字

发布于 2024-12-02 03:01:38 字数 254 浏览 1 评论 0 原文

我有以下数字列表:

3.16, 4.72, 6.44, 8.25, 3.76, 4.87, 5.76, 6.5, 7.32

我必须重新调整 (0, 1) 之间的数字,以便:

1) 最小的数字得到最接近的值0 但不是 0。

2) 最大的数字得到的值最接近 1,但不是 1。

0 在我的Study 表示完全适合,1 表示完全不适合,这就是为什么我想将它们从最终结果中排除。

任何帮助将不胜感激。

I have the following list of numbers:

3.16, 4.72, 6.44, 8.25, 3.76, 4.87, 5.76, 6.5, 7.32

I have to rescale the numbers between (0, 1) such that:

1)The smallest number gets a value closest to 0 but not 0.

2) The largest number gets a value closest to 1 but not 1.

0 in my study denotes perfectly suitable and 1 denotes perfectly unsuitable, that's why I want to exclude them from the end result.

Any help will be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谢绝鈎搭 2024-12-09 03:01:38

这种转变有帮助吗?

V' = 1/(1 + e^(-V)) -------- Logistic function

域 - 实数,因此 V 可以采用任何实数值
范围 - (0,1) 因此,0V'<>0 V'<>1

Would this transform help?

V' = 1/(1 + e^(-V)) -------- Logistic function

Domain - Real numbers so V can take any real values
Range - (0,1) so that, 0<V'<1, V'<>0 and V'<>1

叹倦 2024-12-09 03:01:38

Python 中使用仿射变换的简单示例:

 list = [3.16, 4.72, 6.44, 8.25, 3.76, 4.87, 5.76, 6.5, 7.32]

 # find the minimum value and range, and add 1% padding
 range_value = max(list) - min(list)
 range_value = range_value + range_value/50
 min_value = min(list) - range_value/100     

 # subtract the minimum value and divide by the range
 for index, item in enumerate(list):
    list[index] = (item - min_value) / range_value

 print list

给出结果:

 [0.010000000000000026, 0.310473824107246, 0.64176547632805592, 0.99039215686274518, 0.1255668554258639, 0.33936553796371205, 0.51078970684541003, 0.65332216187064218, 0.81126353095265591]

当然,您可以将填充量更改为您想要的大小 - 对于范围,您需要添加两倍的填充量对于最小值,因为您需要在范围的每一端添加填充。

A quick example in Python, using an affine transformation:

 list = [3.16, 4.72, 6.44, 8.25, 3.76, 4.87, 5.76, 6.5, 7.32]

 # find the minimum value and range, and add 1% padding
 range_value = max(list) - min(list)
 range_value = range_value + range_value/50
 min_value = min(list) - range_value/100     

 # subtract the minimum value and divide by the range
 for index, item in enumerate(list):
    list[index] = (item - min_value) / range_value

 print list

Gives the result:

 [0.010000000000000026, 0.310473824107246, 0.64176547632805592, 0.99039215686274518, 0.1255668554258639, 0.33936553796371205, 0.51078970684541003, 0.65332216187064218, 0.81126353095265591]

You can, of course, change the amount of padding to be as small as you'd like - for the range, you'll want to add twice what you do for the minimum value, because you need to add padding to each end of the range.

为你拒绝所有暧昧 2024-12-09 03:01:38

我不确定我是否理解你的问题,但是找到集合中的最大数字,然后将集合中的每个数字除以该最大数字将为您提供一个合适的范围。

I'm not sure I understand your question, but finding the maximum number in the set, and dividing each number in the set by that maximum number will give you a suitable range.

永不分离 2024-12-09 03:01:38

您可能需要仿射映射(即形式 y = mx + c),这样:

not_quite_0 = m*min_val + c
not_quite_1 = m*max_val + c

求解这些方程,您将得到:

m = (not_quite_1 - not_quite_0) / (max_val - min_val)
c = (max_val*not_quite_0 - min_val*not_quite_1) / (max_val - min_val)

您可以定义 not_quite_0 = 0 + epsnot_quite_1 = 1 - eps,其中 eps 是一些非常非常小的值。

You probably want an affine mapping (i.e. of the form y = mx + c), such that:

not_quite_0 = m*min_val + c
not_quite_1 = m*max_val + c

Solving these equations, you get:

m = (not_quite_1 - not_quite_0) / (max_val - min_val)
c = (max_val*not_quite_0 - min_val*not_quite_1) / (max_val - min_val)

You can probably define not_quite_0 = 0 + eps and not_quite_1 = 1 - eps, where eps is some very very small value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文