示例#1
0
 /**
  * converts two dimensional array of vectors to the dataset
  *
  * @param points
  * @return
  */
 public static Dataset arrayToDataSet(int[][] points) {
   Dataset dataset = new DefaultDataset();
   for (int i = 0; i < points[0].length; i++) {
     double[] values = new double[points.length];
     for (int j = 0; j < points.length; j++) {
       values[j] = points[j][i];
     }
     dataset.add(new DenseInstance(values));
   }
   return dataset;
 }
示例#2
0
  public setsMeanStdDev produceDataSets(Vector<String> all, int tooHigh, int tooLow) {

    double mean = 0;
    double standardDev = 0;
    double standardDevTimesN = 0;
    double sum = 0;
    double curCount = 0;

    DexComReading garbage = new DexComReading(0, "empty", 0);
    Vector<DexComReading> dexReadings = new Vector<DexComReading>();
    for (String curString : all) {
      try {
        DexComReading newRead = produceReading(curString);
        dexReadings.add(newRead);
      } catch (NumberFormatException e) {
        Log.d("KNNMethods", "Bad Date Format");
      }
    }
    Vector<Boolean> dangerListHigh = new Vector<Boolean>();
    Vector<Boolean> dangerListLow = new Vector<Boolean>();
    for (int i = 0; i < 12; ++i) {
      dangerListHigh.add(false);
      dangerListLow.add(false);
    }
    for (int i = 12; i < dexReadings.size() - 6; ++i) {

      sum = sum + dexReadings.get(i + 6).getSgv();
      ++curCount;
    }
    mean = sum / curCount;
    curCount = 0;

    for (int i = 12; i < dexReadings.size() - 6; ++i) {
      standardDevTimesN = standardDevTimesN + Math.pow((dexReadings.get(i).getSgv() - mean), 2);
      ++curCount;
      if (dexReadings.get(i + 6).getSgv() > tooHigh) {
        dangerListHigh.add(true);
        dangerListLow.add(false);
      } else if (dexReadings.get(i + 6).getSgv() > tooLow) {
        dangerListHigh.add(false);
        dangerListLow.add(false);
      } else if (dexReadings.get(i + 6).getSgv() < tooLow) {
        dangerListLow.add(true);
        dangerListHigh.add(false);
      }
    }

    standardDev = standardDevTimesN / curCount;

    double[][] sets13 = new double[dangerListHigh.size()][13];
    for (int i = 12; i < dexReadings.size() - 6; ++i) {
      double[] set13 = new double[13];
      for (int j = 0; j < 12; ++j) {
        set13[11 - j] = (dexReadings.get(i - j).getDoubleSgv() - mean) / standardDev;
      }
      set13[12] = dexReadings.get(i).getTime();
      sets13[i - 12] = set13;
    }

    Dataset dataHigh = new DefaultDataset();
    Dataset dataLow = new DefaultDataset();
    Log.d(TAG, "Value=" + tooHigh);
    for (int i = 0; i < sets13.length; ++i) {
      Instance instanceWClassValueHigh = new DenseInstance(sets13[i], dangerListHigh.get(i));
      Instance instanceWClassValueLow = new DenseInstance(sets13[i], dangerListLow.get(i));
      dataHigh.add(instanceWClassValueHigh);
      dataLow.add(instanceWClassValueLow);
    }
    Vector<Dataset> dataSets = new Vector<Dataset>();
    dataSets.add(dataHigh);
    dataSets.add(dataLow);
    setsMeanStdDev toReturn = new setsMeanStdDev(dataSets, mean, standardDev);
    return toReturn;
  }