當前位置: 首頁>>代碼示例>>Java>>正文


Java Instance.classIndex方法代碼示例

本文整理匯總了Java中weka.core.Instance.classIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java Instance.classIndex方法的具體用法?Java Instance.classIndex怎麽用?Java Instance.classIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weka.core.Instance的用法示例。


在下文中一共展示了Instance.classIndex方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: classifyInstance

import weka.core.Instance; //導入方法依賴的package包/類
@Override
public double classifyInstance(Instance sample) throws Exception {
	// transform instance to sequence
	MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
	int shift = (sample.classIndex() == 0) ? 1 : 0;
	for (int t = 0; t < sequence.length; t++) {
		sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
	}
	SymbolicSequence seq = new SymbolicSequence(sequence);

	double minD = Double.MAX_VALUE;
	String classValue = null;
	seq.LB_KeoghFillUL(bestWarpingWindow, U, L);
	
	for (int i = 0; i < train.length; i++) {
		SymbolicSequence s = train[i];
		if (SymbolicSequence.LB_KeoghPreFilled(s, U, L) < minD) {
			double tmpD = seq.DTW(s,bestWarpingWindow, warpingMatrix);
			if (tmpD < minD) {
				minD = tmpD;
				classValue = classMap[i];
			}
		}
	}
	// System.out.println(prototypes.size());
	return sample.classAttribute().indexOfValue(classValue);
}
 
開發者ID:ChangWeiTan,項目名稱:FastWWSearch,代碼行數:28,代碼來源:LbKeoghPrunedDTW.java

示例2: classifyInstance

import weka.core.Instance; //導入方法依賴的package包/類
@Override
public double classifyInstance(Instance sample) throws Exception {
	// transform instance to sequence
	MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
	int shift = (sample.classIndex() == 0) ? 1 : 0;
	for (int t = 0; t < sequence.length; t++) {
		sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
	}
	SymbolicSequence seq = new SymbolicSequence(sequence);

	double minD = Double.MAX_VALUE;
	String classValue = null;
	seq.LB_KeoghFillUL(bestWarpingWindow, U, L);
	
	for (int i = 0; i < train.length; i++) {
		SymbolicSequence s = train[i];
		if (SymbolicSequence.LB_KeoghPreFilled(s, U, L) < minD) {
			double tmpD = seq.DTW(s,bestWarpingWindow);
			if (tmpD < minD) {
				minD = tmpD;
				classValue = classMap[i];
			}
		}
	}
	// System.out.println(prototypes.size());
	return sample.classAttribute().indexOfValue(classValue);
}
 
開發者ID:ChangWeiTan,項目名稱:FastWWSearch,代碼行數:28,代碼來源:Trillion.java

示例3: buildClassifier

import weka.core.Instance; //導入方法依賴的package包/類
@Override
public void buildClassifier(Instances data) throws Exception {
   	// Initialise training dataset
	Attribute classAttribute = data.classAttribute();
	
	classedData = new HashMap<>();
	classedDataIndices = new HashMap<>();
	for (int c = 0; c < data.numClasses(); c++) {
		classedData.put(data.classAttribute().value(c), new ArrayList<SymbolicSequence>());
		classedDataIndices.put(data.classAttribute().value(c), new ArrayList<Integer>());
	}

	train = new SymbolicSequence[data.numInstances()];
	classMap = new String[train.length];
	maxLength = 0;
	for (int i = 0; i < train.length; i++) {
		Instance sample = data.instance(i);
		MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
		maxLength = Math.max(maxLength, sequence.length);
		int shift = (sample.classIndex() == 0) ? 1 : 0;
		for (int t = 0; t < sequence.length; t++) {
			sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
		}
		train[i] = new SymbolicSequence(sequence);
		String clas = sample.stringValue(classAttribute);
		classMap[i] = clas;
		classedData.get(clas).add(train[i]);
		classedDataIndices.get(clas).add(i);
	}
	warpingMatrix = new double[maxLength][maxLength];	
	U = new double[maxLength];
	L = new double[maxLength];
	
	maxWindow = Math.round(1 * maxLength);
	searchResults = new String[maxWindow+1];
	nns = new int[maxWindow+1][train.length];
	dist = new double[train.length][train.length];
	
	// Start searching for the best window
	searchBestWarpingWindow();
	
	// Saving best windows found
	System.out.println("Windows found=" + bestWarpingWindow + " Best Acc=" + (1-bestScore));
}
 
開發者ID:ChangWeiTan,項目名稱:FastWWSearch,代碼行數:45,代碼來源:LbKeoghPrunedDTW.java

示例4: buildClassifier

