void GDBPlot2DCommand::HandleSuccess ( const JString& data ) { JArray<JFloat>* x = GetX(); JArray<JFloat>* y = GetY(); if ((GetLastResult()).BeginsWith("error,msg=\"No symbol")) { x->RemoveAll(); y->RemoveAll(); return; } const JIndex count = x->GetElementCount(); JIndex i; JIndexRange r; JArray<JIndexRange> matchRange1, matchRange2; JString v1, v2; for (i=1; i<=count; i++) { if (!prefixPattern.MatchAfter(data, r, &matchRange1)) { break; } r = matchRange1.GetElement(1); if (!prefixPattern.MatchAfter(data, r, &matchRange2)) { break; } r = matchRange2.GetElement(1); v1 = data.GetSubstring(matchRange1.GetElement(2)); v1.TrimWhitespace(); v2 = data.GetSubstring(matchRange2.GetElement(2)); v2.TrimWhitespace(); JFloat x1, y1; if (!v1.ConvertToFloat(&x1) || !v2.ConvertToFloat(&y1)) { break; } x->SetElement(i, x1); y->SetElement(i, y1); } if (i <= count) { const JSize delta = count - (i-1); x->RemoveNextElements(count - delta + 1, delta); y->RemoveNextElements(count - delta + 1, delta); } }
void GRaggedFloatTableData::SetElement ( const JIndex row, const JIndex col, const JFloat data ) { CreateCellIfNeeded(row, col); JArray<JFloat>* dataCol = itsCols->NthElement(col); dataCol->SetElement(row, data); if (itsBroadcast) { Broadcast(JTableData::RectChanged(row,col)); } }
void GRaggedFloatTableData::SetRow ( const JIndex index, const JArray<JFloat>& rowData ) { const JSize colCount = GetDataColCount(); assert( rowData.GetElementCount() == colCount ); for (JIndex i=1; i<=colCount; i++) { JArray<JFloat>* dataCol = itsCols->NthElement(i); dataCol->SetElement(index, rowData.GetElement(i)); } Broadcast(JTableData::RectChanged(JRect(index, 1, index+1, colCount+1))); }
void GRaggedFloatTableData::SetCol ( const JIndex index, const JOrderedSet<JFloat>& colData ) { JArray<JFloat>* dataCol = itsCols->NthElement(index); const JSize rowCount = colData.GetElementCount(); CreateCellIfNeeded(rowCount, index); for (JIndex i=1; i<=rowCount; i++) { dataCol->SetElement(i, colData.GetElement(i)); } JRect rect(1, index, rowCount + 1, index + 1); if (itsBroadcast) { Broadcast(JTableData::RectChanged(rect)); } }
JBoolean JPartition::SetCompartmentSize ( const JIndex index, const JCoordinate reqSize ) { const JCoordinate origSize = GetCompartmentSize(index); JArray<JCoordinate> newSizes; JCoordinate trueSize; if (reqSize > origSize && CreateSpace(*itsSizes, *itsMinSizes, itsElasticIndex, reqSize - origSize, reqSize - origSize, &newSizes, &trueSize)) { assert( trueSize == reqSize - origSize ); newSizes.SetElement(index, reqSize); *itsSizes = newSizes; SetCompartmentSizes(); return kJTrue; } else if (reqSize < origSize) { itsSizes->SetElement(index, reqSize); FillSpace(*itsSizes, itsElasticIndex, origSize - reqSize, &newSizes); *itsSizes = newSizes; SetCompartmentSizes(); return kJTrue; } else { return JI2B(reqSize == origSize); } }
void TestWidget::DrawStuff ( JPainter& p ) { JIndex i; JXColormap* colormap = GetColormap(); p.SetPenColor(colormap->GetGreenColor()); JRect ellipseRect(100,50,150,300); p.Ellipse(ellipseRect); p.SetPenColor(colormap->GetBlackColor()); if (itsFillFlag) { p.SetFilling(kJTrue); } JRect ap = GetAperture(); p.Line(ap.topLeft(), ap.bottomRight()); p.Line(ap.topRight(), ap.bottomLeft()); p.SetLineWidth(2); p.SetFontName("Times"); p.SetFontSize(18); p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect); its2Rect = JRect(150, 5, 200, 30); p.SetPenColor(colormap->GetRedColor()); p.Rect(its2Rect); p.SetFontStyle(colormap->GetRedColor()); p.String(its2Rect.topLeft(), "2", its2Rect.width(), JPainter::kHAlignCenter, its2Rect.height(), JPainter::kVAlignCenter); its3Rect = JRect(10, 150, 40, 200); p.SetPenColor(colormap->GetBlueColor()); p.Rect(its3Rect); p.SetFontStyle(colormap->GetBlueColor()); p.String(its3Rect.topLeft(), "3", its3Rect.width(), JPainter::kHAlignCenter, its3Rect.height(), JPainter::kVAlignCenter); p.SetLineWidth(1); p.SetFont(GetFontManager()->GetDefaultFont()); p.ShiftOrigin(10,10); p.Point(0,0); for (i=1; i<=itsRandPointCount; i++) { p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200)); } p.SetPenColor(colormap->GetRedColor()); p.Line(10,0, 0,10); p.SetPenColor(colormap->GetGreenColor()); p.LineTo(10,20); p.SetPenColor(colormap->GetBlueColor()); p.LineTo(0,30); p.ShiftOrigin(2,0); JPoint textPt(40,30); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.ShiftOrigin(-2, 0); p.SetPenColor(colormap->GetBlueColor()); JRect r(70, 290, 150, 390); p.Rect(r); /* for (JCoordinate y=70; y<150; y++) { p.SetPenColor(colormap->GetGrayColor(y-50)); p.Line(290,y, 390,y); } for (JCoordinate x=290; x<390; x++) { p.SetPenColor(colormap->GetGrayColor(x-290)); p.Line(x,70, x,150); } p.SetLineWidth(2); for (JCoordinate y=70; y<150; y+=2) { p.SetPenColor(colormap->GetGrayColor(y%4 ? 40 : 60)); p.Line(290,y, 390,y); } p.SetLineWidth(1); p.SetLineWidth(2); for (JCoordinate x=290; x<390; x+=2) { p.SetPenColor(colormap->GetGrayColor(x%4 ? 40 : 60)); p.Line(x,70, x,150); } p.SetLineWidth(1); */ p.String( 0.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String( 90.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String(180.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String(270.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String( 0.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String( 90.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String(180.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String(270.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.SetPenColor(colormap->GetBlueColor()); p.Rect(200, 10, 100, 50); p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft); p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter); p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight); p.SetPenColor(colormap->GetDarkGreenColor()); p.SetFilling(kJTrue); p.Rect(290, 160, 100, 80); p.SetFilling(kJFalse); /* for (JCoordinate y=160; y<240; y++) { p.SetPenColor(colormap->GetGrayColor(y-140)); p.Line(290,y, 390,y); } for (JCoordinate x=290; x<390; x++) { p.SetPenColor(colormap->GetGrayColor(x-290)); p.Line(x,160, x,240); } p.SetLineWidth(2); for (JCoordinate y=160; y<240; y+=2) { p.SetPenColor(colormap->GetGrayColor(y%4 ? 40 : 60)); p.Line(290,y, 390,y); } p.SetLineWidth(1); p.SetLineWidth(2); for (JCoordinate x=290; x<390; x+=2) { p.SetPenColor(colormap->GetGrayColor(x%4 ? 40 : 60)); p.Line(x,160, x,240); } p.SetLineWidth(1); */ textPt.Set(340, 200); p.SetFontName("Times"); p.SetFontStyle(colormap->GetBlueColor()); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.SetFontStyle(colormap->GetYellowColor()); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.SetPenColor(colormap->GetYellowColor()); r.Set(0,11,80,91); p.Rect(r); r.Shrink(1,1); p.SetPenColor(colormap->GetBlueColor()); p.Ellipse(r); r.Shrink(1,1); p.SetPenColor(colormap->GetRedColor()); p.Arc(r, 270.0-45.0, -270.0); JPolygon poly; poly.AppendElement(JPoint(0,85)); poly.AppendElement(JPoint(10,85)); poly.AppendElement(JPoint(5,95)); p.Polygon(poly); p.Line(0,100, 2,98); p.LineTo(4,100); p.LineTo(2,102); p.LineTo(0,100); poly.SetElement(1, JPoint(0,5)); poly.SetElement(2, JPoint(2,0)); poly.SetElement(3, JPoint(4,5)); p.Polygon(2,105, poly); // test filling rule p.SetPenColor(colormap->GetRedColor()); p.SetFilling(kJTrue); JPolygon fillRulePoly; fillRulePoly.AppendElement(JPoint(175,45)); fillRulePoly.AppendElement(JPoint(165,65)); fillRulePoly.AppendElement(JPoint(190,50)); fillRulePoly.AppendElement(JPoint(160,50)); fillRulePoly.AppendElement(JPoint(185,65)); p.Polygon(fillRulePoly); p.SetFilling(kJFalse); // dashed lines p.DrawDashedLines(kJTrue); p.SetPenColor(colormap->GetBlackColor()); JArray<JSize> dashList; // pixel rulers dashList.AppendElement(1); dashList.AppendElement(1); p.SetDashList(dashList); p.Line(100,110, 200,110); p.Line(100,114, 200,114); p.Line(100,118, 200,118); dashList.SetElement(1, 2); // simple pattern dashList.SetElement(2, 3); p.SetDashList(dashList); p.Line(100,112, 200,112); p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse)); p.String(130,155, "underline without dashes"); p.SetDashList(dashList, 3); // test offset p.Line(100,116, 200,116); dashList.SetElement(1, 1); // example with odd # of values from X manuals dashList.SetElement(2, 2); dashList.AppendElement(3); p.SetDashList(dashList); p.Line(100,120, 200,120); dashList.SetElement(1, 5); // dash-dot pattern dashList.SetElement(2, 2); dashList.SetElement(3, 1); dashList.AppendElement(2); p.SetDashList(dashList); p.Line(100,122, 200,122); p.Ellipse(210,110, 20,20); p.DrawDashedLines(kJFalse); p.Ellipse(213,113, 14,14); p.Rect(207,107, 26,26); p.SetPenColor(colormap->GetYellowColor()); p.DrawDashedLines(kJTrue); p.Ellipse(213,113, 14,14); // icons p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110); p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121); }
void TestWidget::DrawStuff ( JPainter& p ) { JIndex i; JXColormap* colormap = GetColormap(); p.SetPenColor(colormap->GetGreenColor()); JRect ellipseRect(100,50,150,300); p.Ellipse(ellipseRect); p.SetPenColor(colormap->GetBlackColor()); if (itsFillFlag) { p.SetFilling(kJTrue); } JRect ap = GetAperture(); p.Line(ap.topLeft(), ap.bottomRight()); p.Line(ap.topRight(), ap.bottomLeft()); p.SetLineWidth(2); p.SetFontName(JXGetTimesFontName()); p.SetFontSize(18); p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect); its2Rect = JRect(150, 5, 200, 30); p.SetPenColor(colormap->GetRedColor()); p.Rect(its2Rect); p.SetFontStyle(colormap->GetRedColor()); p.String(its2Rect.topLeft(), "2", its2Rect.width(), JPainter::kHAlignCenter, its2Rect.height(), JPainter::kVAlignCenter); its3Rect = JRect(10, 150, 40, 200); p.SetPenColor(colormap->GetBlueColor()); p.Rect(its3Rect); p.SetFontStyle(colormap->GetBlueColor()); p.String(its3Rect.topLeft(), "3", its3Rect.width(), JPainter::kHAlignCenter, its3Rect.height(), JPainter::kVAlignCenter); p.SetLineWidth(1); p.SetFont(JGetDefaultFontName(), kJXDefaultFontSize, colormap->GetBlackColor()); p.ShiftOrigin(10,10); p.Point(0,0); for (i=1; i<=itsRandPointCount; i++) { p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200)); } p.SetPenColor(colormap->GetRedColor()); p.Line(10,0, 0,10); p.SetPenColor(colormap->GetGreenColor()); p.LineTo(10,20); p.SetPenColor(colormap->GetBlueColor()); p.LineTo(0,30); p.ShiftOrigin(2,0); JPoint textPt(40,30); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.Rect(310, 70, 80, 80); p.String( 0.0, 310, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String( 90.0, 310,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(180.0, 390,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(270.0, 390, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.Rect(200, 10, 100, 50); p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft); p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter); p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight); p.SetPenColor(colormap->GetYellowColor()); JRect r(0,11,80,91); p.Rect(r); r.Shrink(1,1); p.SetPenColor(colormap->GetBlueColor()); p.Ellipse(r); r.Shrink(1,1); p.SetPenColor(colormap->GetRedColor()); p.Arc(r, 270.0-45.0, -270.0); JPolygon poly; poly.AppendElement(JPoint(0,85)); poly.AppendElement(JPoint(10,85)); poly.AppendElement(JPoint(5,95)); p.Polygon(poly); p.Line(0,100, 2,98); p.LineTo(4,100); p.LineTo(2,102); p.LineTo(0,100); poly.SetElement(1, JPoint(0,5)); poly.SetElement(2, JPoint(2,0)); poly.SetElement(3, JPoint(4,5)); p.Polygon(2,105, poly); // test filling rule p.SetPenColor(colormap->GetRedColor()); p.SetFilling(kJTrue); JPolygon fillRulePoly; fillRulePoly.AppendElement(JPoint(175,45)); fillRulePoly.AppendElement(JPoint(165,65)); fillRulePoly.AppendElement(JPoint(190,50)); fillRulePoly.AppendElement(JPoint(160,50)); fillRulePoly.AppendElement(JPoint(185,65)); p.Polygon(fillRulePoly); p.SetFilling(kJFalse); // dashed lines p.DrawDashedLines(kJTrue); p.SetPenColor(colormap->GetBlackColor()); JArray<JSize> dashList; // pixel rulers dashList.AppendElement(1); dashList.AppendElement(1); p.SetDashList(dashList); p.Line(100,110, 200,110); p.Line(100,114, 200,114); p.Line(100,118, 200,118); dashList.SetElement(1, 2); // simple pattern dashList.SetElement(2, 3); p.SetDashList(dashList); p.Line(100,112, 200,112); p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse)); p.String(130,155, "underline without dashes"); p.SetDashList(dashList, 3); // test offset p.Line(100,116, 200,116); dashList.SetElement(1, 1); // example with odd # of values from X manuals dashList.SetElement(2, 2); dashList.AppendElement(3); p.SetDashList(dashList); p.Line(100,120, 200,120); dashList.SetElement(1, 5); // dash-dot pattern dashList.SetElement(2, 2); dashList.SetElement(3, 1); dashList.AppendElement(2); p.SetDashList(dashList); p.Line(100,122, 200,122); p.Ellipse(210,110, 20,20); p.DrawDashedLines(kJFalse); p.Ellipse(213,113, 14,14); p.Rect(207,107, 26,26); p.SetPenColor(colormap->GetYellowColor()); p.DrawDashedLines(kJTrue); p.Ellipse(213,113, 14,14); // animated colors p.SetFilling(kJTrue); JCoordinate x = 25; const JSize animColorCount = itsAnimColorList->GetElementCount(); for (i=1; i<=animColorCount; i++) { p.SetPenColor(itsAnimColorList->GetElement(i)); p.Rect(x, 150, 10, 10); x += 10; } // icons p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110); p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121); // *NEVER* do this in your code! I do it here ONLY to test JXColormap. // (Besides, look at how messy it is!) unsigned long xPixel; if (colormap->CalcPreallocatedXPixel(62720, 56832, 45824, &xPixel)) { JXDisplay* display = GetDisplay(); Display* xdisplay = display->GetXDisplay(); GC gc = DefaultGC(xdisplay, display->GetScreen()); XSetForeground(xdisplay, gc, xPixel); XFillRectangle(xdisplay, (GetWindow())->GetXWindow(), gc, 110,40, 20,20); } }
void JPlotFitQuad2::CalculateFirstPass() { JFloat Y, X, X2, YX, X3, YX2, X4, Sig; JFloat tempa, tempb, tempc, det; JSize i,j, k; JArray<JFloat> yAdjError; const JPlotDataBase* data = GetData(); J2DDataPoint point; JSize rcount = GetRealElementCount(); for (i=1; i<= rcount; i++) { J2DDataPoint point = GetRealElement(i); JFloat newVal = 1; if (point.yerr != 0) { newVal = point.yerr; } yAdjError.AppendElement(newVal); } JMatrix odata(rcount, 3, 1.0); JVector yData(rcount); for (i=1; i<= rcount; i++) { point = GetRealElement(i); JFloat yerr = yAdjError.GetElement(i); odata.SetElement(i, 1, 1/(yerr*yerr)); odata.SetElement(i, 2, point.x/(yerr*yerr)); odata.SetElement(i, 3, point.x*point.x/(yerr*yerr)); yData.SetElement(i, point.y/(yerr*yerr)); } JMatrix tData = odata.Transpose(); JMatrix lData = tData * odata; JMatrix rData = tData * yData; JMatrix parms(3,1); JGaussianElimination(lData, rData, &parms); for (k=1; k<= 4; k++) { Y = 0; X = 0; X2 = 0; YX = 0; X3 = 0; YX2 = 0; X4 = 0; Sig = 0; for (i=1; i<= rcount; i++) { point = GetRealElement(i); JFloat yerr = yAdjError.GetElement(i); Y += point.y/(yerr*yerr); X += point.x/(yerr*yerr); X2 += point.x*point.x/(yerr*yerr); YX += point.y*point.x/(yerr*yerr); X3 += point.x*point.x*point.x/(yerr*yerr); YX2 += point.x*point.x*point.y/(yerr*yerr); X4 += point.x*point.x*point.x*point.x/(yerr*yerr); Sig += 1/(yerr*yerr); } JFloat cv1 = 0, cv2 = 0, cv3 = 0; for (i=1; i<= rcount; i++) { point = GetRealElement(i); JFloat syi = yAdjError.GetElement(i); JFloat yi = point.y; JFloat xi = point.x; for (j = 1; j <= rcount; j++) { point = GetRealElement(j); JFloat syj = yAdjError.GetElement(j); JFloat yj = point.y; JFloat xj = point.x; cv1 += xi*xj*xj*(xi*yj-yi*xj)/(syi*syi*syj*syj); cv2 += (xi*xj*xj*(yi - yj))/(syi*syi*syj*syj); cv3 += (xi*xj*xj*(xj - xi))/(syi*syi*syj*syj); } } det = Sig*(X2*X4-X3*X3) + X*(X3*X2-X*X4) + X2*(X*X3-X2*X2); tempa = (Y*(X2*X4-X3*X3) + X*(X3*YX2-YX*X4) + X2*(YX*X3-X2*YX2))/det; tempb = (Sig*(YX*X4-YX2*X3) + Y*(X3*X2-X*X4) + X2*(X*YX2-YX*X2))/det; tempc = (Sig*cv1 + X*cv2 + Y*cv3)/det; for (i=1; i<=rcount; i++) { J2DDataPoint point = GetRealElement(i); JFloat newVal = sqrt(point.yerr*point.yerr + (tempb+2*tempc*point.x)*(tempb+2*tempc*point.x)*point.xerr*point.xerr); if (newVal == 0) { newVal = 1; } yAdjError.SetElement(i, newVal); } } // itsAParameter = tempa; // itsBParameter = tempb; // itsCParameter = tempc; itsAParameter = parms.GetElement(1, 1); itsBParameter = parms.GetElement(2, 1); itsCParameter = parms.GetElement(3, 1); itsChi2Start = 0; for (i=1; i<= rcount; i++) { point = GetRealElement(i); JFloat yerr = yAdjError.GetElement(i); itsChi2Start += pow(point.y - tempa - tempb*point.x - tempc*point.x*point.x,2)/(yerr*yerr); } itsAErrParameter = 0; itsBErrParameter = 0; itsCErrParameter = 0; }
int main() { long i; JSubset s1(10); // constructor cout << "subset s1 created" << endl << endl; cout << "s1 itemCount should be 0" << endl; cout << "s1 itemCount = " << s1.GetElementCount() << endl << endl; s1.AddRange(3,4); s1.Add(9); cout << "s1 itemCount should be 3" << endl; cout << "s1 itemCount = " << s1.GetElementCount() << endl << endl; cout << "s1 should contain: 10FFTTFFFFTF" << endl; cout << "s1 contains : " << s1 << endl; cout << "using Contains() : "; for (i=1; i<=10; i++) { cout << s1.Contains(i); } cout << endl; JSubset s2 = s1; cout << endl; cout << "subset s2 created" << endl << endl; s2.Remove(1); cout << "s1 should equal s2" << endl; cout << "s1 equals s2? " << (s1 == s2) << endl; s2.Remove(4); s2.Add(2); cout << "s2 should contain: 10FTTFFFFFTF" << endl; cout << "s2 contains : " << s2 << endl; cout << "s1 should not equal s2" << endl; cout << "s1 equals s2? " << (s1 == s2) << endl; JWaitForReturn(); JSubset s3 = s1 + s2; JSubset s4 = s1 - s2; JSubset s5 = s2 - s1; JSubset s7 = JIntersection(s4, s5); cout << "s3 should contain: 10FTTTFFFFTF" << endl; cout << "s3 contains : " << s3 << endl << endl; cout << "s4 should contain: 10FFFTFFFFFF" << endl; cout << "s4 contains : " << s4 << endl << endl; cout << "s5 should contain: 10FTFFFFFFFF" << endl; cout << "s5 contains : " << s5 << endl << endl; cout << "s7 should contain: 10FFFTFFFFFF" << endl; cout << "s7 contains : " << s4 << endl << endl; JWaitForReturn(); s3.RemoveAll(); s3.AddRange(3,8); s3.RemoveRange(4,6); cout << "s3 should contain: 10FFTFFFTTFF" << endl; cout << "s3 contains : " << s3 << endl << endl; JSubsetIterator iter = s3.NewIterator(); JIndex index; cout << "s3 contains: "; while (iter.Next(&index)) { cout << ' ' << index; } cout << endl << endl; JSubset s6 = s3.Complement(); cout << "s6 should contain: 10TTFTTTFFTT" << endl; cout << "s6 contains : " << s6 << endl << endl; s6 = s3; // assignment operator cout << "s6 assigned from s3" << endl << endl; cout << "s6 itemCount should be 3" << endl; cout << "s6 itemCount=" << s6.GetElementCount() << endl << endl; cout << "s6 should contain: 10FFTFFFTTFF" << endl; cout << "s6 contains : " << s6 << endl << endl; JWaitForReturn(); cout << "Twenty random samples of size 3:" << endl << endl; for (i=1; i<=20; i++) { if (JGetRandomSample(&s1, 3)) { assert( s1.GetElementCount() == 3 ); cout << s1 << endl; } else { cerr << "Unable to generate random subset of that size." << endl; } } // JGetRandomSample() JHistogram<JSize> h(10); for (i=1; i<=5000; i++) { JGetRandomSample(&s3, 3, 2,8); iter.MoveTo(kJIteratorStartAtBeginning, 0); while (iter.Next(&index)) { h.IncrementCount(index, 1); } } JProbDistr p = h.ConvertToProbabilities(); cout << endl; cout << "Probability of each element (2-8) being in the subset:" << endl; cout << "(averaged over ensemble of 5000 subsets)" << endl << endl; cout << p << endl; // JSubset::GetRandomSample() JBoolean ok = JGetRandomSample(&s1, 7); assert( ok ); h.Clear(); for (i=1; i<=5000; i++) { s1.GetRandomSample(&s3, 3); iter.MoveTo(kJIteratorStartAtBeginning, 0); while (iter.Next(&index)) { h.IncrementCount(index, 1); } } p = h.ConvertToProbabilities(); cout << endl; cout << "Probability of each element (sample of 7) being in the subset:" << endl; cout << "(averaged over ensemble of 5000 subsets)" << endl << endl; cout << p << endl; // JSubset::GetRandomDisjointSamples() JPtrArray<JSubset> sampleList(JPtrArrayT::kDeleteAll); JArray<JSize> sampleSizeList; sampleSizeList.AppendElement(2); sampleSizeList.AppendElement(2); JHistogram<JSize> h1(10), h2(10); JHistogram<JSize>* hist[] = { &h1, &h2 }; for (i=1; i<=5000; i++) { s1.GetRandomDisjointSamples(&sampleList, sampleSizeList); for (JIndex j=1; j<=2; j++) { JSubsetIterator iter = (sampleList.NthElement(j))->NewIterator(); while (iter.Next(&index)) { hist[j-1]->IncrementCount(index, 1); assert( !(sampleList.NthElement(3-j))->Contains(index) ); } } } cout << endl; cout << "Probability of each element (2 from sample of 7) being in the subset:" << endl; cout << "(averaged over ensemble of 5000 subsets)" << endl << endl; cout << "1) " << h1.ConvertToProbabilities() << endl; cout << "2) " << h2.ConvertToProbabilities() << endl; // JSubset::GetRandomDisjointSamples() -- partitioning sampleSizeList.SetElement(1, 3); sampleSizeList.SetElement(2, 4); h1.Clear(); h2.Clear(); for (i=1; i<=5000; i++) { s1.GetRandomDisjointSamples(&sampleList, sampleSizeList); for (JIndex j=1; j<=2; j++) { JSubsetIterator iter = (sampleList.NthElement(j))->NewIterator(); while (iter.Next(&index)) { hist[j-1]->IncrementCount(index, 1); assert( !(sampleList.NthElement(3-j))->Contains(index) ); } } } sampleList.DeleteAll(); cout << endl; cout << "Probability of each element (3,4 from sample of 7) being in the subset:" << endl; cout << "(averaged over ensemble of 5000 subsets)" << endl << endl; cout << "1) " << h1.ConvertToProbabilities() << endl; cout << "2) " << h2.ConvertToProbabilities() << endl; return 0; }