internal virtual double getLikelihoodRatio(double num, int num2, Array2DRowRealMatrix array2DRowRealMatrix)
        {
            int    num3               = 13;
            double num4               = 0.5 * ((double)num3 + 0.5 * (double)num3 * (double)(num3 + 1)) * java.lang.Math.log((double)array2DRowRealMatrix.getRowDimension()) * 2.0;
            int    rowDimension       = array2DRowRealMatrix.getRowDimension();
            int    columnDimension    = array2DRowRealMatrix.getColumnDimension();
            Array2DRowRealMatrix mat  = (Array2DRowRealMatrix)array2DRowRealMatrix.getSubMatrix(0, num2 - 1, 0, columnDimension - 1);
            Array2DRowRealMatrix mat2 = (Array2DRowRealMatrix)array2DRowRealMatrix.getSubMatrix(num2, rowDimension - 1, 0, columnDimension - 1);
            double num5               = SpeakerIdentification.getBICValue(mat);
            double num6               = SpeakerIdentification.getBICValue(mat2);

            return(num - num5 - num6 - num4);
        }
Пример #2
0
        /**
         *
         * @param bicValue
         *            The bicValue of the model represented by only one Gaussian.
         *            This parameter it's useful when this function is called
         *            repeatedly for different frame values and the same features
         *            parameter
         * @param frame
         *            the frame which is tested for being a change point
         * @param features
         *            the feature vectors matrix
         * @return the likelihood ratio
         */

        static double GetLikelihoodRatio(double bicValue, int frame, Array2DRowRealMatrix features)
        {
            double bicValue1, bicValue2;
            int    d = Segment.FeaturesSize;
            double penalty = 0.5 * (d + 0.5 * d * (d + 1)) * Math.Log(features.getRowDimension()) * 2;
            int    nrows = features.getRowDimension(), ncols = features.getColumnDimension();
            Array2DRowRealMatrix sub1, sub2;

            sub1      = (Array2DRowRealMatrix)features.getSubMatrix(0, frame - 1, 0, ncols - 1);
            sub2      = (Array2DRowRealMatrix)features.getSubMatrix(frame, nrows - 1, 0, ncols - 1);
            bicValue1 = GetBICValue(sub1);
            bicValue2 = GetBICValue(sub2);
            return(bicValue - bicValue1 - bicValue2 - penalty);
        }
        public virtual ArrayList cluster(ArrayList features)
        {
            ArrayList            arrayList            = new ArrayList();
            Array2DRowRealMatrix array2DRowRealMatrix = this.ArrayToRealMatrix(features, features.size());
            LinkedList           allChangingPoints    = this.getAllChangingPoints(array2DRowRealMatrix);
            Iterator             iterator             = allChangingPoints.iterator();
            int num = ((Integer)iterator.next()).intValue();
            Array2DRowRealMatrix array2DRowRealMatrix2;

            while (iterator.hasNext())
            {
                int     num2 = ((Integer)iterator.next()).intValue();
                Segment s    = new Segment(num * 10, (num2 - num) * 10);
                array2DRowRealMatrix2 = (Array2DRowRealMatrix)array2DRowRealMatrix.getSubMatrix(num, num2 - 1, 0, 12);
                arrayList.add(new SpeakerCluster(s, array2DRowRealMatrix2, SpeakerIdentification.getBICValue(array2DRowRealMatrix2)));
                num = num2;
            }
            int num3 = arrayList.size();

            new Array2DRowRealMatrix(num3, num3);
            array2DRowRealMatrix2 = this.updateDistances(arrayList);
            for (;;)
            {
                double num4 = (double)0f;
                int    num5 = -1;
                int    num6 = -1;
                for (int i = 0; i < num3; i++)
                {
                    for (int j = 0; j < num3; j++)
                    {
                        if (i != j)
                        {
                            num4 += array2DRowRealMatrix2.getEntry(i, j);
                        }
                    }
                }
                num4 /= (double)(num3 * (num3 - 1) * 4);
                for (int i = 0; i < num3; i++)
                {
                    for (int j = 0; j < num3; j++)
                    {
                        if (array2DRowRealMatrix2.getEntry(i, j) < num4 && i != j)
                        {
                            num4 = array2DRowRealMatrix2.getEntry(i, j);
                            num5 = i;
                            num6 = j;
                        }
                    }
                }
                if (num5 == -1)
                {
                    break;
                }
                ((SpeakerCluster)arrayList.get(num5)).mergeWith((SpeakerCluster)arrayList.get(num6));
                this.updateDistances(arrayList, num5, num6, array2DRowRealMatrix2);
                arrayList.remove(num6);
                num3 += -1;
            }
            return(arrayList);
        }
