예제 #1
0
  /**
   * Main Function
   *
   * @param args the Command line arguments. Only one is processed: the name of the file containing
   *     the
   *     <p>parameters
   */
  public static void main(String[] args) throws IOException {

    double[][] X;

    double[][] Y;

    int nInpt, nOutpl, ndata, i, j;

    Rbfn net;

    try {

      // Help required

      if (args.length > 0) {

        if (args[0].equals("--help")
            || args[0].equals("-help")
            || args[0].equals("-h")
            || args[0].equals("-?")) {

          doHelp();

          return;
        }
      }

      System.out.println("- Executing doRbfnDec " + args.length);

      // Reading parameters

      String paramFile = (args.length > 0) ? args[0] : "parameters.txt";

      setParameters(paramFile);

      System.out.println("    - Parameters file: " + paramFile);

      // Random generator setup

      if (reallySeed) {
        Randomize.setSeed((long) seed);
      }

      // Reading Training dataset

      ProcDataset Dtrn = new ProcDataset(trnFile, true);

      // Training
      System.out.println("Modeling Dataset");
      Dtrn.processModelDataset();
      nInpt = Dtrn.getninputs();
      nOutpl = 1; // PD.getnvariables()-nInpt;
      ndata = Dtrn.getndata();
      Y = new double[ndata][1];
      X = Dtrn.getX();
      double[] auxY;
      auxY = Dtrn.getY();
      for (i = 0; i < ndata; i++) Y[i][0] = auxY[i];
      // Building and training the net
      net = new Rbfn(nNeuronsIni, X, ndata, nInpt, nOutpl);
      net.decremental(X, Y, ndata, percent, alfa);
      double[] obtained = new double[ndata];
      net.testModeling(X, ndata, obtained);
      Dtrn.generateResultsModeling(outTrnFile, auxY, obtained);
      // TEST
      ProcDataset Dtst = new ProcDataset(tstFile, false);
      Dtst.processModelDataset();
      nInpt = Dtst.getninputs();
      nOutpl = 1; // PD.getnvariables()-nInpt;
      ndata = Dtst.getndata();
      X = Dtst.getX();
      auxY = Dtst.getY();
      Y = new double[ndata][1];
      for (i = 0; i < ndata; i++) Y[i][0] = auxY[i];
      obtained = new double[ndata];
      net.testModeling(X, ndata, obtained);
      Dtst.generateResultsModeling(outTstFile, auxY, obtained);
      RBFUtils.createOutputFile(trnFile, outRbfFile);
      net.printRbfn(outRbfFile);

      if (Dtrn.datasetType() == 2) System.out.println("This is not a clustering algorithm");

      System.out.println(
          "- End of doRbfnDec. See results in output files named according to "
              + paramFile
              + " parameters file.");

    } catch (Exception e) {

      throw new InternalError(e.toString());
    }
  }
예제 #2
0
  /**
   * Reads parameters from parameter file.
   *
   * @param _fileName Name of file with parameters.
   * @return True if everything goes right. False otherwise.
   */
  private static boolean setParameters(String fileName) {

    Hashtable parameters = RBFUtils.parameters(fileName);

    RBFUtils.setVerbosity(parameters);

    String tmp;

    tmp = ((String) ((Vector) parameters.get("inputData")).get(0));

    trnFile = tmp.substring(1, tmp.length() - 1); // Character " must be removed.

    tmp = (String) ((Vector) parameters.get("inputData")).get(2);

    tstFile = tmp.substring(1, tmp.length() - 1); // Character " must be removed.

    tmp = (String) ((Vector) parameters.get("outputData")).get(0);

    outTrnFile = tmp.substring(1, tmp.length() - 1); // Character " must be removed.

    tmp = (String) ((Vector) parameters.get("outputData")).get(1);

    outTstFile = tmp.substring(1, tmp.length() - 1); // Character " must be removed.

    tmp = (String) ((Vector) parameters.get("outputData")).get(2);

    outRbfFile = tmp.substring(1, tmp.length() - 1); // Character " must be removed.

    percent = Double.parseDouble((String) ((Vector) parameters.get("percent")).get(0));

    alfa = Double.parseDouble((String) ((Vector) parameters.get("alfa")).get(0));

    nNeuronsIni =
        (int) Double.parseDouble((String) ((Vector) parameters.get("nNeuronsIni")).get(0));

    if (parameters.containsKey("seed")) {

      reallySeed = true;

      seed = (double) Double.parseDouble((String) ((Vector) parameters.get("seed")).get(0));

    } else {

      reallySeed = false;
    }

    RBFUtils.verboseln("Training file      : " + trnFile);

    RBFUtils.verboseln("Test file          : " + tstFile);

    RBFUtils.verboseln("Ouput Training file: " + outTrnFile);

    RBFUtils.verboseln("Ouput Test file    : " + outTstFile);

    RBFUtils.verboseln("Ouput RBF file     : " + outRbfFile);

    RBFUtils.verboseln("percent            : " + percent);

    RBFUtils.verboseln("alfa               : " + alfa);

    RBFUtils.verbose("Seed               : ");

    if (reallySeed) {

      RBFUtils.verboseln("" + seed);

    } else {

      RBFUtils.verboseln("No seed, i.e., pure random execution");
    }

    RBFUtils.verboseln("Verbosity          : " + RBFUtils.getVerbosity());

    return (trnFile != ""
        && tstFile != ""
        && outTrnFile != ""
        && outTstFile != ""
        && percent > 0
        && alfa > 0);
  }