当前位置: 首页>>代码示例>>Java>>正文


Java HashBag类代码示例

本文整理汇总了Java中org.apache.commons.collections4.bag.HashBag的典型用法代码示例。如果您正苦于以下问题:Java HashBag类的具体用法?Java HashBag怎么用?Java HashBag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HashBag类属于org.apache.commons.collections4.bag包,在下文中一共展示了HashBag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: predict

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * 
 * @return {@code null} if there are no neighbors in the dataset, the majority vote of the
 *         nearest neighbors otherwise and in the case of a tie, it returns the first result
 *         which reached that number of votes
 * @throws PredictionFailedException if the {@code instanceParameter} was not a
 *            {@link BaselearnerInstance}
 */
@Override
public Double predict(IInstance<?, ?, ?> instanceParameter) throws PredictionFailedException {
   assertInstanceHasCorrectType(instanceParameter, BaselearnerInstance.class);
   BaselearnerInstance instance = (BaselearnerInstance) instanceParameter;
   List<VectorDistanceTuple<Double>> neighbors;
   neighbors = kdTree.getNearestNeighbours(new DenseDoubleVector(instance.getContextFeatureVector()), k);

   logger.debug(FOUND_NEIGHBORS, neighbors.toString());
   Bag<Double> voteBag = new HashBag<>();
   for (VectorDistanceTuple<Double> pair : neighbors) {
      Double vote = pair.getValue();
      voteBag.add(vote);
   }

   logger.debug(VOTES, voteBag.toString());
   Double result = null;
   int winningCount = 0;
   for (Double object : voteBag.uniqueSet()) {
      if (voteBag.getCount(object) > winningCount) {
         winningCount = voteBag.getCount(object);
         result = object;
      }
   }
   return result;
}
 
开发者ID:Intelligent-Systems-Group,项目名称:jpl-framework,代码行数:35,代码来源:KNearestNeighborLearningModel.java

示例2: main

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
public static void main(String[] args) {
    // Parse text to separate words
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Create Multiset
    Bag bag = SynchronizedBag.synchronizedBag(new HashBag(Arrays.asList(INPUT_TEXT.split(" "))));

    // Print count words
    System.out.println(bag); // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders
    // Print all unique words
    System.out.println(bag.uniqueSet());    // print [Hi, Hello, World!, All!] - in random orders

    // Print count occurrences of words
    System.out.println("Hello = " + bag.getCount("Hello"));    // print 2
    System.out.println("World = " + bag.getCount("World!"));    // print 2
    System.out.println("All = " + bag.getCount("All!"));    // print 1
    System.out.println("Hi = " + bag.getCount("Hi"));    // print 1
    System.out.println("Empty = " + bag.getCount("Empty"));    // print 0

    // Print count all words
    System.out.println(bag.size());    //print 6

    // Print count unique words
    System.out.println(bag.uniqueSet().size());    //print 4
}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:25,代码来源:ApacheSynchronizedBagTest.java

示例3: main

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
public static void main(String[] args) {
    // Parse text to separate words
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Create Multiset
    Bag bag = new HashBag(Arrays.asList(INPUT_TEXT.split(" ")));

    // Print count words
    System.out.println(bag); // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders
    // Print all unique words
    System.out.println(bag.uniqueSet());    // print [Hi, Hello, World!, All!] - in random orders

    // Print count occurrences of words
    System.out.println("Hello = " + bag.getCount("Hello"));    // print 2
    System.out.println("World = " + bag.getCount("World!"));    // print 2
    System.out.println("All = " + bag.getCount("All!"));    // print 1
    System.out.println("Hi = " + bag.getCount("Hi"));    // print 1
    System.out.println("Empty = " + bag.getCount("Empty"));    // print 0

    // Print count all words
    System.out.println(bag.size());    //print 6

    // Print count unique words
    System.out.println(bag.uniqueSet().size());    //print 4
}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:25,代码来源:ApacheHashBagTest.java

