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);
        }
Пример #2
0
        public static void testSpeakerIdentification(string inputFile)
        {
            FileInputStream stream   = new FileInputStream(inputFile);
            ArrayList       speakers = new SpeakerIdentification().cluster(stream);

            Tester.printIntervals(speakers);
            Tester.printSpeakerIntervals(speakers, inputFile);
        }
        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);
        }
        internal virtual double computeDistance(SpeakerCluster speakerCluster, SpeakerCluster speakerCluster2)
        {
            int rowDimension    = speakerCluster.getFeatureMatrix().getRowDimension() + speakerCluster2.getFeatureMatrix().getRowDimension();
            int columnDimension = speakerCluster.getFeatureMatrix().getColumnDimension();
            Array2DRowRealMatrix array2DRowRealMatrix = new Array2DRowRealMatrix(rowDimension, columnDimension);

            array2DRowRealMatrix.setSubMatrix(speakerCluster.getFeatureMatrix().getData(), 0, 0);
            array2DRowRealMatrix.setSubMatrix(speakerCluster2.getFeatureMatrix().getData(), speakerCluster.getFeatureMatrix().getRowDimension(), 0);
            double num  = SpeakerIdentification.getBICValue(array2DRowRealMatrix);
            double num2 = 13.0;
            double num3 = 0.5 * (num2 + 0.5 * num2 * (num2 + (double)1f)) * java.lang.Math.log((double)array2DRowRealMatrix.getRowDimension()) * 2.0;

            return(num - speakerCluster.getBicValue() - speakerCluster2.getBicValue() - num3);
        }
        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
        public virtual void mergeWith(SpeakerCluster target)
        {
            if (target == null)
            {
                throw new NullPointerException();
            }
            Iterator iterator = target.segmentSet.iterator();

            while (iterator.hasNext())
            {
                if (!this.addSegment((Segment)iterator.next()).booleanValue())
                {
                    [email protected]("Something doesn't work in mergeWith method, Cluster class");
                }
            }
            int rowDimension    = this.featureMatrix.getRowDimension() + target.getFeatureMatrix().getRowDimension();
            int columnDimension = this.featureMatrix.getColumnDimension();
            Array2DRowRealMatrix array2DRowRealMatrix = new Array2DRowRealMatrix(rowDimension, columnDimension);

            array2DRowRealMatrix.setSubMatrix(this.featureMatrix.getData(), 0, 0);
            array2DRowRealMatrix.setSubMatrix(target.getFeatureMatrix().getData(), this.featureMatrix.getRowDimension(), 0);
            this.bicValue      = SpeakerIdentification.getBICValue(array2DRowRealMatrix);
            this.featureMatrix = new Array2DRowRealMatrix(array2DRowRealMatrix.getData());
        }