예제 #1
0
  /**
   * Populates test and training datasets.
   *
   * <p>Note: (1) assumes a 50:50 split, (2) training data set is stored in the dataArray structure
   * in which the input data is stored, (3) method called from application class as same training
   * and test sets may be required if using (say) "hill climbing" approach to maximise accuracy, (4)
   * method is not called from constructor partly for same reason as 3 but also because the input
   * data set may (given a particular application) first require ordering and possibly also pruning
   * and recasting (see recastClassifiers method).
   *
   * @param test myDataset Class where examples are stored to build the classifier
   * @param dataBase DataBase Class to store the examples to work with the algorithm and some other
   *     useful information
   */
  public void testDataSet(myDataset test, DataBase dataBase) {
    int i, j, k;
    int[] example;
    short value;

    // Determine size of training and test sets.
    setNumRowsInTrainingSet();
    numRowsInTestSet = test.getnData();

    // Dimension and populate test set
    testDataArray = new short[numRowsInTestSet][];
    for (i = 0; i < numRowsInTestSet; i++) {
      example = test.getExample(i);
      testDataArray[i] = new short[dataBase.numVariablesUsed() + 1];
      value = 1;
      for (j = 0, k = 0; j < example.length; j++) {
        if (dataBase.numLabels(j) > 1) {
          testDataArray[i][k] = (short) example[j];
          testDataArray[i][k] += value;
          value += dataBase.numLabels(j);
          //					System.out.print (testDataArray[i][k] + " ");
          k++;
        }
      }
      testDataArray[i][k] = (short) test.getOutputAsInteger(i);
      testDataArray[i][k] += value;
      //			System.out.print (testDataArray[i][k] + " ");
      //			System.out.println ("");
    }
  }
예제 #2
0
 private void init(String fileName, String[] projection, int startPosition) {
   this.fileName = fileName;
   DataBase.loadFile(fileName);
   this.count = singleGame ? 1 : DataBase.getSize();
   this.startPosition = startPosition;
   handleProjection(projection);
 }
예제 #3
0
 public boolean setProteinFile(ExperimentBean exp) {
   ExperimentBean tempExp = db.readyExper(exp.getExpId()); // confirm that the experiment is new
   if (tempExp.getReady() == 0) {
     boolean test = db.setProteinFile(exp);
     return test;
   } else {
     return false;
   }
 }
예제 #4
0
 public boolean setStandardPlotProt(ExperimentBean exp) {
   boolean test = false;
   List<StandardProteinBean> standardPlotList = db.getStandardProtPlotList(exp.getExpId());
   if (standardPlotList.isEmpty()) ;
   else {
     test = db.removeStandarPlot(exp.getExpId());
   }
   test = db.setStandardPlotProt(exp);
   return test;
 }
예제 #5
0
 public boolean updateProteinFile(ExperimentBean exp) {
   boolean test;
   ExperimentBean tempExp = db.readyExper(exp.getExpId()); // check the previous uploaded file
   if (tempExp.getReady() == 1
       && tempExp.getFractionsNumber()
           > 0) // we need to update ready number to 2 -- previous file was protein fraction file
   {
     tempExp.setReady(2);
   }
   tempExp.setProteinsNumber(exp.getProteinsNumber());
   db.updateExperiment(null, tempExp);
   test = db.checkAndUpdateProt(exp);
   return test;
 }
예제 #6
0
  /// new v-2
  public List<ProteinBean> searchProtein(String accession, int expId, List<ProteinBean> protList) {

    ProteinBean pb = db.searchProtein(accession, expId);
    if (pb != null && protList != null) {
      protList.add(pb);
    }
    if (protList != null) {
      protList = db.searchOtherProteins(accession, expId, protList);
    } else {
      protList = new ArrayList<ProteinBean>();
      protList.add(pb);
    }
    return protList;
  }
예제 #7
0
파일: Crawler.java 프로젝트: KevalS/Crawler
  public static void processPage(String URL) throws SQLException, IOException {
    // check if the given URL is already in database
    String sql = "select * from Record where URL = '" + URL + "'";
    ResultSet rs = db.runSql(sql);
    if (rs.next()) {

    } else {
      // store the URL to database to avoid parsing again
      sql = "INSERT INTO  test.Record " + "(URL) VALUES " + "(?);";
      PreparedStatement stmt = db.conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
      stmt.setString(1, URL);
      stmt.execute();

      // get useful information
      Document doc = Jsoup.connect("http://www.mit.edu/").get();

      if (doc.text().contains("PhD")) {
        System.out.println(URL);
      }

      // get all links and recursively call the processPage method
      Elements questions = doc.select("a[href]");
      for (Element link : questions) {
        if (link.attr("href").contains("mit.edu")) processPage(link.attr("abs:href"));
      }
    }
  }
