本文整理汇总了Java中com.carrotsearch.hppc.DoubleArrayList.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleArrayList.toArray方法的具体用法?Java DoubleArrayList.toArray怎么用?Java DoubleArrayList.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.carrotsearch.hppc.DoubleArrayList
的用法示例。
在下文中一共展示了DoubleArrayList.toArray方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readSampleSubsequence
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public static TimeSeries readSampleSubsequence(File dataset) throws IOException {
try (BufferedReader br = new BufferedReader(new FileReader(dataset))) {
DoubleArrayList data = new DoubleArrayList();
String line = null;
while ((line = br.readLine()) != null) {
line = line.trim();
String[] values = line.split("[ \\t]");
if (values.length > 0) {
for (String value : values) {
try {
value = value.trim();
if (isNonEmptyColumn(value)) {
data.add(Double.parseDouble(value));
}
} catch (NumberFormatException nfe) {
// Parse-Exception ignored
}
}
}
}
return new TimeSeries(data.toArray());
}
}
示例2: computeCPFs
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
private void computeCPFs ()
{
isFactorsAdded = true;
DoubleArrayList residTmp = new DoubleArrayList ();
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();
}
示例3: readSparseVector
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
private SparseVector readSparseVector (String str, Alphabet dict) throws IOException
{
IntArrayList idxs = new IntArrayList ();
DoubleArrayList vals = new DoubleArrayList ();
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 ());
}
示例4: ignoretestSample
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public void ignoretestSample ()
{
Variable var = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Factor f = new UniNormalFactor (var, -1.0, 2.0);
DoubleArrayList lst = new DoubleArrayList ();
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);
}
示例5: make3dMatrix
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
private SparseMatrixn make3dMatrix ()
{
int[] sizes = new int[]{2, 3, 4};
IntArrayList idxs = new IntArrayList ();
DoubleArrayList vals = new DoubleArrayList ();
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;
}
示例6: summarize
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
@Override
public double summarize(double[] values, double[] weights) {
if (values.length == 0) {
throw new IllegalArgumentException(
"The given array has to have at least one element to determine the modus.");
}
DoubleArrayList weightedValues = new DoubleArrayList(values.length);
for (int i = 0; i < values.length; ++i) {
if (!Double.isNaN(values[i])) {
weightedValues.add(weights[i] * values[i]);
}
}
if (weightedValues.size() == 0) {
return 0;
}
double weightedValuesAsArray[] = weightedValues.toArray();
Arrays.sort(weightedValuesAsArray);
if ((weightedValuesAsArray.length & 1) > 0) {
return weightedValuesAsArray[weightedValuesAsArray.length / 2];
} else {
return (weightedValuesAsArray[weightedValuesAsArray.length / 2] + weightedValuesAsArray[(weightedValuesAsArray.length / 2) - 1]) / 2.0;
}
}
示例7: retainMass
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public static TableFactor retainMass (DiscreteFactor ptl, double alpha)
{
int[] idxs = new int [ptl.numLocations ()];
double[] vals = new double [ptl.numLocations ()];
for (int i = 0; i < idxs.length; i++) {
idxs[i] = ptl.indexAtLocation (i);
vals[i] = ptl.logValue (i);
}
RankedFeatureVector rfv = new RankedFeatureVector (new Alphabet(), idxs, vals);
IntArrayList idxList = new IntArrayList ();
DoubleArrayList valList = new DoubleArrayList ();
double mass = Double.NEGATIVE_INFINITY;
double logAlpha = Math.log (alpha);
for (int rank = 0; rank < rfv.numLocations (); rank++) {
int idx = rfv.getIndexAtRank (rank);
double val = rfv.value (idx);
mass = Maths.sumLogProb (mass, val);
idxList.add (idx);
valList.add (val);
if (mass > logAlpha) {
break;
}
}
int[] szs = computeSizes (ptl);
SparseMatrixn m = new SparseMatrixn (szs, idxList.toArray (), valList.toArray ());
TableFactor result = new TableFactor (computeVars (ptl));
result.setValues (m);
return result;
}
示例8: checkMeanStd
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
void checkMeanStd (DoubleArrayList ell, double mu, double sigma)
{
double[] vals = ell.toArray ();
double mean1 = MatrixOps.mean (vals);
double std1 = MatrixOps.stddev (vals);
assertEquals (mu, mean1, 0.025);
assertEquals (sigma, std1, 0.01);
}
示例9: testSample
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public void testSample ()
{
Variable var = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Factor f = new BetaFactor (var, 0.7, 0.5);
DoubleArrayList lst = new DoubleArrayList ();
for (int i = 0; i < 100000; i++) {
Assignment assn = f.sample (r);
lst.add (assn.getDouble (var));
}
double[] vals = lst.toArray ();
double mean = MatrixOps.mean (vals);
assertEquals (0.7 / (0.5 + 0.7), mean, 0.01);
}
示例10: testSample2
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public void testSample2 ()
{
Variable var = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Factor f = new BetaFactor (var, 0.7, 0.5, 3.0, 8.0);
DoubleArrayList lst = new DoubleArrayList ();
for (int i = 0; i < 100000; i++) {
Assignment assn = f.sample (r);
lst.add (assn.getDouble (var));
}
double[] vals = lst.toArray ();
double mean = MatrixOps.mean (vals);
assertEquals (5.92, mean, 0.01);
}
示例11: ignoretestSample
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public void ignoretestSample ()
{
Variable var = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Factor f = new UniformFactor (var, -1.0, 1.5);
DoubleArrayList lst = new DoubleArrayList ();
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);
assertEquals (0.25, mean, 0.01);
}
示例12: readGoldStandard
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public static double[] readGoldStandard(String file) throws IOException {
List<String> lines = FileUtils.readLines(new File(file));
DoubleArrayList ratings = new DoubleArrayList();
for (String line : lines) {
try {
ratings.add(Double.parseDouble(line));
} catch (NumberFormatException e) {
throw new IOException("Error while reading gold standard.", e);
}
}
return ratings.toArray();
}