当前位置: 首页>>代码示例>>Java>>正文


Java DenseInstance类代码示例

本文整理汇总了Java中net.sf.javaml.core.DenseInstance的典型用法代码示例。如果您正苦于以下问题:Java DenseInstance类的具体用法?Java DenseInstance怎么用?Java DenseInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DenseInstance类属于net.sf.javaml.core包,在下文中一共展示了DenseInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDTWScore

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
private double getDTWScore(double[] array1, double[] array2) {
    double[] constantArray1 = new double[array1.length];
    Arrays.fill(constantArray1, 0);
    double[] constantArray2 = new double[array2.length];
    Arrays.fill(constantArray2, 0);
    
    double dtwAB = DTW.getWarpDistBetween(
            new TimeSeries(new DenseInstance(array1)),
            new TimeSeries(new DenseInstance(array2)));
    double dtwA0 = DTW.getWarpDistBetween(
            new TimeSeries(new DenseInstance(array1)),
            new TimeSeries(new DenseInstance(constantArray2)));
    double dtwB0 = DTW.getWarpDistBetween(
            new TimeSeries(new DenseInstance(array2)),
            new TimeSeries(new DenseInstance(constantArray1)));
    
    if ((dtwA0 + dtwB0) == 0)
        return 0;
    
    return (1 - (dtwAB/(dtwA0 + dtwB0)));
}
 
开发者ID:ViDA-NYU,项目名称:data-polygamy,代码行数:22,代码来源:CorrelationTechniquesReducer.java

示例2: clustering

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public List[] clustering(List<Objective> objectives) {
	Dataset ds = new DefaultDataset();
	for (Objective obj : objectives) {
		ds.add(new DenseInstance(obj.getArray(),obj));
	}
	long time = System.currentTimeMillis();
	//SpearmanRankCorrelation sc = new SpearmanRankCorrelation();
	//System.out.print("Correlation " + sc.measure(ds.get(1), ds.get(2)) + "\n");
	//SpearmanRankCorrelation
	CustomKMean ckm = new CustomKMean(2, 1000, new SpearmanDistance());
	Dataset[] clusters = ckm.cluster(ds);
	System.out.print("Time taken on clustering: " + ( System.currentTimeMillis() - time) + "\n");
	
	return clusters;
}
 
开发者ID:taochen,项目名称:ssascaling,代码行数:18,代码来源:JavaMLNeighborhood.java

示例3: filter

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
@Override
public void filter(Instance instance) {
    if (currentRange == null || currentMiddle == null)
        throw new TrainingRequiredException();

    if (instance instanceof DenseInstance) {
        Instance tmp = instance.minus(currentMiddle).divide(currentRange).multiply(normalRange).add(normalMiddle);
        instance.clear();
        instance.putAll(tmp);

    }
    if (instance instanceof SparseInstance) {
        for (int index : instance.keySet()) {
            instance.put(index, ((instance.value(index) - currentMiddle.value(index)) / currentRange.value(index))
                    * normalRange + normalMiddle);
        }
    }
    new ReplaceValueFilter(Double.NEGATIVE_INFINITY, normalMiddle).filter(instance);
    new ReplaceValueFilter(Double.POSITIVE_INFINITY, normalMiddle).filter(instance);
    new ReplaceValueFilter(Double.NaN, normalMiddle).filter(instance);
}
 
开发者ID:eracle,项目名称:gap,代码行数:22,代码来源:NormalizeMidrange.java

示例4: normalize

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
/**
 * Normalizes the data to mean 0 and standard deviation 1. This method
 * discards all instances that cannot be normalized, i.e. they have the same
 * value for all attributes.
 * 
 * @param data
 * @return
 */
private Vector<TaggedInstance> normalize(Dataset data) {
	Vector<TaggedInstance> out = new Vector<TaggedInstance>();

	for (int i = 0; i < data.size(); i++) {
		Double[] old = data.instance(i).values().toArray(new Double[0]);
		double[] conv = new double[old.length];
		for (int j = 0; j < old.length; j++) {
			conv[j] = old[j];
		}

		Mean m = new Mean();

		double MU = m.evaluate(conv);
		// System.out.println("MU = "+MU);
		StandardDeviation std = new StandardDeviation();
		double SIGM = std.evaluate(conv, MU);
		// System.out.println("SIGM = "+SIGM);
		if (!MathUtils.eq(SIGM, 0)) {
			double[] val = new double[old.length];
			for (int j = 0; j < old.length; j++) {
				val[j] = (float) ((old[j] - MU) / SIGM);

			}
			// System.out.println("VAL "+i+" = "+Arrays.toString(val));
			out.add(new TaggedInstance(new DenseInstance(val, data.instance(i).classValue()), i));
		}
	}
	// System.out.println("FIRST = "+out.get(0));

	return out;
}
 
开发者ID:eracle,项目名称:gap,代码行数:40,代码来源:AQBC.java

