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

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

WBOY
WBOYOriginal
2016-06-06 20:44:061650browse

要对数据排序,其中有个时间和状态分别有权重值,需将时间戳转为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>

$w可以根据需要调整。

Statement:
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