void ERP_drawChannel_number (ERP me, Graphics graphics, long channelNumber, double tmin, double tmax, double vmin, double vmax, bool garnish) { if (channelNumber < 1 || channelNumber > my ny) return; /* * Automatic domain. */ if (tmin == tmax) { tmin = my xmin; tmax = my xmax; } /* * Domain expressed in sample numbers. */ long ixmin, ixmax; Matrix_getWindowSamplesX (me, tmin, tmax, & ixmin, & ixmax); /* * Automatic vertical range. */ if (vmin == vmax) { Matrix_getWindowExtrema (me, ixmin, ixmax, channelNumber, channelNumber, & vmin, & vmax); if (vmin == vmax) { vmin -= 1.0; vmax += 1.0; } } /* * Set coordinates for drawing. */ Graphics_setInner (graphics); Graphics_setWindow (graphics, tmin, tmax, vmin, vmax); Graphics_function (graphics, my z [channelNumber], ixmin, ixmax, Matrix_columnToX (me, ixmin), Matrix_columnToX (me, ixmax)); Graphics_unsetInner (graphics); if (garnish) { Graphics_drawInnerBox (graphics); Graphics_textTop (graphics, true, Melder_wcscat (L"Channel ", my channelNames [channelNumber])); Graphics_textBottom (graphics, true, L"Time (s)"); Graphics_marksBottom (graphics, 2, true, true, false); if (0.0 > tmin && 0.0 < tmax) Graphics_markBottom (graphics, 0.0, true, true, true, NULL); Graphics_markLeft (graphics, vmin, true, true, false, NULL); Graphics_markLeft (graphics, vmax, true, true, false, NULL); Graphics_markBottom (graphics, 0.0, true, true, true, NULL); if (vmin != 0.0 && vmax != 0.0 && (vmin > 0.0) != (vmax > 0.0)) { Graphics_markLeft (graphics, 0.0, true, true, true, NULL); } } }
void GaussianMixture_drawMarginalPdf (GaussianMixture me, Graphics g, long d, double xmin, double xmax, double ymin, double ymax, long npoints, long nbins, int garnish) { if (d < 1 || d > my dimension) { Melder_warning1 (L"Dimension doesn't agree."); return;} if (npoints <= 1) npoints = 1000; double *p = NUMdvector (1, npoints); if (p == 0) return; double nsigmas = 2, *v = NUMdvector (1, my dimension); if (v == NULL) goto end; if (xmax <= xmin && ! GaussianMixture_getIntervalAlongDirection (me, d, nsigmas, &xmin, &xmax)) goto end; { double pmax = 0, dx = (xmax - xmin) / (npoints - 1); double scalef = nbins <= 0 ? 1 : 1; // TODO for (long i = 1; i <= npoints; i++) { double x = xmin + (i - 1) * dx; for (long k = 1; k <= my dimension; k++) v[k] = k == d ? 1 : 0; p[i] = scalef * GaussianMixture_getMarginalProbabilityAtPosition (me, v, x); if (p[i] > pmax) pmax = p[i]; } if (ymin >= ymax) { ymin = 0; ymax = pmax; } Graphics_setInner (g); Graphics_setWindow (g, xmin, xmax, ymin, ymax); Graphics_function (g, p, 1, npoints, xmin, xmax); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_markBottom (g, xmin, 1, 1, 0, NULL); Graphics_markBottom (g, xmax, 1, 1, 0, NULL); Graphics_markLeft (g, ymin, 1, 1, 0, NULL); Graphics_markLeft (g, ymax, 1, 1, 0, NULL); } } end: NUMdvector_free (p, 1); NUMdvector_free (v, 1); }
void GaussianMixture_and_PCA_drawMarginalPdf (GaussianMixture me, PCA thee, Graphics g, long d, double xmin, double xmax, double ymin, double ymax, long npoints, long nbins, int garnish) { if (my dimension != thy dimension || d < 1 || d > my dimension) { Melder_warning1 (L"Dimensions don't agree."); return;} if (npoints <= 1) npoints = 1000; double *p = NUMdvector (1, npoints); if (p == 0) return; double nsigmas = 2; if (xmax <= xmin && ! GaussianMixture_and_PCA_getIntervalAlongDirection (me, thee, d, nsigmas, &xmin, &xmax)) goto end; { double pmax = 0, dx = (xmax - xmin) / npoints, x1 = xmin + 0.5 * dx; double scalef = nbins <= 0 ? 1 : 1; // TODO for (long i = 1; i <= npoints; i++) { double x = x1 + (i - 1) * dx; p[i] = scalef * GaussianMixture_getMarginalProbabilityAtPosition (me, thy eigenvectors[d], x); if (p[i] > pmax) pmax = p[i]; } if (ymin >= ymax) { ymin = 0; ymax = pmax; } Graphics_setInner (g); Graphics_setWindow (g, xmin, xmax, ymin, ymax); Graphics_function (g, p, 1, npoints, x1, xmax - 0.5 * dx); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_markBottom (g, xmin, 1, 1, 0, NULL); Graphics_markBottom (g, xmax, 1, 1, 0, NULL); Graphics_markLeft (g, ymin, 1, 1, 0, NULL); Graphics_markLeft (g, ymax, 1, 1, 0, NULL); } } end: NUMdvector_free (p, 1); }
void Matrix_drawAsSquares (Matrix me, Graphics g, double xmin, double xmax, double ymin, double ymax, int garnish) { Graphics_Colour colour = Graphics_inqColour (g); long ixmin, ixmax, iymin, iymax; if (xmax <= xmin) { xmin = my xmin; xmax = my xmax; } long nx = Matrix_getWindowSamplesX (me, xmin, xmax, &ixmin, &ixmax); if (ymax <= ymin) { ymin = my ymin; ymax = my ymax; } long ny = Matrix_getWindowSamplesY (me, ymin, ymax, &iymin, &iymax); double min, max = nx > ny ? nx : ny; double dx = (xmax - xmin) / max, dy = (ymax - ymin) / max; Graphics_setInner (g); Graphics_setWindow (g, xmin, xmax, ymin, ymax); Matrix_getWindowExtrema (me, ixmin, ixmax, iymin, iymax, & min, & max); double wAbsMax = fabs (max) > fabs (min) ? fabs (max) : fabs (min); for (long i = iymin; i <= iymax; i++) { double y = Matrix_rowToY (me, i); for (long j = ixmin; j <= ixmax; j++) { double x = Matrix_columnToX (me, j); double d = 0.95 * sqrt (fabs (my z[i][j]) / wAbsMax); if (d > 0) { double x1WC = x - d * dx / 2, x2WC = x + d * dx / 2; double y1WC = y - d * dy / 2, y2WC = y + d * dy / 2; if (my z[i][j] > 0) { Graphics_setColour (g, Graphics_WHITE); } Graphics_fillRectangle (g, x1WC, x2WC, y1WC, y2WC); Graphics_setColour (g, colour); Graphics_rectangle (g, x1WC, x2WC , y1WC, y2WC); } } } Graphics_setGrey (g, 0.0); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_marksLeft (g, 2, true, true, false); if (ymin * ymax < 0.0) { Graphics_markLeft (g, 0.0, true, true, true, nullptr); } Graphics_marksBottom (g, 2, true, true, false); if (xmin * xmax < 0.0) { Graphics_markBottom (g, 0.0, true, true, true, nullptr); } } }
void Matrix_scatterPlot (Matrix me, Graphics g, long icx, long icy, double xmin, double xmax, double ymin, double ymax, double size_mm, const char32 *mark, int garnish) { long ix = labs (icx), iy = labs (icy); if (ix < 1 || ix > my nx || iy < 1 || iy > my nx) { return; } if (xmax <= xmin) { (void) Matrix_getWindowExtrema (me, ix, ix, 1, my ny, & xmin, & xmax); if (xmax <= xmin) { xmin -= 0.5; xmax += 0.5; } } if (ymax <= ymin) { (void) Matrix_getWindowExtrema (me, iy, iy, 1, my ny, & ymin, & ymax); if (ymax <= ymin) { ymin -= 0.5; ymax += 0.5; } } Graphics_setInner (g); if (icx < 0) { double t = xmin; xmin = xmax; xmax = t; } if (icy < 0) { double t = ymin; ymin = ymax; ymax = t; } Graphics_setWindow (g, xmin, xmax, ymin, ymax); for (long i = 1; i <= my ny; i++) { if (my z[i][ix] >= xmin && my z[i][ix] <= xmax && my z[i][iy] >= ymin && my z[i][iy] <= ymax) { Graphics_mark (g, my z[i][ix], my z[i][iy], size_mm, mark); } } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_marksLeft (g, 2, true, true, false); if (ymin * ymax < 0.0) { Graphics_markLeft (g, 0.0, true, true, true, nullptr); } Graphics_marksBottom (g, 2, true, true, false); if (xmin * xmax < 0.0) { Graphics_markBottom (g, 0.0, true, true, true, nullptr); } } }
void Polygon_Categories_draw (Polygon me, thou, Graphics graphics, double xmin, double xmax, double ymin, double ymax, int garnish) { thouart (Categories); double min, max, tmp; if (my numberOfPoints != thy size) { return; } if (xmax == xmin) { NUMvector_extrema (my x, 1, my numberOfPoints, & min, & max); tmp = max - min == 0 ? 0.5 : 0.0; xmin = min - tmp; xmax = max + tmp; } if (ymax == ymin) { NUMvector_extrema (my y, 1, my numberOfPoints, & min, & max); tmp = max - min == 0 ? 0.5 : 0.0; ymin = min - tmp; ymax = max + tmp; } Graphics_setInner (graphics); Graphics_setWindow (graphics, xmin, xmax, ymin, ymax); Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_HALF); for (long i = 1; i <= my numberOfPoints; i++) { OrderedOfString_drawItem (thee, graphics, i, my x[i], my y[i]); } Graphics_unsetInner (graphics); if (garnish) { Graphics_drawInnerBox (graphics); Graphics_marksLeft (graphics, 2, 1, 1, 0); if (ymin * ymax < 0.0) { Graphics_markLeft (graphics, 0.0, 1, 1, 1, NULL); } Graphics_marksBottom (graphics, 2, 1, 1, 0); if (xmin * xmax < 0.0) { Graphics_markBottom (graphics, 0.0, 1, 1, 1, NULL); } } }
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); } } }