⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rankreordering.java

📁 rank reording example for classification
💻 JAVA
字号:

import mslab.kddcup2008.roc.*;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
import java.io.PrintWriter;

import java.util.*;


public class RankReordering {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		
		double[] score = ROC.loadDataFromFile("score.txt");
		double[] patientId = ROC.loadDataFromFile("pid.txt");

		PrintWriter pw_reordered = new PrintWriter(new FileOutputStream ("score.txt"));
		PrintWriter pw_backup = new PrintWriter(new FileOutputStream ("score_bak.txt"));

		int patientNumber = 1712;	// Should be 1602 when testing data
		int patientIdDifference = 0;	// Should be 10000 when testing data
		int imageNumber = score.length;
		int currentPatientId = 0;
		int[] highestScoreIndex = new int[patientNumber];
		double maxScore = Double.NEGATIVE_INFINITY;
		double[] highestScore = new double[patientNumber];

		// Initialize
		for (int j=patientIdDifference; j<patientNumber+patientIdDifference; j++) {
			highestScore[j] = Double.NEGATIVE_INFINITY;
		}

		// Compute highest score images for each patient and the max score of all images
		for (int i=0; i<imageNumber; i++) {
			currentPatientId = (int)patientId[i];
			if(score[i] > highestScore[currentPatientId]) {
				highestScore[currentPatientId] = score[i];
				highestScoreIndex[currentPatientId] = i;
				if(score[i] > maxScore) {
					maxScore = score[i];
				}
			}
			pw_backup.println(score[i]);
		}
		
		// Every highest scores add "max score + 1" to become highest than all other scores
		for (int j=patientIdDifference; j<patientNumber+patientIdDifference; j++) {
			score[highestScoreIndex[j]] += (maxScore + 1);
		}

		// Write data back to original and backup files
		for (int i=0; i<imageNumber; i++) {
			pw_reordered.println(score[i]);
		}
		
		pw_reordered.close();
		pw_backup.close();
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -