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


Java TDoubleArrayList类代码示例

本文整理汇总了Java中gnu.trove.list.array.TDoubleArrayList的典型用法代码示例。如果您正苦于以下问题:Java TDoubleArrayList类的具体用法?Java TDoubleArrayList怎么用?Java TDoubleArrayList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: parseToken

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
void parseToken(int i, String token) {
    if (dataTypes[i - 2] == null) {
        // test double parsing, in case of error we consider it a string time series
        if (Doubles.tryParse(token) != null) {
            dataTypes[i - 2] = TimeSeriesDataType.DOUBLE;
            TDoubleArrayList doubleValues = createDoubleValues();
            doubleValues.add(parseDouble(token));
            values[i - 2] = doubleValues;
        } else {
            dataTypes[i - 2] = TimeSeriesDataType.STRING;
            List<String> stringValues = createStringValues();
            stringValues.add(checkString(token));
            values[i - 2] = stringValues;
        }
    } else {
        if (dataTypes[i - 2] == TimeSeriesDataType.DOUBLE) {
            ((TDoubleArrayList) values[i - 2]).add(parseDouble(token));
        } else if (dataTypes[i - 2] == TimeSeriesDataType.STRING) {
            ((List<String>) values[i - 2]).add(checkString(token));
        } else {
            throw assertDataType(dataTypes[i - 2]);
        }
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:25,代码来源:TimeSeries.java

示例2: getAverageSpeedForTrips

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的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: computeCPFs

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
private void computeCPFs ()
{
  isFactorsAdded = true;
  TDoubleArrayList residTmp = new TDoubleArrayList ();
  for (Iterator it = cliques.iterator(); it.hasNext();) {
    UnrolledVarSet clique = (UnrolledVarSet) it.next();
    AbstractTableFactor ptl = clique.tmpl.computeFactor (clique);
    addFactorInternal (clique, ptl);
    clique.tmpl.modifyPotential (this, clique, ptl);
    uvsMap.put (ptl, clique);
    
    // sigh
    LogTableFactor unif = new LogTableFactor (clique);
    residTmp.add (Factors.distLinf (unif, ptl));
  }

  lastResids = residTmp.toArray();
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:19,代码来源:ACRF.java

示例4: readSparseVector

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
private SparseVector readSparseVector (String str, Alphabet dict) throws IOException
{
  TIntArrayList idxs = new TIntArrayList ();
  TDoubleArrayList vals = new TDoubleArrayList ();
  String[] lines = str.split ("\n");
  for (int li = 0; li < lines.length; li++) {
    String line = lines[li];
    if (Pattern.matches ("^\\s*$", line)) continue;

    String[] fields = line.split ("\t");
    int idx;
    if (dict != null) {
      idx = dict.lookupIndex (fields[0]);
    } else {
      idx = Integer.parseInt (fields[0]);
    }

    double val = Double.parseDouble (fields[1]);
    idxs.add (idx);
    vals.add (val);
  }
  return new SparseVector (idxs.toArray(), vals.toArray());
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:24,代码来源:ACRF.java

示例5: testSample

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
public void testSample ()
  {
    Variable v1 = new Variable (Variable.CONTINUOUS);
    Variable v2 = new Variable (Variable.CONTINUOUS);
    Randoms r = new Randoms (2343);

    Vector mu = new DenseVector (new double[] { 1.0, 2.0 });
    Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 0, 1 }});
//    Matrix var = new DenseMatrix (new double[][] {{ 0.5, 2.0 }, { 2.0, 0.75 }});

    VarSet vars = new HashVarSet (new Variable[] { v1, v2 });
    Factor f = new NormalFactor (vars, mu, var);

    TDoubleArrayList v1lst = new TDoubleArrayList();
    TDoubleArrayList v2lst = new TDoubleArrayList ();
    for (int i = 0; i < 100000; i++) {
      Assignment assn = f.sample (r);
      v1lst.add (assn.getDouble (v1));
      v2lst.add (assn.getDouble (v2));
    }

    checkMeanStd (v1lst, 1.0, Math.sqrt (1/0.5));
    checkMeanStd (v2lst, 2.0, Math.sqrt (1/0.75));
  }
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:25,代码来源:TestNormalFactor.java

示例6: testSample

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
public void testSample ()
{
  Variable var = new Variable (Variable.CONTINUOUS);
  Randoms r = new Randoms (2343);
  Factor f = new UniNormalFactor (var, -1.0, 2.0);
  TDoubleArrayList lst = new TDoubleArrayList();
  for (int i = 0; i < 10000; i++) {
    Assignment assn = f.sample (r);
    lst.add (assn.getDouble (var));
  }

  double[] vals = lst.toArray ();
  double mean = MatrixOps.mean (vals);
  double std = MatrixOps.stddev (vals);
  assertEquals (-1.0, mean, 0.025);
  assertEquals (Math.sqrt(2.0), std, 0.01);
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:18,代码来源:TestUniNormalFactor.java

示例7: createDirectedModel

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
private DirectedModel createDirectedModel ()
{
  int NUM_OUTCOMES = 2;
  cc.mallet.util.Randoms random = new cc.mallet.util.Randoms (13413);

  Dirichlet dirichlet = new Dirichlet (NUM_OUTCOMES, 1.0);
  double[] pA = dirichlet.randomVector (random);
  double[] pB = dirichlet.randomVector (random);

  TDoubleArrayList pC = new TDoubleArrayList (NUM_OUTCOMES * NUM_OUTCOMES * NUM_OUTCOMES);
  for (int i = 0; i < (NUM_OUTCOMES * NUM_OUTCOMES); i++) {
    pC.add (dirichlet.randomVector (random));
  }

  Variable[] vars = new Variable[] { new Variable (NUM_OUTCOMES), new Variable (NUM_OUTCOMES),
          new Variable (NUM_OUTCOMES) };
  DirectedModel mdl = new DirectedModel ();
  mdl.addFactor (new CPT (new TableFactor (vars[0], pA), vars[0]));
  mdl.addFactor (new CPT (new TableFactor (vars[1], pB), vars[1]));
  mdl.addFactor (new CPT (new TableFactor (vars, pC.toArray ()), vars[2]));

  return mdl;
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:24,代码来源:TestInference.java

示例8: make3dMatrix

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
private SparseMatrixn make3dMatrix ()
{
  int[] sizes = new int[]{2, 3, 4};
  TIntArrayList idxs = new TIntArrayList ();
  TDoubleArrayList vals = new TDoubleArrayList ();

  for (int i = 0; i < 24; i++) {
    if (i % 3 != 0) {
      idxs.add (i);
      vals.add (2.0 * i);
    }
  }

  SparseMatrixn a = new SparseMatrixn (sizes, idxs.toArray (), vals.toArray ());
  return a;
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:17,代码来源:TestSparseMatrixn.java

示例9: train

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
public void train(int imin, int imax, List<SparseFloatArray> xp, TDoubleArrayList yp) {
	System.out.println("Training on [" + imin + ", " + imax + "].");
	assert (imin <= imax);
	assert (eta0 > 0);
	for (int i = imin; i <= imax; i++) {
		final double eta = eta0 / (1 + lambda * eta0 * t);
		trainOne(xp.get(i), yp.get(i), eta);
		t += 1;
	}
	// cout << prefix << setprecision(6) << "wNorm=" << wnorm();
	System.out.format("wNorm=%.6f", wnorm());
	if (BIAS) {
		// cout << " wBias=" << wBias;
		System.out.format(" wBias=%.6f", wBias);
	}
	System.out.println();
	// cout << endl;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:19,代码来源:SvmSgd.java

示例10: test

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
public void test(int imin, int imax, List<SparseFloatArray> xp, TDoubleArrayList yp, String prefix) {
	// cout << prefix << "Testing on [" << imin << ", " << imax << "]." <<
	// endl;
	System.out.println(prefix + "Testing on [" + imin + ", " + imax + "].");
	assert (imin <= imax);
	final double nerr[] = { 0 };
	final double loss[] = { 0 };
	for (int i = imin; i <= imax; i++)
		testOne(xp.get(i), yp.get(i), loss, nerr);
	nerr[0] = nerr[0] / (imax - imin + 1);
	loss[0] = loss[0] / (imax - imin + 1);
	final double cost = loss[0] + 0.5 * lambda * wnorm();
	// cout << prefix
	// << "Loss=" << setprecision(12) << loss
	// << " Cost=" << setprecision(12) << cost
	// << " Misclassification=" << setprecision(4) << 100 * nerr << "%."
	// << endl;
	System.out.println(prefix + "Loss=" + loss[0] + " Cost=" + cost + " Misclassification="
			+ String.format("%2.4f", 100 * nerr[0]) + "%");
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:21,代码来源:SvmSgd.java

示例11: determineEta0

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
public void determineEta0(int imin, int imax, List<SparseFloatArray> xp, TDoubleArrayList yp) {
	final double factor = 2.0;
	double loEta = 1;
	double loCost = evaluateEta(imin, imax, xp, yp, loEta);
	double hiEta = loEta * factor;
	double hiCost = evaluateEta(imin, imax, xp, yp, hiEta);
	if (loCost < hiCost)
		while (loCost < hiCost) {
			hiEta = loEta;
			hiCost = loCost;
			loEta = hiEta / factor;
			loCost = evaluateEta(imin, imax, xp, yp, loEta);
		}
	else if (hiCost < loCost)
		while (hiCost < loCost) {
			loEta = hiEta;
			loCost = hiCost;
			hiEta = loEta * factor;
			hiCost = evaluateEta(imin, imax, xp, yp, hiEta);
		}
	eta0 = loEta;
	// cout << "# Using eta0=" << eta0 << endl;
	System.out.println("# Using eta0=" + eta0 + "\n");
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:25,代码来源:SvmSgd.java

示例12: load_datafile

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
private static int load_datafile(String file, List<SparseFloatArray> x, TDoubleArrayList y, int[] dims,
		boolean normalize, int maxn) throws IOException
{
	final Loader loader = new Loader(file);

	final int[] maxdim = { 0 };
	final int[] pcount = { 0 }, ncount = { 0 };
	loader.load(x, y, normalize, maxn, maxdim, pcount, ncount);
	if (pcount[0] + ncount[0] > 0)
		System.out.println("# Read " + pcount + "+" + ncount
				+ "=" + pcount + ncount + " examples "
				+ "from \"" + file + "\".");
	if (dims[0] < maxdim[0])
		dims[0] = maxdim[0];
	return pcount[0] + ncount[0];
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:17,代码来源:SvmSgdMain.java

示例13: recomputeBias

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的package包/类
public void recomputeBias(double[][] datai, double[][] dataj, boolean[] same) {
	final TDoubleArrayList posDistances = new TDoubleArrayList();
	final TDoubleArrayList negDistances = new TDoubleArrayList();
	for (int i = 0; i < datai.length; i++) {
		final Matrix diff = diff(datai[i], dataj[i]);
		final Matrix diffProj = W.times(diff);
		final double dist = sumsq(diffProj);

		if (same[i]) {
			posDistances.add(dist);
		} else {
			negDistances.add(dist);
		}
	}

	b = computeOptimal(posDistances, negDistances);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:18,代码来源:LargeMarginDimensionalityReduction.java

示例14: getScalars

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的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;
}
 
开发者ID:numenta,项目名称:htm.java,代码行数:24,代码来源:SDRCategoryEncoder.java

示例15: anomalyScoreMovingAverage

import gnu.trove.list.array.TDoubleArrayList; //导入依赖的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);
}
 
开发者ID:numenta,项目名称:htm.java,代码行数:41,代码来源:AnomalyLikelihood.java


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