本文整理汇总了Java中gnu.trove.list.TDoubleList类的典型用法代码示例。如果您正苦于以下问题:Java TDoubleList类的具体用法?Java TDoubleList怎么用?Java TDoubleList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TDoubleList类属于gnu.trove.list包,在下文中一共展示了TDoubleList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subList
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/** {@inheritDoc} */
public TDoubleList subList( int begin, int end ) {
if ( end < begin ) {
throw new IllegalArgumentException( "end index " + end +
" greater than begin index " + begin );
}
if ( begin < 0 ) {
throw new IndexOutOfBoundsException( "begin index can not be < 0" );
}
if ( end > _data.length ) {
throw new IndexOutOfBoundsException( "end index < " + _data.length );
}
TDoubleArrayList list = new TDoubleArrayList( end - begin );
for ( int i = begin; i < end; i++ ) {
list.add( _data[ i ] );
}
return list;
}
示例2: subList
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/** {@inheritDoc} */
public TDoubleList subList(int begin, int end) {
if (end < begin) {
throw new IllegalArgumentException("begin index " + begin +
" greater than end index " + end);
}
if (size < begin) {
throw new IllegalArgumentException("begin index " + begin +
" greater than last index " + size);
}
if (begin < 0) {
throw new IndexOutOfBoundsException("begin index can not be < 0");
}
if (end > size) {
throw new IndexOutOfBoundsException("end index < " + size);
}
TDoubleLinkedList ret = new TDoubleLinkedList();
TDoubleLink tmp = getLinkAt(begin);
for (int i = begin; i < end; i++) {
ret.add(tmp.getValue()); // copy
tmp = tmp.getNext();
}
return ret;
}
示例3: equals
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public boolean equals( Object other ) {
if ( other == this ) {
return true;
}
if ( !( other instanceof TDoubleList ) ) return false;
TDoubleList that = ( TDoubleList )other;
if ( size() != that.size() ) return false;
for( int i = 0; i < size(); i++ ) {
if ( get( i ) != that.get( i ) ) {
return false;
}
}
return true;
}
示例4: subList
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public TDoubleList subList( int begin, int end ) {
if ( end < begin ) {
throw new IllegalArgumentException( "end index " + end +
" greater than begin index " + begin );
}
if ( begin < 0 ) {
throw new IndexOutOfBoundsException( "begin index can not be < 0" );
}
if ( end > _data.length ) {
throw new IndexOutOfBoundsException( "end index < " + _data.length );
}
TDoubleArrayList list = new TDoubleArrayList( end - begin );
for ( int i = begin; i < end; i++ ) {
list.add( _data[ i ] );
}
return list;
}
示例5: getAverageSpeedForTrips
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/**
* Get average speed for set of trips that begin within the time window in meters per second.
* @param trips
* @param from
* @param to
* @return avg. speed (meters per second)
*/
public double getAverageSpeedForTrips (Collection<Trip> trips, LocalTime from, LocalTime to) {
TDoubleList speeds = new TDoubleArrayList();
for (Trip trip : trips) {
StopTime firstStopTime = feed.stop_times.ceilingEntry(Fun.t2(trip.trip_id, null)).getValue();
LocalTime tripBeginTime = LocalTime.ofSecondOfDay(firstStopTime.departure_time % 86399); // convert 24hr+ seconds to 0 - 86399
// skip trip if begin time is before or after specified time period
if (tripBeginTime.isAfter(to) || tripBeginTime.isBefore(from)) {
continue;
}
// TODO: swap straight lines for actual geometry?
double speed = feed.getTripSpeed(trip.trip_id, true);
if (!Double.isNaN(speed)) {
speeds.add(speed);
}
}
if (speeds.isEmpty()) return -1;
return speeds.sum() / speeds.size();
}
示例6: sumprod
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
public static double sumprod(TIntList fi, TDoubleList fv, double[][] w,
int cl) {
if (fi == null || fv == null || w == null) {
logger.warn("[EXCEPTION]sumprod(" + fi + ", " + fv + "," + w
+ ")@V has null argument.");
return 0;
}
if (fi.size() != fv.size()) {
logger.warn("[EXCEPTION]sumprod(fi=" + fi.size() + ", fv="
+ fv.size() + ")@V has two lists in different lengths.");
return 0;
}
if (cl > w.length || cl < 0) {
logger.warn("[EXCEPTION]sumprod(cl=" + cl + ", w.len=" + w.length
+ ")@V has different lengths.");
return 0;
}
double result = 0;
for (int i = 0; i < fi.size(); i++) {
result += w[cl][fi.get(i)] * fv.get(i);
}
return result;
}
示例7: encodeIntoArray
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
// Adapted from MultiEncoder
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void encodeIntoArray(DateTime inputData, int[] output) {
if(inputData == null) {
throw new IllegalArgumentException("DateEncoder requires a valid Date object but got null");
}
// Get the scalar values for each sub-field
TDoubleList scalars = getScalars(inputData);
int fieldCounter = 0;
for (EncoderTuple t : getEncoders(this)) {
Encoder encoder = t.getEncoder();
int offset = t.getOffset();
int[] tempArray = new int[encoder.getWidth()];
encoder.encodeIntoArray(scalars.get(fieldCounter), tempArray);
System.arraycopy(tempArray, 0, output, offset, tempArray.length);
++fieldCounter;
}
}
示例8: getBucketIndices
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/**
* Returns an array containing the sub-field bucket indices for
* each sub-field of the inputData. To get the associated field names for each of
* the buckets, call getScalarNames().
* @param input The data from the source. This is typically a object with members.
*
* @return array of bucket indices
*/
public int[] getBucketIndices(DateTime input) {
TDoubleList scalars = getScalars(input);
TIntList l = new TIntArrayList();
List<EncoderTuple> encoders = getEncoders(this);
if(encoders != null && encoders.size() > 0) {
int i = 0;
for(EncoderTuple t : encoders) {
l.addAll(t.getEncoder().getBucketIndices(scalars.get(i)));
++i;
}
}else{
throw new IllegalStateException("Should be implemented in base classes that are not " +
"containers for other encoders");
}
return l.toArray();
}
示例9: getScalars
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public <S> TDoubleList getScalars(S input) {
String inputCasted = (String)input;
int index = 0;
TDoubleList result = new TDoubleArrayList();
if (inputCasted == null || inputCasted.isEmpty()) {
result.add(0);
return result;
}
if (!sdrByCategory.containsKey(input)) {
if (isEncoderLearningEnabled()) {
index = sdrByCategory.size();
addCategory(inputCasted);
}
} else {
index = sdrByCategory.getIndexByCategory(inputCasted);
}
result.add(index);
return result;
}
示例10: anomalyScoreMovingAverage
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/**
* Given a list of anomaly scores return a list of averaged records.
* anomalyScores is assumed to be a list of records of the form:
* <pre>
* Sample:
* dt = Tuple(2013, 8, 10, 23, 0) --> Date Fields
* sample = (double) 6.0
* metric(avg) = (double) 1.0
* </pre>
*
* @param anomalyScores List of {@link Sample} objects (described contents above)
* @param windowSize Count of historical items over which to compute the average
*
* @return Each record in the returned list contains [datetime field, value, averaged score]
*/
public AveragedAnomalyRecordList anomalyScoreMovingAverage(List<Sample> anomalyScores, int windowSize) {
TDoubleList historicalValues = new TDoubleArrayList();
double total = 0.0;
List<Sample> averagedRecordList = new ArrayList<Sample>();
for(Sample record : anomalyScores) {
////////////////////////////////////////////////////////////////////////////////////////////
// Python version has check for malformed records here, but can't happen in java version. //
////////////////////////////////////////////////////////////////////////////////////////////
Calculation calc = MovingAverage.compute(historicalValues, total, record.score, windowSize);
Sample avgRecord = new Sample(
record.date,
record.value,
calc.getAverage());
averagedRecordList.add(avgRecord);
total = calc.getTotal();
if(LOG.isDebugEnabled()) {
LOG.debug("Aggregating input record: {}, Result: {}", record, averagedRecordList.get(averagedRecordList.size() - 1));
}
}
return new AveragedAnomalyRecordList(averagedRecordList, historicalValues, total);
}
示例11: compute
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/**
* Internal method which does actual calculation
*
* @param calc Re-used calculation object
* @param slidingWindow a list of previous values to use in the computation that
* will be modified and returned
* @param total total the sum of the values in the slidingWindow to be used in the
* calculation of the moving average
* @param newVal newVal a new number to compute the new windowed average
* @param windowSize windowSize how many values to use in the moving window
* @return
*/
private static Calculation compute(
Calculation calc, TDoubleList slidingWindow, double total, double newVal, int windowSize) {
if(slidingWindow == null) {
throw new IllegalArgumentException("slidingWindow cannot be null.");
}
if(slidingWindow.size() == windowSize) {
total -= slidingWindow.removeAt(0);
}
slidingWindow.add(newVal);
total += newVal;
if(calc == null) {
return new Calculation(slidingWindow, total / (double)slidingWindow.size(), total);
}
return copyInto(calc, slidingWindow, total / (double)slidingWindow.size(), total);
}
示例12: testCloseInner
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
@Ignore
private void testCloseInner(int[] bitmap1, int[] bitmap2, double expectedScore){
PassThroughEncoder<int[]> encoder = new PassThroughEncoder<>(9, ArrayUtils.where(bitmap1, ArrayUtils.WHERE_1).length);
encoder.setName("foo");
int[] out1 = encoder.encode(bitmap1);
encoder.setW(ArrayUtils.where(bitmap2, ArrayUtils.WHERE_1).length);
int[] out2 = encoder.encode(bitmap2);
TDoubleList result = encoder.closenessScores(new TDoubleArrayList(ArrayUtils.toDoubleArray(out1)), new TDoubleArrayList(ArrayUtils.toDoubleArray(out2)), true);
assertTrue(result.size() == 1 );
assertEquals(expectedScore, result.get(0), 0.0);
encoder = PassThroughEncoder.builder()
.n(9)
.w(ArrayUtils.where(bitmap1, ArrayUtils.WHERE_1).length)
.name("foo")
.build();
out1 = encoder.encode(bitmap1);
encoder.setW(ArrayUtils.where(bitmap2, ArrayUtils.WHERE_1).length);
out2 = encoder.encode(bitmap2);
result = encoder.closenessScores(new TDoubleArrayList(ArrayUtils.toDoubleArray(out1)), new TDoubleArrayList(ArrayUtils.toDoubleArray(out2)), true);
assertTrue(result.size() == 1 );
assertEquals(expectedScore, result.get(0), 0.0);
}
示例13: testCloseness
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/**
* Test closenessScores for a periodic encoder
*/
@Test
public void testCloseness() {
setUp();
builder.name("day of week")
.w(7)
.radius(1.0)
.minVal(0.0)
.maxVal(7.0)
.periodic(true)
.forced(true);
initSE();
TDoubleList expValues = new TDoubleArrayList(new double[] { 2, 4, 7 });
TDoubleList actValues = new TDoubleArrayList(new double[] { 4, 2, 1 });
TDoubleList scores = se.closenessScores(expValues, actValues, false);
for(Tuple t : ArrayUtils.zip(Arrays.asList(2, 2, 1), Arrays.asList(scores.get(0)))) {
double a = (int)t.get(0);
double b = (double)t.get(1);
assertTrue(a == b);
}
}
示例14: grep
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/** {@inheritDoc} */
public TDoubleList grep( TDoubleProcedure condition ) {
TDoubleArrayList list = new TDoubleArrayList();
for ( int i = 0; i < _pos; i++ ) {
if ( condition.execute( _data[ i ] ) ) {
list.add( _data[ i ] );
}
}
return list;
}
示例15: inverseGrep
import gnu.trove.list.TDoubleList; //导入依赖的package包/类
/** {@inheritDoc} */
public TDoubleList inverseGrep( TDoubleProcedure condition ) {
TDoubleArrayList list = new TDoubleArrayList();
for ( int i = 0; i < _pos; i++ ) {
if ( !condition.execute( _data[ i ] ) ) {
list.add( _data[ i ] );
}
}
return list;
}