比较两个图表并获得相似性百分比

时间:2014-12-08 08:21:26

标签: php python algorithm math

问题:如何比较两个图表范围,并获得百分比作为结果。

我想比较两个图表部分(60个值的范围),结果得到差异的百分比。所以我可以找到非常相似的图表曲线。 (示例:获取与此图表90%相似的所有图表)

对于每个范围,数据都存储在60个数字数组中。 每个范围都以0开头,所有下一个数字代表该时刻的图表值。(" +"图表上升," - "图表下降)

$range1 = array(0.00,-0.90,2.10,0.10,-3.40,-4.30,-1.90,-0.30,0.00,0.10,-0.60,-0.20,-0.30,-0.30,1.00,-0.90,-0.50,1.00,2.80,5.00,5.50,5.20,6.70,5.50,5.70,7.30,6.00,5.10,5.30,11.10,10.90,9.00,7.10,6.60,7.00,5.50,5.50,12.60,15.60,14.30,18.50,16.60,16.60,20.30,20.60,18.10,16.10,19.10,14.40,18.70,17.40,17.80,17.20,19.90,20.60,17.70,17.00,17.50,16.70,14.70);
$range2 = array(0.00,-2.90,-3.60,-3.10,-3.90,-5.90,-11.80,-8.40,-8.00,-8.40,-8.20,-7.00,-7.60,-7.30,-5.10,-7.20,-7.30,-7.40,-7.70,-8.90,-9.30,-9.30,-9.90,-7.50,-11.70,-12.20,-19.80,-19.60,-19.90,-19.00,-22.10,-19.10,-20.10,-18.90,-19.70,-19.90,-16.50,-23.70,-26.60,-24.20,-28.30,-27.00,-28.60,-28.90,-22.90,-24.00,-25.10,-24.30,-18.40,-31.70,-29.80,-29.00,-29.50,-28.30,-35.50,-27.60,-34.00,-32.80,-36.00,-34.40,);


$result = some_specific_manual_written_function($range1, $range2);

//as a result i want get percentage or something else from what i can how similar charts are

我会读取csv文件,然后将其存储到db,所以可以用php或python完成。

2 个答案:

答案 0 :(得分:0)

试试这个

function some_specific_manual_written_function($range1, $range2)
{
    $match = 0;
    for($i=0; count($range1); $i++)
    {
        if(in_array($range[$i],$range2))
        {
            $match++;               
        }
    }

    $percentage_match = (count($range1)/$match ) * 100;

    echo "Perncetage Match is : ".$percentage_match."%";

    return $percentage_match;
}

答案 1 :(得分:0)

function similiar($range1, $range2) {
    $i = 0;
    foreach ($range1 as $k => $v) {
        if ($range2[$k] == $v) {
            $i++;
        }
    }
    $return ($i/count($range1))*100);
}