示例4: main

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
public static void main(String[] args) {
    // Разберем текст на слова
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Создаем Multiset
    Bag bag = SynchronizedBag.synchronizedBag(new HashBag(Arrays.asList(INPUT_TEXT.split(" "))));

    // Выводим кол-вом вхождений слов
    System.out.println(bag); // напечатает [1:Hi,2:Hello,2:World!,1:All!] - в произвольном порядке
    // Выводим все уникальные слова
    System.out.println(bag.uniqueSet());    // напечатает [Hi, Hello, World!, All!] - в произвольном порядке

    // Выводим количество по каждому слову
    System.out.println("Hello = " + bag.getCount("Hello"));    // напечатает 2
    System.out.println("World = " + bag.getCount("World!"));    // напечатает 2
    System.out.println("All = " + bag.getCount("All!"));    // напечатает 1
    System.out.println("Hi = " + bag.getCount("Hi"));    // напечатает 1
    System.out.println("Empty = " + bag.getCount("Empty"));    // напечатает 0

    // Выводим общее количества всех слов в тексте
    System.out.println(bag.size());    //напечатает 6

    // Выводим общее количество всех уникальных слов
    System.out.println(bag.uniqueSet().size());    //напечатает 4
}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:25,代码来源:ApacheSynchronizedBagTest.java

示例5: main

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
public static void main(String[] args) {
    // Разберем текст на слова
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Создаем Multiset
    Bag bag = new HashBag(Arrays.asList(INPUT_TEXT.split(" ")));

    // Выводим кол-вом вхождений слов
    System.out.println(bag); // напечатает [1:Hi,2:Hello,2:World!,1:All!] - в произвольном порядке
    // Выводим все уникальные слова
    System.out.println(bag.uniqueSet());    // напечатает [Hi, Hello, World!, All!] - в произвольном порядке

    // Выводим количество по каждому слову
    System.out.println("Hello = " + bag.getCount("Hello"));    // напечатает 2
    System.out.println("World = " + bag.getCount("World!"));    // напечатает 2
    System.out.println("All = " + bag.getCount("All!"));    // напечатает 1
    System.out.println("Hi = " + bag.getCount("Hi"));    // напечатает 1
    System.out.println("Empty = " + bag.getCount("Empty"));    // напечатает 0

    // Выводим общее количества всех слов в тексте
    System.out.println(bag.size());    //напечатает 6

    // Выводим общее количество всех уникальных слов
    System.out.println(bag.uniqueSet().size());    //напечатает 4
}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:25,代码来源:ApacheHashBagTest.java

示例6: displayCategoryConceptDistribution

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
/**
 * find category articles distribution, each output line like the following format:
 * [article count] \t [the category count which contains this specified article count]
 */
