本文整理汇总了Java中gnu.trove.TDoubleArrayList类的典型用法代码示例。如果您正苦于以下问题:Java TDoubleArrayList类的具体用法?Java TDoubleArrayList怎么用?Java TDoubleArrayList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TDoubleArrayList类属于gnu.trove包,在下文中一共展示了TDoubleArrayList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
public void read(String inputDir, CotrainOutputData data) throws Exception {
java.io.File f = new java.io.File(inputDir);
if (!f.exists())
throw new FileNotFoundException("The input directory " + inputDir
+ " does not exist!");
String fname = inputDir + Os.pathSeparator() + "cotraining.db";
DataInputStream is = new DataInputStream(
new java.io.BufferedInputStream(new FileInputStream(fname)));
data.catsThreshold = new TDoubleArrayList();
int numCats = is.readInt();
for (int i = 0; i < numCats; i++) {
double threshold = is.readDouble();
data.catsThreshold.add(threshold);
}
is.close();
}
示例2: testSample
import gnu.trove.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));
}
示例3: testSample
import gnu.trove.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.toNativeArray ();
double mean = MatrixOps.mean (vals);
double std = MatrixOps.stddev (vals);
assertEquals (-1.0, mean, 0.025);
assertEquals (Math.sqrt(2.0), std, 0.01);
}
示例4: createDirectedModel
import gnu.trove.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.toNativeArray ()), vars[2]));
return mdl;
}
示例5: make3dMatrix
import gnu.trove.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.toNativeArray (), vals.toNativeArray ());
return a;
}
示例6: readDoubleArray
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
public static double[] readDoubleArray(JsonReaderEx reader) {
checkIsNull(reader, null);
reader.beginArray();
if (!reader.hasNext()) {
reader.endArray();
return new double[]{0};
}
TDoubleArrayList result = new TDoubleArrayList();
do {
result.add(reader.nextDouble());
}
while (reader.hasNext());
reader.endArray();
return result.toNativeArray();
}
示例7: classify
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
protected double classify()
{
int numCorrect = 0;
for (int j = 0; j < m_trainingData.size(); j++)
{
TDoubleArrayList currDatum = m_trainingData.get(j);
// classify using current weights
double pos = generateTestVal(currDatum);
pos = new LDouble(pos).exponentiate();
if ((pos >= 0.5 && m_trainingLabels.get(j) == 1) || (pos < 0.5 && m_trainingLabels.get(j) == 0)) {
numCorrect++;
}
}
double acc = ((double)numCorrect) / ((double)m_trainingData.size());
System.out.println("Train: " + numCorrect + " / " + m_trainingData.size() + " = " + acc);
return acc;
}
示例8: classifyDev
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
protected double classifyDev()
{
int numCorrect = 0;
for (int j = 0; j < m_devData.size(); j++) {
TDoubleArrayList currDatum = m_devData.get(j);
// classify using current weights
double pos = generateTestVal(currDatum);
pos = new LDouble(pos).exponentiate();
if ((pos >= 0.5 && m_devLabels.get(j) == 1) || (pos < 0.5 && m_devLabels.get(j) == -1)) {
numCorrect++;
}
}
double acc = ((double)numCorrect) / ((double)m_devData.size());
System.out.println("Dev: " + numCorrect + " / " + m_devData.size() + " = " + acc);
return acc;
}
示例9: classifyTest
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
protected double classifyTest()
{
int numCorrect = 0;
for (int j = 0; j < m_testData.size(); j++) {
TDoubleArrayList currDatum = m_testData.get(j);
// classify using current weights
double pos = generateTestVal(currDatum);
pos = new LDouble(pos).exponentiate();
if ((pos >= 0.5 && m_testLabels.get(j) == 1) || (pos < 0.5 && m_testLabels.get(j) == -1)) {
numCorrect++;
}
}
double acc = ((double)numCorrect) / ((double)m_testData.size());
System.out.println("Test: " + numCorrect + " / " + m_testData.size() + " = " + acc);
return acc;
}
示例10: classifyRavine
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
public double classifyRavine(String outputFile)
{
setParametersWhileTest(outputFile);
int correct = 0;
for (int j = 0; j < m_testData.size(); j++) {
TDoubleArrayList currDatum = m_testData.get(j);
// classify using current weights
double pos = generateTestVal(currDatum);
pos = new LDouble(pos).exponentiate();
System.out.println(pos);
if(pos>=0.5&&m_testLabels.get(j)==1)
correct++;
if(pos<0.5&&m_testLabels.get(j)==-1)
correct++;
}
double acc = (double)correct/m_testData.size();
System.out.println("Accuracy="+acc);
return 0;
}
示例11: initializeParameterIndexes
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
protected void initializeParameterIndexes() {
A = new Alphabet();
V = new LDouble[PARAMETER_TABLE_INITIAL_CAPACITY];
G = new LDouble[PARAMETER_TABLE_INITIAL_CAPACITY];
m_trainingData = new ArrayList<TDoubleArrayList>(1000);
m_trainingLabels = new TIntArrayList(1000);
m_testData = new ArrayList<TDoubleArrayList>(100);
m_testLabels = new TIntArrayList(100);
m_devData = new ArrayList<TDoubleArrayList>(100);
m_devLabels = new TIntArrayList(100);
savedValues = new TObjectDoubleHashMap<String>(1000);
m_savedFormulas = new ArrayList<LogFormula>(FORMULA_LIST_INITIAL_CAPACITY);
m_current = 0;
m_savedLLFormulas = new ArrayList<LazyLookupLogFormula>(LLFORMULA_LIST_INITIAL_CAPACITY);
m_llcurrent = 0;
mLookupChart = new THashMap<Integer,LogFormula>(PARAMETER_TABLE_INITIAL_CAPACITY);
}
示例12: computeVariance
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
public ClassificationResult computeVariance(IIndex index, int doc) {
ClassificationResult bagres = new ClassificationResult();
bagres.documentID = doc;
double[] avg = null;
TDoubleArrayList[] values = null;
for (int i = 0; i < _classifiers.length; ++i) {
ClassificationResult res = _classifiers[i].classify(index, doc);
if (bagres.categoryID.size() == 0) {
avg = new double[res.categoryID.size()];
values = new TDoubleArrayList[res.categoryID.size()];
for (int j = 0; j < res.categoryID.size(); ++j) {
bagres.categoryID.add(res.categoryID.getQuick(j));
bagres.score.add(0);
avg[j] = 0;
values[j] = new TDoubleArrayList();
}
}
for (int j = 0; j < res.score.size(); ++j) {
double value = res.score.getQuick(j);
values[j].add(value);
avg[j] += value;
}
}
for (int j = 0; j < bagres.score.size(); ++j) {
avg[j] /= _classifiers.length;
}
for (int j = 0; j < bagres.score.size(); ++j) {
for (int i = 0; i < values[j].size(); ++i) {
bagres.score.setQuick(j, bagres.score.getQuick(j) + Math.pow(avg[j] - values[j].getQuick(i), 2.0));
}
}
return bagres;
}
示例13: retainMass
import gnu.trove.TDoubleArrayList; //导入依赖的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);
TIntArrayList idxList = new TIntArrayList ();
TDoubleArrayList valList = new TDoubleArrayList ();
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.toNativeArray (), valList.toNativeArray ());
TableFactor result = new TableFactor (computeVars (ptl));
result.setValues (m);
return result;
}
示例14: checkMeanStd
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
void checkMeanStd (TDoubleArrayList ell, double mu, double sigma)
{
double[] vals = ell.toNativeArray ();
double mean1 = MatrixOps.mean (vals);
double std1 = MatrixOps.stddev (vals);
assertEquals (mu, mean1, 0.025);
assertEquals (sigma, std1, 0.01);
}
示例15: testSample
import gnu.trove.TDoubleArrayList; //导入依赖的package包/类
public void testSample ()
{
Variable var = new Variable (Variable.CONTINUOUS);
Randoms r = new Randoms (2343);
Factor f = new BetaFactor (var, 0.7, 0.5);
TDoubleArrayList lst = new TDoubleArrayList ();
for (int i = 0; i < 100000; i++) {
Assignment assn = f.sample (r);
lst.add (assn.getDouble (var));
}
double[] vals = lst.toNativeArray ();
double mean = MatrixOps.mean (vals);
assertEquals (0.7 / (0.5 + 0.7), mean, 0.01);
}