static double[,] calculateMaxResults(List <Task> all_tasks, contextCompare comp) { double[,] results = new double[all_tasks.Count(), all_tasks.Count()]; for (int i = 0; i < all_tasks.Count(); i++) { results[i, i] = 1.0; for (int j = i + 1; j < all_tasks.Count(); j++) { double sim = 1.0 - all_tasks[i].getCostMaxLength(all_tasks[j], comp); results[i, j] = sim; results[j, i] = sim; } } return(results); }
/* Builds a distance matrix from a function instead of converting to a simularity function * @param second the second flattened list * @param comp The type of comparision to do between each element * @param self Says if the recurrence is a self recurrance, and should ignore the diagonal * @returns a 2-D matrix of comparision values */ public double[,] buildCostMatrix(string[] second, contextCompare comp, bool self) { double[,] result = new double[this.task_string.Count(), second.Count()]; //We build an nxm array bool f = false; for (int i = 0; i < this.task_string.Count(); i++) { if (i > 0) { if (connectives.ContainsKey(this.task_string[i - 1])) { f = true; } else { f = false; } } bool s = false; for (int j = 0; j < second.Count(); j++) { if (self && i == j)//We obviously have a recurrence in self on the diagonal, which may prove problematic down the road { result[i, j] = 0.0; } else { if (j > 0) { if (connectives.ContainsKey(second[j - 1])) { s = true; } else { s = false; } } result[i, j] = comp(this.task_string[i], second[j], f, s); } } } return(result); }
public double getCostMaxLength(Task second, contextCompare comp) { double[,] recur = this.buildCostMatrix(second.getTask().ToArray(), comp, false); recur = this.warp(recur); //this.simToDist(recur) return(recur[this.task_string.Count() - 1, second.getTask().Count() - 1] / Math.Max(this.getTask().Count, second.getTask().Count)); //Gets the last value }