Esempio n. 1
0
        public ArrayList <KeyDat <double, int> > RankFeatures() // Guyon et al. 2002
        {
            Utils.ThrowException(mModelId == -1 ? new InvalidOperationException() : null);
            ArrayList <KeyDat <double, int> > result = new ArrayList <KeyDat <double, int> >();

            if (mKernelType != SvmLightKernelType.Linear)
            {
                // any kernel
                int    numFeat = SvmLightLib.GetFeatureCount(mModelId);
                double allFeat = 0.5 * ComputeCost(-1);
                for (int i = 0; i < numFeat; i++)
                {
                    //Console.WriteLine("{0} / {1}", i + 1, numFeat);
                    double featScore = Math.Abs(allFeat - 0.5 * ComputeCost(/*rmvFeatIdx=*/ i));
                    result.Add(new KeyDat <double, int>(featScore, i));
                }
            }
            else
            {
                // linear kernel (fast)
                double[] w = GetLinearWeights();
                for (int i = 0; i < w.Length; i++)
                {
                    result.Add(new KeyDat <double, int>(0.5 * w[i] * w[i], i));
                }
            }
            result.Sort(DescSort <KeyDat <double, int> > .Instance);
            return(result);
        }
Esempio n. 2
0
        public double[] GetLinearWeights()
        {
            Utils.ThrowException(mModelId == -1 ? new InvalidOperationException() : null);
            Utils.ThrowException(mKernelType != SvmLightKernelType.Linear ? new InvalidOperationException() : null);
            if (mWeights != null)
            {
                return(mWeights);
            }
            int featureCount = SvmLightLib.GetFeatureCount(mModelId);

            double[] weights = new double[featureCount];
            for (int i = 0; i < featureCount; i++)
            {
                weights[i] = SvmLightLib.GetLinearWeight(mModelId, i);
            }
            mWeights = weights;
            return(weights);
        }