Ejemplo n.º 1
0
 public static function kmeans($k, $vecs)
 {
     // $vecs:[Vec]
     $cfile = self::centroidFile();
     if ($cfile->exists()) {
         if (self::$verbose) {
             showProgress("kmeans: Loading prev centroids");
         }
         $centroids = self::loadCentroids();
         $skip = true;
     } else {
         if (self::$verbose) {
             showProgress("kmeans: setting random group");
         }
         foreach ($vecs as $vec) {
             $vec->label = rand(0, $k - 1);
         }
         $skip = false;
     }
     $changed = 1;
     while ($changed > 0) {
         $changed = 0;
         if ($skip) {
             $skip = false;
         } else {
             $centroids = array();
             // [Vec]
             for ($i = 0; $i < $k; $i++) {
                 $centroid = new Vec();
                 $centroid->cnt = 0;
                 $centroid->label = $i;
                 $centroids[] = $centroid;
             }
             $ccnt = count($vecs);
             foreach ($vecs as $i => $vec) {
                 $centroid = $centroids[$vec->label];
                 $centroid->addX($vec);
                 $centroid->cnt++;
             }
             foreach ($centroids as $centroid) {
                 if ($centroid->cnt > 0) {
                     $centroid->mulX(1 / $centroid->cnt);
                 }
             }
         }
         $cl = new VecCluster2($centroids);
         $ccnt = count($vecs);
         foreach ($vecs as $i => $vec) {
             $n = $cl->nearest($vec);
             if ($vec->label != $n->label) {
                 $vec->label = $n->label;
                 $changed++;
             }
         }
         self::saveCentroids($centroids);
         if (self::$verbose) {
             showProgress("kmeans: {$changed} samples changed. Retrying...");
         }
     }
     return $cl;
 }
