DataSet.java
Go to the documentation of this file.
00001 package edu.wpi.rail.jinteractiveworld.data;
00002 
00003 import java.util.ArrayList;
00004 
00005 import edu.wpi.rail.jinteractiveworld.ros.msgs.interactiveworldmsgs.*;
00006 import weka.core.*;
00007 
00015 public class DataSet {
00016 
00020         public static final int N = 4;
00021 
00025         public static final Attribute X_ATTRIBUTE = new Attribute("x");
00026 
00030         public static final Attribute Y_ATTRIBUTE = new Attribute("y");
00031 
00035         public static final Attribute Z_ATTRIBUTE = new Attribute("z");
00036 
00040         public static final Attribute THETA_ATTRIBUTE = new Attribute("theta");
00041 
00042         private ArrayList<DataPoint> data;
00043         private Item item;
00044         private Room room;
00045         private Surface surface;
00046         private String referenceFrame;
00050         public DataSet() {
00051                 this(new Item(), new Room(), new Surface(), "");
00052         }
00053 
00066         public DataSet(Item item, Room room, Surface surface, String referenceFrame) {
00067                 this.item = item;
00068                 this.room = room;
00069                 this.surface = surface;
00070                 this.referenceFrame = referenceFrame;
00071                 this.data = new ArrayList<DataPoint>();
00072         }
00073 
00079         public String getReferenceFrame() {
00080                 return this.referenceFrame;
00081         }
00082 
00088         public Item getItem() {
00089                 return this.item;
00090         }
00091 
00097         public Room getRoom() {
00098                 return this.room;
00099         }
00100 
00106         public Surface getSurface() {
00107                 return this.surface;
00108         }
00109 
00115         public int size() {
00116                 return this.data.size();
00117         }
00118 
00131         public void add(double x, double y, double z, double theta) {
00132                 this.add(new DataPoint(x, y, z, theta));
00133         }
00134 
00141         public void add(DataPoint point) {
00142                 this.data.add(point);
00143         }
00144 
00152         public DataPoint get(int index) {
00153                 return this.data.get(index);
00154         }
00155 
00161         public Instances toInstances() {
00162                 // attributes for the set
00163                 FastVector attributes = new FastVector(DataSet.N);
00164                 attributes.addElement(DataSet.X_ATTRIBUTE);
00165                 attributes.addElement(DataSet.Y_ATTRIBUTE);
00166                 attributes.addElement(DataSet.Z_ATTRIBUTE);
00167                 attributes.addElement(DataSet.THETA_ATTRIBUTE);
00168 
00169                 Instances instances = new Instances("data", attributes, this.size());
00170                 // add each instance
00171                 for (int i = 0; i < this.size(); i++) {
00172                         // get the data
00173                         DataPoint point = this.get(i);
00174 
00175                         Instance inst = new Instance(DataSet.N);
00176                         inst.setDataset(instances);
00177                         // x, y, z, theta
00178                         inst.setValue(DataSet.X_ATTRIBUTE, point.getX());
00179                         inst.setValue(DataSet.Y_ATTRIBUTE, point.getY());
00180                         inst.setValue(DataSet.Z_ATTRIBUTE, point.getZ());
00181                         inst.setValue(DataSet.THETA_ATTRIBUTE, point.getTheta());
00182 
00183                         instances.add(inst);
00184                 }
00185 
00186                 return instances;
00187         }
00188 
00194         public double getMinX() {
00195                 double minX = Double.POSITIVE_INFINITY;
00196                 for (DataPoint point : this.data) {
00197                         if (point.getX() < minX) {
00198                                 minX = point.getX();
00199                         }
00200                 }
00201                 return minX;
00202         }
00203 
00209         public double getMaxX() {
00210                 double maxX = Double.NEGATIVE_INFINITY;
00211                 for (DataPoint point : this.data) {
00212                         if (point.getX() > maxX) {
00213                                 maxX = point.getX();
00214                         }
00215                 }
00216                 return maxX;
00217         }
00218 
00224         public double getMinY() {
00225                 double minY = Double.POSITIVE_INFINITY;
00226                 for (DataPoint point : this.data) {
00227                         if (point.getY() < minY) {
00228                                 minY = point.getY();
00229                         }
00230                 }
00231                 return minY;
00232         }
00233 
00239         public double getMaxY() {
00240                 double maxY = Double.NEGATIVE_INFINITY;
00241                 for (DataPoint point : this.data) {
00242                         if (point.getY() > maxY) {
00243                                 maxY = point.getY();
00244                         }
00245                 }
00246                 return maxY;
00247         }
00248 
00254         public double getMinZ() {
00255                 double minZ = Double.POSITIVE_INFINITY;
00256                 for (DataPoint point : this.data) {
00257                         if (point.getZ() < minZ) {
00258                                 minZ = point.getZ();
00259                         }
00260                 }
00261                 return minZ;
00262         }
00263 
00269         public double getMaxZ() {
00270                 double maxZ = Double.NEGATIVE_INFINITY;
00271                 for (DataPoint point : this.data) {
00272                         if (point.getZ() > maxZ) {
00273                                 maxZ = point.getZ();
00274                         }
00275                 }
00276                 return maxZ;
00277         }
00278 }


jinteractiveworld
Author(s): Russell Toris
autogenerated on Thu Jun 6 2019 21:34:23