/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the current instance weights. The weights of the * instances in the new dataset are set to one. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @return the new dataset */ public Instances resampleWithWeights(Random random) { return resampleWithWeights(random, false); }
@Override public Instances resampleWithWeights(Random arg0, double[] arg1) { return super.resampleWithWeights(arg0, arg1); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the current instance weights. The weights of the * instances in the new dataset are set to one. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @return the new dataset */ public Instances resampleWithWeights(Random random) { return resampleWithWeights(random, false); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the current instance weights. The weights of the * instances in the new dataset are set to one. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @param sampled an array indicating what has been sampled * @return the new dataset */ public Instances resampleWithWeights(Random random, boolean[] sampled) { return resampleWithWeights(random, sampled, false); }
@Override public Instances resampleWithWeights(Random arg0) { return super.resampleWithWeights(arg0); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the current instance weights. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @param representUsingWeights if true, copies are represented using weights * in resampled data * @return the new dataset */ public Instances resampleWithWeights(Random random, boolean representUsingWeights) { return resampleWithWeights(random, null, representUsingWeights); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the current instance weights. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @param representUsingWeights if true, copies are represented using weights * in resampled data * @return the new dataset */ public Instances resampleWithWeights(Random random, boolean representUsingWeights) { return resampleWithWeights(random, null, representUsingWeights); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the current instance weights. The weights of the * instances in the new dataset are set to one. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @param sampled an array indicating what has been sampled * @return the new dataset */ public Instances resampleWithWeights(Random random, boolean[] sampled) { return resampleWithWeights(random, sampled, false); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the current instance weights. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @param sampled an array indicating what has been sampled * @param representUsingWeights if true, copies are represented using weights * in resampled data * @return the new dataset */ public Instances resampleWithWeights(Random random, boolean[] sampled, boolean representUsingWeights) { return resampleWithWeights(random, sampled, representUsingWeights, 100.0); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the given weight vector. The weights of the * instances in the new dataset are set to one. The length of the weight * vector has to be the same as the number of instances in the dataset, and * all weights have to be positive. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @param weights the weight vector * @return the new dataset * @throws IllegalArgumentException if the weights array is of the wrong * length or contains negative weights. */ public Instances resampleWithWeights(Random random, double[] weights) { return resampleWithWeights(random, weights, null); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the current instance weights. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @param sampled an array indicating what has been sampled * @param representUsingWeights if true, copies are represented using weights * in resampled data * @return the new dataset */ public Instances resampleWithWeights(Random random, boolean[] sampled, boolean representUsingWeights) { return resampleWithWeights(random, sampled, representUsingWeights, 100.0); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the given weight vector. The weights of the * instances in the new dataset are set to one. The length of the weight * vector has to be the same as the number of instances in the dataset, and * all weights have to be positive. See also * resampleWithWeights(Random, double[], boolean[]). * * @param random a random number generator * @param weights the weight vector * @return the new dataset * @throws IllegalArgumentException if the weights array is of the wrong * length or contains negative weights. */ public Instances resampleWithWeights(Random random, double[] weights) { return resampleWithWeights(random, weights, null); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the given weight vector. The length of the weight * vector has to be the same as the number of instances in the dataset, and * all weights have to be positive. Uses Walker's method, see pp. 232 of * "Stochastic Simulation" by B.D. Ripley (1987). * * @param random a random number generator * @param weights the weight vector * @param sampled an array indicating what has been sampled, can be null * @param representUsingWeights if true, copies are represented using weights * in resampled data * @return the new dataset * @throws IllegalArgumentException if the weights array is of the wrong * length or contains negative weights. */ public Instances resampleWithWeights(Random random, double[] weights, boolean[] sampled, boolean representUsingWeights) { return resampleWithWeights(random, weights, sampled, representUsingWeights, 100.0); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the given weight vector. The weights of the * instances in the new dataset are set to one. The length of the weight * vector has to be the same as the number of instances in the dataset, and * all weights have to be positive. Uses Walker's method, see pp. 232 of * "Stochastic Simulation" by B.D. Ripley (1987). * * @param random a random number generator * @param weights the weight vector * @param sampled an array indicating what has been sampled, can be null * @return the new dataset * @throws IllegalArgumentException if the weights array is of the wrong * length or contains negative weights. */ public Instances resampleWithWeights(Random random, double[] weights, boolean[] sampled) { return resampleWithWeights(random, weights, sampled, false); }
/** * Creates a new dataset of the same size as this dataset using random sampling with * replacement according to the given weight vector. The weights of the * instances in the new dataset are set to one. The length of the weight * vector has to be the same as the number of instances in the dataset, and * all weights have to be positive. Uses Walker's method, see pp. 232 of * "Stochastic Simulation" by B.D. Ripley (1987). * * @param random a random number generator * @param weights the weight vector * @param sampled an array indicating what has been sampled, can be null * @return the new dataset * @throws IllegalArgumentException if the weights array is of the wrong * length or contains negative weights. */ public Instances resampleWithWeights(Random random, double[] weights, boolean[] sampled) { return resampleWithWeights(random, weights, sampled, false); }
/** * Resamples the dataset using {@link Instances#resampleWithWeights(Random)} * if there are any instance weights other than 1.0 set. Simply returns the * dataset if no instance weights other than 1.0 are set. * * @param insts the dataset to resample * @param rand the random number generator to use * @return the (potentially) resampled dataset */ public static Instances resampleWithWeightIfNecessary(Instances insts, Random rand) { if (hasInstanceWeights(insts)) return insts.resampleWithWeights(rand); else return insts; } }
/** * Resamples the dataset using {@link Instances#resampleWithWeights(Random)} * if there are any instance weights other than 1.0 set. Simply returns the * dataset if no instance weights other than 1.0 are set. * * @param insts the dataset to resample * @param rand the random number generator to use * @return the (potentially) resampled dataset */ public static Instances resampleWithWeightIfNecessary(Instances insts, Random rand) { if (hasInstanceWeights(insts)) return insts.resampleWithWeights(rand); else return insts; } }
/** * Returns a training set for a particular iteration. * * @param iteration the number of the iteration for the requested training set. * @return the training set for the supplied iteration number * @throws Exception if something goes wrong when generating a training set. */ @Override protected synchronized Instances getTrainingSet(int iteration) throws Exception { Random r = new Random(m_Seed + iteration); // create the in-bag indicator array if necessary if (m_CalcOutOfBag) { m_inBag[iteration] = new boolean[m_data.numInstances()]; return m_data.resampleWithWeights(r, m_inBag[iteration], getRepresentCopiesUsingWeights(), m_BagSizePercent); } else { return m_data.resampleWithWeights(r, null, getRepresentCopiesUsingWeights(), m_BagSizePercent); } }
/** * Returns a training set for a particular iteration. * * @param iteration the number of the iteration for the requested training set. * @return the training set for the supplied iteration number * @throws Exception if something goes wrong when generating a training set. */ @Override protected synchronized Instances getTrainingSet(int iteration) throws Exception { Random r = new Random(m_Seed + iteration); // create the in-bag indicator array if necessary if (m_CalcOutOfBag) { m_inBag[iteration] = new boolean[m_data.numInstances()]; return m_data.resampleWithWeights(r, m_inBag[iteration], getRepresentCopiesUsingWeights(), m_BagSizePercent); } else { return m_data.resampleWithWeights(r, null, getRepresentCopiesUsingWeights(), m_BagSizePercent); } }
/** * builds the classifier. * * @param data the training data to be used for generating the * classifier. * @throws Exception if the classifier could not be built successfully */ public void buildClassifier(Instances data) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(data); boolean resample = getForceResampleWithWeights() || (!(m_Classifier instanceof WeightedInstancesHandler) && ResampleUtils.hasInstanceWeights(data)); if (resample) { if (getDebug()) System.err.println(getClass().getName() + ": resampling training data"); data = data.resampleWithWeights(new Random(m_Seed)); } m_Classifier.buildClassifier(data); }