Package de.jungblut.math.dense

Examples of de.jungblut.math.dense.SingleEntryDoubleVector


      }

      outcomeHistogram.set(classIndex, outcomeHistogram.get(classIndex) + 1);
    }
    if (numOutcomes == 2) {
      return new SingleEntryDoubleVector(outcomeHistogram.maxIndex());
    } else {
      return outcomeHistogram;
    }
  }
View Full Code Here


    DoubleVector[] features = new DoubleVector[list.size()];
    DoubleVector[] outcome = new DoubleVector[list.size()];
    for (int i = 0; i < list.size(); i++) {
      DoubleVector doubleVector = list.get(i);
      features[i] = doubleVector.slice(doubleVector.getLength() - 1);
      outcome[i] = new SingleEntryDoubleVector(doubleVector.get(doubleVector
          .getLength() - 1));
    }

    return new Dataset(features, outcome);
  }
View Full Code Here

        for (int i = 0; i < length; i++) {
          vector.set(i, in.readDouble());
        }
        break;
      case SINGLE:
        vector = new SingleEntryDoubleVector(in.readDouble());
        break;
      default:
        throw new IllegalArgumentException(
            "Can't deserialize vector of type byte: " + typeByte);
    }
View Full Code Here

    SparseKNearestNeighbours neighbours = new SparseKNearestNeighbours(2, 2,
        new CosineDistance());

    // we seperate stuff in two dimensions each
    DoubleVector left = new SingleEntryDoubleVector(0d);
    DoubleVector right = new SingleEntryDoubleVector(1d);
    DoubleVector v1 = new SparseDoubleVector(4);
    v1.set(0, 1d);
    v1.set(1, 1d);

    DoubleVector v2 = new SparseDoubleVector(4);
View Full Code Here

    KNearestNeighbours knn = new KNearestNeighbours(5, 2);
    List<DoubleVector> features = new ArrayList<>();
    List<DoubleVector> outcome = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
      features.add(new SingleEntryDoubleVector(i));
      double[] arr = new double[5];
      arr[i % 5] = 1d;
      outcome.add(new DenseDoubleVector(arr));
    }
    knn.train(features, outcome);

    DoubleVector prediction = knn.predict(new SingleEntryDoubleVector(5));
    assertArrayEquals(new double[] { 1d, 0, 0, 0, 1d }, prediction.toArray());
    prediction = knn.predictProbability(new SingleEntryDoubleVector(5));
    assertArrayEquals(new double[] { 0.5, 0, 0, 0, 0.5 }, prediction.toArray());
  }
View Full Code Here

    assertTrue(check instanceof SparseDoubleVector);
  }

  @Test
  public void testSingleSerDe() throws Exception {
    SingleEntryDoubleVector vec = new SingleEntryDoubleVector(1d);
    DoubleVector check = check(vec);
    assertTrue(check instanceof SingleEntryDoubleVector);
  }
View Full Code Here

          features[i].set(index, 1d);
        }
      }

      if (classes == 2) {
        outcome[i] = new SingleEntryDoubleVector(labels.get(i));
      } else {
        outcome[i] = new SparseDoubleVector(classes);
        outcome[i].set(labels.get(i), 1d);
      }
    }
View Full Code Here

TOP

Related Classes of de.jungblut.math.dense.SingleEntryDoubleVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.