You are here

function recommender_similarity_classical in Recommender API 5

Same name and namespace in other branches
  1. 6 recommender.module \recommender_similarity_classical()
  2. 6.2 recommender.module \recommender_similarity_classical()

classical collaborative filtering algorithm based on correlation coefficient. could be used in the classical user-user or item-item algorithm see the README file for more details

Parameters

$app_name the application name that uses this function.:

$table_name the input table name:

$field_mouse the input table field for mouse:

$field_cheese the input table field for cheese:

$field_weight the input table field weight:

$options an array of options: 'performance': whether to do calculation in memory or in database. 'auto' is to decide automatically. 'missing': how to handle missing data -- 'none' do nothing; 'zero' fill in missing data with zero; 'adjusted' skip mice that don't share cheese in common. 'sensitivity': if similarity is smaller enough to be less than a certain value (sensitivity), we just discard those

Return value

null {recommender_similarity} will be filled with similarity data

File

./recommender.module, line 25
Providing generic recommender system algorithms.

Code

function recommender_similarity_classical($app_name, $table_name, $field_mouse, $field_cheese, $field_weight, $options = array()) {

  // get param value
  $app_id = recommender_get_app_id($app_name);
  $op = $options['performance'];
  if (!isset($op) || $op == 'auto') {

    // decide the scale, then choose which algorithm to use.
    $result = db_result(db_query("SELECT COUNT(DISTINCT {$field_mouse}) count_mouse, COUNT(DISTINCT {$field_mouse}) count_mouse FROM {{$table_name}}"));
    $op = $result['count_mouse'] <= 2000 && $result['count_cheese'] <= 10000 && $options['missing'] == 'zero' ? 'memory' : 'database';
  }
  if ($op == 'memory') {
    _recommender_similarity_classical_in_memory($app_id, $table_name, $field_mouse, $field_cheese, $field_weight, $options);
  }
  else {
    if ($op == 'database') {
      _recommender_similarity_classical_in_database($app_id, $table_name, $field_mouse, $field_cheese, $field_weight, $options);
    }
  }
}