private void calculateSimiliarity( Trie window ) { List<Node> windowWords = window.getAll(); List<string> windowVector = new List<string>(); Distribution X = new Distribution(); double xmax = 0; foreach ( Node n in windowWords ) { string s = n.ToString(); windowVector.Add(s); double x = window.weight > 0 ? n.getNumOfAppearances() / (double)window.weight : 0; X.add(s , x ); xmax += x * x; } double rmin = 0; foreach ( Topic t in SuggestionUtils.fringeTopics.Values ) { Distribution Y = t.topicVector; t.rtmin = 0; for ( int i = 0 ; i < Math.Max(Y.count , X.count) ; i++ ) t.rtmin += Math.Pow(Y[i] - X[i] , 2); rmin = Math.Min(rmin,t.rtmin); t.rtmax = xmax; for ( int i = 0 ; i < Y.count ; i++ ) t.rtmax += Math.Pow(Y[i], 2); List<string> union = new List<string>(windowVector); foreach (object o in Y.keys ) if (union.Contains((string)o)) union.Add((string)o); t.rt = 0; for ( int i = 0 ; i < union.Count ; i++ ) { string s = union[i]; double xs = X[s]; double ys = Y[s]; t.rt += Math.Pow(xs - ys , 2); } } foreach ( Topic t in SuggestionUtils.fringeTopics.Values ) { double frt = ( t.rt - rmin ) / ( t.rtmax - rmin ); t.similiarity = similiarity1(frt); if ( onTopicReady != null ) onTopicReady(t); Form3.updateChartForTopic(t.topic , frt); Stats.updateChartForTopic(t.topic , frt); } Form2.showPlots(1); }