public void displayCategoryConceptDistribution() throws MissedException {
    Collection<String> categories = listNames();
    Bag<Integer> catDistBag = new HashBag<>();

    ProgressCounter counter = new ProgressCounter();
    for (String c : categories) {
        counter.increment();
        int articleCount = getConceptCount(getIdByName(c));
        catDistBag.add(articleCount);
    }

    for (int key: catDistBag.uniqueSet()) {
        System.out.println(key + "\t" + catDistBag.getCount(key));
    }
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:20,代码来源:CategoryTreeGraphRedisImpl.java

示例7: displayCategoryArticlesDistribution

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
/**
 * find category articles distribution, each output line like the following format:
 * [article count] \t [the category count which contains this specified article count]
 */
public void displayCategoryArticlesDistribution() throws MissedException {
    Collection<String> categories = listNames();
    Bag<Integer> catDistBag = new HashBag<>();

    ProgressCounter counter = new ProgressCounter();
    for (String c : categories) {
        counter.increment();
        int articleCount = getArticleCount(getIdByName(c));
        catDistBag.add(articleCount);
    }

    for (int key: catDistBag.uniqueSet()) {
        System.out.println(key + "\t" + catDistBag.getCount(key));
    }
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:20,代码来源:CategoryCacheRedisImpl.java

示例8: expand

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
private Bag<State> expand(Bag<State> input, Event event, int g, boolean forward) {
	TransitionSystem ts = utility.getTransitionSystem();
	Bag<State> result = new HashBag<State>();

	for (State state : ts.getNodes()) {
		int increment = 0;
		for (Arc arc : forward ? state.getPostsetEdges() : state.getPresetEdges()) {
			if (arc.getEvent().equals(event)) {
				int value = getGradient(input, arc) - g;
				if (!forward)
					value = -value;
				if (value > increment)
					increment = value;
			}
		}
		result.add(state, input.getCount(state) + increment);
	}

	return result;
}
 
开发者ID:CvO-Theory,项目名称:apt,代码行数:21,代码来源:KBoundedSeparation.java

示例9: addExcitationAndSwitchingRegions

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
/**
 * Add the excitation and switching regions of each event to the given collection.
 * The excitation region of an event e is the (multi)set of states in which it is enabled. Analogously, the
 * switching region is the (multi)set of states reached by some arc with label e.
 */
private void addExcitationAndSwitchingRegions(Collection<Bag<State>> result) {
	TransitionSystem ts = utility.getTransitionSystem();
	for (Event event : ts.getAlphabetEvents()) {
		Set<State> excitation = new HashSet<>();
		Set<State> switching = new HashSet<>();

		for (Arc arc : ts.getEdges()) {
			if (arc.getEvent().equals(event)) {
				excitation.add(arc.getSource());
				switching.add(arc.getTarget());
			}
		}

		debugFormat("For event %s, excitation=%s and switching=%s", event, excitation, switching);

		if (!excitation.isEmpty())
			result.add(new HashBag<>(excitation));
		if (!switching.isEmpty())
			result.add(new HashBag<>(switching));
	}
}
 
开发者ID:CvO-Theory,项目名称:apt,代码行数:27,代码来源:KBoundedSeparation.java

示例10: getPeers

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
public Iterable<Node> getPeers(int k) {
	if (this.partialView.size() == k || k == Integer.MAX_VALUE) {
		return this.getPeers();
	} else {
		HashBag<Node> sample = new HashBag<Node>();
		ArrayList<Node> clone = new ArrayList<Node>(this.partialView);
		while (sample.size() < Math.min(k, this.partialView.size())) {
			int rn = CommonState.r.nextInt(clone.size());
			sample.add(clone.get(rn));
			clone.remove(rn);
		}
		return sample;
	}
}
 
开发者ID:Chat-Wane,项目名称:peersim-pcbroadcast,代码行数:15,代码来源:PartialView.java

示例11: clone

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
@Override
public SprayPartialView clone() {
	SprayPartialView spv = new SprayPartialView();
	spv.partialView = new HashBag<Node>(this.partialView);
	spv.ages = new HashMap<Node, Integer>(this.ages);
	return spv;
}
 
开发者ID:Chat-Wane,项目名称:peersim-pcbroadcast,代码行数:8,代码来源:SprayPartialView.java

示例12: BiSpray

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
public BiSpray(String prefix) {
	super(prefix);

	BiSpray.listener = Configuration.getPid(prefix + "." + BiSpray.PAR_LISTENER, -1);

	this.inview = new HashBag<Node>();
	this.outview = new HashBag<Node>();
}
 
开发者ID:Chat-Wane,项目名称:peersim-pcbroadcast,代码行数:9,代码来源:BiSpray.java

示例13: getValuesAsBag

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
/**
 * Gets a Bag from <code>MultiValuedMap</code> in a null-safe manner.
 *
 * @param <K> the key type
 * @param <V> the value type
 * @param map  the {@link MultiValuedMap} to use
 * @param key  the key to look up
 * @return the Collection in the {@link MultiValuedMap} as Bag, or null if input map is null
 */
public static <K, V> Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key) {
    if (map != null) {
        Collection<V> col = map.get(key);
        if (col instanceof Bag) {
            return (Bag<V>) col;
        }
        return new HashBag<V>(col);
    }
    return null;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:20,代码来源:MultiMapUtils.java

示例14: IncrementalSemanticsWidget

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
private IncrementalSemanticsWidget(Map<Predicate, Proposition> propositions, int timestamp, boolean fullSentence)
{
    this.propositions = propositions;
    predicatesWithSense = new HashSet<Predicate>();
    predicates = new HashSet<String>();
    argWords = new HashBag<String>();
    argRoles = new HashSet<Pair<Integer, Argument>>();
    incompleteArcs = new HashBag<String>();
    this.timestamp = timestamp;
    this.fullSentence = fullSentence;
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:12,代码来源:IncrementalSemanticsWidget.java

示例15: cardinality_add2167

import org.apache.commons.collections4.bag.HashBag; //导入依赖的package包/类
@Test(timeout = 1000)
public void cardinality_add2167() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "cardinality_add2167");
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6613,null,6612,org.apache.commons.collections4.CollectionUtils.cardinality(1, iterableA));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6615,null,6614,org.apache.commons.collections4.CollectionUtils.cardinality(2, iterableA));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6617,null,6616,org.apache.commons.collections4.CollectionUtils.cardinality(3, iterableA));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6619,null,6618,org.apache.commons.collections4.CollectionUtils.cardinality(4, iterableA));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6621,null,6620,org.apache.commons.collections4.CollectionUtils.cardinality(5, iterableA));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6623,null,6622,org.apache.commons.collections4.CollectionUtils.cardinality(1L, iterableB));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6625,null,6624,org.apache.commons.collections4.CollectionUtils.cardinality(2L, iterableB));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6627,null,6626,org.apache.commons.collections4.CollectionUtils.cardinality(3L, iterableB));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6629,null,6628,org.apache.commons.collections4.CollectionUtils.cardinality(4L, iterableB));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6631,null,6630,org.apache.commons.collections4.CollectionUtils.cardinality(5L, iterableB));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6633,null,6632,org.apache.commons.collections4.CollectionUtils.cardinality(2L, iterableA2));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6635,null,6634,org.apache.commons.collections4.CollectionUtils.cardinality(2, iterableB2));
    final Set<java.lang.String> set = new HashSet<java.lang.String>();
    set.add("A");
    set.add("A");
    set.add("C");
    set.add("E");
    set.add("E");
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6637,null,6636,org.apache.commons.collections4.CollectionUtils.cardinality("A", set));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6639,null,6638,org.apache.commons.collections4.CollectionUtils.cardinality("B", set));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6641,null,6640,org.apache.commons.collections4.CollectionUtils.cardinality("C", set));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6643,null,6642,org.apache.commons.collections4.CollectionUtils.cardinality("D", set));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6645,null,6644,org.apache.commons.collections4.CollectionUtils.cardinality("E", set));
    final Bag<java.lang.String> bag = new HashBag<java.lang.String>();
    bag.add("A", 3);
    bag.add("C");
    bag.add("E");
    bag.add("E");
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6647,null,6646,org.apache.commons.collections4.CollectionUtils.cardinality("A", bag));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6649,null,6648,org.apache.commons.collections4.CollectionUtils.cardinality("B", bag));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6651,null,6650,org.apache.commons.collections4.CollectionUtils.cardinality("C", bag));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6653,null,6652,org.apache.commons.collections4.CollectionUtils.cardinality("D", bag));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),6655,null,6654,org.apache.commons.collections4.CollectionUtils.cardinality("E", bag));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:39,代码来源:CollectionUtilsTest.java


注:本文中的org.apache.commons.collections4.bag.HashBag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。