gnu.trove.TDoubleArrayList Java Examples
The following examples show how to use
gnu.trove.TDoubleArrayList.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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; }
Example #2
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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; }
Example #3
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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; }
Example #4
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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; }
Example #5
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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; }
Example #6
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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); }
Example #7
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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; }
Example #8
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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; }
Example #9
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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; }
Example #10
Source File: CoTrainerDataManager.java From jatecs with GNU General Public License v3.0 | 6 votes |
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(); }
Example #11
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
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); }
Example #12
Source File: AbstractProgressIndicatorBase.java From consulo with Apache License 2.0 | 6 votes |
public void initStateFrom(@Nonnull final ProgressIndicator indicator) { synchronized (getLock()) { myRunning = indicator.isRunning(); myCanceled = indicator.isCanceled(); myFraction = indicator.getFraction(); myIndeterminate = indicator.isIndeterminate(); myText = indicator.getText(); myText2 = indicator.getText2(); myFraction = indicator.getFraction(); if (indicator instanceof AbstractProgressIndicatorBase) { AbstractProgressIndicatorBase stacked = (AbstractProgressIndicatorBase)indicator; myTextStack = stacked.myTextStack == null ? null : new Stack<>(stacked.getTextStack()); myText2Stack = stacked.myText2Stack == null ? null : new Stack<>(stacked.getText2Stack()); myFractionStack = stacked.myFractionStack == null ? null : new TDoubleArrayList(stacked.getFractionStack().toNativeArray()); } dontStartActivity(); } }
Example #13
Source File: BaggingClassifier.java From jatecs with GNU General Public License v3.0 | 5 votes |
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; }
Example #14
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
private double generateTestVal(TDoubleArrayList datum) { m_current = 0; m_llcurrent = 0; LogFormula epower = getFormulaObject(LogFormula.Op.EXP); LogFormula featweightsum1 = getFormulaObject(LogFormula.Op.PLUS); for (int i = 0; i < datum.size(); i++) { LogFormula featweight1 = getFormulaObject(LogFormula.Op.TIMES); int paramId = A.getInt("param_"+i); LogFormula formula = getLazyLookupFormulaObjectCustom(paramId,"param_"+i); featweight1.add_arg(formula); featweight1.add_arg(getFormulaObject(LDouble.convertToLogDomain(datum.get(i)))); featweightsum1.add_arg(featweight1); } epower.add_arg(featweightsum1); LogFormula logpart = getFormulaObject(LogFormula.Op.LOG); LogFormula logsum = getFormulaObject(LogFormula.Op.PLUS); logsum.add_arg(getFormulaObject(IdentityElement.TIMES_IDENTITY)); logsum.add_arg(epower); logpart.add_arg(logsum); LogFormula ret = getFormulaObject(LogFormula.Op.PLUS); LogFormula term2 = getFormulaObject(LogFormula.Op.TIMES); term2.add_arg(getFormulaObject(LDouble.convertToLogDomain(-1.0))); term2.add_arg(logpart); ret.add_arg(featweightsum1); ret.add_arg(term2); return ret.evaluate(this).exponentiate(); }
Example #15
Source File: LogLogisticRegressionModel.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
private double generateTestVal(TDoubleArrayList datum) { m_current = 0; m_llcurrent = 0; LogFormula epower = getFormulaObject(LogFormula.Op.EXP); LogFormula featweightsum1 = getFormulaObject(LogFormula.Op.PLUS); for (int i = 0; i < datum.size(); i++) { LogFormula featweight1 = getFormulaObject(LogFormula.Op.TIMES); int paramId = A.getInt("param_"+i); LogFormula formula = getLazyLookupFormulaObjectCustom(paramId,"param_"+i); featweight1.add_arg(formula); featweight1.add_arg(getFormulaObject(LDouble.convertToLogDomain(datum.get(i)))); featweightsum1.add_arg(featweight1); } epower.add_arg(featweightsum1); LogFormula logpart = getFormulaObject(LogFormula.Op.LOG); LogFormula logsum = getFormulaObject(LogFormula.Op.PLUS); logsum.add_arg(getFormulaObject(IdentityElement.TIMES_IDENTITY)); logsum.add_arg(epower); logpart.add_arg(logsum); LogFormula ret = getFormulaObject(LogFormula.Op.PLUS); LogFormula term2 = getFormulaObject(LogFormula.Op.TIMES); term2.add_arg(getFormulaObject(LDouble.convertToLogDomain(-1.0))); term2.add_arg(logpart); ret.add_arg(featweightsum1); ret.add_arg(term2); return ret.evaluate(this).exponentiate(); }
Example #16
Source File: AbstractProgressIndicatorBase.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private TDoubleArrayList getFractionStack() { TDoubleArrayList stack = myFractionStack; if (stack == null) myFractionStack = stack = new TDoubleArrayList(2); return stack; }
Example #17
Source File: TroveWeightingDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeFeatures(IIntIterator removedFeatures) { for (int i = 0; i < _documentsWeights.size(); ++i) { TIntDoubleHashMap weigs = _documentsWeights.get(i); TIntArrayList feats = new TIntArrayList(weigs.size()); TDoubleArrayList weigths = new TDoubleArrayList(weigs.size()); TIntDoubleIterator wit = weigs.iterator(); while (wit.hasNext()) { wit.advance(); feats.add(wit.key()); weigths.add(wit.value()); } int j = 0; int shift = 0; int feat; int rem; if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); while (true) { if (feat == rem) { feats.remove(j); weigths.remove(j); if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); ++shift; } else break; } else if (feat > rem) { if (removedFeatures.hasNext()) { rem = removedFeatures.next(); ++shift; } else break; } else { feats.setQuick(j, feat - shift); ++j; if (j < feats.size()) feat = feats.getQuick(j); else break; } } ++shift; } while (j < feats.size()) { feats.setQuick(j, feats.getQuick(j) - shift); ++j; } weigs.clear(); for (j = 0; j < feats.size(); ++j) weigs.put(feats.getQuick(j), weigths.getQuick(j)); removedFeatures.begin(); } }
Example #18
Source File: ClassificationResult.java From jatecs with GNU General Public License v3.0 | 4 votes |
public ClassificationResult(int size) { categoryID = new TShortArrayList(); categoryID.ensureCapacity(size); score = new TDoubleArrayList(); score.ensureCapacity(size); }
Example #19
Source File: ClassificationResult.java From jatecs with GNU General Public License v3.0 | 4 votes |
public ClassificationResult() { categoryID = new TShortArrayList(); score = new TDoubleArrayList(); }
Example #20
Source File: Centroid.java From jatecs with GNU General Public License v3.0 | 4 votes |
public Centroid(int numFeatures) { features = new double[numFeatures]; documents = new TIntArrayList(); distances = new TDoubleArrayList(); }
Example #21
Source File: ClusterDescriptor.java From jatecs with GNU General Public License v3.0 | 4 votes |
public ClusterDescriptor() { description = ""; documents = new TIntArrayList(); distance = new TDoubleArrayList(); }