net.sf.javaml.core.DenseInstance Java Examples

The following examples show how to use net.sf.javaml.core.DenseInstance. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CorrelationTechniquesReducer.java    From data-polygamy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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)));
}
 
Example #2
Source File: JMLNeurophSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Test JMLNeurophClassifier
 *
 * @param jmlDataset Dataset Java-ML data set
 */
private static void testJMLNeurophClassifier(Dataset jmlDataset) {
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(4, 16, 3);
    
    // set labels for output neurons
    neuralNet.getOutputNeurons().get(0).setLabel("Setosa");
    neuralNet.getOutputNeurons().get(1).setLabel("Versicolor");
    neuralNet.getOutputNeurons().get(2).setLabel("Virginica");

    // initialize NeurophJMLClassifier
    JMLNeurophClassifier jmlnClassifier = new JMLNeurophClassifier(neuralNet);

    // Process Java-ML data set
    jmlnClassifier.buildClassifier(jmlDataset);

    // test item
    //double[] item = {5.1, 3.5, 1.4, 0.2}; // normalized item is below
    double[] item = {-0.27777777777777773, 0.1249999999999999, -0.4322033898305085, -0.45833333333333337};

    // Java-ML instance out of test item
    Instance instance = new DenseInstance(item);

    // why are these not normalised?
    System.out.println("NeurophJMLClassifier - classify of {0.22222222222222213, 0.6249999999999999, 0.06779661016949151, 0.04166666666666667}");
    System.out.println(jmlnClassifier.classify(instance));
    System.out.println("NeurophJMLClassifier - classDistribution of {0.22222222222222213, 0.6249999999999999, 0.06779661016949151, 0.04166666666666667}");
    System.out.println(jmlnClassifier.classDistribution(instance));
}
 
Example #3
Source File: TrackHolder.java    From HMMRATAC with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Access the data as a Dataset, for kmeans
 * @return a Dataset representing the data for kmeans and javaml applications
 */
public Dataset getDataSet(){
	Dataset data = new DefaultDataset();
	for (int i = 0;i < tracks.size();i++){
		DenseInstance ins = new DenseInstance(tracks.get(i));
		//for (int a = 0;a < tracks.get(i).length;a++){
			//System.out.println(tracks.get(i)[a]);
		//}
		data.add(ins);
	}
	
	return data;
}
 
Example #4
Source File: DomDistance.java    From apogen with Apache License 2.0 4 votes vote down vote up
public Dataset createDataset() {

		for (String k : domDistancesMap.keySet()) {

			Collection<BigDecimal> v = domDistancesMap.get(k).values();
			double[] features = new double[v.size()];
			int count = 0;

			for (BigDecimal bd : v) {
				features[count] = bd.doubleValue();
				count++;
			}

			Instance instance = new DenseInstance(features, k);
			data.add(instance);

		}

		return data;

	}
 
Example #5
Source File: UrlDistance.java    From apogen with Apache License 2.0 4 votes vote down vote up
/**
 * create the URL distances matrix
 * 
 * @return
 */
public Dataset createDataset() {

	for (String k : urlDistancesMap.keySet()) {

		Collection<BigDecimal> v = urlDistancesMap.get(k).values();
		double[] features = new double[v.size()];
		int count = 0;

		for (BigDecimal bd : v) {
			features[count] = bd.doubleValue();
			count++;
		}

		Instance instance = new DenseInstance(features, k);
		data.add(instance);

	}

	return data;

}
 
Example #6
Source File: WordFrequency.java    From apogen with Apache License 2.0 4 votes vote down vote up
/**
 * create the dataset for body frequencies
 * 
 * @return
 */
public Dataset createDatasetBody() {

	for (String k : wordsBodyFrequenciesMap.keySet()) {

		Collection<BigDecimal> v = wordsBodyFrequenciesMap.get(k).values();
		double[] features = new double[v.size()];
		int count = 0;

		for (BigDecimal bd : v) {
			features[count] = bd.doubleValue();
			count++;
		}

		Instance instance = new DenseInstance(features, k);
		dataBody.add(instance);

	}

	return dataBody;

}
 
Example #7
Source File: WordFrequency.java    From apogen with Apache License 2.0 4 votes vote down vote up
/**
 * create the dataset for thal frequencies
 * 
 * @return
 */
public Dataset createDatasetThal() {

	for (String k : wordsThalFrequenciesMap.keySet()) {

		Collection<BigDecimal> v = wordsThalFrequenciesMap.get(k).values();
		double[] features = new double[v.size()];
		int count = 0;

		for (BigDecimal bd : v) {
			features[count] = bd.doubleValue();
			count++;
		}

		Instance instance = new DenseInstance(features, k);
		dataThal.add(instance);

	}

	return dataThal;

}
 
Example #8
Source File: TagFrequency.java    From apogen with Apache License 2.0 4 votes vote down vote up
/**
 * exports the tags frequencies map in a Java-ML Dataset
 * 
 * @return
 */
public Dataset createDataset() {

	for (String k : tagsFrequenciesMap.keySet()) {

		Collection<BigDecimal> v = tagsFrequenciesMap.get(k).values();
		double[] features = new double[v.size()];
		int count = 0;

		for (BigDecimal bd : v) {
			features[count] = bd.doubleValue();
			count++;
		}

		Instance instance = new DenseInstance(features, k);
		data.add(instance);

	}

	return data;

}