import weka.core.Instance; //導入方法依賴的package包/類
@Override
public void buildClassifier(Instances data) throws Exception {
   	// Initialise training dataset
   	Attribute classAttribute = data.classAttribute();
	
	classedData = new HashMap<>();
	classedDataIndices = new HashMap<>();
	for (int c = 0; c < data.numClasses(); c++) {
		classedData.put(data.classAttribute().value(c), new ArrayList<SymbolicSequence>());
		classedDataIndices.put(data.classAttribute().value(c), new ArrayList<Integer>());
	}

	train = new SymbolicSequence[data.numInstances()];
	classMap = new String[train.length];
	maxLength = 0;
	for (int i = 0; i < train.length; i++) {
		Instance sample = data.instance(i);
		MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
		maxLength = Math.max(maxLength, sequence.length);
		int shift = (sample.classIndex() == 0) ? 1 : 0;
		for (int t = 0; t < sequence.length; t++) {
			sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
		}
		train[i] = new SymbolicSequence(sequence);
		String clas = sample.stringValue(classAttribute);
		classMap[i] = clas;
		classedData.get(clas).add(train[i]);
		classedDataIndices.get(clas).add(i);
	}
			
	warpingMatrix = new double[maxLength][maxLength];
	U = new double[maxLength];
	L = new double[maxLength];
	U1 = new double[maxLength];
	L1 = new double[maxLength];
	
	maxWindow = Math.round(1 * maxLength);
	searchResults = new String[maxWindow+1];
	nns = new int[maxWindow+1][train.length];
	dist = new double[maxWindow+1][train.length];

	cache = new SequenceStatsCache(train, maxWindow);
	
	lazyUCR = new LazyAssessNNEarlyAbandon[train.length][train.length];
	
	for (int i = 0; i < train.length; i++) {
		for (int j  = 0; j < train.length; j++) {
			lazyUCR[i][j] = new LazyAssessNNEarlyAbandon(cache);
		}
	}
	
	// Start searching for the best window
	searchBestWarpingWindow();
	
	// Saving best windows found
	System.out.println("Windows found=" + bestWarpingWindow + " Best Acc=" + (1-bestScore));
}
 
開發者ID:ChangWeiTan,項目名稱:FastWWSearch,代碼行數:58,代碼來源:UCRSuite.java

示例5: buildClassifier

import weka.core.Instance; //導入方法依賴的package包/類
@Override
public void buildClassifier(Instances data) throws Exception {
   	// Initialise training dataset
	Attribute classAttribute = data.classAttribute();
	
	classedData = new HashMap<>();
	classedDataIndices = new HashMap<>();
	for (int c = 0; c < data.numClasses(); c++) {
		classedData.put(data.classAttribute().value(c), new ArrayList<SymbolicSequence>());
		classedDataIndices.put(data.classAttribute().value(c), new ArrayList<Integer>());
	}

	train = new SymbolicSequence[data.numInstances()];
	classMap = new String[train.length];
	maxLength = 0;
	for (int i = 0; i < train.length; i++) {
		Instance sample = data.instance(i);
		MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
		maxLength = Math.max(maxLength, sequence.length);
		int shift = (sample.classIndex() == 0) ? 1 : 0;
		for (int t = 0; t < sequence.length; t++) {
			sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
		}
		train[i] = new SymbolicSequence(sequence);
		String clas = sample.stringValue(classAttribute);
		classMap[i] = clas;
		classedData.get(clas).add(train[i]);
		classedDataIndices.get(clas).add(i);
	}
			
	warpingMatrix = new double[maxLength][maxLength];
	U = new double[maxLength];
	L = new double[maxLength];
	U1 = new double[maxLength];
	L1 = new double[maxLength];
	
	maxWindow = Math.round(1 * maxLength);
	searchResults = new String[maxWindow+1];
	nns = new int[maxWindow+1][train.length];
	dist = new double[train.length][train.length];

	cache = new SequenceStatsCache(train, maxWindow);
	
	lazyUCR = new LazyAssessNNEarlyAbandon[train.length][train.length];
	
	for (int i = 0; i < train.length; i++) {
		for (int j  = 0; j < train.length; j++) {
			lazyUCR[i][j] = new LazyAssessNNEarlyAbandon(cache);
		}
	}
	
	// Start searching for the best window
	searchBestWarpingWindow();

	// Saving best windows found
	System.out.println("Windows found=" + bestWarpingWindow + " Best Acc=" + (1-bestScore));
}
 
開發者ID:ChangWeiTan,項目名稱:FastWWSearch,代碼行數:58,代碼來源:UCRSuitePrunedDTW.java

示例6: buildClassifier

import weka.core.Instance; //導入方法依賴的package包/類
@Override
public void buildClassifier(Instances data) throws Exception {
   	// Initialise training dataset
	Attribute classAttribute = data.classAttribute();
	
	classedData = new HashMap<>();
	classedDataIndices = new HashMap<>();
	for (int c = 0; c < data.numClasses(); c++) {
		classedData.put(data.classAttribute().value(c), new ArrayList<SymbolicSequence>());
		classedDataIndices.put(data.classAttribute().value(c), new ArrayList<Integer>());
	}

	train = new SymbolicSequence[data.numInstances()];
	classMap = new String[train.length];
	maxLength = 0;
	for (int i = 0; i < train.length; i++) {
		Instance sample = data.instance(i);
		MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
		maxLength = Math.max(maxLength, sequence.length);
		int shift = (sample.classIndex() == 0) ? 1 : 0;
		for (int t = 0; t < sequence.length; t++) {
			sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
		}
		train[i] = new SymbolicSequence(sequence);
		String clas = sample.stringValue(classAttribute);
		classMap[i] = clas;
		classedData.get(clas).add(train[i]);
		classedDataIndices.get(clas).add(i);
	}
	
	warpingMatrix = new double[maxLength][maxLength];
	U = new double[maxLength];
	L = new double[maxLength];
	
	maxWindow = Math.round(1 * maxLength);
	searchResults = new String[maxWindow+1];
	nns = new int[maxWindow+1][train.length];
	dist = new double[maxWindow+1][train.length];
	
	// Start searching for the best window
	searchBestWarpingWindow();
	
	// Saving best windows found
	System.out.println("Windows found=" + bestWarpingWindow + " Best Acc=" + (1-bestScore));
}
 
開發者ID:ChangWeiTan,項目名稱:FastWWSearch,代碼行數:46,代碼來源:WindowSearcher.java


注:本文中的weka.core.Instance.classIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。