protected HashMap<String, Object> selectAttribute( ArrayList<DataInstance> instances, ArrayList<Integer> attributeList) { Random r = new Random(); Integer attr = attributeList.get(r.nextInt(attributeList.size())); selectedInstances = new HashMap<Integer, ArrayList<DataInstance>>(); ArrayList<DataInstance> data; for (DataInstance di : instances) { int value = di.getAttributes().get(attr.intValue()).intValue(); if (selectedInstances.containsKey(value)) { data = selectedInstances.get(value); data.add(di); selectedInstances.put(value, data); } else { data = new ArrayList<DataInstance>(); data.add(di); selectedInstances.put(value, data); } } HashMap<String, Object> choice = new HashMap<String, Object>(); choice.put("attribute", attr); choice.put("discrete", "true"); choice.put("multiway", "true"); return choice; }
@Override public List<DataInstance> getDataFromFile(String fileName, int inputDim, int outputDim) { List<DataInstance> data = new ArrayList<DataInstance>(); try { Scanner scn = new Scanner(new File(fileName)); while (scn.hasNextLine()) { String[] line = scn.nextLine().split("\\s+|,"); double[] arr = new double[line.length]; for (int i = 0; i < line.length; i++) arr[i] = Double.parseDouble(line[i]); DataInstance d = new DataInstance(inputDim, outputDim, arr); double[] out = d.getOutputTruthValue(); if (out[0] == 1) out = new double[] {1, 0}; else out = new double[] {0, 1}; d.replaceOutputTruthValue(out); data.add(d); } scn.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } return data; }
@Override public void send(Enum<?> msgId, DustObject msgOb, boolean wait, ResponseProcessor respProc) { data.send(this, msgId, msgOb, wait, respProc); }
@Override public DustObject getNeighbor(DustIdentifier typeId) { return data.getNeighbor(typeId); }
@Override public Variant getFieldVariant(int idx) { return data.getFieldVariant(idx); }
@Override public boolean isNull(int idx) { return data.isNull(idx); }
@Override public int getFieldCount() { return data.getFieldCount(); }
@Override public DustIdentifier getObTypeID() { return data.getObTypeID(); }
@Override public Entity getEntity() { return data.getEntity(); }