當前位置: 首頁>>代碼示例>>Java>>正文


Java ArrayUtils.toPrimitive方法代碼示例

本文整理匯總了Java中org.apache.commons.lang.ArrayUtils.toPrimitive方法的典型用法代碼示例。如果您正苦於以下問題:Java ArrayUtils.toPrimitive方法的具體用法?Java ArrayUtils.toPrimitive怎麽用?Java ArrayUtils.toPrimitive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang.ArrayUtils的用法示例。


在下文中一共展示了ArrayUtils.toPrimitive方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAllPredictions

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
public List<Double> getAllPredictions(List<Double> data, int T){
    //returns all the predictions for a time serie
    //this is expensive, but helps in testing
    double[] dObs=ArrayUtils.toPrimitive(data.toArray(new Double[data.size()]));
    double[] sol= new double[data.size()+T];
    for(int i=0;i<data.size();i++){
        List<Double> subList = new ArrayList<Double>(data.subList(0, i));
        if(i<T){
            sol[i]=dObs[i];
            sol[i+T]=getPrediction(subList);
        }
        else{
            sol[i+T]=getPrediction(subList);
        }
    }//for

    List<Double> auxSOl=convertDoubletoArrayList(sol);
    return auxSOl;
}
 
開發者ID:borjalor,項目名稱:DroidSentinel,代碼行數:20,代碼來源:DoubleMovingAverage.java

示例2: getPrediction

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
public double getPrediction(List<Double> data){
    //Predict a simple value
    //pred[i]= SMA[i-1]+(O[i-2]-SMA[i-2])
    double pred=0.0;

    double[] dObs=ArrayUtils.toPrimitive(data.toArray(new Double[data.size()]));
    List<Double> SMA_data = get2MA((List) ((ArrayList) data).clone());
    double[] dSMA=ArrayUtils.toPrimitive(SMA_data.toArray(new Double[SMA_data.size()]));

    int i = data.size()-1;
    if(i>2){
        pred=dSMA[i]+(dObs[i-1]-dSMA[i-1]);
        //System.out.println("pred: "+pred+"dSMA[i-1]:" + dSMA[i-1]+" + (dObs[i-2]"+dObs[i-2]+"-dSMA[i-2]): "+dSMA[i-2]+")");
    }
    else{
        pred= 0;
    }
    return pred;
}
 
開發者ID:borjalor,項目名稱:DroidSentinel,代碼行數:20,代碼來源:DoubleMovingAverage.java

示例3: getPrediction

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
public double getPrediction(List<Double> data){
    //Predict a simple value
    //pred[i]= SMA[i-1]+(O[i-2]-SMA[i-2])
    double pred=0.0;

    double[] dObs=ArrayUtils.toPrimitive(data.toArray(new Double[data.size()]));
    List<Double> SMA_data = getWMA((List) ((ArrayList) data).clone());
    double[] dSMA=ArrayUtils.toPrimitive(SMA_data.toArray(new Double[SMA_data.size()]));

    int i = data.size()-1;
    if(i>2){
        pred=dSMA[i]+(dObs[i-1]-dSMA[i-1]);
        //System.out.println("pred: "+pred+"dSMA[i-1]:" + dSMA[i-1]+" + (dObs[i-2]"+dObs[i-2]+"-dSMA[i-2]): "+dSMA[i-2]+")");
    }
    else{
        pred= 0;
    }
    return pred;
}
 
開發者ID:borjalor,項目名稱:DroidSentinel,代碼行數:20,代碼來源:WeightedMovingAverage.java

示例4: getAllFtrVect

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * @param ftrCount
 *            the number of features.
 * @param excludedFeatures
 *            the features that have to be excluded from the feature list.
 * @return a vector containing all feature ids from 1 to ftrCount
 *         (included), except those in excludedFeatures.
 */
