getData() public method

public getData ( ) : List
return List
Example #1
0
 /**
  * Make a deep copy of another Gesture object.
  *
  * @param original Another Gesture object
  */
 public Gesture(Gesture original)
 {
     this.data = new List<AccelerationVector>();
     var origin = original.getData();
     for (int i = 0; i < origin.Count; i++)
     {
         this.add((AccelerationVector)origin[i]);
     }
 }
Example #2
0
        /**
         * Make a deep copy of another Gesture object.
         *
         * @param original Another Gesture object
         */
        public Gesture(Gesture original)
        {
            this.data = new List <AccelerationVector>();
            var origin = original.getData();

            for (int i = 0; i < origin.Count; i++)
            {
                this.add((AccelerationVector)origin[i]);
            }
        }
Example #3
0
        /**
         * This methods looks up a Gesture to a group matrix, used by the
         * k-mean-algorithm (traincenteroid method) above.
         *
         * @param gesture
         *            the gesture
         */
        private int[,] deriveGroups(Gesture gesture)
        {
            List <AccelerationVector> data = gesture.getData();

            int[,] groups = new int[this.map.Length, data.Count];

            // Calculate cartesian distance
            double[,] d = new double[this.map.Length, data.Count];
            double[] curr   = new double[3];
            double[] vector = new double[3];

            for (int i = 0; i < this.map.Length; i++)
            { // lines
                var line = this.map[i];
                for (var j = 0; j < data.Count; j++)
                { // split
                    var accel = data[j];

                    curr[0] = accel.X;
                    curr[1] = accel.Y;
                    curr[2] = accel.Z;

                    vector[0] = line[0] - curr[0];
                    vector[1] = line[1] - curr[1];
                    vector[2] = line[2] - curr[2];
                    d[i, j]   = Math.Sqrt((vector[0] * vector[0])
                                          + (vector[1] * vector[1]) + (vector[2] * vector[2]));
                }
            }

            // look, to which group a value belongs
            for (int j = 0; j < data.Count; j++)
            {
                double smallest = Double.MaxValue;
                int    row      = 0;
                for (int i = 0; i < this.map.GetLength(0); i++)
                {
                    if (d[i, j] < smallest)
                    {
                        smallest = d[i, j];
                        row      = i;
                    }
                    groups[i, j] = 0;
                }
                groups[row, j] = 1; // group set
            }

            return(groups);
        }
