Пример #1
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);
        }
        private LinkedList getAllChangingPoints(Array2DRowRealMatrix array2DRowRealMatrix)
        {
            LinkedList linkedList = new LinkedList();

            linkedList.add(Integer.valueOf(0));
            int rowDimension = array2DRowRealMatrix.getRowDimension();
            int num          = 500;
            int num2         = 0;
            int i            = num;

            while (i < rowDimension)
            {
                int point = this.getPoint(num2, i - num2 + 1, num / 10, array2DRowRealMatrix);
                if (point > 0)
                {
                    num2 = point;
                    i    = num2 + num;
                    linkedList.add(Integer.valueOf(point));
                }
                else
                {
                    i += num;
                }
            }
            linkedList.add(Integer.valueOf(rowDimension));
            return(linkedList);
        }
Пример #3
0
        /**
         *
         * @param features
         *            Matrix with feature vectors as rows
         * @return A list with all changing points detected in the file
         */
        private LinkedList <Integer> GetAllChangingPoints(Array2DRowRealMatrix features)
        {
            LinkedList <Integer> ret = new LinkedList <Integer>();

            ret.Add(0);
            int framesCount = features.getRowDimension(), step = 500;
            int start = 0, end = step, cp;

            while (end < framesCount)
            {
                cp = GetPoint(start, end - start + 1, step / 10, features);
                if (cp > 0)
                {
                    start = cp;
                    end   = start + step;
                    ret.Add(cp);
                }
                else
                {
                    end += step;
                }
            }
            ret.Add(framesCount);
            return(ret);
        }
 internal virtual void printMatrix(Array2DRowRealMatrix array2DRowRealMatrix)
 {
     for (int i = 0; i < array2DRowRealMatrix.getRowDimension(); i++)
     {
         for (int j = 0; j < array2DRowRealMatrix.getColumnDimension(); j++)
         {
             [email protected](new StringBuilder().append(array2DRowRealMatrix.getEntry(i, j)).append(" ").toString());
         }
         [email protected]();
     }
 }
Пример #5
0
 void PrintMatrix(Array2DRowRealMatrix a)
 {
     for (int i = 0; i < a.getRowDimension(); i++)
     {
         for (int j = 0; j < a.getColumnDimension(); j++)
         {
             Console.Write(a.getEntry(i, j) + " ");
         }
         Console.WriteLine();
     }
 }
        public static double getBICValue(Array2DRowRealMatrix mat)
        {
            double             num = (double)0f;
            EigenDecomposition eigenDecomposition = new EigenDecomposition(new Covariance(mat).getCovarianceMatrix());

            double[] realEigenvalues = eigenDecomposition.getRealEigenvalues();
            for (int i = 0; i < realEigenvalues.Length; i++)
            {
                num += java.lang.Math.log(realEigenvalues[i]);
            }
            return(num * (double)(mat.getRowDimension() / 2));
        }
Пример #7
0
        /**
         * @param mat
         *            A matrix with feature vectors as rows.
         * @return Returns the BICValue of the Gaussian model that approximates the
         *         the feature vectors data samples
         */
        public static double GetBICValue(Array2DRowRealMatrix mat)
        {
            double             ret = 0;
            EigenDecomposition ed  = new EigenDecomposition(new Covariance(mat).getCovarianceMatrix());

            double[] re = ed.getRealEigenvalues();
            for (int i = 0; i < re.Length; i++)
            {
                ret += Math.Log(re[i]);
            }
            return(ret * (mat.getRowDimension() / 2));
        }
        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);
        }
Пример #9
0
        static double ComputeDistance(SpeakerCluster c1, SpeakerCluster c2)
        {
            int rowDim = c1.FeatureMatrix.getRowDimension() + c2.FeatureMatrix.getRowDimension();
            int colDim = c1.FeatureMatrix.getColumnDimension();
            Array2DRowRealMatrix combinedFeatures = new Array2DRowRealMatrix(rowDim, colDim);

            combinedFeatures.setSubMatrix(c1.FeatureMatrix.getData(), 0, 0);
            combinedFeatures.setSubMatrix(c2.FeatureMatrix.getData(), c1.FeatureMatrix.getRowDimension(), 0);
            double bicValue = GetBICValue(combinedFeatures);
            double d        = Segment.FeaturesSize;
            double penalty  = 0.5 * (d + 0.5 * d * (d + 1)) * Math.Log(combinedFeatures.getRowDimension()) * 2;

            return(bicValue - c1.GetBicValue() - c2.GetBicValue() - penalty);
        }
        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);
        }