示例5: retrieveInstances

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
private Vector<TaggedInstance> retrieveInstances(Vector<TaggedInstance> sp, double[] me2, double radnw2) {
	Instance tmp = new DenseInstance(me2);
	Vector<TaggedInstance> out = new Vector<TaggedInstance>();
	for (TaggedInstance inst : sp) {
		if (dm.measure(inst.inst, tmp) < radnw2)
			out.add(inst);
	}
	return out;
}
 
开发者ID:eracle,项目名称:gap,代码行数:10,代码来源:AQBC.java

示例6: average

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
/**
 * Creates an instance that contains the average values for the attributes.
 * 
 * @param data
 *            data set to calculate average attribute values for
 * @return Instance representing the average attribute values
 */
public static Instance average(Dataset data) {
	double[] tmpOut = new double[data.noAttributes()];
	
	for (int i = 0; i < data.noAttributes(); i++) {
		double sum=0;
		for (int j = 0; j < data.size(); j++) {
			sum+= data.get(j).value(i);
		}
		tmpOut[i] = sum/data.size();

	}
	return new DenseInstance(tmpOut);
}
 
开发者ID:eracle,项目名称:gap,代码行数:21,代码来源:DatasetTools.java

示例7: percentile

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
/**
 * Calculates the percentile hinge for a given percentile.
 * 
 * @param data
 *            data set to calculate percentile for
 * @param perc
 *            percentile to calculate, Q1=25, Q2=median=50,Q3=75
 * @return
 */
public static Instance percentile(Dataset data, double perc) {
	double[] tmpOut = new double[data.noAttributes()];
	for (int i = 0; i < data.noAttributes(); i++) {
		double[] vals = new double[data.size()];
		for (int j = 0; j < data.size(); j++) {
			vals[j] = data.get(j).value(i);
		}
		tmpOut[i] = StatUtils.percentile(vals, perc);

	}
	return new DenseInstance(tmpOut);
}
 
开发者ID:eracle,项目名称:gap,代码行数:22,代码来源:DatasetTools.java

示例8: load

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
public static Dataset load(Reader in, int classIndex, String separator) {

	        LineIterator it = new LineIterator(in);
	        it.setSkipBlanks(true);
	        it.setSkipComments(true);
	        Dataset out = new DefaultDataset();
	        for (String line : it) {
	            String[] arr = line.split(separator);
	            double[] values;
	            if (classIndex == -1)
	                values = new double[arr.length];
	            else
	                values = new double[arr.length - 1];
	            String classValue = null;
	            for (int i = 0; i < arr.length; i++) {
	                if (i == classIndex) {
	                    classValue = arr[i];
	                } else {
	                    double val;
	                    try {
	                        val = Double.parseDouble(arr[i]);
	                    } catch (NumberFormatException e) {
	                        val = Double.NaN;
	                    }
	                    if (classIndex != -1 && i > classIndex)
	                        values[i - 1] = val;
	                    else
	                        values[i] = val;
	                }
	            }
	            out.add(new DenseInstance(values, classValue));

	        }
	        return out;
	    }
 
开发者ID:eracle,项目名称:gap,代码行数:36,代码来源:StreamHandler.java

示例9: normalizeMidrange

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
private Instance normalizeMidrange(double normalMiddle, double normalRange, Instance min, Instance max,
        Instance instance) {
    double[] out = new double[instance.noAttributes()];
    for (int i = 0; i < out.length; i++) {
        double range = Math.abs(max.value(i) - min.value(i));
        double middle = Math.abs(max.value(i) + min.value(i)) / 2;
        out[i] = ((instance.value(i) - middle) / range) * normalRange + normalMiddle;
    }
    return new DenseInstance(out, instance);
}
 
开发者ID:eracle,项目名称:gap,代码行数:11,代码来源:NormalizedEuclideanDistance.java

示例10: predictFalsePositive

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
public int predictFalsePositive(Boolean IsSQLI) throws IOException{
        int fp;       
        int sum_att = this.getSumOfAttributes();
        
        if (IsSQLI == true){
            if (sum_att == 0)
                return 0; // is a real vv           
        }
        else{
            if (sum_att == 8)
                return 0; // is a real vv
        }
/*
for (int i = 0; i<this.getAttributes().length; i++){
    System.out.print(this.getValueOfAttribute(i) + " ");
}
System.out.println();
*/        
        /* predict fp with machine learning
         * 1. Logistic Regression (LR)
         * 2. If LR returns FP, then aplly Random Tree (RT)
         * 3. If RT returns FP, then apply Support Vector Machine (SVM)
         * 4. If SVM returns FP, then we have an FP
         */
        
        /* Create the instance to classify */
        Instance instance = new DenseInstance(this.attributes);
               
        int result_fp = 0;
        fp = this.applyClassifier("lr", instance);

        if (fp == 1){
            result_fp++;
            //GlobalDataApp.cf = GlobalDataApp.loadClassifier("rt");
            fp = this.applyClassifier("rt", instance);
            if (fp == 1){
                result_fp++;
                //GlobalDataApp.cf = GlobalDataApp.loadClassifier("svm");
                fp = this.applyClassifier("svm", instance);
                if (fp == 1){
                    result_fp++;
                }
            }
        }
       
        // volta a colocar cf em LR para a classificaçao da proxima vv
        //GlobalDataApp.cf = GlobalDataApp.loadClassifier("lr");
     
        
        if (result_fp == 3){
            //GlobalDataApp.cf = GlobalDataApp.loadClassifier("jrip");
            fp = this.applyClassifier("jrip", instance);
            //FastVector fv = GlobalDataApp.jrip.getRuleset();
            //System.out.println("Rules: " + fv.size());
            //double[] distributionForInstance = GlobalDataApp.jrip.distributionForInstance((weka.core.Instance) instance);
            return 1;
        }
        else
            return 0;
        
    }
 
