本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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[] {}));
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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()]));
}