本文整理汇总了Java中mulan.data.MultiLabelInstances.getLabelIndices方法的典型用法代码示例。如果您正苦于以下问题:Java MultiLabelInstances.getLabelIndices方法的具体用法?Java MultiLabelInstances.getLabelIndices怎么用?Java MultiLabelInstances.getLabelIndices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mulan.data.MultiLabelInstances
的用法示例。
在下文中一共展示了MultiLabelInstances.getLabelIndices方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttributePairs
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Get pairs of attributes
*
* @param dataset Dataset
* @return List of pairs
*/
public static ArrayList<AttributesPair> getAttributePairs(
MultiLabelInstances dataset)
{
Instances instances = dataset.getDataSet();
//Return possible combinations among labels
int possibleCombinations = getPossibleCombinations(dataset.getNumLabels());
int [] labelPairAppearances = new int[possibleCombinations];
int [] currentLabelValues;
int[] labelIndices = dataset.getLabelIndices();
for(int i=0; i<instances.size(); i++)
{
currentLabelValues = DataInfoUtils.getCurrentValueLabels(instances, i, labelIndices);
labelPairAppearances = updateAttributePairs(labelPairAppearances, currentLabelValues);
}
return makeAttributePairs(labelPairAppearances, labelIndices, dataset);
}
示例2: calculateCoocurrences
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Calculate co-ocurrences of labels
*
* @param mldata Multi-label dataset
* @return Matrix of double with co-ocurrence values
*/
public static double[][] calculateCoocurrences(MultiLabelInstances mldata)
{
int nLabels = mldata.getNumLabels();
Instances data = mldata.getDataSet();
double [][] coocurrenceMatrix = new double[nLabels][nLabels];
int [] labelIndices = mldata.getLabelIndices();
Instance temp = null;
for(int k=0; k<data.numInstances(); k++){
temp = data.instance(k);
for(int i=0; i<nLabels; i++){
for(int j=i+1; j<nLabels; j++){
if((temp.value(labelIndices[i]) == 1.0) && (temp.value(labelIndices[j]) == 1.0)){
coocurrenceMatrix[i][j]++;
}
}
}
}
return coocurrenceMatrix;
}
示例3: getImbalancedDataByAppearances
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Obtain labels ordered by number of appearances
*
* @param dataset Dataset
* @return Labels as ImbalanceFeature objects
*/
public static ImbalancedFeature[] getImbalancedDataByAppearances(
MultiLabelInstances dataset)
{
int[] labelIndices = dataset.getLabelIndices();
ImbalancedFeature[] imbalancedData = new ImbalancedFeature[labelIndices.length];
Instances instances = dataset.getDataSet();
int appearances = 0;
double is;
Attribute current;
for(int i=0; i<labelIndices.length;i++)
{
current = instances.attribute(labelIndices[i]);
for(int j=0; j<instances.size();j++)
{
is = instances.instance(j).value(current);
if(is ==1.0) {
appearances++;
}
}
imbalancedData[i] = new ImbalancedFeature(current.name(), appearances);
appearances = 0;
}
return imbalancedData;
}
示例4: getLabelByIndex
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Obtain label by index
*
* @param dataset Dataset
* @param id Label id
* @return Label
*/
public static Attribute getLabelByIndex(MultiLabelInstances dataset, int id)
{
int[] labelIndices = dataset.getLabelIndices();
Attribute result = dataset.getDataSet().instance(1).attribute(labelIndices[id]);
return result;
}
示例5: calculate
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Calculate metric value
*
* @param mlData Multi-label dataset to which calculate the metric
* @return Value of the metric
*/
public double calculate(MultiLabelInstances mlData){
Instances instances = mlData.getDataSet();
int nLabels = mlData.getNumLabels();
int [] labels = mlData.getLabelIndices();
double [] entropies = new double[nLabels];
for(int i=0; i<nLabels; i++){
AttributeStats attStats = instances.attributeStats(labels[i]);
if(attStats.nominalCounts != null){
entropies[i] = Utils.entropy(attStats.nominalCounts);
}
}
double minEntropy = Double.MAX_VALUE;
for(double e : entropies){
if(e < minEntropy){
minEntropy = e;
}
}
this.value = minEntropy;
return value;
}
示例6: calculate
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Calculate metric value
*
* @param mlData Multi-label dataset to which calculate the metric
* @return Value of the metric
*/
public double calculate(MultiLabelInstances mlData){
Instances instances = mlData.getDataSet();
int nLabels = mlData.getNumLabels();
int [] labels = mlData.getLabelIndices();
double [] entropies = new double[nLabels];
for(int i=0; i<nLabels; i++){
AttributeStats attStats = instances.attributeStats(labels[i]);
if(attStats.nominalCounts != null){
entropies[i] = Utils.entropy(attStats.nominalCounts);
}
}
double maxEntropy = Double.MIN_VALUE;
for(double e : entropies){
if(e > maxEntropy){
maxEntropy = e;
}
}
this.value = maxEntropy;
return value;
}
示例7: calculate
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Calculate metric value
*
* @param mlData Multi-label dataset to which calculate the metric
* @return Value of the metric
*/
public double calculate(MultiLabelInstances mlData){
Instances instances = mlData.getDataSet();
int nLabels = mlData.getNumLabels();
int [] labels = mlData.getLabelIndices();
double [] entropies = new double[nLabels];
for(int i=0; i<nLabels; i++){
AttributeStats attStats = instances.attributeStats(labels[i]);
if(attStats.nominalCounts != null){
entropies[i] = Utils.entropy(attStats.nominalCounts);
}
}
double meanEntropy = 0;
for(double e : entropies){
meanEntropy += e;
}
meanEntropy /= entropies.length;
this.value = meanEntropy;
return value;
}
示例8: getAppearances
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
public int [] getAppearances(MultiLabelInstances mlData){
int [] appearances = new int[mlData.getNumLabels()];
int [] labelIndices = mlData.getLabelIndices();
for(Instance instance : mlData.getDataSet()){
for(int label=0; label<mlData.getNumLabels(); label++){
if(instance.value(labelIndices[label]) == 1){
appearances[label]++;
}
}
}
return appearances;
}
示例9: getAppearancesPerLabel
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Get array of ImbalancedFeature with labels frequency
*
* @param dataset Multi-label dataset
* @return Array of ImbalancedFeature with the labels frequency
*/
public static ImbalancedFeature[] getAppearancesPerLabel( MultiLabelInstances dataset)
{
int[] labelIndices = dataset.getLabelIndices();
ImbalancedFeature[] labels = new ImbalancedFeature[labelIndices.length];
Instances instances = dataset.getDataSet();
int appearances = 0;
Attribute currentAtt;
for(int i=0; i<labelIndices.length;i++)
{
currentAtt = instances.attribute(labelIndices[i]);
appearances=0;
for(int j=0; j<instances.size();j++)
{
if(instances.instance(j).value(currentAtt) == 1.0){
appearances++;
}
}
labels[i] = new ImbalancedFeature(currentAtt.name(), appearances);
}
return labels;
}
示例10: saveMVMekaDataset
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Save multi-view multi-label meka dataset
*
* @param wr PrintWriter
* @param dataset Dataset
* @param relationName Name of the relation
* @param views String with views intervals
*/
public static void saveMVMekaDataset(PrintWriter wr, MultiLabelInstances dataset,
String relationName, String views)
{
int maxAttIndex;
int minAttIndex;
String c;
c = "-C ";
int [] attIndex = dataset.getFeatureIndices();
maxAttIndex = getMax(attIndex);
minAttIndex = getMin(attIndex);
int [] labelIndices = dataset.getLabelIndices();
boolean areLabelMaxIndices = true;
boolean areLabelMinIndices = false;
for(int i=0; i<labelIndices.length && areLabelMaxIndices; i++){
if(labelIndices[i] < maxAttIndex){
areLabelMaxIndices = false;
}
}
if(!areLabelMaxIndices){
areLabelMinIndices = true;
for(int i=0; i<labelIndices.length && areLabelMinIndices; i++){
if(labelIndices[i] > minAttIndex){
areLabelMinIndices = false;
}
}
}
if((!areLabelMaxIndices) && (!areLabelMinIndices)){
JOptionPane.showMessageDialog(null, "Cannot save as meka.", "alert", JOptionPane.ERROR_MESSAGE);
return;
}
else if(areLabelMaxIndices){
c = c + "-" + labelIndices.length;
}
else{
c = c + labelIndices.length;
}
wr.write("@relation " + "\'" + relationName + ": " + c + " " + views + "\'");
wr.write(System.getProperty("line.separator"));
Instances instances = dataset.getDataSet();
Attribute att;
for (int i=0; i< instances.numAttributes();i++)
{
att = instances.attribute(i);
wr.write(att.toString());
wr.write(System.getProperty("line.separator"));
}
String current;
wr.write("@data");
wr.write(System.getProperty("line.separator"));
for(int i=0; i<dataset.getNumInstances();i++)
{
current = dataset.getDataSet().get(i).toString();
wr.write(current);
wr.write(System.getProperty("line.separator"));
}
}
示例11: getImbalancedDataByIRInterClass
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Obtain labels ordered by IR inter class
*
* @param dataset Dataset
* @param labelsByFrequency Labels
* @return Labels sorted by IR inter class
*/
public static ImbalancedFeature[] getImbalancedDataByIRInterClass(
MultiLabelInstances dataset, ImbalancedFeature[] labelsByFrequency)
{
int[] labelIndices = dataset.getLabelIndices();
ImbalancedFeature[] imbalancedData = new ImbalancedFeature[labelIndices.length];
Instances instances = dataset.getDataSet();
int n1=0, n0=0, maxAppearance;
double is, IRIntraClass, variance, IRInterClass;
double mean = dataset.getNumInstances()/2;
Attribute currentAttribute;
ImbalancedFeature currentLabel;
for(int i=0; i<labelIndices.length;i++)
{
currentAttribute = instances.attribute(labelIndices[i]);
for(int j=0; j<instances.size();j++)
{
is = instances.instance(j).value(currentAttribute);
if(is == 1.0) {
n1++;
}
else {
n0++;
}
}
try {
if(n0 ==0 || n1 ==0) {
IRIntraClass = 0;
}
else if(n0>n1) {
IRIntraClass = n0/(n1*1.0);
}
else {
IRIntraClass = n1/(n0*1.0);
}
} catch(Exception e1)
{
e1.printStackTrace();
IRIntraClass = 0;
}
variance = (Math.pow((n0-mean), 2) + Math.pow((n1-mean), 2))/2;
currentLabel = getLabelByLabelname(currentAttribute.name(), labelsByFrequency);
maxAppearance = labelsByFrequency[0].getAppearances();
if(currentLabel.getAppearances() <= 0){
IRInterClass = Double.NaN;
}
else{
IRInterClass = maxAppearance/(currentLabel.getAppearances()*1.0);
}
imbalancedData[i] = new ImbalancedFeature(currentAttribute.name(),currentLabel.getAppearances(),IRIntraClass, variance, IRInterClass);
n0 = 0;
n1 = 0;
}
return imbalancedData;
}
示例12: getImbalancedData
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Obtain labels as ImbalancedFeature objects
*
* @param dataset Datasets
* @return Labels as ImbalanceFeature array
*/
public static ImbalancedFeature[] getImbalancedData(
MultiLabelInstances dataset)
{
int[] labelIndices = dataset.getLabelIndices();
ImbalancedFeature[] imbalancedData = new ImbalancedFeature[labelIndices.length];
Instances instances = dataset.getDataSet();
int n1=0, n0=0;
double is, IR, variance;
double mean = dataset.getNumInstances()/2;
Attribute current;
for(int i=0; i<labelIndices.length;i++)
{
current= instances.attribute(labelIndices[i]);
for(int j=0; j<instances.size();j++)
{
is = instances.instance(j).value(current);
if(is == 1.0) {
n1++;
}
else {
n0++;
}
} try {
if(n0 ==0 || n1 ==0) {
IR=0;
}
else if(n0>n1) {
IR= n0/(n1*1.0);
}
else {
IR=n1/(n0*1.0);
}
} catch(Exception e1)
{
e1.printStackTrace();
IR=0;
}
variance = (Math.pow((n0-mean), 2) + Math.pow((n1-mean), 2))/2;
imbalancedData[i] = new ImbalancedFeature(current.name(), IR, variance);
n0 = 0;
n1 = 0;
}
return imbalancedData;
}
示例13: calculate
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Calculate metric value
*
* @param mlData Multi-label dataset to which calculate the metric
* @return Value of the metric
*/
public double calculate(MultiLabelInstances mlData){
double SCUMBLE = 0.0;
// ImbalancedFeature [] imbalanced_data = Utils.getImbalancedWithIR(mlData, Utils.getSortedByFrequency(Utils.getAppearancesPerLabel(mlData)));
//
// ImbalancedFeature[] new_imbalanced_data = new ImbalancedFeature[imbalanced_data.length];
//
// for(int i=0; i<imbalanced_data.length; i++){
// for(int j=0; j<imbalanced_data.length; j++){
// if(mlData.getLabelNames()[i].equals(imbalanced_data[j].getName())){
// new_imbalanced_data[i] = imbalanced_data[j];
// }
// }
// }
double [] ir = getIRperLabel(mlData);
int nLabels = mlData.getNumLabels();
Instances instances = mlData.getDataSet();
double IRLmean = 0;
int nActive = 0;
double prod = 1;
double sum = 0;
int [] labelIndices = mlData.getLabelIndices();
for(Instance inst : instances){
IRLmean = 0;
prod = 1;
nActive = 0;
for(int l=0; l<nLabels; l++){
if(inst.value(labelIndices[l]) == 1){
prod *= ir[l];
IRLmean += ir[l];
nActive++;
}
// else{
// prod *= 0;
// }
}
if(nActive == 0){
sum += 0;
}
else{
IRLmean /= nActive;
// System.out.println(IRLmean);
sum += 1 - (Math.pow(prod, 1.0/nActive) / IRLmean);
}
}
SCUMBLE = sum / mlData.getNumInstances();
this.value = SCUMBLE;
return value;
}
示例14: getImbalancedWithIR
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Calculate IRs of the ImbalancedFeatures
*
* @param dataset Multi-label dataset
* @param labels Labels of the dataset as ImbalancedFeature objects
* @return Array of ImbalancedFeature objects with calculated IR
*/
public static ImbalancedFeature[] getImbalancedWithIR (MultiLabelInstances dataset, ImbalancedFeature[] labels)
{
int[] labelIndices = dataset.getLabelIndices();
ImbalancedFeature[] labels_imbalanced = new ImbalancedFeature[labelIndices.length];
Instances instances = dataset.getDataSet();
int nOnes=0, nZeros=0, maxAppearance=0;
double IRIntraClass;
double variance;
double IRInterClass;
double mean = dataset.getNumInstances()/2;
Attribute current;
ImbalancedFeature currentLabel;
for(int i=0; i<labelIndices.length;i++) //for each label
{
nZeros=0;
nOnes=0;
current = instances.attribute(labelIndices[i]); //current label
for(int j=0; j<instances.size();j++) //for each instance
{
if(instances.instance(j).value(current) == 1.0){
nOnes++;
}
else{
nZeros++;
}
}
try {
if(nZeros ==0 || nOnes ==0){
IRIntraClass = 0;
}
else if(nZeros > nOnes){
IRIntraClass = (double)nZeros/nOnes;
}
else{
IRIntraClass = (double)nOnes/nZeros;
}
}
catch(Exception e1)
{
IRIntraClass = 0;
}
variance = (Math.pow((nZeros-mean), 2) + Math.pow((nOnes-mean), 2)) / 2;
currentLabel = getLabelByName(current.name(), labels);
maxAppearance = labels[0].getAppearances();
if(currentLabel.getAppearances() <= 0){
IRInterClass = Double.NaN;
}
else{
IRInterClass = (double)maxAppearance/currentLabel.getAppearances();
}
labels_imbalanced[i] = new ImbalancedFeature(current.name(), currentLabel.getAppearances(), IRInterClass, IRIntraClass, variance);
}
return labels_imbalanced;
}