예제 #8
0
 private void doCommit() {
   try {
     System.out.println(currTable.commit());
   } catch (IOException e) {
     System.err.println(e.getMessage());
     System.exit(1);
   }
 }
예제 #9
0
 @Override
 public void execute(DataBase base) throws Exception {
   if (base.data.containsKey(key)) {
     base.data.remove(key);
     base.dump();
     System.out.println("removed");
   } else {
     System.out.println("not found");
   }
 }
예제 #10
0
 /**
  * @param oldPosition the position that we're moving from
  * @param newPosition the position that we're moving to
  * @return true if the move is successful, false otherwise
  */
 @Override
 public boolean onMove(int oldPosition, int newPosition) {
   boolean result = true;
   int gameNo = startPosition + newPosition;
   boolean onlyHeaders = !loadPGN;
   boolean isFavorite = DataBase.loadGame(gameNo, onlyHeaders);
   setGameInfo(gameNo, isFavorite);
   this.reloadIndex = false;
   return result;
 }
예제 #11
0
 private void setGameInfo(int gameNo, boolean isFavorite) {
   this.gameInfo = new GameInfo();
   try {
     gameInfo.setEvent(getSanitizedString(DataBase.getEvent()));
     if (gameInfo.getEvent().equals("?")) {
       gameInfo.setEvent("");
     }
     gameInfo.setSite(getSanitizedString(DataBase.getSite()));
     if (gameInfo.getSite().equals("?")) {
       gameInfo.setSite("");
     }
     String date = DataBase.getDate();
     if (date == null) {
       date = "";
     } else if (date.endsWith(".??.??")) {
       date = date.substring(0, date.length() - 6);
     } else if (date.endsWith(".??")) {
       date = date.substring(0, date.length() - 3);
     }
     if (date.equals("?") || date.equals("????")) {
       date = "";
     }
     gameInfo.setDate(date);
     gameInfo.setRound(getSanitizedString(DataBase.getRound()));
     if (gameInfo.getRound().equals("?")) {
       gameInfo.setRound("");
     }
     gameInfo.setWhite(getSanitizedString(DataBase.getWhite()));
     gameInfo.setBlack(getSanitizedString(DataBase.getBlack()));
     String[] results = {"*", "1-0", "0-1", "1/2"};
     gameInfo.setResult(results[DataBase.getResult()]);
     byte[] dbPgn = DataBase.getPGN();
     if (dbPgn != null) {
       gameInfo.setPgn(loadPGN ? new String(DataBase.getPGN(), DataBase.SCID_ENCODING) : null);
     }
   } catch (UnsupportedEncodingException e) {
     Log.e("SCID", "Error converting byte[] to String", e);
   }
   gameInfo.setId(gameNo);
   gameInfo.setFavorite(isFavorite);
   gameInfo.setDeleted(DataBase.isDeleted());
 }
  public void run() {
    ClientInterface ci = new ClientInterface(dataBase);

    while (true) {
      System.out.println();
      try {
        byte[] headerData;

        headerData = readRequestHeader();
        ci.setMember(headerData);
        // ci.printMember();

        if (Define.objec.SYSTEM == ci.getObjec()) {
          if (Define.order.MAJORITYCREATE == ci.getOrder()) {
            dataBase.createMajority(ci.getDataOfMajority());
          } else if (Define.order.MAJORITYADD == ci.getOrder()) {
            dataBase.addMajority(ci.getDataOfMajority());
          } else if (Define.order.MAJORITYRESET == ci.getOrder()) {
            dataBase.resetMajority();
          }
        } else if (Define.objec.NODE == ci.getObjec()) {
          if (Define.order.CREATE == ci.getOrder()) {
            Node createNode = ci.getCreateNode();
            dataBase.registrationNode(createNode, clientNumber);
          } else if (Define.order.EDIT == ci.getOrder()) {
            Node createNode = ci.getCreateNode();
            System.out.println(
                "EditidentNumber = " + createNode.identNumber); // /////////////////////////
            dataBase.EditNode(createNode, clientNumber);
          } else if (Define.order.DELETE == ci.getOrder()) {
            ID delID = ci.getDelId();
            dataBase.DelateNode(delID);
          } else {
            // 未実装
          }
        } else if (Define.objec.AGENDA == ci.getObjec()) {
          if (Define.order.CREATE == ci.getOrder()) {
            AgendaPacket ciAgendaPacket = ci.getAgendaPacket();
            dataBase.getAgendaDataBase().addNode(ciAgendaPacket, ciAgendaPacket.getID());
          }
        }

        Vector cloneDatabase = (Vector) dataBase.getDataBaseClone();
        Vector tempDatabase = (Vector) cloneDatabase.get(0);
      } catch (IOException e) {
        // TODO 自動生成された catch ブロック
        e.printStackTrace();
        break;
      }
    }
  }
