⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 box.java

📁 一个数据挖掘系统的源码
💻 JAVA
字号:

/**
 *   
 *   AgentAcademy - an open source Data Mining framework for
 *   training intelligent agents
 *
 *   Copyright (C)   2001-2003 AA Consortium.
 *
 *   This library is open source software; you can redistribute it 
 *   and/or modify it under the terms of the GNU Lesser General 
 *   Public License as published by the Free Software Foundation;   
 *   either version 2.0 of the License, or (at your option) any later 
 *   version.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free 
 *   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 *   MA  02111-1307 USA
 * 
 */

package org.agentacademy.modules.dataminer.classifiers.flnmap;

import java.util.*;
import org.agentacademy.modules.dataminer.core.*;
/**
 * Title:        s-FLNMAP learning
 * Description:  s-FLNMAP learning algorithm implementation in Java.
 * Copyright:    Copyright (c) 2002
 * Company:      ISSEL
 * @author Ioannis N. Athanasiadis
 * @version 1.0
 */

 public class Box {

private  double min[];
private  double max[];
private  int categ;




  public double valuation(){
  double resp =0.0;

  for (int i = 0 ; i < min.length ; i++){

  resp +=  1-(min[i]);
  resp +=    (max[i]);
//System.out.println(sigmaFlnmap.getMinMax(i,0));
//   resp +=  1-(min[i]-Flnmap.getMinMax(i,0))/(Flnmap.getMinMax(i,1)-Flnmap.getMinMax(i,0));
//   resp +=    (max[i]-Flnmap.getMinMax(i,1))/(Flnmap.getMinMax(i,1)-Flnmap.getMinMax(i,0));
//   resp +=  1-(min[i]-Flnmap.getMinMax(i,0))/(Flnmap.getMinMax(i,1)-Flnmap.getMinMax(i,0));
//   resp +=    (max[i]-getMinMax(i,1))/(getMinMax(i,1)-getMinMax(i,0));

//  System.out.println(i);
//  System.out.println(resp);
  }
  return resp;
  }


  public double valuation(Box bounds){
  double resp =0.0;

  for (int i = 0 ; i < min.length ; i++){

//  resp +=  1-(min[i]);
//  resp +=    (max[i]);

   resp +=  1-(min[i]-bounds.getMin(i))/(bounds.getMax(i)-bounds.getMin(i));
   resp +=    (max[i]-bounds.getMin(i))/(bounds.getMax(i)-bounds.getMin(i));

//  System.out.println(i);
//  System.out.println(resp);
  }
  return resp;
  }


/*
public float size(){
    int i;
    float resp =0;
    for (i = 0 ; i< min.length ; i++){
      resp +=(max[i]-min[i])/(DataReader.minmax[i][1] - DataReader.minmax[i][0]);
    }
    return resp;
  }
public float volume(){
    int i;
    float resp = 1;
    for (i = 0 ; i< min.length ; i++){
      resp *= (max[i]-min[i])/(DataReader.minmax[i][1] - DataReader.minmax[i][0]);
    }
    return resp;
  }
*/
public int length(){
    return min.length;
  }
/*
  public Box(Drecord dR) {
	min = new float[dR.length()];
	max = new float[dR.length()];

	for (int i = 0 ; i<=dR.length()-1; i++){
  		min[i] = dR.geti(i);
  		max[i] = dR.geti(i);
	}
	categ = dR.getCateg();
  }
*/
 public Box(Instance dR) {

	min = new double[dR.numAttributes()-1];
	max = new double[dR.numAttributes()-1];
        int k=0;
        for (int i=0; i<dR.numAttributes();i++){
          if (i!=dR.classIndex()) {
  	    min[k] = dR.value(i);
  	    max[k] = dR.value(i);
            k=k+1;
	  }

        }
	categ = (int) dR.value(dR.classIndex());

  }

 public Box(int length) {
	min = new double[length];
	max = new double[length];

	for (int i = 0 ; i<length; i++){
  		min[i] = 0;
  		max[i] = 0;
	}
	categ = -1;
  }


public static Box join(Box b1, Box b2){         // Lattice Join
        Box b = new Box(b1.length());
//        b=b1;
//       System.out.println("join");
//        b.showbox();
        int i;
	for (i=0; i < b1.min.length  ; i++){
          b.min[i]= (b1.min[i]<b2.min[i]) ? b1.min[i] : b2.min[i];
          b.max[i]= (b1.max[i]>b2.max[i]) ? b1.max[i] : b2.max[i];
         }
         b.categ = b1.categ;
//        b1.showbox();
//        b2.showbox();
//        b.showbox();
    return b;
  }

public int getCateg(){
    return  categ;
    }





public void setCateg(int i){
    categ = i ;
    }
public double getMin(int i ){
    return min[i];
    }
public double getMax(int i ){
    return max[i];
    }
public void setMin(int i, double val){
    min[i] = val;
    }
public void setMax(int i, double val){
    max[i] = val;
    }


public void saveMbox(){ // To be done

}
public void saveUbox(){ // To be done
}
public void showbox(){

  for (int i=0 ; i<min.length;i++){
    System.out.print("  [");
    System.out.print (min[i]);
    System.out.print("   ");
    System.out.print(max[i]);
    System.out.print("]  ");
  }
  System.out.print("in Class : ");
  System.out.print(categ);
  System.out.print("\n");
}

public String toString(){
   String rule = "";
  for (int i=0 ; i<min.length; i++){
    rule =  rule + "[ " + min[i] +"  "+ max[i] + " ]  ";
  }
  rule = rule + "in Class:  " + categ +" \n";
  return rule;
}



public Box (String rule){
   String seperator =" ";
//   Box code =new Box(3);

   int counter = 0;
    for ( int i = 0 ; i < rule.length(); i++ ) {
      String s = rule.substring(i,i+1);
    if ( s.equalsIgnoreCase(seperator) ){
        counter++;
        }
    }

 System.out.println("counter="+ counter);
 int size = (counter - 4)/6;
 System.out.println("size="+ size);
 	min = new double[size];
	max = new double[size];
    //    categ = -1;

int i=0;
int k=0;
 String temp="";
 Vector v = new Vector();
int s=0;
do{
    String character = rule.substring(s,s+1);
    temp = temp+character;
    if (character.equalsIgnoreCase(seperator)){
      if (!temp.equalsIgnoreCase(" ") ){
        k=k+1;
//       System.out.println(k%4 + "  " + temp);

        if (k%4==2){

          min[i] = Double.parseDouble(temp);
          System.out.println(i +" Min " + min[i]);
        } //if
        else if(k%4==3){
          max[i] = Double.parseDouble(temp);
          System.out.println(i +" Max " + max[i]);
          i=i+1;
        } //else
      }// if (!temp.equalsIgnoreCase(" ") ){
      temp="";
    }//if (character.equalsIgnoreCase(seperator)){
  s=s+1;
  }while(i<size);

  temp = rule.substring(s+12,rule.length()-1);
  temp=temp.trim();
  System.out.println(temp);
  categ = Integer.parseInt(temp);
System.out.print("OK");

}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -