当前位置: 首页>>代码示例>>Java>>正文


Java TDoubleList.size方法代码示例

本文整理汇总了Java中gnu.trove.list.TDoubleList.size方法的典型用法代码示例。如果您正苦于以下问题:Java TDoubleList.size方法的具体用法?Java TDoubleList.size怎么用?Java TDoubleList.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnu.trove.list.TDoubleList的用法示例。


在下文中一共展示了TDoubleList.size方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:19,代码来源:TDoubleLinkedList.java

示例2: 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();
}
 
开发者ID:conveyal,项目名称:gtfs-lib,代码行数:31,代码来源:PatternStats.java

示例3: 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;
}
 
开发者ID:zhangcongle,项目名称:NewsSpikeRe,代码行数:24,代码来源:V.java

示例4: 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);
}
 
开发者ID:numenta,项目名称:htm.java,代码行数:32,代码来源:MovingAverage.java

示例5: closenessScores

import gnu.trove.list.TDoubleList; //导入方法依赖的package包/类
public TDoubleList closenessScores(TDoubleList expValues, TDoubleList actValues, boolean fractional) {
	TDoubleList retVal = new TDoubleArrayList();

	//Fallback closenss is a percentage match
	List<EncoderTuple> encoders = getEncoders(this);
	if(encoders == null || encoders.size() < 1) {
		double err = Math.abs(expValues.get(0) - actValues.get(0));
		double closeness = -1;
		if(fractional) {
			double denom = Math.max(expValues.get(0), actValues.get(0));
			if(denom == 0) {
				denom = 1.0;
			}

			closeness = 1.0 - err/denom;
			if(closeness < 0) {
				closeness = 0;
			}
		}else{
			closeness = err;
		}

		retVal.add(closeness);
		return retVal;
	}

	int scalarIdx = 0;
	for(EncoderTuple res : getEncoders(this)) {
		TDoubleList values = res.getEncoder().closenessScores(
			expValues.subList(scalarIdx, expValues.size()), actValues.subList(scalarIdx, actValues.size()), fractional);

		scalarIdx += values.size();
		retVal.addAll(values);
	}

	return retVal;
}
 
开发者ID:numenta,项目名称:htm.java,代码行数:38,代码来源:Encoder.java

示例6: MovingAverage

import gnu.trove.list.TDoubleList; //导入方法依赖的package包/类
/**
 * Constructs a new {@code MovingAverage}
 * 
 * @param historicalValues  list of entry values
 * @param windowSize        length over which to take the average
 */
public MovingAverage(TDoubleList historicalValues, double total, int windowSize) {
    if(windowSize <= 0) {
        throw new IllegalArgumentException("Window size must be > 0");
    }
    this.windowSize = windowSize;
    
    calc = new Calculation();
    calc.historicalValues = 
        historicalValues == null || historicalValues.size() < 1 ?
            new TDoubleArrayList(windowSize) : historicalValues;
    calc.total = total != -1 ? total : calc.historicalValues.sum();
}
 
开发者ID:numenta,项目名称:htm.java,代码行数:19,代码来源:MovingAverage.java

示例7: estimateAnomalyLikelihoods

import gnu.trove.list.TDoubleList; //导入方法依赖的package包/类
/**
 * Given a series of anomaly scores, compute the likelihood for each score. This
 * function should be called once on a bunch of historical anomaly scores for an
 * initial estimate of the distribution. It should be called again every so often
 * (say every 50 records) to update the estimate.
 * 
 * @param anomalyScores
 * @param averagingWindow
 * @param skipRecords
 * @return
 */
public AnomalyLikelihoodMetrics estimateAnomalyLikelihoods(List<Sample> anomalyScores, int averagingWindow, int skipRecords) {
    if(anomalyScores.size() == 0) {
        throw new IllegalArgumentException("Must have at least one anomaly score.");
    }
    
    // Compute averaged anomaly scores
    AveragedAnomalyRecordList records = anomalyScoreMovingAverage(anomalyScores, averagingWindow);
    
    // Estimate the distribution of anomaly scores based on aggregated records
    Statistic distribution;
    if(records.averagedRecords.size() <= skipRecords) {
        distribution = nullDistribution();
    }else{
        TDoubleList samples = records.getMetrics();
        final int numRecordsToCopy = samples.size() - skipRecords;
        distribution = estimateNormal(samples.toArray(skipRecords, numRecordsToCopy), true);
        
        /*  Taken from the Python Documentation
           
         # HACK ALERT! The CLA model currently does not handle constant metric values
         # very well (time of day encoder changes sometimes lead to unstable SDR's
         # even though the metric is constant). Until this is resolved, we explicitly
         # detect and handle completely flat metric values by reporting them as not
         # anomalous.
         
         */
        samples = records.getSamples();
        Statistic metricDistribution = estimateNormal(samples.toArray(skipRecords, numRecordsToCopy), false);
        
        if(metricDistribution.variance < 1.5e-5) {
            distribution = nullDistribution();
        }
    }
    
    // Estimate likelihoods based on this distribution
    int i = 0;
    double[] likelihoods = new double[records.averagedRecords.size()];
    for(Sample sample : records.averagedRecords) {
        likelihoods[i++] = normalProbability(sample.score, distribution);
    }
    
    // Filter likelihood values
    double[] filteredLikelihoods = filterLikelihoods(likelihoods);
    
    int len = likelihoods.length;
    AnomalyParams params = new AnomalyParams(
        new String[] { "distribution", "movingAverage", "historicalLikelihoods" },
            distribution, 
            new MovingAverage(records.historicalValues, records.total, averagingWindow), 
            len > 0 ? 
                Arrays.copyOfRange(likelihoods, len - Math.min(averagingWindow, len), len) : 
                    new double[0]); 
    
    if(LOG.isDebugEnabled()) {
        LOG.debug(
            "Discovered params={} Number of likelihoods:{}  First 20 likelihoods:{}", 
                params, len, Arrays.copyOfRange(filteredLikelihoods, 0, 20));
    }
    
    return new AnomalyLikelihoodMetrics(filteredLikelihoods, records, params); 
}
 
开发者ID:numenta,项目名称:htm.java,代码行数:73,代码来源:AnomalyLikelihood.java


注:本文中的gnu.trove.list.TDoubleList.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。