예제 #13
0
 private void doRemove(String key) {
   try {
     Storeable value = currTable.remove(key);
     if (value == null) {
       System.out.println("not found");
     } else {
       System.out.println("removed");
     }
   } catch (IllegalArgumentException e) {
     System.out.println(e.getMessage());
   }
 }
예제 #14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demographic);
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle("Sector");

    /** opening the database */
    db = new DataBase(this);
    db.open();

    /** creating the session */
    settings = getSharedPreferences("settingsFile", 0);
    sessionID = settings.getInt("Session", 0);

    /** retrieving data from DemographicsData */
    data = new DemographicsData(db, sessionID);

    /** declaration of certain class variables */
    sectorList = (ExpandableListView) findViewById(R.id.sectorList);
    Sector_And_Subs = data.createMapList();
    Sector_List = new ArrayList<String>(Sector_And_Subs.keySet());
    sectorAdapter = new SectorAdapter(this, Sector_And_Subs, Sector_List);

    /** setting adapter to its default state */
    sectorAdapter.setDefault(data.getSectorName(), data.getSubSectorName());
    sectorList.setAdapter(sectorAdapter);
    int g = sectorAdapter.getDefaultGroup();
    if (g >= 0) sectorList.expandGroup(g);

    /** what happens when a sub-sector is clicked */
    sectorList.setOnChildClickListener(
        new ExpandableListView.OnChildClickListener() {
          @Override
          public boolean onChildClick(
              ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            v.setSelected(true);
            Toast.makeText(
                    getBaseContext(),
                    Sector_And_Subs.get(Sector_List.get(groupPosition)).get(childPosition)
                        + " was clicked",
                    Toast.LENGTH_LONG)
                .show();
            String sid = sectorAdapter.getGroup(groupPosition).toString();
            String subID = sectorAdapter.getChild(groupPosition, childPosition).toString();
            data.updateSession(sid, subID);

            return true;
          }
        });
  }
예제 #15
0
 private void doPut(String key, String value) {
   try {
     Storeable oldValue = currTable.put(key, prov.deserialize(currTable, value));
     if (oldValue == null) {
       System.out.println("new");
     } else {
       System.out.println("overwrite");
       System.out.println(prov.serialize(currTable, oldValue));
     }
   } catch (ParseException e) {
     printError("Cannot parse arguments");
   }
 }
예제 #16
0
 private void doGet(String key) {
   try {
     Storeable value = currTable.get(key);
     if (value == null) {
       System.out.println("not found");
     } else {
       System.out.println("found");
       System.out.println(prov.serialize(currTable, value));
     }
   } catch (IllegalArgumentException e) {
     System.out.println(e.getMessage());
   }
 }
  public static void main(String[] args) {

    DataBase banco_de_dados = new DataBase();

    Customer rodrigo = new Customer(10, "Rodrigo");

    banco_de_dados.addCustomer(rodrigo);

    ShoppingCart carrinho = new ShoppingCart();

    rodrigo.setShoppingCart(carrinho);

    Product p1 = banco_de_dados.SelectProdut(1);
    Product p2 = banco_de_dados.SelectProdut(3);

    rodrigo.getShoppingCart().add(p1);
    rodrigo.getShoppingCart().add(p2);

    double amount = rodrigo.getShoppingCart().getamount();

    banco_de_dados.processPayment(rodrigo, amount);
  }
예제 #18
0
 @Override
 public void printError(String errStr) {
   if (isPacket) {
     try {
       currTable.unloadData();
     } finally {
       System.err.println(errStr);
       System.exit(1);
     }
   } else {
     System.out.println(errStr);
   }
 }