public static int[] getAllFtrVect(int ftrCount, int[] excludedFeatures) {
	Arrays.sort(excludedFeatures);
	Vector<Integer> res = new Vector<>();
	for (int i = 1; i < ftrCount + 1; i++)
		if (Arrays.binarySearch(excludedFeatures, i) < 0)
			res.add(i);
	return ArrayUtils.toPrimitive(res.toArray(new Integer[] {}));
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:17,代碼來源:SmaphUtils.java

示例5: createMergedPage

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
private int[] createMergedPage(int skip, int count, List<Integer> s1, int[] s2)
{
    int[] s1Primitive = (s1 == null || s1.isEmpty()) ? new int[] {} : ArrayUtils.toPrimitive((Integer[]) s1
                .toArray());

    return createMergedPage(skip,
                            count,
                            s1Primitive,
                            s2);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:11,代碼來源:PageCollatorTest.java

示例6: compute

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * Computes the Geometric Median of a given array of word embeddings
 * @param senseEmbeddings Array of Word Embeddings
 * @return The vector that represents the geometric median of the given array
 */
public double[] compute(ArrayList<Double[]> senseEmbeddings) {
    Double[] senseEmbedding = new Double[300];
    Double[] sum1;
    double sum2;

    int iterations = 10;
    double norm;

    for (int i = 0; i < 300; i++) {
        senseEmbedding[i] = 0d;
    }

    for (int i = 0; i < iterations; i++) {
        sum1 = new Double[300]; sum2 = 0;

        for (int j = 0; j < 300; j++) {
            sum1[j] = 0d;
        }

        for(Double[] tmpSenseEmbedding : senseEmbeddings) {
            // this is x
            norm = MathUtil.computeNorm(tmpSenseEmbedding, senseEmbedding);

            sum1 = MathUtil.sumVectors(sum1, MathUtil.divideVectors(tmpSenseEmbedding, norm));
            sum2 += 1 / norm;
        }

        senseEmbedding = MathUtil.divideVectors(sum1, sum2);
    }

    return ArrayUtils.toPrimitive(senseEmbedding);
}
 
開發者ID:butnaruandrei,項目名稱:ShotgunWSD,代碼行數:38,代碼來源:GeometricMedianComputation.java

示例7: getSenseEmbedding

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 *
 * @param wordVector The Word Embeddings dictionary
 * @param synset The synset ...
 * @param word The word ...
 * @return The sense embedding of a synset
 */
public static double[] getSenseEmbedding(WordVectors wordVector, Synset synset, String word, SenseComputation senseComputation) {
    if(wordEmbeddings.containsKey(synset)){
        return ArrayUtils.toPrimitive(wordEmbeddings.get(synset));
    }

    String[] words = getSenseBag(synset, word);

    double[] senseEmbedding, tmpEmbedding;
    Double[] tmpEmbedding2, tmpSenseEmbedding;
    ArrayList<Double[]> senseEmbeddings = new ArrayList<>();

    // For each word in the sense bag, get the coresponding word embeddings and store them in an array
    for (String w : words) {
        if (w != null) {
            if (wordVector.hasWord(w)) {
                tmpEmbedding = wordVector.getWordVector(w);

                tmpEmbedding2 = new Double[tmpEmbedding.length];
                for (int i = 0; i < tmpEmbedding.length; i++) {
                    tmpEmbedding2[i] = tmpEmbedding[i];
                }
                senseEmbeddings.add(tmpEmbedding2);
            }
        }
    }

    senseEmbedding = senseComputation.compute(senseEmbeddings);

    tmpSenseEmbedding = new Double[senseEmbedding.length];
    for (int i = 0; i < tmpSenseEmbedding.length; i++) {
        tmpSenseEmbedding[i] = senseEmbedding[i];
    }
    wordEmbeddings.put(synset, tmpSenseEmbedding);

    return senseEmbedding;
}
 
開發者ID:butnaruandrei,項目名稱:ShotgunWSD,代碼行數:44,代碼來源:SenseEmbedding.java

示例8: serializeAndWrite

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * Serialize the set of in flights into a byte longBuffer.
 *
 * @return Returns the checksum of the buffer that is being
 * asynchronously written to disk.
 */
public void serializeAndWrite() throws Exception {
  Collection<Long> values = inflightEvents.values();
  if (!fileChannel.isOpen()) {
    file = new RandomAccessFile(inflightEventsFile, "rw");
    fileChannel = file.getChannel();
  }
  if (values.isEmpty()) {
    file.setLength(0L);
  }
  //What is written out?
  //Checksum - 16 bytes
  //and then each key-value pair from the map:
  //transactionid numberofeventsforthistxn listofeventpointers

  try {
    int expectedFileSize = (((inflightEvents.keySet().size() * 2) //for transactionIDs and
                                                                  //events per txn ID
        + values.size()) * 8) //Event pointers
        + 16; //Checksum
    //There is no real need of filling the channel with 0s, since we
    //will write the exact number of bytes as expected file size.
    file.setLength(expectedFileSize);
    Preconditions.checkState(file.length() == expectedFileSize,
        "Expected File size of inflight events file does not match the "
            + "current file size. Checkpoint is incomplete.");
    file.seek(0);
    final ByteBuffer buffer = ByteBuffer.allocate(expectedFileSize);
    LongBuffer longBuffer = buffer.asLongBuffer();
    for (Long txnID : inflightEvents.keySet()) {
      Set<Long> pointers = inflightEvents.get(txnID);
      longBuffer.put(txnID);
      longBuffer.put((long) pointers.size());
      LOG.debug("Number of events inserted into "
          + "inflights file: " + String.valueOf(pointers.size())
          + " file: " + inflightEventsFile.getCanonicalPath());
      long[] written = ArrayUtils.toPrimitive(
          pointers.toArray(new Long[0]));
      longBuffer.put(written);
    }
    byte[] checksum = digest.digest(buffer.array());
    file.write(checksum);
    buffer.position(0);
    fileChannel.write(buffer);
    fileChannel.force(true);
    syncRequired = false;
  } catch (IOException ex) {
    LOG.error("Error while writing checkpoint to disk.", ex);
    throw ex;
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:57,代碼來源:FlumeEventQueue.java

示例9: toInt

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * 
 * @param myList
 * @return
 */
public static int[] toInt(List<Integer> myList) {
	return ArrayUtils.toPrimitive(myList.toArray(new Integer[myList.size()]));
}
 
開發者ID:smart-facility,項目名稱:calendar-based-microsim,代碼行數:9,代碼來源:ArrayHandler.java


注:本文中的org.apache.commons.lang.ArrayUtils.toPrimitive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。