本文整理汇总了Java中com.carrotsearch.hppc.DoubleArrayList.add方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleArrayList.add方法的具体用法?Java DoubleArrayList.add怎么用?Java DoubleArrayList.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.carrotsearch.hppc.DoubleArrayList
的用法示例。
在下文中一共展示了DoubleArrayList.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: readSamplesQuerySeries
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public static TimeSeries[] readSamplesQuerySeries(File dataset) throws IOException {
List<TimeSeries> samples = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(dataset))) {
String line = null;
while ((line = br.readLine()) != null) {
DoubleArrayList data = new DoubleArrayList();
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
}
}
samples.add(new TimeSeries(data.toArray()));
}
}
}
return samples.toArray(new TimeSeries[]{});
}
示例3: 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();
}
示例4: 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 ());
}
示例5: ignoretestSample
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public void ignoretestSample ()
{
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);
DoubleArrayList v1lst = new DoubleArrayList ();
DoubleArrayList v2lst = new DoubleArrayList ();
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));
}
示例6: 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);
}
示例7: createDirectedModel
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的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);
DoubleArrayList pC = new DoubleArrayList (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;
}
示例8: 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;
}
示例9: 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;
}
}
示例10: 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;
}
示例11: 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);
}
示例12: 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);
}
示例13: 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);
}
示例14: 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();
}
示例15: populateWeights
import com.carrotsearch.hppc.DoubleArrayList; //导入方法依赖的package包/类
public void populateWeights()
{
int i, size = s_values.size();
b_weight = true;
d_weights = new DoubleArrayList();
for (i=0; i<size; i++)
d_weights.add(1d);
}