Permalink
Browse files

Small bug (bisecting)

  • Loading branch information...
1 parent a9c4907 commit 854da455bab37abe99a3e263ed375489ab47f6a6 Mihai Maruseac committed Mar 19, 2011
Showing with 57 additions and 7 deletions.
  1. +1 −1 Doxyfile
  2. +1 −1 Makefile
  3. +6 −4 globals.h
  4. +49 −1 id3graph.c
View
@@ -270,7 +270,7 @@ SUBGROUPING = YES
# be useful for C code in case the coding convention dictates that all compound
# types are typedef'ed and only the typedef is referenced, never the tag name.
-TYPEDEF_HIDES_STRUCT = NO
+TYPEDEF_HIDES_STRUCT = YES
# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
# determine which symbols to keep in memory and which to flush to disk.
View
@@ -20,7 +20,7 @@ test_learn: $(TARGET)
$(DEBUG) $(TARGET) l tests/1/atribute.txt tests/1/invatare.txt tests/1/dump.txt
test_graph: $(TARGET)
- $(DEBUG) $(TARGET) g -gscheme tests/1/dump.txt -
+ $(DEBUG) $(TARGET) g -gdot tests/1/dump.txt - | dot -Tpng > test.png
test_classify: $(TARGET)
$(DEBUG) $(TARGET) c tests/1/dump.txt tests/1/test.txt -
View
@@ -93,10 +93,9 @@ enum attr_type {
*
* If the attribute is numeric, the ptr vector will be used only after reading
* the learning example. It will be an index into the example data, used to
- * sort in ascending order the example data by this attribute. If at a later
- * time the example is splitted, the index will remain the same but some of
- * the values will not be relevant for that example. However, code doing this
- * will take care of that, thus, it is not a concern right now.
+ * sort in ascending order the example data by this attribute. After
+ * discretization, this vector will contain the limits used in the
+ * discretization.
*
* Otherwise, the ptr will point to a vector of names, used for the discrete
* values. Each name can be obtained by converting the integer to a char* and
@@ -173,6 +172,9 @@ struct example_set {
int missing[MISS_COUNT];
};
+/**
+ * @brief Structure representing the id3 classifier (or id3 tree).
+ */
struct classifier {
/** Id of classifier (tag used to generate it) */
int tag;
View
@@ -94,10 +94,58 @@ void graph_ascii(const struct description *descr,
}
}
+int dot_output(const struct description *descr,
+ const struct classifier *cls, FILE *out, int level)
+{
+ char *name, *dname, *aname;
+ int i, l, ll, type;
+
+ if (cls->C == 0) {
+ name = descr->classes[cls->id];
+ fprintf(out, "%s%d [label=%s];\n", name, level, name);
+ return level + 1;
+ }
+
+ name = descr->attribs[cls->id]->name;
+ type = descr->attribs[cls->id]->type;
+ fprintf(out, "%s%d [label=%s][shape=box];\n", name, level, name);
+ l = level++;
+ for (i = 0; i < cls->C; i++){
+ ll = level;
+ level = dot_output(descr, cls->cls[i], out, level);
+ if (cls->cls[i]->C == 0)
+ dname = descr->classes[cls->cls[i]->id];
+ else
+ dname = descr->attribs[cls->cls[i]->id]->name;
+ if (type == NUMERIC) {
+ if (i < cls->C - 1)
+ fprintf(out, "%s%d -- %s%d [label=\"<%d\"]"
+ "[fontsize=10];\n",
+ name, l, dname, ll,
+ cls->values[i]);
+ else
+ fprintf(out, "%s%d -- %s%d[label=\">=%d\"]"
+ "[fontsize=10];\n",
+ name, l, dname, ll,
+ cls->values[i - 1]);
+ } else {
+ aname = (char *)
+ descr->attribs[cls->id]->ptr[cls->values[i]];
+ fprintf(out, "%s%d -- %s%d[label=\"%s\"]"
+ "[fontsize=10];\n",
+ name, l, dname, ll, aname);
+ }
+ }
+ return level;
+}
+
void graph_dot(const struct description *descr,
- const struct classifier *cls, FILE* out)
+ const struct classifier *cls, FILE *out)
{
fprintf(stderr, "TODO output dot %s %d\n", __FILE__, __LINE__);
+ fprintf(out, "graph {\n");
+ dot_output(descr, cls, out, 0);
+ fprintf(out, "}\n");
}
void g_sch_print(const struct description *descr,

0 comments on commit 854da45

Please sign in to comment.