miqdadm/multidistance

此包最新版本(2.0.0)没有可用的许可信息。

基于多距离相似度计算方法

2.0.0 2016-08-20 03:51 UTC

This package is not auto-updated.

Last update: 2024-09-23 06:43:32 UTC


README

Build Status Total Downloads Latest Unstable Version

使用基于8种距离相似度的方法计算2个向量

  • 欧几里得距离法
  • 曼哈顿距离法
  • 闵可夫斯基距离法
  • 切比雪夫距离法
  • 堪培拉距离法
  • Bray Curtis距离法
  • Kullback-Leibler距离法
  • Jensen-Shannon距离法

要求

PHP 5.4 +

安装

通过 Composer 运行

composer require miqdadm/multidistance

或者,您可以将它放入您的 composer.json 文件中。

"require": {
  "miqdadm/multidistance": "*"
}

然后运行 composer update

composer update

基本用法

<?php

require 'vendor/autoload.php';
use MiqdadM\Multidistance\multidistance as Calculate;

$test = new Calculate([4, 3, 6], [2, 3, 7]);
$test->distance(); //do this method first

echo 'Euclidean Distance Method';
echo'<pre>';
print_r($test->getEuclidean()); // 2.2360679774998
echo'</pre>';

echo '</br>';
echo 'Manhatan (City Block) Distance Method';
echo'<pre>';
print_r($test->getManhatan()); // 3
echo'</pre>';

echo '</br>';
echo 'Minkowski Distance (&#955 = 3) Method';
echo'<pre>';
print_r($test->getMinkowski()); // 1.9129311827724
echo'</pre>';

echo '</br>';
echo 'Chebychef Distance Method';
echo'<pre>';
print_r($test->getChebychef()); // 2
echo'</pre>';

echo '</br>';
echo 'Canbera Distance Method';
echo'<pre>';
print_r($test->getCanbera()); // 0.41025641025641
echo'</pre>';

echo '</br>';
echo 'Bray Curtis Distance Method';
echo'<pre>';
print_r($test->getBrayCurtis()); // 0.12
echo'</pre>';

echo '</br>';
echo 'Kullback Leibler Distance Method';
echo'<pre>';
print_r($test->getKullbackLeibler()); // 1.8476846432762
echo'</pre>';

echo '</br>';
echo 'Jensen Shannon Distance Method';
echo'<pre>';
print_r($test->getJensenShannon()); // 0.37829763262563
echo'</pre>';