/** * Adapts data from the 'DataSet' object to de 'BaseDatos' object * * @param ds Data set */ private void convierteDatos(Dataset ds) { boolean seguir; base = new Vector(); Vector ejemplo = null; for (int i = 0; i < ds.getNdatos(); i++) { ejemplo = new Vector(); seguir = true; for (int j = 0; (j < ds.getNvariables() - 1) && seguir; j++) { // 'DataSet' object stores data in 'String' objects, but 'BaseDatos' does it in 'Double' or // 'Integer' objects if (!ds.isMissing(i, j)) { if (tipos.get(j).equals("real")) { ejemplo.add(new Double(ds.getExample(i)[j])); } else if (tipos.get(j).equals("integer")) { ejemplo.add(new Integer((int) ds.getExample(i)[j])); } else if (tipos.get(j).equals("enumerado")) { Integer dato = new Integer((int) ds.getExample(i)[j]); ejemplo.add(dato); } } /*if (!ds.getDatosIndex(i, j).equals("?") && !ds.getDatosIndex(i, j).equals("<null>")) { if (tipos.get(j).equals("real")) { ejemplo.add(new Double(ds.getDatosIndex(i, j))); } else if (tipos.get(j).equals("integer")) { ejemplo.add(new Integer(ds.getDatosIndex(i, j))); } else if (tipos.get(j).equals("enumerado")) { Integer dato = new Integer(((Vector) valEnum.get(j)). indexOf(ds.getDatosIndex(i, j))); ejemplo.add(dato); } } */ else { seguir = false; } } if (seguir) { ejemplo.add(new Integer(ds.getOutputAsInteger(i))); base.add(ejemplo); } } numEjemplos = base.size(); }
/** * @param ds * @return Output files' header */ public static String obtieneCabecera(Dataset ds) { // Obtain file header in 'cabecera' /*String cabecera = "@relation " + ds.getRelacion() + "\n"; for (int i = 0; i < ds.getAtributos().size(); i++) { if (!ds.getTiposIndex(i).equals("enumerado")) { cabecera += "@attribute " + ds.getAtributosIndex(i) + " " + ds.getTiposIndex(i) + " [" + ds.getRangosVar(i).get(0) + ", " + ds.getRangosVar(i).get(1) + "]\n"; } else { cabecera += "@attribute " + ds.getAtributosIndex(i) + " {"; for (int j = 0; j < ds.getRangosVar(i).size(); j++) { if (j > 0) { cabecera += ", " + ds.getRangosVar(i).get(j); } else { cabecera += ds.getRangosVar(i).get(j); } } cabecera += "}\n"; } } cabecera += "@inputs "; for (int i = 0; i < ds.getEntradas().size(); i++) { if (i > 0) { cabecera += ", " + ds.getEntradas().get(i); } else { cabecera += ds.getEntradas().get(i); } } cabecera += "\n@outputs "; for (int i = 0; i < ds.getSalidas().size(); i++) { if (i > 0) { cabecera += ", " + ds.getSalidas().get(i); } else { cabecera += ds.getSalidas().get(i); } } cabecera += "\n@data\n";*/ return ds.copyHeader(); }
/** * Constructor * * @param ds */ public BaseDatos(Dataset ds) { this.numEjemplos = ds.getNdatos(); this.tipos = ds.getTipos(); this.cabecera = obtieneCabecera(ds); // rangos, inicial, finales & valEnum this.convierte(ds.getRangos()); this.nombres = ds.getAtributos(); this.numAtributos = ds.getNvariables(); // ds.getAtributos().size(); /*try{ this.clase = this.nombres.indexOf(ds.getSalidas().get(0)); }catch(Exception e){ this.clase = numAtributos-1; //class is the last attribute }*/ this.clase = ds.getnInputs(); // la clase es siempre el ultimo atributo // System.err.println("Mira -> "+clase); this.convierteDatos(ds); // Set base Vector }