Exemplo n.º 1
0
$vec = $logD->rel("{$class}-vector.json");
if (!$vec->exists()) {
    ?>
Run <a href="a.php?MkCluster">MkCluster</a><?php 
    return;
}
$vecs = $vec->obj();
$cluster = new VecCluster($vecs);
$count = 0;
foreach ($files as $file) {
    if ($file->startsWith($class) && $file->endsWith("-data.log")) {
        $data = array_map(function ($line) {
            global $count, $cluster;
            $e = json2array($line);
            $code = LogUtil::detectProgram($e);
            $vec = VecUtil::mkvec($code);
            $a = $cluster->nearest($vec);
            $e["nearest"] = $a[0];
            $e["dist"] = $a[1];
            /*if (isset($e["code"])) {
                  $code=$e["code"];
                  if (is_array($code)) {
                      $e["nearest"]=array();
                      $e["dist"]=array();
                      foreach ($code as $k=>$c) {
                          $v=VecUtil::mkvec($c);
                          $a=$cluster->nearest($v);
                          $e["nearest"][$k]=$a[0];
                          $e["dist"][$k]=$a[1];
                      }
                  } else {
Exemplo n.º 2
0
 function nearest($vec)
 {
     $min = -1;
     $minN;
     $vecs = $this->vecs;
     foreach ($vecs as $name => $cvec) {
         $d = VecUtil::dist($vec, $cvec);
         if ($min < 0 || $d < $min) {
             $minN = $name;
             $min = $d;
         }
     }
     return array($minN, $d);
 }
Exemplo n.º 3
0
    echo $k;
    ?>
";</script>
    <?php 
} else {
    $logDir = LogUtil::getLogDir();
    $vecs = array();
    $lines = $logDir->rel("{$class}-allvec.txt")->lines();
    $c = count($lines);
    showProgress("Read lines");
    foreach ($lines as $i => $line) {
        $vecs[] = new Vec(json2array($line));
    }
    showProgress("Starting kmeans");
    VecUtil::$verbose = 1;
    $cluster = VecUtil::kmeans($k, $vecs);
    /*$res=array();
      foreach ($cluster->centroids as $vec) {
          $res[nameOf($vec)]=$vec->ary;
          //echo json_encode($vec)."<BR>";
      }
      $logD=LogUtil::getLogDir();
      $class=Auth::curClass();
      $vecFile=$logD->rel("$class-vector.json");
      $vecFile->obj($res);*/
    ?>
    <script>location.href="a.php?DetectFile";</script>
    <?php 
}
function nameOf($vec)
{