Hauptseite   Packages   Klassenhierarchie   ?bersicht   Auflistung der Dateien   Datenstruktur-Elemente  

Gauss2ARFF.java

gehe zur Dokumentation dieser Datei
00001 /*
00002  * $Source: /shared/cvsroot/diplom/app/src/java/de/picana/generator/Gauss2ARFF.java,v $
00003  * $Author: mstolpe $
00004  * $Date: 2003/04/22 09:51:28 $
00005  * $Revision: 1.4 $
00006  * $Release$
00007  *
00008  * Created on 14. November 2002, 11:02
00009  * 
00010  * Copyright 2002 by Marco Stolpe
00011  */
00012 
00013 package de.picana.generator;
00014 
00015 import de.picana.control.*;
00016 import de.picana.logging.*;
00017 
00018 import java.util.*;
00019 import java.io.*;
00020 
00021 
00028 public class Gauss2ARFF extends Task {
00029 
00030     private String out_filename;
00031     private String relation;
00032     private int num_instances;
00033     private boolean invert;
00034     private Vector attributes;
00035     
00036     
00037     class Attr {
00038         public String name;
00039         public double min;
00040         public double max;
00041         
00042         Attr(String name, double min, double max) {
00043             this.name = name;
00044             this.min = min;
00045             this.max = max;
00046         }
00047     }
00048     
00049         
00051     public Gauss2ARFF() {
00052     }
00053 
00054     public void init(ParameterSet params, Logger logger) {
00055         
00056         super.init(params, logger);
00057         
00058         attributes = new Vector();   
00059         
00060         out_filename = (String)params.getParameter("out");
00061         relation = (String)params.getParameter("relation");
00062         
00063         num_instances = 1000;
00064         try {
00065             num_instances = Integer.parseInt((String)params.getParameter("num_instances"));
00066         } catch (NumberFormatException nfe) {}
00067         
00068         invert = false;
00069         try {
00070             invert = (Boolean.valueOf((String)params.getParameter("invert"))).booleanValue();
00071         } catch (NumberFormatException nfe) {}
00072         
00073         ParameterSet attribute_set = (ParameterSet)params.getParameter("attributes");
00074         Enumeration attribute_names = attribute_set.getParameterNames();
00075         while (attribute_names.hasMoreElements()) {
00076             String name = (String)attribute_names.nextElement();
00077             ParameterSet attribute = (ParameterSet)attribute_set.getParameter(name);
00078             
00079             double min = 0.0;
00080             try {
00081                 min = Double.parseDouble((String)attribute.getParameter("min"));
00082             } catch (NumberFormatException nfe) {}
00083             
00084             double max = 0.0;
00085             try {
00086                 max = Double.parseDouble((String)attribute.getParameter("max"));
00087             } catch (NumberFormatException nfe) {}
00088             
00089             attributes.addElement(new Attr(attribute.getName(), min, max));
00090         }       
00091     }
00092     
00093     public void start() throws TaskException {
00094         
00095         try {
00096             logger.info(LOGSRC, "Started.");
00097             
00098             Random rand = new Random();
00099             
00100             FileOutputStream output = new FileOutputStream(new File(out_filename));
00101             PrintWriter pw = new PrintWriter(output);
00102             
00103             pw.println("% ARFF file for picture data from PNG files");
00104             pw.println("%");
00105             pw.println("@relation " + relation);
00106             pw.println();
00107             for (int i=0; i < attributes.size(); i++) {
00108                 Attr a = (Attr)attributes.elementAt(i);
00109                 pw.println("@attribute " + a.name + " numeric");
00110             }
00111             pw.println();
00112             pw.println("@data");
00113             pw.println("%");
00114             pw.println("% x instances");
00115             pw.println("%");
00116     
00117             for (int n=0; n < num_instances; n++) {
00118                 for (int i=0; i < attributes.size(); i++) {
00119                     Attr a = (Attr)attributes.elementAt(i);
00120                     boolean found = false;
00121                     double g = 0.0;
00122                     while (!found) {
00123                         if (!invert) {
00124                             g = rand.nextGaussian() + 0.5;
00125                             if ((g >= 0.0) && (g <= 1.0))
00126                                 found = true;
00127                         } else {
00128                             g = rand.nextGaussian();
00129                             if ((g >= -0.5) && (g < 0.0)) {
00130                                 //System.out.print(g);
00131                                 g = Math.abs(g);
00132                                 //System.out.println(" -> " + g);
00133                                 found = true;
00134                             } else if ((g >= 0.0) && (g <= 0.5)) {
00135                                 //System.out.print(g);
00136                                 g = (1-g);
00137                                 //System.out.println(" -> " + g);
00138                                 found = true;
00139                             }
00140                         }
00141                     }
00142                     pw.print(g * (a.max-a.min) + a.min);
00143                     if (i != attributes.size()-1) {
00144                         pw.print(",");    
00145                     }
00146                 }
00147                 pw.println();
00148             }
00149             
00150             pw.close();
00151             
00152             logger.info(LOGSRC, "Stopped.");
00153             
00154         } catch (Exception e) {
00155             throw new TaskException(e.toString());    
00156         }
00157     }
00158     
00159     public void stop() {
00160     }
00161     public void pause() {
00162     }
00163     public void resume() {
00164     }
00165 }

Erzeugt am Tue Apr 22 11:22:55 2003 f?r Picana von doxygen1.2.18