Пример #4
0
        /**
         * @param start
         *            The starting frame
         * @param length
         *            The length of the interval, as numbers of frames
         * @param features
         *            The matrix build with feature vectors as rows
         * @return Returns the changing point in the input represented by features
         *
         */

        private static int GetPoint(int start, int length, int step, Array2DRowRealMatrix features)
        {
            double max = Double.NegativeInfinity;
            int    ncols = features.getColumnDimension(), point = 0;
            var    sub      = (Array2DRowRealMatrix)features.getSubMatrix(start, start + length - 1, 0, ncols - 1);
            double bicValue = GetBICValue(sub);

            for (int i = Segment.FeaturesSize + 1; i < length - Segment.FeaturesSize; i += step)
            {
                double aux = GetLikelihoodRatio(bicValue, i, sub);
                if (aux > max)
                {
                    max   = aux;
                    point = i;
                }
            }
            if (max < 0)
            {
                point = Integer.MIN_VALUE;
            }
            return(point + start);
        }
        private int getPoint(int num, int num2, int num3, Array2DRowRealMatrix array2DRowRealMatrix)
        {
            double num4            = double.NegativeInfinity;
            int    columnDimension = array2DRowRealMatrix.getColumnDimension();
            int    num5            = 0;
            Array2DRowRealMatrix array2DRowRealMatrix2 = (Array2DRowRealMatrix)array2DRowRealMatrix.getSubMatrix(num, num + num2 - 1, 0, columnDimension - 1);
            double num6 = SpeakerIdentification.getBICValue(array2DRowRealMatrix2);

            for (int i = 14; i < num2 - 13; i += num3)
            {
                double num7 = this.getLikelihoodRatio(num6, i, array2DRowRealMatrix2);
                if (num7 > num4)
                {
                    num4 = num7;
                    num5 = i;
                }
            }
            if (num4 < (double)0f)
            {
                num5 = int.MinValue;
            }
            return(num5 + num);
        }
Пример #6
0
        /**
         * @param features The feature vectors to be used for clustering
         * @return A cluster for each speaker detected based on the feature vectors provided
         */
        public List <SpeakerCluster> Cluster(List <float[]> features)
        {
            List <SpeakerCluster> ret            = new List <SpeakerCluster>();
            Array2DRowRealMatrix  featuresMatrix = ArrayToRealMatrix(features, features.Count);
            LinkedList <Integer>  l = GetAllChangingPoints(featuresMatrix);
            var it = l.GetEnumerator();
            int curent;

            it.MoveNext();
            int previous = it.Current;

            while (it.MoveNext())
            {
                curent = it.Current;
                Segment s = new Segment(previous * Segment.FrameLength, (curent - previous)
                                        * (Segment.FrameLength));
                Array2DRowRealMatrix featuresSubset = (Array2DRowRealMatrix)featuresMatrix.getSubMatrix(
                    previous, curent - 1, 0, 12);
                ret.Add(new SpeakerCluster(s, featuresSubset, GetBICValue(featuresSubset)));
                previous = curent;
            }
            int clusterCount = ret.Count;

            Array2DRowRealMatrix distance;

            distance = new Array2DRowRealMatrix(clusterCount, clusterCount);
            distance = UpdateDistances(ret);
            while (true)
            {
                double distmin = 0;
                int    imin = -1, jmin = -1;

                for (int i = 0; i < clusterCount; i++)
                {
                    for (int j = 0; j < clusterCount; j++)
                    {
                        if (i != j)
                        {
                            distmin += distance.getEntry(i, j);
                        }
                    }
                }
                distmin /= (clusterCount * (clusterCount - 1) * 4);

                for (int i = 0; i < clusterCount; i++)
                {
                    for (int j = 0; j < clusterCount; j++)
                    {
                        if (distance.getEntry(i, j) < distmin && i != j)
                        {
                            distmin = distance.getEntry(i, j);
                            imin    = i;
                            jmin    = j;
                        }
                    }
                }
                if (imin == -1)
                {
                    break;
                }
                ret[imin].MergeWith(ret[jmin]);
                UpdateDistances(ret, imin, jmin, distance);
                ret.Remove(jmin);
                clusterCount--;
            }
            return(ret);
        }