/** * @param _d le tableau a moyenne * @return la moyenne des valeurs du tableau _d. "0" si null ou vide */ public static double getMoyenne(final TDoubleArrayList _d) { if (_d == null || _d.size() == 0) { return 0; } double r = 0; for (int i = _d.size() - 1; i >= 0; i--) { r += _d.getQuick(i); } return r / _d.size(); }
/** * Compares this list to another list, value by value. * * @param other the object to compare against * @return true if other is a TDoubleArrayList and has exactly the * same values. */ public boolean equals(Object other) { if (other == this) { return true; } else if (other instanceof TDoubleArrayList) { TDoubleArrayList that = (TDoubleArrayList)other; if (that.size() != this.size()) { return false; } else { for (int i = _pos; i-- > 0;) { if (this._data[i] != that._data[i]) { return false; } } return true; } } else { return false; } }
public int getNbValues() { return (val_ == null || t_ == null) ? 0 : Math.min(t_.length, val_.size()); }
/** * Finds the maximum value in the list. * * @return the largest value in the list. * @exception IllegalStateException if the list is empty */ public double max() { if (size() == 0) { throw new IllegalStateException("cannot find maximum of an empty list"); } double max = _data[_pos - 1]; for (int i = _pos - 1; i-- > 0;) { max = Math.max(max, _data[_pos]); } return max; }
/** * Finds the minimum value in the list. * * @return the smallest value in the list. * @exception IllegalStateException if the list is empty */ public double min() { if (size() == 0) { throw new IllegalStateException("cannot find minimum of an empty list"); } double min = _data[_pos - 1]; for (int i = _pos - 1; i-- > 0;) { min = Math.min(min, _data[_pos]); } return min; }
public GISCoordinateSequence(final TDoubleArrayList _l) { super(_l.toNativeArray(), 3); if (_l.size() % 3 != 0) { throw new IllegalArgumentException("size must be a multiple of 3"); } }
/** * Suppose que les x sont donnees dans l'ordre croissant et renvoie donc le premier x . * * @return la valeur min de x. */ public double getMinX() { return (t_.size() == 0) ? 0 : t_.getQuick(0); }
/** * Suppose que les x sont donnees dans l'ordre croissant et renvoie donc le x au dernier indice. * * @return la valeur max. */ public double getMaxX() { final int n = t_.size() - 1; return n < 0 ? 0 : t_.getQuick(n); }
public void write(String outDir, CotrainOutputData data) throws Exception { java.io.File f = new java.io.File(outDir); f.mkdirs(); String fname = outDir + Os.pathSeparator() + "cotraining.db"; DataOutputStream os = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(fname))); os.writeInt(data.catsThreshold.size()); for (int i = 0; i < data.catsThreshold.size(); i++) { os.writeDouble(data.catsThreshold.get(i)); } // Close the stream. os.close(); }
/** * @param _l la liste a parcourir * @param _r l'intervalle qui contiendra le min,max */ public static final void getRangeFor(final TDoubleArrayList _l, final CtuluRange _r) { if (_l.size() <= 0) { _r.max_ = 0; _r.min_ = 0; } else { _r.max_ = _l.getQuick(0); _r.min_ = _r.max_; for (int i = _l.size() - 1; i > 0; i--) { _r.expandTo(_l.getQuick(i)); } } }
/** * Permet d'enlever plusieurs indices d'un tableau. Les anciennes valeurs peuvent etre enregistree. Attention, si un * index n'est pas correct cela peut tout fausser. * * @param _init le tableau a modifier * @param _sortedIdx les indices a enlever donner dans l'ordre * @param _removedValues le tableau qui va contenir (si non null et si de meme taille qui _init) les valeurs enlevees. * @return true si toutes les valeurs */ public static boolean removeIdx(final TDoubleArrayList _init, final int[] _sortedIdx, final double[] _removedValues) { if (_init == null) { return false; } final int n = _init.size(); final double[] newValues = new double[n]; int idx = 0; if (_removedValues != null) { final boolean addOld = _removedValues.length == _sortedIdx.length; int idxOld = 0; for (int i = 0; i < n; i++) { if (Arrays.binarySearch(_sortedIdx, i) < 0) { newValues[idx++] = _init.getQuick(i); } else if (addOld) { _removedValues[idxOld++] = _init.getQuick(i); } } } _init.clear(); _init.add(newValues, 0, idx); // true si les tailles concordent return n == _sortedIdx.length + _init.size(); }
public ClassificationResult computeScore(KnnCommitteeClassifier cl, Vector<ClassificationResult> results, IIndex testIndex, int docID) { if (results.size() != _matrixes.size()) throw new RuntimeException("The number of matrixes and classifiers must be the same"); ClassificationResult cr = new ClassificationResult(); cr.documentID = docID; for (int i = 0; i < results.get(0).categoryID.size(); i++) { cr.categoryID.add(results.get(0).categoryID.get(i)); cr.score.add(0); } for (int i = 0; i < results.size(); i++) { ClassificationResult res = results.get(i); for (int j = 0; j < res.score.size(); j++) { double val = cr.score.get(j) + (res.score.get(j) * _matrixes.get(i).getWeight(res.categoryID.get(j), docID, 0)); res.score.set(j, val); } } return cr; }
/** * Compare les X de cette evolution avec <code>_toCompare</code>. Si les x sont diffrents renvoie false et stocke * dans <code>_commonX</code> l'union des valeurs des x. * * @param _toCompare l'evolution a comparer * @param _commonX la liste a remplir avec l'union des x des 2 evolutions si differentes * @return true si identique */ public boolean isEvolutionWithSameX(final EvolutionReguliere _toCompare, final TDoubleHashSet _commonX) { if (_toCompare == null) { return false; } if (t_.equals(_toCompare.t_)) { return true; } if (_commonX != null) { _commonX.ensureCapacity(t_.size() + _toCompare.t_.size()); _commonX.addAll(t_.toNativeArray()); _commonX.addAll(_toCompare.t_.toNativeArray()); } return false; }
private int[] checkIdx(final int[] _idx) { if (CtuluLibArray.isEmpty(_idx)) { return _idx; } final TIntArrayList r = new TIntArrayList(_idx.length); final int max = t_ == null ? 0 : t_.size(); for (int i = 0; i < _idx.length; i++) { final int test = _idx[i]; if (test >= 0 && test < max) { r.add(test); } } return r.toNativeArray(); }
/** * Le x est ajoute et l'ordre des x est conserve. * * @param _x le x ajouter * @param _y le y correspondant */ void put(final double _x, final double _y) { if (t_.size() == 0) { t_.add(_x); val_.add(_y); } else { int k = t_.binarySearch(_x); if (k < 0) { k = -k; if (k > t_.size()) { t_.add(_x); val_.add(_y); } else { t_.insert(k - 1, _x); val_.insert(k - 1, _y); } } else { val_.set(k, _y); } } }
public static double[][] getCorrectValue(final String[][] _values, final CtuluDoubleParser _parser) { final int nbValues = _values.length; if (nbValues == 0) { return null; } final int nbLine = _values[0].length; final TDoubleArrayList[] newValues = new TDoubleArrayList[nbValues]; for (int i = 0; i < nbValues; i++) { newValues[i] = new TDoubleArrayList(nbLine); } for (int j = 0; j < nbLine; j++) { boolean ok = true; for (int i = 0; i < nbValues && ok; i++) { ok = _parser.isValid(_values[i][j]); } if (ok) { for (int k = nbValues - 1; k >= 0; k--) { newValues[k].add(_parser.parse(_values[k][j])); } } } final double[][] res = new double[nbValues][newValues[0].size()]; for (int k = nbValues - 1; k >= 0; k--) { res[k] = newValues[k].toNativeArray(); } return res; }
public ClassificationResult classify(IIndex testIndex, int docID) { ClassificationResult bagres = new ClassificationResult(); bagres.documentID = docID; for (int i = 0; i < _classifiers.length; ++i) { ClassificationResult res = _classifiers[i].classify(testIndex, docID); if (bagres.categoryID.size() == 0) { for (int j = 0; j < res.categoryID.size(); ++j) { bagres.categoryID.add(res.categoryID.getQuick(j)); bagres.score.add(0); } } for (int j = 0; j < res.score.size(); ++j) { bagres.score.setQuick(j, bagres.score.getQuick(j) + res.score.getQuick(j)); } } for (int j = 0; j < bagres.score.size(); ++j) { bagres.score.setQuick(j, bagres.score.getQuick(j) / _classifiers.length); } return bagres; }
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(); }