I've got a code where I need to create a map with key values as double (value of the f-test between two clusters, I need to calculate the residual sum of squares for this) and the mapped value of cluspair which is pair of the class Cluster that I created. Map aims to store the F-test values of each cluster with the cluster that gives the minimum f-value for it. Therefore I would not need to do the calculation again and again in every step. BTW cluster is a tree structure where every cluster contains two subclusters and the stored values are 70-dimensional vectors.
Problem is, in order to calculate the RSS, I need to implement a recursive code where I need to find the distance of every element of the cluster with the mean of the cluster and this seems to be consuming an enormous amount of memory. When I create the same map with the key values being the simple distance between the means of two clusters, the program uses minimal memory so I think the increase in the memory use is caused by the call of the recursive function RSS. What should I do to manage the memory use in the code below? In its current implementation the system runs out of memory and windows closes the application saying that the system ran out of virtual memory.
Btw below is the code that I use to create a map with keys being simple euclidian distance between two cluster means. As I've said above, it is quite similar and uses minimal memory. It only differs in the calculation of the fvalue. Instead of the recursive calculation, there is the calculation of simple distance of means of two clusters. Hope it helps to identify the problem
If they are even sized, they are going to pass each other.
Say begin is 0 and end is 2, for the first run..
it1 is 0 and it checks against 1 (because it is reduced before the check).
For the next pass, it1 is 1 and is checked against 0 now, so they will pass each other and you have a problem. Plus, if begin == end, you have a problem also. You need to rethink your for loops from what I can see.
EDIT: Scratch most of that.... I was treating end() like a var. If end == begin though, there might still be a problem.
Thanks for the input. You are right, if begin is same with end this would be a problem but the algorithm deals with a large amount of data and therefore I didn't think I should be worrying for that case. It just seemed straigtforward to implement in such a way and as you said, end() is not a variable. Therefore I think the implementation of the for loop is ok.