Exemple #1
0
        /*
         * private IEnumerable<TupleStruct<Kmer<Ty>, double>> ExtractUncharacteristicKmersForClass (int classIndex, MultisetKmer<Ty> thisClass, MultisetKmer<Ty> baseline)
         * {
         *      //This will only work with an enormous amount of data for low k.
         * }
         */


        //Calculation:

        //Synthesize features for an item.
        //TODO: Enforce contract
        public double[] SynthesizeFeatures(DiscreteEventSeries <Ty> item)
        {
            double[] vals = new double[kmerCount];

            MultisetKmer <Ty> ms = item.ToMultisetVarKmer <Ty>(k);

            foreach (KeyValuePair <Kmer <Ty>, int> kvp in ms)
            {
                int index = 0;
                if (kmersOntoIndex.TryGetValue(kvp.Key, out index))
                {
                    vals[index] = kvp.Value / (double)ms.Size((int)kvp.Key.Count);
                }
            }

            return(vals);
        }
Exemple #2
0
        //Extract characteristic kmers (top n more common than baseline that occur at least q times).
        private IEnumerable <TupleStruct <Kmer <Ty>, double> > ExtractCharacteristicKmersForClass(int classIndex, MultisetKmer <Ty> thisClass, MultisetKmer <Ty> baseline)
        {
            List <TupleStruct <Kmer <Ty>, double> > thisClassCharacteristicKmersStore = new List <TupleStruct <Kmer <Ty>, double> >();

            foreach (KeyValuePair <Kmer <Ty>, int> kvp in thisClass)
            {
                if (kvp.Value > minKmerCount)
                {
                    double thisFreq = kvp.Value / (double)thisClass.Size(kvp.Key.Count);
                    double baseFreq = baseline.GetKeyFracLaplace(kvp.Key, smoothingAmt);

                    //Console.WriteLine ("Class: " +  classIndex + " Kmer: " + kvp.Value + ", class freq " + thisFreq + ", base freq " + baseFreq);

                    //TODO: Advanced logic.
                    if (thisFreq > baseFreq)
                    {
                        double kmerValue = thisFreq / baseFreq - 1;
                        //Console.WriteLine ("Adding kmer " + kvp.Key + " weight " + kmerValue + " for class " + classIndex);
                        thisClassCharacteristicKmersStore.Add(new TupleStruct <Kmer <Ty>, double>(kvp.Key, kmerValue));
                    }
                }
            }
            return(thisClassCharacteristicKmersStore.OrderByDescending(tup => Math.Abs(tup.Item2)).Take((int)kmersToTake));
        }