/** * Code for exercise 3 * Lecture Series Informatik II D-BAUG ETH Zürich * Felix Friedrich, Georg Ofenbeck, Lars Widmer */ class LCG { //this is the random number generator from last exercise static final long m = 2147483647; static final long b = 12345; static final long a = 1103515245; static long u = 0; //to use within the judge we fix the "seed", such that we always get the same random numbers public static double Uniform(){ u = (u * a + b) % m; return(double)u/m; } } // provide your modifications in this class only class RandomSurfer{ // pre: non-empty matrix m // post: matrix printout on System.out public static void printMatrix(double[][] m) { // implement this } // pre: matrix data provided via scanner // post: returns matrix data public static double[][] readMatrix(java.util.Scanner scanner){ // implement this return null; } // pre: non-empty input vector of length N, matrix of size N times M // post: return vector-matrix product v * m. Vector of size M public static double[] multiplyVectorMatrix(double[] v, double[][] m) { // implement this return null; } // non-empty vector v and probability matrix m, precision > 0 // returns if v * m is close at v public static boolean checkConvergence(double[] v, double[][] P, double precision){ // implement this return true; } // single step simulation from the lecture public static int simulateLine(double[] prob) { int res=0; double r = LCG.Uniform(); double sum = 0.0; for (int j = 0; j < prob.length; j++) { sum += prob[j]; if (r < sum) {res = j; break;} } return res; } // pre: non-empty probability matrix P // post: return relative frequencies of visits in each point // after MCMC simulation until convergence reached public static double[] simulate(double[][] P, double precision) { // implement this return null; } // pre: non-empty vector v and n times n probability matrix // post: vector v close at stationary distribution of m // returns number of vector-matrix multiplications required public static int calculateDirect(double[] v, double[][] m, double precision){ // implement this return 0; } // pre: non-null vector // post: vector output to standard out public static void show(double[] v) { for (int i=0; i