本文整理汇总了Java中mulan.data.MultiLabelInstances.getNumInstances方法的典型用法代码示例。如果您正苦于以下问题:Java MultiLabelInstances.getNumInstances方法的具体用法?Java MultiLabelInstances.getNumInstances怎么用?Java MultiLabelInstances.getNumInstances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mulan.data.MultiLabelInstances
的用法示例。
在下文中一共展示了MultiLabelInstances.getNumInstances方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLabelFrequency
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Get label frequency given the index
*
* @param dataset Dataset
* @param labelIndex Label index
* @return Frequency of label
*/
public static double getLabelFrequency(MultiLabelInstances dataset,
int labelIndex)
{
double value = 0.0;
Instances instances = dataset.getDataSet();
double isLabel;
for(int i=0; i<instances.size();i++)
{
isLabel=instances.instance(i).value(labelIndex);
if(isLabel==1.0) {
value++;
}
}
return value/dataset.getNumInstances();
}
示例2: 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){
super.calculate(mlData);
Statistics stat = new Statistics();
stat.calculateStats(mlData);
HashMap<LabelSet, Integer> combCount = stat.labelCombCount();
int max = 0;
for(LabelSet key : combCount.keySet()){
if(combCount.get(key) > max){
max = combCount.get(key);
}
}
this.value = ((double) max)/mlData.getNumInstances();
return value;
}
示例3: saveDataset
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Save dataset
*
* @param wr PrintWriter
* @param dataset Dataset
* @param relationName Name of the relation
*/
public static void saveDataset(PrintWriter wr, MultiLabelInstances dataset,
String relationName)
{
//relationName = relationName.replaceAll(" ", "_");
if(relationName.contains("-")){
wr.write("@relation " + "\'" + relationName + "\'");
}
else if(relationName.contains(":")){
wr.write("@relation " + "\'" + relationName + "\'");
}
else{
wr.write("@relation " + relationName);
}
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"));
}
}
示例4: saveDatasetMV
import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
* Save multi-label multi-view dataset
*
* @param wr PrintWriter
* @param dataset Dataset
* @param relationName Name of the relation
* @param views String with views intervals
*/
public static void saveDatasetMV(PrintWriter wr, MultiLabelInstances
dataset, String relationName, String views)
{
//relationName = relationName.replaceAll(" ", "_");
wr.write("@relation " + "\'" + relationName + " " + views + "\'");
wr.write(System.getProperty("line.separator"));
Instances instancias = dataset.getDataSet();
Attribute att;
for (int i=0; i< instancias.numAttributes();i++)
{
att = instancias.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"));
}
}
示例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 nInstances = mlData.getNumInstances();
Set<Attribute> attributesSet = mlData.getFeatureAttributes();
int nNumeric = 0;
double mean = 0;
double avg;
double var;
double stdev;
for(Attribute att : attributesSet){
if(att.isNumeric()){
nNumeric++;
avg = instances.meanOrMode(att);
var = 0;
for(Instance inst : instances){
var += Math.pow(inst.value(att) - avg, 3);
}
stdev = Math.sqrt(instances.variance(att));
mean += nInstances*var / ((nInstances-1)*(nInstances-2)*Math.pow(stdev, 3));
}
}
if(nNumeric > 0){
this.value = mean / nNumeric;
}
else{
this.value = Double.NaN;
}
//this.value = mean;
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){
Statistics stat = new Statistics();
stat.calculateStats(mlData);
this.value = ((double)stat.labelCombCount().size()) / mlData.getNumInstances();
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){
Statistics stat = new Statistics();
stat.calculateStats(mlData);
this.value = ((double)mlData.getNumInstances()) / stat.labelSets().size();
return value;
}
示例8: 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){
super.calculate(mlData);
Statistics stat = new Statistics();
stat.calculateStats(mlData);
Cardinality card = new Cardinality();
double cardinality = card.calculate(mlData);
int [] labelsForInstance = Utils.labelsForInstance(mlData);
int nInstances = mlData.getNumInstances();
double v;
double sum2 = 0;
double sum4 = 0;
for(int i=0; i<nInstances; i++){
v = labelsForInstance[i] - cardinality;
sum2 += Math.pow(v, 2);
sum4 += Math.pow(v, 4);
}
double kurtosis = (nInstances*sum4/Math.pow(sum2,2))-3;
double sampleKurtosis = (kurtosis*(nInstances+1) + 6) * (nInstances-1)/((nInstances-2)*(nInstances-3));
this.value = sampleKurtosis;
return value;
}
示例9: 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){
super.calculate(mlData);
Statistics stat = new Statistics();
stat.calculateStats(mlData);
UniqueLabelsets uniqueLabelsets = new UniqueLabelsets();
double uniq = uniqueLabelsets.calculate(mlData);
this.value = uniq / mlData.getNumInstances();
return value;
}
示例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){
Instances instances = mlData.getDataSet();
int nInstances = mlData.getNumInstances();
double avg;
double var2;
double var4;
double val;
int nNumeric = 0;
double mean = 0;
Set<Attribute> attributesSet = mlData.getFeatureAttributes();
for(Attribute att : attributesSet){
if(att.isNumeric()){
nNumeric++;
avg = instances.meanOrMode(att);
var2 = 0;
var4 = 0;
for(Instance inst : instances){
val = inst.value(att);
var2 += Math.pow(val-avg, 2);
var4 += Math.pow(val-avg, 4);
}
double kurtosis = (nInstances*var4/Math.pow(var2,2))-3;
double sampleKurtosis = (kurtosis*(nInstances+1) + 6) * (nInstances-1)/((nInstances-2)*(nInstances-3));
mean += sampleKurtosis;
}
}
if(nNumeric > 0){
mean = mean/nNumeric;
}
else{
mean = Double.NaN;
}
this.value = mean;
return value;
}
示例14: 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 nInstances = mlData.getNumInstances();
double alpha = 0.05;
int numToTrimAtSide = (int)(nInstances*alpha / 2);
int nNumeric = 0;
int nOutliers = 0;
Set<Attribute> attributeSet = mlData.getFeatureAttributes();
double variance, varianceTrimmed;
double [] values;
double [] trimmed = new double[nInstances - (numToTrimAtSide * 2)];
double ratio;
for(Attribute att : attributeSet){
if(att.isNumeric()){
nNumeric++;
variance = instances.variance(att);
values = instances.attributeToDoubleArray(att.index());
Arrays.sort(values);
for(int i=0; i<trimmed.length; i++){
trimmed[i] = values[i + numToTrimAtSide];
}
varianceTrimmed = Utils.variance(trimmed);
ratio = varianceTrimmed / variance;
if(ratio < 0.7){
nOutliers++;
}
}
}
if(nNumeric > 0){
this.value = ((double) nOutliers) / nNumeric;
}
else{
this.value = Double.NaN;
}
return value;
}
示例15: 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;
}