Example #4
0
        /**
         * Trains this Quantizer with a specific gesture. This means that the
         * positions of the centeroids would adapt to this training gesture. In our
         * case this would happen with a summarized virtual gesture, containing all
         * the other gestures.
         *
         * @param gesture
         *            the summarized virtual gesture
         */
        public void trainCenteroids(Gesture gesture)
        {
            List <AccelerationVector> data = gesture.getData();
            double pi = Math.PI;

            this.radius = (gesture.getMaxAcceleration() + gesture.getMinAcceleration()) / 2;

            // x , z , y
            if (!this.maptrained)
            {
                this.maptrained = true;
                this.map[0]     = new double[] { this.radius, 0.0, 0.0 };
                this.map[1]     = new double[] { Math.Cos(pi / 4) * this.radius, 0.0,
                                                 Math.Sin(pi / 4) * this.radius };
                this.map[2] = new double[] { 0.0, 0.0, this.radius };
                this.map[3] = new double[] { Math.Cos(pi * 3 / 4) * this.radius,
                                             0.0, Math.Sin(pi * 3 / 4) * this.radius };
                this.map[4] = new double[] { -this.radius, 0.0, 0.0 };
                this.map[5] = new double[] { Math.Cos(pi * 5 / 4) * this.radius,
                                             0.0, Math.Sin(pi * 5 / 4) * this.radius };
                this.map[6] = new double[] { 0.0, 0.0, -this.radius };
                this.map[7] = new double[] { Math.Cos(pi * 7 / 4) * this.radius,
                                             0.0, Math.Sin(pi * 7 / 4) * this.radius };

                this.map[8] = new double[] { 0.0, this.radius, 0.0 };
                this.map[9] = new double[] { 0.0, Math.Cos(pi / 4) * this.radius,
                                             Math.Sin(pi / 4) * this.radius };
                this.map[10] = new double[] { 0.0,
                                              Math.Cos(pi * 3 / 4) * this.radius,
                                              Math.Sin(pi * 3 / 4) * this.radius };
                this.map[11] = new double[] { 0.0, -this.radius, 0.0 };
                this.map[12] = new double[] { 0.0,
                                              Math.Cos(pi * 5 / 4) * this.radius,
                                              Math.Sin(pi * 5 / 4) * this.radius };
                this.map[13] = new double[] { 0.0,
                                              Math.Cos(pi * 7 / 4) * this.radius,
                                              Math.Sin(pi * 7 / 4) * this.radius };
            }

            int[,] g_alt = new int[this.map.Length, data.Count];
            int[,] g     = new int[this.map.Length, data.Count];

            do
            {
                // Derive new Groups...
                g_alt = this.copyarray(g);
                g     = this.deriveGroups(gesture);

                // calculate new centeroids
                for (int i = 0; i < this.map.GetLength(0); i++)
                {
                    double zaehlerX = 0;
                    double zaehlerY = 0;
                    double zaehlerZ = 0;
                    int    nenner   = 0;
                    for (int j = 0; j < data.Count; j++)
                    {
                        if (g[i, j] == 1)
                        {
                            var e = data[j];
                            zaehlerX += e.X;
                            zaehlerY += e.Y;
                            zaehlerZ += e.Z;
                            nenner++;
                        }
                    }
                    if (nenner > 1) // nur wenn der nenner>0 oder >1??? ist muss
                                    // was
                    // geaendert werden
                    // Log.write("Setze neuen Centeroid!");
                    {
                        this.map[i] = new double[] { (zaehlerX / (double)nenner),
                                                     (zaehlerY / (double)nenner),
                                                     (zaehlerZ / (double)nenner) };
                        // Log.write("Centeroid: "+i+": "+newcenteroid[0]+":"+newcenteroid[1]);
                    }
                } // new centeroids
            } while (!equalarrays(g_alt, g));

            // Debug: Printout groups

            /*
             * for (int i = 0; i < n; i++) { for (int j = 0; j < this.data.Count;
             * j++) { Log.write(g[i][j] + "|"); } Log.write(""); }
             */
        }
Example #5
0
        /**
         * This methods looks up a Gesture to a group matrix, used by the
         * k-mean-algorithm (traincenteroid method) above.
         *
         * @param gesture
         *            the gesture
         */
        private int[,] deriveGroups(Gesture gesture)
        {
            List<AccelerationVector> data = gesture.getData();
            int[,] groups = new int[this.map.Length, data.Count];

            // Calculate cartesian distance
            double[,] d = new double[this.map.Length, data.Count];
            double[] curr = new double[3];
            double[] vector = new double[3];

            for (int i = 0; i < this.map.Length; i++)
            { // lines
                var line = this.map[i];
                for (var j = 0; j < data.Count; j++)
                { // split
                    var accel = data[j];

                    curr[0] = accel.X;
                    curr[1] = accel.Y;
                    curr[2] = accel.Z;

                    vector[0] = line[0] - curr[0];
                    vector[1] = line[1] - curr[1];
                    vector[2] = line[2] - curr[2];
                    d[i,j] = Math.Sqrt((vector[0] * vector[0])
                            + (vector[1] * vector[1]) + (vector[2] * vector[2]));
                }
            }

            // look, to which group a value belongs
            for (int j = 0; j < data.Count; j++)
            {
                double smallest = Double.MaxValue;
                int row = 0;
                for (int i = 0; i < this.map.GetLength(0); i++)
                {
                    if (d[i, j] < smallest)
                    {
                        smallest = d[i, j];
                        row = i;
                    }
                    groups[i, j] = 0;
                }
                groups[row, j] = 1; // group set
            }

            return groups;
        }
