void FFNet_drawActivation (FFNet me, Graphics g) { long node = 1, maxNumOfUnits = my nUnitsInLayer[0]; int dxIsFixed = 1; Graphics_Colour colour = Graphics_inqColour (g); double dy = 1.0 / (my nLayers + 1); Graphics_setInner (g); Graphics_setWindow (g, 0.0, 1.0, 0.0, 1.0); for (long i = 1; i <= my nLayers; i++) { if (my nUnitsInLayer[i] > maxNumOfUnits) { maxNumOfUnits = my nUnitsInLayer[i]; } } double dx = 1.0 / maxNumOfUnits; double r1 = dx / 2.0; /* May touch when neighbouring activities are both 1 (very rare). */ for (long i = 0; i <= my nLayers; i++, node++) { double dx2 = dx, x2WC, y2WC = dy / 2.0 + i * dy; double x2 = (maxNumOfUnits - my nUnitsInLayer[i] + 1) * dx2 / 2.0; if (! dxIsFixed) { dx2 = 1.0 / my nUnitsInLayer[i]; x2 = dx2 / 2.0; } x2WC = x2; for (long j = 1; j <= my nUnitsInLayer[i]; j++, node++) { double activity = my activity[node]; double radius = r1 * (fabs (activity) < 0.05 ? 0.05 : fabs (activity)); /*Graphics_setColour (g, activity < 0 ? Graphics_BLACK : Graphics_RED);*/ Graphics_circle (g, x2WC, y2WC, radius); if (activity < 0) { Graphics_fillCircle (g, x2WC, y2WC, radius); } x2WC += dx2; } } Graphics_setColour (g, colour); Graphics_unsetInner (g); }
void Confusion_Matrix_draw (Confusion me, Matrix thee, Graphics g, long index, double lowerPercentage, double xmin, double xmax, double ymin, double ymax, int garnish) { long ib = 1, ie = my numberOfRows; if (index > 0 && index <= my numberOfColumns) { ib = ie = index; } if (thy ny != my numberOfRows) { Melder_throw (U"Wrong number of positions."); } if (xmax <= xmin) { (void) Matrix_getWindowExtrema (thee, 1, 1, 1, thy ny, &xmin, &xmax); } if (xmax <= xmin) { return; } if (ymax <= ymin) { (void) Matrix_getWindowExtrema (thee, 2, 2, 1, thy ny, &ymin, &ymax); } if (ymax <= ymin) { return; } double rmax = fabs (xmax - xmin) / 10.0; double rmin = rmax / 10; Graphics_setInner (g); Graphics_setWindow (g, xmin - rmax, xmax + rmax, ymin - rmax, ymax + rmax); Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_HALF); for (long i = 1; i <= my numberOfRows; i++) { Graphics_text (g, thy z[i][1], thy z[i][2], my rowLabels[i]); } for (long i = ib; i <= ie; i++) { double xSum = 0.0; for (long j = 1; j <= my numberOfColumns; j++) { xSum += my data[i][j]; } if (xSum <= 0.0) { continue; /* no confusions */ } double x1 = thy z[i][1]; double y1 = thy z[i][2]; double r = rmax * my data[i][i] / xSum; Graphics_circle (g, x1, y1, r > rmin ? r : rmin); for (long j = 1; j <= my numberOfColumns; j++) { double x2 = thy z[j][1], y2 = thy z[j][2]; double perc = 100.0 * my data[i][j] / xSum; double dx = x2 - x1, dy = y2 - y1; double alpha = atan2 (dy, dx); if (perc == 0.0 || perc < lowerPercentage || j == i) { continue; } xmin = x1; xmax = x2; if (x2 < x1) { xmin = x2; xmax = x1; } ymin = y1; xmax = y2; if (y2 < y1) { ymin = y2; ymax = y1; } autoPolygon p = Polygon_createPointer(); double xs = sqrt (dx * dx + dy * dy) - 2.2 * r; if (xs < 0.0) { xs = 0.0; } double ys = perc * rmax / 100.0; Polygon_scale (p.get(), xs, ys); Polygon_translate (p.get(), x1, y1 - ys / 2); Polygon_rotate (p.get(), alpha, x1, y1); Polygon_translate (p.get(), 1.1 * r * cos (alpha), 1.1 * r * sin (alpha)); Polygon_drawInside (p.get(), g); } } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_marksBottom (g, 2, true, true, false); if (ymin * ymax < 0.0) { Graphics_markLeft (g, 0.0, true, true, true, nullptr); } Graphics_marksLeft (g, 2, true, true, false); if (xmin * xmax < 0.0) { Graphics_markBottom (g, 0.0, true, true, true, nullptr); } } }
void FFNet_drawTopology (FFNet me, Graphics g) { long maxNumOfUnits = my nUnitsInLayer[0]; int dxIsFixed = 1; double dy = 1.0 / (my nLayers + 1); for (long i = 1; i <= my nLayers; i++) { if (my nUnitsInLayer[i] > maxNumOfUnits) { maxNumOfUnits = my nUnitsInLayer[i]; } } double dx = 1.0 / maxNumOfUnits; double radius = dx / 10.0; Graphics_setInner (g); Graphics_setWindow (g, 0.0, 1.0, 0.0, 1.0); for (long i = 0; i <= my nLayers; i++) { double dx2 = dx, x2WC, y2WC = dy / 2 + i * dy; double x2 = (maxNumOfUnits - my nUnitsInLayer[i] + 1) * dx2 / 2; /* draw the units */ if (! dxIsFixed) { dx2 = 1.0 / my nUnitsInLayer[i]; x2 = dx2 / 2.0; } if (i == 0) { Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_TOP); x2WC = x2; for (long j = 1; j <= my nInputs; j++) { Graphics_arrow (g, x2WC, y2WC - radius - dy / 4.0, x2WC, y2WC - radius); x2WC += dx2; } } Graphics_setColour (g, Graphics_RED); x2WC = x2; for (long j = 1; j <= my nUnitsInLayer[i]; j++) { Graphics_circle (g, x2WC, y2WC, radius); if (i > 0) { Graphics_fillCircle (g, x2WC, y2WC, radius); } x2WC += dx2; } Graphics_setColour (g, Graphics_BLACK); if (i > 0) { double dx1 = dx; double x1 = (maxNumOfUnits - my nUnitsInLayer[i - 1] + 1) * dx1 / 2.0; double y1WC = y2WC - dy; if (! dxIsFixed) { dx1 = 1.0 / my nUnitsInLayer[i - 1]; x1 = dx1 / 2.0; } x2WC = x2; for (long j = 1; j <= my nUnitsInLayer[i]; j++) { double x1WC = x1; for (long k = 1; k <= my nUnitsInLayer[i - 1]; k++) { double xd = x2WC - x1WC; double cosa = xd / sqrt (xd * xd + dy * dy); double sina = dy / sqrt (xd * xd + dy * dy); Graphics_line (g, x1WC + radius * cosa, y1WC + radius * sina, x2WC - radius * cosa, y2WC - radius * sina); x1WC += dx1; } x2WC += dx2; } } if (i == my nLayers) { x2WC = x2; Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_BOTTOM); for (long j = 1; j <= my nOutputs; j++) { Graphics_arrow (g, x2WC, y2WC + radius, x2WC, y2WC + radius + dy / 4.0); if (my outputCategories) { Categories_drawItem (my outputCategories.peek(), g, j, x2WC, y2WC + radius + dy / 4.0); } x2WC += dx2; } } } Graphics_unsetInner (g); }