[
https://issues.apache.org/jira/browse/MAHOUT-1130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13599193#comment-13599193
]
Sebastian Schelter commented on MAHOUT-1130:
--------------------------------------------
This thing is really, really broken. I wrote a small test mimicing the way the
seeds are picked. When I make it pick 10 items from a 100k candidates, it
always picks them from the last 100...
Try [0]: 99973 99981 99988 99991 99992 99993 99995 99997 99998 99999
Try [1]: 99976 99983 99986 99990 99991 99993 99994 99996 99997 99998
Try [2]: 99957 99984 99986 99987 99989 99993 99994 99997 99998 99999
Try [3]: 99969 99975 99976 99984 99985 99988 99994 99995 99998 99999
Try [4]: 99967 99971 99978 99990 99991 99992 99994 99995 99997 99998
Try [5]: 99935 99981 99987 99988 99990 99991 99996 99997 99998 99999
Try [6]: 99967 99971 99988 99990 99991 99992 99995 99997 99998 99999
Try [7]: 99986 99987 99989 99991 99992 99993 99995 99997 99998 99999
Try [8]: 99967 99982 99988 99991 99992 99993 99996 99997 99998 99999
Try [9]: 99960 99981 99984 99986 99988 99995 99996 99997 99998 99999
Try [10]: 99969 99974 99977 99988 99991 99993 99994 99997 99998 99999
Try [11]: 99969 99977 99986 99991 99992 99993 99994 99995 99996 99998
Try [12]: 99980 99984 99989 99991 99992 99994 99995 99997 99998 99999
Try [13]: 99968 99971 99988 99990 99991 99992 99996 99997 99998 99999
Try [14]: 99938 99976 99978 99985 99986 99989 99991 99993 99995 99997
Try [15]: 99981 99984 99990 99992 99994 99995 99996 99997 99998 99999
Try [16]: 99966 99976 99983 99985 99989 99991 99995 99996 99997 99999
Try [17]: 99969 99972 99973 99981 99987 99988 99991 99994 99998 99999
Try [18]: 99976 99984 99987 99990 99991 99992 99994 99996 99998 99999
Try [19]: 99982 99987 99989 99992 99993 99994 99996 99997 99998 99999
{code}
@Test
public void testSeedSelection() {
int k = 10;
int[] candidates = new int[100000];
int numExperiments = 20;
for (int n = 0; n < candidates.length; n++) {
candidates[n] = n;
}
for (int experiment = 0; experiment < numExperiments; experiment++) {
Random random = RandomUtils.getRandom(System.currentTimeMillis());
List<Integer> seeds = Lists.newArrayListWithCapacity(k);
for (int candidate : candidates) {
int currentSize = seeds.size();
if (currentSize < k) {
seeds.add(candidate);
} else if (random.nextInt(currentSize + 1) != 0) {
int indexToRemove = random.nextInt(currentSize); // evict one chosen
randomly
seeds.remove(indexToRemove);
seeds.add(candidate);
}
}
System.out.print("Try [" + experiment + "]: ");
for (int seed : seeds) {
System.out.print(seed + " ");
}
System.out.println();
}
}
{code}
> Wrong logic in org.apache.mahout.clustering.kmeans.RandomSeedGenerator
> ----------------------------------------------------------------------
>
> Key: MAHOUT-1130
> URL: https://issues.apache.org/jira/browse/MAHOUT-1130
> Project: Mahout
> Issue Type: Bug
> Environment: mahout 0.7 from maven central
> Reporter: Andrey Davydov
>
> There is following code in line 101:
> } else if (random.nextInt(currentSize + 1) != 0) { // with
> chance 1/(currentSize+1) pick new element
> but it actually means pick new element with chance currentSize/(currentSize+1)
> so generator takes initial centers from the end of source data file.
> It seems that chance of replace vector in output set should decrease with
> number of processed input vectors
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira