@@ -0,0 +1,2086 @@
+/**%0A    This file is part of JkernelMachines.%0A%0A    JkernelMachines is free software: you can redistribute it and/or modify%0A    it under the terms of the GNU General Public License as published by%0A    the Free Software Foundation, either version 3 of the License, or%0A    (at your option) any later version.%0A%0A    JkernelMachines is distributed in the hope that it will be useful,%0A    but WITHOUT ANY WARRANTY; without even the implied warranty of%0A    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A    GNU General Public License for more details.%0A%0A    You should have received a copy of the GNU General Public License%0A    along with JkernelMachines.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A%0A    Copyright David Picard - 2014%0A%0A */%0Apackage fr.lip6.jkernelmachines.active;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Random;%0A%0Aimport fr.lip6.jkernelmachines.classifier.Classifier;%0Aimport fr.lip6.jkernelmachines.type.TrainingSample;%0A%0A/**%0A * %3Cp%3E%0A * Absurd active strategy that randomly selects a sample%0A * %3C/p%3E%0A * %0A * @author picard%0A * %0A */%0Apublic class RandomAL%3CT%3E extends ActiveLearner%3CT%3E %7B%0A%0A%09Random rand;%0A%0A%09public RandomAL(Classifier%3CT%3E c, List%3CTrainingSample%3CT%3E%3E l) %7B%0A%09%09classifier = c;%0A%09%09train = new ArrayList%3CTrainingSample%3CT%3E%3E(l.size());%0A%09%09train.addAll(l);%0A%09%09rand = new Random();%0A%09%7D%0A%0A%09/*%0A%09 * (non-Javadoc)%0A%09 * %0A%09 * @see%0A%09 * fr.lip6.jkernelmachines.active.ActiveLearner#getActiveSample(java.util%0A%09 * .List)%0A%09 */%0A%09@Override%0A%09public TrainingSample%3CT%3E getActiveSample(List%3CTrainingSample%3CT%3E%3E l) %7B%0A%09%09if (classifier == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%0A%09%09int index = rand.nextInt(l.size());%0A%09%09return l.get(index);%0A%09%7D%0A%0A%09/*%0A%09 * (non-Javadoc)%0A%09 * %0A%09 * @see fr.lip6.jkernelmachines.active.ActiveLearner#updateClassifier(int)%0A%09 */%0A%09@Override%0A%09public void updateClassifier(int nbSamples) %7B%0A%09%09if (classifier == null) %7B%0A%09%09%09return;%0A%09%09%7D%0A%0A%09%09for (int i = 0; i %3C nbSamples; i++) %7B%0A%09%09%09if (train.isEmpty()) %7B%0A%09%09%09%09return;%0A%09%09%09%7D%0A%0A%09%09%09TrainingSample%3CT%3E t = getActiveSample(train);%0A%09%09%09if (t == null) %7B%0A%09%09%09%09return;%0A%09%09%09%7D%0A%09%09%09train.remove(t);%0A%09%09%09classifier.train(t);%0A%09%09%7D%0A%0A%09%7D%0A%0A%7D%0A

add new active strategy: random