gnu.trove.iterator.TDoubleIterator Java Examples

The following examples show how to use gnu.trove.iterator.TDoubleIterator. 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: ContinuousQueryDispatcher.java    From cineast with MIT License 5 votes vote down vote up
private ContinuousQueryDispatcher(Function<Retriever, RetrievalTask> taskFactory,
    TObjectDoubleMap<Retriever> retrieverWeights,
    RetrieverInitializer initializer) {
  this.taskFactory = taskFactory;
  this.initializer = initializer;
  this.retrieverWeights = retrieverWeights;

  double weightSum = 0d;
  TDoubleIterator i = retrieverWeights.valueCollection().iterator();
  while (i.hasNext()) {
    weightSum += i.next();
  }
  this.retrieverWeightSum = weightSum;
  LOGGER.trace("Initialized continuous query dispatcher with retrievers {}", retrieverWeights);
}
 
Example #2
Source File: TDoubleArrayList.java    From baleen with Apache License 2.0 4 votes vote down vote up
/** See {@link gnu.trove.list.array.TDoubleArrayList#iterator()} */
public TDoubleIterator iterator() {
  return delegate.iterator();
}
 
Example #3
Source File: AnomalyLikelihoodTest.java    From htm.java with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * A slight more complex test. This calls estimateAnomalyLikelihoods
 * to estimate the distribution on fake data, followed by several calls
 * to updateAnomalyLikelihoods.
 */
@Test
public void testUpdateAnomalyLikelihoods() {
    
    //----------------------------------------
    // Step 1. Generate an initial estimate using fake distribution of anomaly scores.
    List<Sample> data1 = generateSampleData(0.2, 0.2, 0.2, 0.2).subList(0, 1000);
    AnomalyLikelihoodMetrics metrics1 = an.estimateAnomalyLikelihoods(data1, 5, 0);
    
    //----------------------------------------
    // Step 2. Generate some new data with a higher average anomaly
    // score. Using the estimator from step 1, to compute likelihoods. Now we
    // should see a lot more anomalies.
    List<Sample> data2 = generateSampleData(0.6, 0.2, 0.2, 0.2).subList(0, 300);
    AnomalyLikelihoodMetrics metrics2 = an.updateAnomalyLikelihoods(data2, metrics1.getParams());
    assertEquals(metrics2.getLikelihoods().length, data2.size());
    assertEquals(metrics2.getAvgRecordList().size(), data2.size());
    assertTrue(an.isValidEstimatorParams(metrics2.getParams()));
    
    // The new running total should be different
    assertFalse(metrics1.getAvgRecordList().total == metrics2.getAvgRecordList().total);
    
    // We should have many more samples where likelihood is < 0.01, but not all
    Condition<Double> cond = new Condition.Adapter<Double>() {
        public boolean eval(double d) { return d < 0.01; }
    };
    int conditionCount = ArrayUtils.where(metrics2.getLikelihoods(), cond).length;
    assertTrue(conditionCount >= 25);
    assertTrue(conditionCount <= 250);
    
    //----------------------------------------
    // Step 3. Generate some new data with the expected average anomaly score. We
    // should see fewer anomalies than in Step 2.
    List<Sample> data3 = generateSampleData(0.2, 0.2, 0.2, 0.2).subList(0, 1000);
    AnomalyLikelihoodMetrics metrics3 = an.updateAnomalyLikelihoods(data3, metrics2.getParams());
    assertEquals(metrics3.getLikelihoods().length, data3.size());
    assertEquals(metrics3.getAvgRecordList().size(), data3.size());
    assertTrue(an.isValidEstimatorParams(metrics3.getParams()));
    
    // The new running total should be different
    assertFalse(metrics1.getAvgRecordList().total == metrics3.getAvgRecordList().total);
    assertFalse(metrics2.getAvgRecordList().total == metrics3.getAvgRecordList().total);
    
    // We should have a small number of samples where likelihood is < 0.02
    conditionCount = ArrayUtils.where(metrics3.getLikelihoods(), cond).length;
    assertTrue(conditionCount >= 1);
    assertTrue(conditionCount <= 100);
    
    //------------------------------------------
    // Step 4. Validate that sending data incrementally is the same as sending
    // in one batch
    List<Sample> allData = new ArrayList<>();
    allData.addAll(data1);
    allData.addAll(data2);
    allData.addAll(data3);
    AveragedAnomalyRecordList recordList = an.anomalyScoreMovingAverage(allData, 5);
    
    double[] historicalValuesAll = new double[recordList.historicalValues.size()];
    int i = 0;
    for(TDoubleIterator it = recordList.historicalValues.iterator();it.hasNext();) {
        historicalValuesAll[i++] = it.next();
    }
    assertEquals(ArrayUtils.sum(historicalValuesAll), ArrayUtils.sum(
        metrics3.getParams().movingAverage().getSlidingWindow().toArray()), 0);
    
    assertEquals(recordList.total, metrics3.getParams().movingAverage().getTotal(), 0);
}