You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by Robert Burrell Donkin <ro...@gmail.com> on 2009/06/14 10:47:12 UTC
[kmeans] Error Handling
(i've been taking a look into the examples starting with clustering.
the kmeans clustering example is broken in trunk but i hope to be able
to track down the problem sometime soonish.)
currently org.apache.mahout.clustering.kmeans.Cluster#decodeCluster[1]
silently returns a null when it encounters an unknown format. i find
that this approach makes it difficult to debug format issues. i'd like
to contribute a patch but i'm unsure about the conventional error
handling strategy used in Mahout...
- robert
[1]
/**
* Decodes and returns a Cluster from the formattedString
*
* @param formattedString a String produced by formatCluster
* @return a new Canopy
*/
public static Cluster decodeCluster(String formattedString) {
int beginIndex = formattedString.indexOf('[');
String id = formattedString.substring(0, beginIndex);
String center = formattedString.substring(beginIndex);
char firstChar = id.charAt(0);
boolean startsWithV = firstChar == 'V';
if (firstChar == 'C' || startsWithV) {
int clusterId = Integer.parseInt(formattedString.substring(1,
beginIndex - 2));
Vector clusterCenter = AbstractVector.decodeVector(center);
Cluster cluster = new Cluster(clusterCenter, clusterId);
cluster.converged = startsWithV;
return cluster;
}
return null;
}
Re: [kmeans] Error Handling
Posted by Ted Dunning <te...@gmail.com>.
If the error is not normally expected, I would tend toward exceptions. If
the natural idiom is to use an if-statement, null might be OK. If
null-return is used and there isn't an if, then you have a bug in k-means at
least.
I/O is an area that is kind of conflicted on this sort of issue.
On Sun, Jun 14, 2009 at 1:47 AM, Robert Burrell Donkin <
robertburrelldonkin@gmail.com> wrote:
> i'd like
> to contribute a patch but i'm unsure about the conventional error
> handling strategy used in Mahout...
>