Ejemplo n.º 2
0
    ?>
    <script>location.href="a.php?MkCluster&state=1&k=<?php 
    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 
}
Ejemplo n.º 3
0
            }
            $progss[$n][] = $l->obj;
            $nonError++;
        }
    }
}
foreach ($progss as $n => $progs) {
    $cnt = count($progs);
    echo "{$n}(Nonerror:{$cnt}) |";
}
echo "Nonerror/All={$nonError}/{$allC} <HR>";
//exit;
$indexBuf = '<link rel="stylesheet" href="scoreSheet.css"/>';
//$scoreSheetDir=LogUtil::getLogDir()->rel("scoreSheet/");
foreach ($progss as $n => $progs) {
    showProgress("Making Scoresheet... {$n}/" . count($progss));
    usort($progs, function ($a, $b) {
        if ($a["dist"] > $b["dist"]) {
            return 1;
        }
        if ($a["dist"] < $b["dist"]) {
            return -1;
        }
        return 0;
    });
    pickIndex($n, $progs[0]);
    //echo "<a name='$n' />";
    //echo "<h1>$n</h1>";
    $shown = array();
    $buf = <<<EOF
<link rel="stylesheet" href="scoreSheet.css"/>
Ejemplo n.º 4
0
function install_sql()
{
    global $db_pre;
    //安装配置信息
    $db_address = url_get('db_address');
    $db_user = url_get('db_user');
    $db_pwd = url_get('db_pwd');
    $db_name = url_get('db_name');
    $db_pre = url_get('db_pre');
    $admin_user = url_get('admin_user');
    $admin_pwd = url_get('admin_pwd');
    $install_type = url_get('install_type');
    //链接mysql数据库
    $mysql_link = @mysql_connect($db_address, $db_user, $db_pwd);
    if (!$mysql_link) {
        showProgress(array('isError' => true, 'message' => 'mysql链接失败' . mysql_error()));
    }
    //检测SQL安装文件
    $sql_file = ROOT_PATH . './install/iwebshop.sql';
    if (!file_exists($sql_file)) {
        showProgress(array('isError' => true, 'message' => '安装的SQL文件' . basename($sql_file) . '不存在'));
    }
    //检测测试数据SQL文件
    $sql_test_file = ROOT_PATH . './install/iwebshop_test.sql';
    if ($install_type == 'all' && !file_exists($sql_test_file)) {
        showProgress(array('isError' => true, 'message' => '测试数据SQL文件' . basename($sql_test_file) . '不存在'));
    }
    //执行SQL,创建数据库操作
    mysql_query("set names 'UTF8'");
    if (!@mysql_select_db($db_name)) {
        $DATABASESQL = '';
        if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
            $DATABASESQL = "DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
        }
        if (!mysql_query('CREATE DATABASE `' . $db_name . '` ' . $DATABASESQL)) {
            showProgress(array('isError' => true, 'message' => '用户权限受限,创建' . $db_name . '数据库失败,请手动创建数据表'));
        }
    }
    if (!@mysql_select_db($db_name)) {
        showProgress(array('isError' => true, 'message' => $db_name . '数据库不存在' . mysql_error()));
    }
    //安装SQL
    parseSQL($sql_file);
    //安装测试数据
    if ($install_type == 'all') {
        parseSQL($sql_test_file);
    }
    //插入管理员数据
    $adminSql = 'insert into `' . $db_pre . 'admin` (`admin_name`,`password`,`role_id`,`create_time`) values ("' . $admin_user . '","' . md5($admin_pwd) . '",0,"' . date('Y-m-d H:i:s') . '")';
    if (!mysql_query($adminSql)) {
        showProgress(array('isError' => true, 'message' => '创建管理员失败' . mysql_error(), 'percent' => 0.9));
    }
    //写入配置文件
    $configDefFile = ROOT_PATH . './config/config_default.php';
    $configFile = ROOT_PATH . './config/config.php';
    $updateData = array('{TABLE_PREFIX}' => $db_pre, '{DB_R_ADDRESS}' => $db_address, '{DB_R_USER}' => $db_user, '{DB_R_PWD}' => $db_pwd, '{DB_R_NAME}' => $db_name, '{DB_W_ADDRESS}' => $db_address, '{DB_W_USER}' => $db_user, '{DB_W_PWD}' => $db_pwd, '{DB_W_NAME}' => $db_name, '{ENCRYPTKEY}' => md5(rand(1000000000, 9999999999)));
    $is_success = create_config($configFile, $configDefFile, $updateData);
    if (!$is_success) {
        showProgress(array('isError' => true, 'message' => '更新配置文件失败', 'percent' => 0.9));
    }
    //修改index.php首页
    $index_file = ROOT_PATH . './index.php';
    $index_content = '<?php
$iweb = dirname(__FILE__)."/lib/iweb.php";
$config = dirname(__FILE__)."/config/config.php";
require($iweb);
IWeb::createWebApp($config)->run();
?>';
    $is_success = file_put_contents($index_file, $index_content);
    if (!$is_success) {
        showProgress(array('isError' => true, 'message' => '生成index.php页面出错', 'percent' => 0.9));
    }
    //执行完毕
    showProgress(array('isError' => false, 'message' => '安装完成', 'percent' => 1));
}
Ejemplo n.º 5
0
		echo "Range too big on line $lineNum\n";
		echo "TrustedXFF has not yet been optimised for large ranges.\n";
		continue;
	}
	if ( $endNum > pow(2,52) ) {
		// This is unreachable unless someone tweaks some constants above
		echo "Loss of precision in floating point number, will cause infinite loop.\n";
		continue;
	}
	for ( $j = $startNum; $j <= $endNum; $j++ ) {
		$hex = strtoupper( base_convert( $j, 10, 16 ) );
		$hex = str_pad( $hex, $suffixLength, '0', STR_PAD_LEFT );
		dba_insert( $prefix . $hex, '1', $outFile );
		$numHosts++;
	}
	showProgress( $i, count( $ranges ) );
}
echo "\n";

dba_close( $outFile );
echo "$numHosts hosts listed\n";


//-----------------------------------------------------------------
function showProgress( $current, $total ) {
	$length = 50;
	$dots = intval( ( $current + 1) / $total * $length );
	printf( "%6.2f%%  [" . 
		str_repeat( '=', $dots ) . str_repeat( '.', $length - $dots ) . "]\r", 
		( $current + 1) / $total * 100 );
}
Ejemplo n.º 6
0
                load()->web('dbapi');
                importFromCenter_handler($guid);
            }
        };
        showProgress($callback);
    } else {
        message('楼盘项目已存在!', url('project/display/'));
    }
    exit;
}
if ($op == 'update') {
    if (empty($project)) {
        message('无效的楼盘项目参数!', url('project/display/'));
    }
    if ($_W['isajax']) {
        $url = url('project/post/', array('op' => 'update', 'guid' => $guid));
        include template('project/update', TEMPLATE_INCLUDEPATH);
        exit;
    }
    $option = $_GPC['options'];
    if (count($option) > 0) {
        $callback = function () use($guid, $option) {
            load()->web('dbexchange');
            updateToErp_handler($guid, $option);
        };
        showProgress($callback, '项目数据同步');
    } else {
        message('没有选择要处理的事项。', url('project/display/'));
    }
    exit;
}