Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.sql.*;
- public class PF {
- private static boolean neato = false;
- private static boolean showTransitionCount = true;
- public static void main(String[] Args){
- System.out.println("I am here");
- (new PF()).go();
- }
- private void goX() {
- String students[] = { "class", "studentA", "studentB", "studentC" };
- int n = students.length;
- Pathfinder pf[] = new Pathfinder[n];
- pf[0] = new Pathfinder();
- System.out.println("reading log file");
- pf[0].readLogfile("example/log.txt");
- for (int i = 1; i < n; i++) pf[i] = new Pathfinder(pf[0]);
- for (int i = 1; i < n; i++) pf[i].restrictTo(students[i]);
- for (int i = 0; i < n; i++) pf[i].setFrequencies();
- for (int i = 0; i < n; i++) pf[i].MCN();
- for (int i = 0; i < n; i++) pf[i].outputGraph("example\\" + students[i]);
- }
- private void go1() {
- Pathfinder pf = new Pathfinder();
- System.out.println("starting...");
- pf.readLogfile("iisdata/visit.txt");
- System.out.println("data read");
- pf.setFrequencies();
- System.out.println("frequencies set");
- pf.MCN();
- System.out.println("MCN computed");
- pf.outputGraph("iisdata/visit");
- System.out.println("XML written");
- }
- private void go() {
- int[] classNumber = { 4 };
- String[] date = {"2001-10-19"};
- for (int i = 0; i < classNumber.length; i++) {
- doClass(classNumber[i],date[i]);
- }
- }
- private void doClass(int classNumber, String dateRestriction) {
- RawData rd = new RawData();
- String[] nodeNames = rd.getNodeNames("%",classNumber, dateRestriction);
- String[] studentNames = rd.getStudentNames("%", classNumber, dateRestriction);
- int n = studentNames.length;
- System.out.print("Class " + classNumber + ", " + dateRestriction + " has " + n + " students");
- System.out.println(" and " + nodeNames.length + " nodes.");
- Pathfinder[] pf = new Pathfinder[n + 1]; // for all students and the class
- Hashtable invNodeNames = new Hashtable();
- for (int i = 0; i < nodeNames.length; i++) {
- invNodeNames.put(nodeNames[i].toLowerCase(),new Integer(i));
- }
- for (int i = 0; i < n+1; i++) {
- double[][] s;
- if (i < n) {
- System.out.print(studentNames[i] + " ");
- s = rd.getTransitionMatrix(classNumber, dateRestriction, studentNames[i], invNodeNames);
- } else {
- System.out.println("all students");
- s = rd.getTransitionMatrix(classNumber, dateRestriction, "%", invNodeNames);
- }
- pf[i] = new Pathfinder();
- pf[i].setFrequencies(s);
- pf[i].setNames(nodeNames);
- pf[i].MCN();
- if (i < n) {
- pf[i].outputGraph("data/" + "/" + classNumber + "_" + studentNames[i] + "_" + dateRestriction,showTransitionCount,neato);
- } else {
- pf[i].outputGraph("data/" + "/" + classNumber + "_" + "CLASS_" + dateRestriction,showTransitionCount,neato);
- }
- }
- System.out.println();
- try {
- //finally generating the comaprison output into a tab delimited file
- System.out.println("Writing comparison file");
- String filename = "data/" + "/" + classNumber + "_" + "CLASS_" + dateRestriction + ".txt";
- PrintWriter outFile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
- outFile.write("Comparing each student to the whole class\n\n");
- for (int i = 0; i < n; i++) {
- double sim = pf[i].sim(pf[n]);
- outFile.write(studentNames[i] + "\t" + sim + "\n");
- }
- outFile.write("\nComparing all student to each other\n\n");
- outFile.write("\t");
- for (int i = 0; i < n; i++) {
- outFile.write(studentNames[i] + "\t");
- }
- outFile.write("\n");
- double[][] matrix = new double[n][n];
- for (int i = 0; i < n; i++) {
- outFile.write(studentNames[i] + "\t");
- for (int j = 0; j < n; j++) {
- double sim = pf[i].sim(pf[j]);
- outFile.write(sim + "\t");
- matrix[i][j] = sim;
- if (sim <= 0) matrix[i][j] = -1;
- }
- outFile.write("\n");
- }
- outFile.close();
- //now we treat similarities as frequencies and use pathfinder again
- //that's probably silly, but...
- /* ling uncomments */
- System.out.println("doing the pathfinder for the big thing");
- Pathfinder p = new Pathfinder();
- System.out.println("setting frequencies");
- p.setFrequencies(matrix);
- System.out.println("setting names");
- p.setNames(studentNames);
- System.out.println("MCN...");
- p.MCN();
- System.out.println("MCN done!");
- p.outputGraph("data/" + "/" + classNumber + "_allstudents_" + dateRestriction,showTransitionCount, neato, 10);
- //now we do the real clustering
- //ling for (int k = 1; k <= 3; k++) {
- int k=3;
- System.out.println("clustering with k = " + k);
- ClusterAlg clusterAlg = new ClusterAlg(k,studentNames);
- for(int i = 0; i < n; i++) {
- clusterAlg.addPNF(pf[i]);
- }
- float v = 0, worstV = 0;
- v = clusterAlg.cluster();
- worstV += clusterAlg.worstClusterValue();
- Pathfinder centroid[] = clusterAlg.getCentroids();
- for (int i = 0; i < k; i++) {
- centroid[i].outputGraph("data/" + "/" + classNumber +"_C_"+k+"_"+(i+1)+"_"+ dateRestriction,showTransitionCount, neato, 10);
- }
- System.out.println("k = " + k + " -> " + v + " -- " + worstV);
- System.out.println(clusterAlg);
- // }
- /*ling end */
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement