Home > Backend Development > PHP Tutorial > 如何对一个数字生成0到1的数字

如何对一个数字生成0到1的数字

WBOY
Release: 2016-06-06 20:44:06
Original
1655 people have browsed it

要对数据排序,其中有个时间和状态分别有权重值,需将时间戳转为0到1之间的数字
log(strtotime($date))/100感觉不好

回复内容:

要对数据排序,其中有个时间和状态分别有权重值,需将时间戳转为0到1之间的数字
log(strtotime($date))/100感觉不好

用sigmoid函数:

<code><?php function sigmod($i){
    $w = 0.000000001;
    return 1.0/(1+exp(-$w*$i));
}

$time = time();
$num = 10;
for($i=$time;$i<$time+$num;$i++){
    echo "f(". $i .")=" . sigmod($i) . "\n";
}
</code></code>
Copy after login

$w可以根据需要调整。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template