Home
News
Feed
search engine
by
freefind
advanced
some code as of 071412_1500
2014-08-29
azim58 - some code as of 071412_1500 public ItemData findEverythingSimilarToItemI(int i) { ArrayList items_similar_to_I = new ArrayList(); ArrayList scores_similar_to_I = new ArrayList(); ArrayList list_of_other_items_to_findEverythingSimilarToItemI = new ArrayList(); int item_with_best_similarity_score = 0; double best_average_similarity_score = 0; Here the program will "pretend" that it is moving through the modifiable list in the form of a matrix to go acrossed the row for i and determine which things are similar. In order to accomplish this, values from the modifiable list have to be retrieved in a special wayl. int row_number = i; for(int column_count=0; column_count<modifiable_list.size(); column_count++) { if(column_count<row_number) { double current_score = Double.valueOf(((ArrayList)modifiable_list.get(column_count)).get(row_numbe r-2-column_count+1).toString()).doubleValue(); if(current_score>threshold) { items_similar_to_I.add(column_count); scores_similar_to_I.add(current_score); items_already_in_groups.add(column_count); now delete the score from the modifiable list ((ArrayList)modifiable_list.get(column_count)).set(row_number-2-column_coun t+1,-1); } } else if(column_count>row_number) { double current_score = Double.valueOf(((ArrayList)modifiable_list.get(row_number)).get(column_coun t-row_number-1).toString()).doubleValue(); if(current_score>threshold) { items_similar_to_I.add(column_count); scores_similar_to_I.add(current_score); items_already_in_groups.add(column_count); now delete the score from the modifiable list ((ArrayList)modifiable_list.get(row_number)).set(column_count-row_number-1, -1); } } } double average_similarity = 0; if(scores_similar_to_I.size()>0) { for(int j=0; j<scores_similar_to_I.size(); j++) { average_similarity+=Double.valueOf(scores_similar_to_I.get(j).toString()).d oubleValue(); } average_similarity = average_similarity/scores_similar_to_I.size(); } best_average_similarity_score = average_similarity; item_with_best_similarity_score = i; now go through and find the items similar to all of the items that were similar to i for(int j=0; j<items_similar_to_I.size(); j++) { int current_item_to_check = Integer.valueOf(items_similar_to_I.get(j).toString()).intValue(); ItemData item_data = findEverythingSimilarToItemI(current_item_to_check); double comparison_average = item_data.getAverage(); if(comparison_average>average_similarity) { best_average_similarity_score = comparison_average; item_with_best_similarity_score = item_data.getItemWithBestScore(); } items_similar_to_I.add(item_data.getList()); items_similar_to_I = useful_tools.flattenList(items_similar_to_I); items_similar_to_I = useful_tools.removeDuplicates(items_similar_to_I); } items_similar_to_I.add(i); //now summarize and package all of the information so that it can be returned as some item data ItemData return_item_data = new ItemData(best_average_similarity_score, items_similar_to_I, item_with_best_similarity_score); return return_item_data; }
azim58wiki: