⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monthly_variance_and_entropy.php

📁 使用php开发的一个“熵”的计算程序
💻 PHP
字号:
<?php/** * Script the reports monthly variance and entropy. */require_once "config.php";require_once PHPMATH . "/IT/ArrayMath.php";require_once PHPMATH . "/IT/TableEntropy.php";$e = new TableEntropy;$e->setTable("Webstats");$e->setColumn("ip");?><html>  <head>    <title>Monthly Variance and Entropy</title>  </head>  <body>   <i>Monthly Variance and Entropy</i></font>  <table border='1' cellpadding='5' cellspacing='0'>    <tr bgcolor='ffffcc'>      <td><b>Period</b></td>      <td align='center'><b>var(Hits)</b></td>      <td align='center'><b>var(Visitors)</b></td>      <td align='center'><b>Entropy</b></td>            <td align='center'><b>MaxEnt</b></td>                  <td align='center'><b>Ratio</b></td>                      </tr>          <?php    $am = new ArrayMath;        for($year=2004; $year<=2004; $year++) {      for($month=1; $month<=12; $month++) {                          $start =  date("Y-m-d", mktime(0,0,0,$month,1,$year));        $end   =  date("Y-m-d", mktime(0,0,0,$month+1,0,$year));           // Do stuff to get the entropy        $clause = " received >= '$start' AND received <= '$end' ";        $e->setWhere($clause);        $e->getEntropy();                                                        // Now, do stuff to get the variance        $sql   = " SELECT received, count(ip) AS hits, count(DISTINCT ip) AS visitors ";        $sql  .= " FROM Webstats ";         $sql  .= " WHERE received >= '$start' AND received <= '$end' ";                $sql  .= " GROUP BY received ";         $res   = &$db->query($sql);        while ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)) {                   $hits[]    = $row['hits'];          $visits[]  = $row['visitors'];        }        $hit_var = sprintf("%.2f", $am->variance($hits));        $vis_var = sprintf("%.2f", $am->variance($visits));        ?>        <tr>          <td align='right'><i><?php echo "$start to $end"; ?></i></td>          <td align='right'><?php echo $hit_var ?></td>          <td align='right'><?php echo $vis_var ?></td>           <td align='right'><?php printf("%01.2f", $e->bits) ?></td>          <td align='right'><?php printf("%01.2f", $e->maxent) ?></td>          <td align='right'><?php printf("%01.2f", $e->ratio) ?></td>                             </tr>        <?php        $hit_vars[]  = $hit_var;        $vis_vars[]  = $vis_var;                $entropies[] = $e->bits;                        $hits   = array();        $visits = array();                if($year == date("Y"))           if($month == date("m"))             break(2);       }    }        ?>   </table>   <?php   echo "correlation(hits, visits): ".$am->correlation($hit_vars,$vis_vars)."<br />";   echo "correlation(hits, entropy): ".$am->correlation($hit_vars,$entropies)."<br />";       echo "correlation(visits, entropy): ".$am->correlation($vis_vars,$entropies);     ?>       </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -