Esempio n. 1
0
 /**
  * 设置表
  *
  * @param $table
  *
  * @return $this
  */
 public function table($table)
 {
     //模型实例时不允许改表名
     $this->table = $this->table ?: c('database.prefix') . $table;
     //缓存表字段
     $this->fields = \Schema::getFields($table);
     //获取表主键
     $this->primaryKey = \Schema::getPrimaryKey($table);
     return $this;
 }
Esempio n. 2
0
File: DataSet.php Progetto: fieg/knn
 /**
  * Calculates distances
  *
  * @param Node   $node
  * @param Node[] $neighbors
  */
 protected function calculateDistances(Node $node, array $neighbors)
 {
     $this->calculateRanges();
     foreach ($neighbors as $neighbor) {
         $deltas = array();
         foreach ($this->schema->getFields() as $field) {
             list($min, $max) = $this->ranges[$field];
             $range = $max - $min;
             $delta = $neighbor->get($field) - $node->get($field);
             $delta = $delta / $range;
             $deltas[$field] = $delta;
         }
         $total = 0;
         foreach ($deltas as $delta) {
             $total += $delta * $delta;
         }
         $neighbor->setDistance(sqrt($total));
     }
 }