protected function assessments_distance(stdclass $assessment, stdclass $referential, array $diminfo, stdclass $settings) {
        $distance = 0;
        $n = 0;
        foreach (array_keys($assessment->dimgrades) as $dimid) {
            $agrade = $assessment->dimgrades[$dimid];
            $rgrade = $referential->dimgrades[$dimid];
            $var    = $diminfo[$dimid]->variance;
            $weight = $diminfo[$dimid]->weight;
            $n     += $weight;

            // variations very close to zero are too sensitive to a small change of data values
            $var = max($var, 0.01);

            if ($agrade != $rgrade) {
                $absdelta   = abs($agrade - $rgrade);
                $reldelta   = pow($agrade - $rgrade, 2) / ($settings->comparison * $var);
                $distance  += $absdelta * $reldelta * $weight;
            }
        }
        if ($n > 0) {
            // average distance across all dimensions
            return round($distance / $n, 4);
        } else {
            return null;
        }
    }
protected function assessments_distance(stdclass $assessment, stdclass $referential, array $diminfo, stdclass $settings) {
        $distance = 0;
        $n = 0;
        foreach (array_keys($assessment->dimgrades) as $dimid) {
            $agrade = $assessment->dimgrades[$dimid];
            $rgrade = $referential->dimgrades[$dimid];
            $var    = $diminfo[$dimid]->variance;
            $weight = $diminfo[$dimid]->weight;
            $n     += $weight;

            // variations very close to zero are too sensitive to a small change of data values
            $var = max($var, 0.01);

            if ($agrade != $rgrade) {
                $absdelta   = abs($agrade - $rgrade);
                $reldelta   = pow($agrade - $rgrade, 2) / ($settings->comparison * $var);
                $distance  += $absdelta * $reldelta * $weight;
            }
        }
        if ($n > 0) {
            // average distance across all dimensions
            return round($distance / $n, 4);
        } else {
            return null;
        }
    }
protected function assessments_distance ( stdclass $ assessment , stdclass $ referential , array $ diminfo , stdclass $ settings ) { $ distance = 0 ; $ n = 0 ; foreach ( array_keys ( $ assessment -> dimgrades ) as $ dimid ) { $ agrade = $ assessment -> dimgrades [ $ dimid ] ; $ rgrade = $ referential -> dimgrades [ $ dimid ] ; $ var = $ diminfo [ $ dimid ] -> variance ; $ weight = $ diminfo [ $ dimid ] -> weight ; $ n += $ weight ; // variations very close to zero are too sensitive to a small change of data values $ var = max ( $ var , 0.01 ) ; if ( $ agrade != $ rgrade ) { $ absdelta = abs ( $ agrade - $ rgrade ) ; $ reldelta = pow ( $ agrade - $ rgrade , 2 ) / ( $ settings -> comparison * $ var ) ; $ distance += $ absdelta * $ reldelta * $ weight ; } } if ( $ n > 0 ) { // average distance across all dimensions return round ( $ distance / $ n , 4 ) ; } else { return null ; } }
Measures the distance of the assessment from a referential one

The passed data structures must contain ->dimgrades property. The referential
assessment is supposed to be close to the average assessment. All dimension grades are supposed to be
normalized to the interval 0 - 100.
Returned value is rounded to 4 valid decimals to prevent some rounding issues - see the unit test
for an example.

@param stdClass $assessment the assessment being measured
@param stdClass $referential assessment
@param array $diminfo of stdclass(->weight ->min ->max ->variance) indexed by dimension id
@param stdClass $settings
@return float|null rounded to 4 valid decimals
Measures the distance of the assessment from a referential one