Contains pre determined code for generating specific data sets. The form and values of the data set are fixed, and do not need to be specified. Training and testing sets are generated by the same methods. @author Edward Raff
| 20 | * @author Edward Raff |
| 21 | */ |
| 22 | public class FixedProblems |
| 23 | { |
| 24 | private static final Vec c2l_m0 = new DenseVector(new double[]{12, 14, 25, 31, 10, 9, 1}); |
| 25 | private static final Vec c2l_m1 = new DenseVector(new double[]{-9, -7, -13, -6, -11, -9, -1}); |
| 26 | private static final NormalM c2l_c0 = new NormalM(c2l_m0, Matrix.eye(c2l_m0.length())); |
| 27 | private static final NormalM c2l_c1 = new NormalM(c2l_m1, Matrix.eye(c2l_m0.length())); |
| 28 | |
| 29 | /** |
| 30 | * Generates a linearly separable binary classification problem |
| 31 | * @param dataSetSize the number of points to generated |
| 32 | * @param rand the source of randomness |
| 33 | * @return a binary classification data set that is linearly separable |
| 34 | */ |
| 35 | public static ClassificationDataSet get2ClassLinear(int dataSetSize, Random rand) |
| 36 | { |
| 37 | ClassificationDataSet train = new ClassificationDataSet(c2l_m0.length(), new CategoricalData[0], new CategoricalData(2)); |
| 38 | |
| 39 | for(Vec s : c2l_c0.sample(dataSetSize, rand)) |
| 40 | train.addDataPoint(s, new int[0], 0); |
| 41 | for(Vec s : c2l_c1.sample(dataSetSize, rand)) |
| 42 | train.addDataPoint(s, new int[0], 1); |
| 43 | |
| 44 | return train; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /** |
| 49 | * Creates a 2D linearly separable problem |
| 50 | * @param dataSetSize0 size of the first class |
| 51 | * @param dataSetSize1 size of the second class |
| 52 | * @param sep the separation between the two classes. The true decision |
| 53 | * boundary stays in the same location regardless of this value |
| 54 | * @param rand source of randomness |
| 55 | * @return a 2d testing set |
| 56 | */ |
| 57 | public static ClassificationDataSet get2ClassLinear2D(int dataSetSize0, int dataSetSize1, double sep, Random rand) |
| 58 | { |
| 59 | ClassificationDataSet train = new ClassificationDataSet(2, new CategoricalData[0], new CategoricalData(2)); |
| 60 | |
| 61 | NormalM a = new NormalM(DenseVector.toDenseVec(sep, sep), Matrix.eye(2)); |
| 62 | NormalM b = new NormalM(DenseVector.toDenseVec(-sep, -sep), Matrix.eye(2)); |
| 63 | |
| 64 | for(Vec s : a.sample(dataSetSize0, rand)) |
| 65 | train.addDataPoint(s, new int[0], 0); |
| 66 | for(Vec s : b.sample(dataSetSize1, rand)) |
| 67 | train.addDataPoint(s, new int[0], 1); |
| 68 | |
| 69 | return train; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Generates a linearly separable binary classification problem |
| 74 | * @param dataSetSize0 the number of points to generated for the first class |
| 75 | * @param dataSetSize1 the number of points to generated for the second class |
| 76 | * @param rand the source of randomness |
| 77 | * @return a binary classification data set that is linearly separable |
| 78 | */ |
| 79 | public static ClassificationDataSet get2ClassLinear(int dataSetSize0, int dataSetSize1, Random rand) |