예제 #19
0
 private void doUseTable(String tableName) {
   if (currTable != null) {
     int changes = currTable.countChanges();
     if (changes != 0) {
       System.out.println(changes + " unsaved changes");
       return;
     }
   }
   try {
     DataBase tmp = (DataBase) prov.getTable(tableName);
     if (tmp == null) {
       System.out.println(tableName + " not exists");
     } else {
       if (currTable != null) {
         currTable.unloadData();
       }
       currTable = tmp;
       System.out.println("using " + tableName);
     }
   } catch (IllegalArgumentException e) {
     System.out.println(e.getMessage());
   }
 }
예제 #20
0
파일: Rule.java 프로젝트: triguero/Keel3.0
  /**
   * Constructor with parameters. It creates a random general rule
   *
   * @param database Data Base associated to the general rule base that includes this rule
   * @param n_classes Number of classes in the training set
   * @param tnorm T-norm used to compute the compatibility degree
   * @param tconorm T-conorm used to compute the compatibility degree
   * @param rule_weight Way of computing the rule weight
   */
  public Rule(DataBase database, int n_classes, int tnorm, int tconorm, int rule_weight) {
    int length_antecedent;
    boolean[] selected_antecedent = new boolean[database.numVariables()];

    antecedent = new ArrayList<FuzzyAntecedent>(database.numVariables());
    for (int i = 0; i < database.numVariables(); i++) {
      selected_antecedent[i] = false;
    }
    do {
      // Select randomly some variables of the database and create randomly its antecedent
      length_antecedent = Randomize.RandintClosed(1, database.numVariables());

      for (int i = 0; i < length_antecedent; i++) {
        int var_selected;
        FuzzyAntecedent new_antecedent;

        do {
          var_selected = Randomize.Randint(0, database.numVariables());
        } while (selected_antecedent[var_selected]);

        new_antecedent = new FuzzyAntecedent(database, var_selected);

        if (new_antecedent.isValid()) {
          selected_antecedent[var_selected] = true;
          antecedent.add((FuzzyAntecedent) new_antecedent);
        }
      }

    } while (antecedent.size() == 0);

    t_norm = tnorm;
    t_conorm = tconorm;
    ruleWeight = rule_weight;
    level = 1;
    clas = Randomize.Randint(0, n_classes);
    n_e = true;
  }
예제 #21
0
파일: Rule.java 프로젝트: triguero/Keel3.0
  /**
   * Adds a new variable to the fuzzy antecedent set of this rule
   *
   * @param data Data Base associated to the general rule base that includes this rule
   */
  public void addVar(DataBase data) {
    boolean found_var = false;
    int selected_var;

    if (antecedent.size() >= data.numVariables()) {
      System.err.println(
          "We cannot add a new var to this rule since it has all the possible vars in it");
      System.exit(-1);
    }

    // Find a label that we do not have in the label set yet
    do {
      selected_var = Randomize.Randint(0, data.numVariables());
      found_var = false;

      for (int i = 0; i < antecedent.size() && !found_var; i++) {
        if (((FuzzyAntecedent) antecedent.get(i)).getAttribute() == selected_var) {
          found_var = true;
        }
      }
    } while (found_var);

    // Add this variable to the Fuzzy set
    FuzzyAntecedent new_antecedent;
    do {
      new_antecedent = new FuzzyAntecedent(data, selected_var);
    } while (!new_antecedent.isValid());
    antecedent.add(new_antecedent);

    weight = 0.0;
    raw_fitness = 0.0;
    penalized_fitness = -1.0;
    n_e = true;
    ideal = 0;
    level = 1;
  }
예제 #22
0
  private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
    mAdi = jTextField1.getText();
    mFirma = jTextField2.getText();
    mAdres = jTextArea1.getText();
    mTel = jTextField3.getText();

    if (mAdi.isEmpty() || mFirma.isEmpty() || mAdres.isEmpty() || mTel.isEmpty()) {
      JOptionPane.showMessageDialog(this, "LÜTFEN TÜM ALANLARI DOLDURUNUZ");
      return;
    } else {
      db.musteriEkle(mAdi, mFirma, mAdres, mTel);
      JOptionPane.showMessageDialog(this, "BAŞARIYLA EKLENDİ");
    }
  } // GEN-LAST:event_jButton1ActionPerformed
