package ole.raeumlicheStatistik; import java.util.Arrays; import java.util.Random; import java.util.Vector; public class RSBlatt6 { static final Geometry2D.Point zero = new Geometry2D.Point(0,0); static final Random r = new Random(); // Fuer die radiale Simulation des Poisson- // Prozesses in Aufgabe 1 double radial_distance=0; double intensity=-1; // Fuer die simulation der typischen // Zelle in Aufgabe 1 Vector points = new Vector(3,1); Geometry2D.ConvexPolygon initialCell; Geometry2D.ConvexPolygon typicalCell; public RSBlatt6(double lambda) { radial_distance=0; intensity = lambda; } /* * * Aufgabe 1 * ***/ // Bestimme die Polar-Koordinaten des naechsten Punktes // in der radialen Simulation eines Poisson-Prozesses // mit der im Konstruktor festgelegten Intensitaet // (Algorithmus siehe Skript) public double[] nextRadialPoissonPoint() { double e = -1.0 * Math.log(r.nextDouble()) / intensity; double theta = 2 * Math.PI * r.nextDouble(); radial_distance += e ; return new double[] {Math.sqrt(radial_distance/Math.PI), theta}; } // Bestimme die Punkte eines Poisson-Prozesses, die noetig sind // um die initiale Zelle zu bestimmen, die bei der Simulation der // typischen Zelle noetig sind. public Geometry2D.Point[] simulateInitialCellPoints() throws Exception { try{ double[] angles = new double[2]; // Bestimme zunaechst die 3 Punkte, die // mindestens noetig sind. double[] point = nextRadialPoissonPoint(); points.add(point); angles[0] = point[1]; point = nextRadialPoissonPoint(); points.add(point); angles[1] = point[1]; point = nextRadialPoissonPoint(); points.add(point); while(true) { /* So geht's auf jeden Fall: boolean[] quads = {false, false, false, false}; for(int i=0; i0) && (point[1]<=Math.PI / 2.0)) { quads[0]=true; continue;} if((point[1]>Math.PI / 2.0) && (point[1]<=Math.PI)) { quads[1]=true; continue;} if((point[1]>Math.PI) && (point[1]<=1.5 * Math.PI )) { quads[2]=true; continue;} if((point[1]>1.5 * Math.PI) && (point[1]<=2 * Math.PI)) { quads[3]=true; continue;} } if(quads[0] && quads[1] && quads[2] && quads[3]) { return PolarToG2D(points); } else { double[] point = nextRadialPoissonPoint(); points.add(points.size(),point); } */ Arrays.sort(angles); // Ob ein weiterer Punkt benoetigt wird, haengt davon ab, wo // der letzte Punkt liegt, d.h. insbesondere davon, wie sein // Winkel zur x-Achse ist. double[] last_added = (double[]) points.lastElement(); double angle = last_added[1]; // Dafuer gibt es 3 Moeglichkeiten: // a) Der Punkt liegt zwischen den bisherigen Punkten. Damit liegt er // nicht im fraglichen Sektor, veraendert den fraglichen Sektor aber // auch nicht. Es muss also ein weiterer Punkt simuliert werden. if ( ((angles[1]-angles[0]>Math.PI) && ((angle>angles[1]) || (angleangles[0])))) { points.add(nextRadialPoissonPoint()); continue; } // b) Der Punkt liegt im fraglichen Sektor. Damit ist das Abbruchkriterium // erfuellt und es sind genug Punkte zur Bestimmung der initialen Zelle // simuliert. double[] anti_angles = {angles[0], angles[1]}; anti_angles[0] += (angles[0]>Math.PI)?(-Math.PI):(Math.PI); anti_angles[1] += (angles[1]>Math.PI)?(-Math.PI):(Math.PI); Arrays.sort(anti_angles); if ( ((anti_angles[1]-anti_angles[0]>Math.PI) && ((angle>anti_angles[1]) || (angleanti_angles[0])))) { return PolarToG2D(points); } // c) Ansonsten liegt der Punkt nicht im fraglichen Sektor, aber auch nicht // zwischen den bisherigen Punkten. Also muss der fragliche Sektor durch // die zugehoerige Gerade erweitert werden und dann ein weiterer Punkt // simuliert werden. double[] diff_angles = {Math.abs(angle-angles[0]), Math.abs(angle-angles[1])}; diff_angles[0] += (diff_angles[0]>Math.PI)?(-Math.PI):(Math.PI); diff_angles[1] += (diff_angles[1]>Math.PI)?(-Math.PI):(Math.PI); if(diff_angles[0]x_max) x_max = intersect.x; if(intersect.xy_max) y_max = intersect.y; if(intersect.ymax) max = d; } return max; } // Fuehre einen asymptotischen Test der Hypothese durch, dass eine i.i.d. Zufallsstichprobe // vom Umfang n mit Stichprobenmittel mean und Standardabweichung sd als Realisierungen // einer Zufallsgroesse mit Erwartungswert theoretical_parameter aufgefasst werden kann public static void AsymptoticTestForExpectation(double theoretical_parameter, double mean, double sd, int n) { double T = Math.abs(Math.sqrt(n) * (mean - theoretical_parameter) / sd ); System.out.println("Test-Statistic T="+T); if(T > 1.65) // 0.95 - Quantil von N(0.1) { System.out.println("Hypothesis rejected at the 10%-Level."); if(T > 1.96) // 0.975 - Quantil von N(0.1) { System.out.println("Hypothesis rejected at the 5%-Level."); if(T > 2.58) // 0.995 - Quantil von N(0,1) { System.out.println("Hypothesis rejected at the 1%-Level."); } else { System.out.println("Hypothesis not rejected at the 1%-Level."); } } else { System.out.println("Hypothesis not rejected at the 5%-Level."); System.out.println("Hypothesis not rejected at the 1%-Level."); } } else { System.out.println("Hypothesis not rejected at the 10%-Level."); System.out.println("Hypothesis not rejected at the 5%-Level."); System.out.println("Hypothesis not rejected at the 1%-Level."); } } public static double[] Aufgabe1cUnd1d() { double[] mean_values = {0,0,0}; double[] sum_of_squares = {0,0,0}; double[] sd = {0,0,0}; try{ // Fuehre die vorgegebene Anzahl von Durchlaeufen // mit der vorgegebenen Intensitaet durch. final int number_of_runs = 10000; final double intensity = 0.0005; for(int i=0; i