Example #6
0
        /**
         * Trains this Quantizer with a specific gesture. This means that the
         * positions of the centeroids would adapt to this training gesture. In our
         * case this would happen with a summarized virtual gesture, containing all
         * the other gestures.
         *
         * @param gesture
         *            the summarized virtual gesture
         */
        public void trainCenteroids(Gesture gesture)
        {
            List<AccelerationVector> data = gesture.getData();
            double pi = Math.PI;
            this.radius = (gesture.getMaxAcceleration() + gesture.getMinAcceleration()) / 2;

            // x , z , y
            if (!this.maptrained) {
            this.maptrained = true;
            this.map[0] = new double[] { this.radius, 0.0, 0.0 };
            this.map[1] = new double[] { Math.Cos(pi / 4) * this.radius, 0.0,
                    Math.Sin(pi / 4) * this.radius };
            this.map[2] = new double[] { 0.0, 0.0, this.radius };
            this.map[3] = new double[] { Math.Cos(pi * 3 / 4) * this.radius,
                    0.0, Math.Sin(pi * 3 / 4) * this.radius };
            this.map[4] = new double[] { -this.radius, 0.0, 0.0 };
            this.map[5] = new double[] { Math.Cos(pi * 5 / 4) * this.radius,
                    0.0, Math.Sin(pi * 5 / 4) * this.radius };
            this.map[6] = new double[] { 0.0, 0.0, -this.radius };
            this.map[7] = new double[] { Math.Cos(pi * 7 / 4) * this.radius,
                    0.0, Math.Sin(pi * 7 / 4) * this.radius };

            this.map[8] = new double[] { 0.0, this.radius, 0.0 };
            this.map[9] = new double[] { 0.0, Math.Cos(pi / 4) * this.radius,
                    Math.Sin(pi / 4) * this.radius };
            this.map[10] = new double[] { 0.0,
                    Math.Cos(pi * 3 / 4) * this.radius,
                    Math.Sin(pi * 3 / 4) * this.radius };
            this.map[11] = new double[] { 0.0, -this.radius, 0.0 };
            this.map[12] = new double[] { 0.0,
                    Math.Cos(pi * 5 / 4) * this.radius,
                    Math.Sin(pi * 5 / 4) * this.radius };
            this.map[13] = new double[] { 0.0,
                    Math.Cos(pi * 7 / 4) * this.radius,
                    Math.Sin(pi * 7 / 4) * this.radius };
            }

            int[,] g_alt = new int[this.map.Length, data.Count];
            int[,] g = new int[this.map.Length, data.Count];

            do {
            // Derive new Groups...
            g_alt = this.copyarray(g);
            g = this.deriveGroups(gesture);

            // calculate new centeroids
            for (int i = 0; i < this.map.GetLength(0); i++) {
                double zaehlerX = 0;
                double zaehlerY = 0;
                double zaehlerZ = 0;
                int nenner = 0;
                for (int j = 0; j < data.Count; j++) {
                    if (g[i,j] == 1) {
                        var e = data[j];
                        zaehlerX += e.X;
                        zaehlerY += e.Y;
                        zaehlerZ += e.Z;
                        nenner++;
                    }
                }
                if (nenner > 1) { // nur wenn der nenner>0 oder >1??? ist muss
                                    // was
                    // geaendert werden
                    // Log.write("Setze neuen Centeroid!");
                    this.map[i] = new double[] {(zaehlerX / (double) nenner),
                                                (zaehlerY / (double) nenner),
                                                (zaehlerZ / (double) nenner) };
                    // Log.write("Centeroid: "+i+": "+newcenteroid[0]+":"+newcenteroid[1]);
                }
            } // new centeroids

            } while (!equalarrays(g_alt, g));

            // Debug: Printout groups
            /*
             * for (int i = 0; i < n; i++) { for (int j = 0; j < this.data.Count;
             * j++) { Log.write(g[i][j] + "|"); } Log.write(""); }
             */
        }