예제 #23
0
  /** It launches the algorithm */
  public void execute() {
    if (somethingWrong) { // We do not execute the program
      System.err.println("An error was found, either the data-set has missing values.");
      System.err.println(
          "Please remove the examples with missing data or apply a MV preprocessing.");
      System.err.println("Aborting the program");
      // We should not use the statement: System.exit(-1);
    } else {
      // We do here the algorithm's operations

      nClasses = train.getnClasses();

      dataBase =
          new DataBase(
              train.getnInputs(), train.getRanges(), train.varNames(), train.getNominals());
      Population pobl =
          new Population(
              train,
              dataBase,
              populationSize,
              nRules,
              crossProb,
              ruleWeight,
              combinationType,
              inferenceType,
              p_DC,
              michProb);
      pobl.Generation(this.nGenerations);

      dataBase.writeFile(this.fileDB);
      ruleBase = pobl.bestRB();
      ruleBase.writeFile(this.fileBR);

      // Finally we should fill the training and test output files
      double accTra = doOutput(this.val, this.outputTr);
      double accTst = doOutput(this.test, this.outputTst);

      System.out.println("Accuracy obtained in training: " + accTra);
      System.out.println("Accuracy obtained in test: " + accTst);
      System.out.println("Algorithm Finished");
    }
  }
예제 #24
0
파일: Rule.java 프로젝트: triguero/Keel3.0
  /**
   * Constructor with parameters. It creates a specific rule from a given sample
   *
   * @param database Data Base associated to the general rule base that includes this rule
   * @param n_classes Number of classes in the training set
   * @param tnorm T-norm used to compute the compatibility degree
   * @param tconorm T-conorm used to compute the compatibility degree
   * @param rule_weight Way of computing the rule weight
   * @param sample Data sample used to generate this rule
   * @param sample_class Output class associated to the data sample used to generate this rule
   */
  public Rule(
      DataBase database,
      int n_classes,
      int tnorm,
      int tconorm,
      int rule_weight,
      double[] sample,
      int sample_class) {
    antecedent = new ArrayList<FuzzyAntecedent>(database.numVariables());
    clas = sample_class;
    t_norm = tnorm;
    t_conorm = tconorm;
    ruleWeight = rule_weight;
    level = 2;
    n_e = true;

    for (int i = 0; i < database.numVariables(); i++) {
      double max = 0.0;
      int etq = -1;
      double per;
      for (int j = 0; j < database.numLabels(); j++) {
        per = database.membershipFunction(i, j, sample[i]);
        if (per > max) {
          max = per;
          etq = j;
        }
      }
      if (max == 0.0) {
        System.err.println("There was an error while searching for the antecedent of the rule");
        System.err.println("Example: ");
        for (int j = 0; j < database.numVariables(); j++) {
          System.err.print(sample[j] + "\t");
        }
        System.err.println("Variable " + i);
        System.exit(1);
      }

      FuzzyAntecedent new_antecedent =
          new FuzzyAntecedent(database.clone(i, etq), i, database.numLabels());
      antecedent.add((FuzzyAntecedent) new_antecedent);
    }
  }
예제 #25
0
파일: Rule.java 프로젝트: triguero/Keel3.0
  /**
   * Adds a label to the fuzzy antecedent of the given variable
   *
   * @param variable_mutated position of the variable that is going to have a label added
   * @param data Data Base associated to the general rule base that includes this rule
   */
  public void addLabel(int variable_mutated, DataBase data) {
    if (variable_mutated >= antecedent.size()) {
      System.err.println("We cannot select a variable outside the antecedent");
      System.exit(-1);
    }

    if ((((FuzzyAntecedent) antecedent.get(variable_mutated)).getnLabels() + 1)
        == data.numLabels()) {
      System.err.println("We cannot add a label to create an any condition");
      System.exit(-1);
    }

    // Add label to the selected fuzzy antecedent
    ((FuzzyAntecedent) antecedent.get(variable_mutated)).addLabel(data);

    weight = 0.0;
    raw_fitness = 0.0;
    penalized_fitness = -1.0;
    n_e = true;
    ideal = 0;
    level = 1;
  }
예제 #26
0
  public boolean updatePeptideFile(ExperimentBean exp) {

    ExperimentBean tempExp = db.readyExper(exp.getExpId()); // check the previous uploaded file
    boolean test = db.updatePeptideFile(tempExp, exp);
    return test;
  }
예제 #27
0
 public boolean setPeptideFile(ExperimentBean exp) {
   boolean test = db.setPeptideFile(exp);
   return test;
 }
예제 #28
0
 public Map<Integer, ExperimentBean> getExperiments() // get experiments list
     {
   Map<Integer, ExperimentBean> expList = db.getExperiments();
   return expList;
 }
예제 #29
0
 public ExperimentBean getExperiment(int expId) {
   ExperimentBean exp = db.getExperiment(expId);
   return exp;
 }
예제 #30
0
 public boolean removeExperiment(int expId) {
   boolean test = db.removeExperiment(expId);
   return test;
 }