开发者ID:asrulhadi,项目名称:wap,代码行数:62,代码来源:FP_Attributes.java

示例11: loadARFF

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
/**
 * Load a data set from an ARFF formatted file. Due to limitations in the
 * Java-ML design only numeric attributes can be read.
 * 
 * @param file
 *            the file to read the data from
 * @param classIndex
 *            the index of the class label
 * @return the data set represented in the provided file
 * @throws FileNotFoundException
 *             if the file can not be found.
 */
public static Dataset loadARFF(File file, int classIndex) throws FileNotFoundException {
    LineIterator it = new LineIterator(file);
    it.setSkipBlanks(true);
    it.setCommentIdentifier("%");
    it.setSkipComments(true);

    Dataset out = new DefaultDataset();

    /* Indicates whether we are reading data */
    boolean dataMode = false;
    for (String line : it) {
        /* When we passed the @data tag, we are reading data */
        if (dataMode) {
            String[] arr = line.split(",");
            double[] values;
            if (classIndex == -1)
                values = new double[arr.length];
            else
                values = new double[arr.length - 1];
            String classValue = null;
            for (int i = 0; i < arr.length; i++) {
                if (i == classIndex) {
                    classValue = arr[i];
                } else {
                    double val;
                    try {
                        val = Double.parseDouble(arr[i]);
                    } catch (NumberFormatException e) {
                        val = Double.NaN;
                    }
                    if (classIndex!=-1 && i > classIndex)
                        values[i - 1] = val;
                    else
                        values[i] = val;
                }
            }
            out.add(new DenseInstance(values, classValue));
        }
        /* Ignore everything in the header, i.e. everything up to @data */
        if (line.equalsIgnoreCase("@data"))
            dataMode = true;
    }
    return out;
}
 
开发者ID:eracle,项目名称:gap,代码行数:57,代码来源:ARFFHandler.java

示例12: standardDeviation

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
/**
 * Creates an instance that contains the standard deviation of the values
 * for each attribute.
 * 
 * @param data
 *            data set to calculate attribute value standard deviations for
 * @param avg
 *            the average instance for the data set
 * @return Instance representing the standard deviation of the values for
 *         each attribute
 */
public static Instance standardDeviation(Dataset data, Instance avg) {
	Instance sum = new DenseInstance(new double[avg.noAttributes()]);
	for (Instance i : data) {
		Instance diff = i.minus(avg);
		sum = sum.add(diff.multiply(diff));
	}
	sum = sum.divide(data.size());
	return sum.sqrt();

}
 
开发者ID:eracle,项目名称:gap,代码行数:22,代码来源:DatasetTools.java

示例13: createInstanceFromClass

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
/**
 * Creates an Instance from the class labels over all Instances in a data
 * set.
 * 
 * The indices of the class labels are used because the class labels can be
 * any Object.
 * 
 * @param data
 *            data set to create class label instance for
 * @return instance with class label indices as values.
 */
public static Instance createInstanceFromClass(Dataset data) {
	Instance out = new DenseInstance(data.size());
	int index = 0;
	for (Instance inst : data)
		out.put(index++, (double) data.classIndex(inst.classValue()));
	return out;
}
 
开发者ID:eracle,项目名称:gap,代码行数:19,代码来源:DatasetTools.java

示例14: createInstanceFromAttribute

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
/**
 * Creates an Instance from the values of one particular attribute over all
 * Instances in a data set.
 * 
 * @param data
 * @param i
 * @return
 */
public static Instance createInstanceFromAttribute(Dataset data, int i) {
	Instance out = new DenseInstance(data.size());
	int index = 0;
	for (Instance inst : data)
		out.put(index++, inst.value(i));
	return out;
}
 
开发者ID:eracle,项目名称:gap,代码行数:16,代码来源:DatasetTools.java

示例15: randomInstance

import net.sf.javaml.core.DenseInstance; //导入依赖的package包/类
/**
 * Creates a random instance with the given number of attributes. The values
 * of all attributes are between 0 and 1.
 * 
 * @param length
 *            the number of attributes in the instance.
 * @return a random instance
 */
public static Instance randomInstance(int length) {
    double[] values = new double[length];
    for (int i = 0; i < values.length; i++) {
        values[i] = rg.nextDouble();
    }
    return new DenseInstance(values);
}
 
开发者ID:eracle,项目名称:gap,代码行数:16,代码来源:InstanceTools.java


注:本文中的net.sf.javaml.core.DenseInstance类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。