/** * 改良過後計算關係度的方法 * @param Annotation $annotation * @return Output_language_variable_collection */ protected function _get_membership_renew(Annotation $annotation, $parameters) { //請由子類別來覆寫此方法 $variables = explode(',', $parameters); $feature = $this->get_feature($annotation); $this->_CI_load('library', 'fuzzy/Output_language_variable_collection', 'output_language_variable_collection'); $membership = new Output_language_variable_collection(); $membership->set_zero(); if (count($variables) > 1) { if ($feature <= $variables[0]) { $membership->set_membership(0, 1); } else { if ($feature >= $variables[count($variables) - 1]) { $membership->set_membership(count($variables) - 1, 1); } else { for ($i = 0; $i < count($variables) - 1; $i++) { $now = $variables[$i]; $next = $variables[$i + 1]; if ($feature > $now && $feature <= $next) { $len = $next - $now; $m1 = 1 - ($feature - $now) / $len; $m2 = 1 - ($next - $feature) / $len; $membership->set_membership($i, $m1); $membership->set_membership($i + 1, $m2); break; } } } } } return $membership; }