예제 #1
0
        private static void makeHistogramsWithHJPD(List <List <Skeleton> > allSkeletons, out List <List <Histogram> > histograms, out SortedDictionary <JointType, BinDefinition> binDefinitions)
        {
            histograms     = new List <List <Histogram> >();
            binDefinitions = HJPDSkeletonHistogrammer.binDefinitionsFor(allSkeletons);
            // Adjust the lower and upper bounds by a very small amount because Math.Net will throw an exception
            // when a Histogram is constructed with explicit data and bounds where a data value is precisely
            // equal to a bound. Seriously, WTF.
            foreach (JointType j in binDefinitions.Keys.ToList())
            {
                BinDefinition binDef = binDefinitions[j];
                binDef.lowerBound = binDef.lowerBound.Decrement();
                binDef.upperBound = binDef.upperBound.Increment();
                binDefinitions[j] = binDef;
            }
            SkeletonHistogrammer histogrammer = new HJPDSkeletonHistogrammer(binDefinitions);

            for (int instNum = 0; instNum < allSkeletons.Count; ++instNum)
            {
                if (allSkeletons[instNum].Count == 0)
                {
                    continue;
                }
                histograms.Add(histogrammer.processSkeletons(allSkeletons[instNum]));
            }
        }
예제 #2
0
        private static SkeletonHistogrammer makeHJPDHistogrammer(string datapath)
        {
            string[] binDefLines = System.IO.File.ReadAllLines(datapath);
            SortedDictionary <JointType, BinDefinition> binDefinitions = new SortedDictionary <JointType, BinDefinition>();

            foreach (string binDefLine in binDefLines)
            {
                string[]      vals   = binDefLine.Split();
                BinDefinition binDef = new BinDefinition();
                binDef.lowerBound = double.Parse(vals[1]);
                binDef.numBins    = int.Parse(vals[2]);
                binDef.upperBound = double.Parse(vals[3]);
                binDefinitions[(JointType)int.Parse(vals[0])] = binDef;
            }
            return(new HJPDSkeletonHistogrammer(binDefinitions));
        }
예제 #3
0
        private static SkeletonHistogrammer makeRADHistogrammer(List <JointType> jointList, string datapath)
        {
            string[]             binDefLines    = System.IO.File.ReadAllLines(datapath);
            List <BinDefinition> binDefinitions = new List <BinDefinition>();

            foreach (string binDefLine in binDefLines)
            {
                string[]      vals   = binDefLine.Split();
                BinDefinition binDef = new BinDefinition()
                {
                    lowerBound = double.Parse(vals[1]),
                    upperBound = double.Parse(vals[3]),
                    numBins    = int.Parse(vals[2])
                };
                binDefinitions.Add(binDef);
            }
            return(new RADSkeletonHistogrammer(jointList, binDefinitions));
        }
        public void UpdateData()
        {
            //Reset scope measures
            ownerCharCount        = 0;
            otherCharCount        = 0;
            ownerWordCount        = 0;
            otherWordCount        = 0;
            ownerMessageCount     = 0;
            otherMessageCount     = 0;
            ownerCommaCount       = 0;
            otherCommaCount       = 0;
            ownerQuestionCount    = 0;
            otherQuestionCount    = 0;
            ownerExclamationCount = 0;
            otherExclamationCount = 0;
            ownerLinkCount        = 0;
            otherLinkCount        = 0;

            //Reset lexical measures
            currentLexic.Clear();
            currentWordCount = 0;

            //Helpful time objects
            TimeSpan fullYear = new TimeSpan(365, 0, 0, 0);
            TimeSpan fullWeek = new TimeSpan(7, 0, 0, 0);
            TimeSpan fullDay  = new TimeSpan(24, 0, 0);

            //Create BoundChecker
            switch (timeMode)
            {
            case TimeMode.Linear:
                boundChecker = (m) => m.time.Ticks > beginTimeScope && m.time.Ticks < endTimeScope;
                break;

            case TimeMode.Year:
                boundChecker = (m) => m.timeMeasures[0] > beginTimeScope && m.timeMeasures[0] < endTimeScope;
                break;

            case TimeMode.WeekDay:
                boundChecker = (m) => m.timeMeasures[1] > beginTimeScope && m.timeMeasures[1] < endTimeScope;
                break;

            case TimeMode.HourMinute:
                boundChecker = (m) => m.timeMeasures[2] > beginTimeScope && m.timeMeasures[2] < endTimeScope;
                break;
            }

            //CreateBins
            binDefinitions = new BinDefinition[binCount];
            for (int i = 0; i < binCount; i++)
            {
                BinDefinition binDef = new BinDefinition();
                binDefinitions[i] = binDef;

                //find bins acording to zoom

                binDef.axisStart = i * (1.0 / binCount);
                binDef.axisEnd   = (i + 1) * (1.0 / binCount);

                switch (timeMode)
                {
                case TimeMode.Linear:
                    binDef.timeStart = beginTimeScope + i * (endTimeScope - beginTimeScope) / (binCount);       //Integer division because of irrelevant sizes
                    binDef.timeEnd   = beginTimeScope + (i + 1) * (endTimeScope - beginTimeScope) / (binCount); //Integer division because of irrelevant sizes

                    binDef.checker = (m) => m.time.Ticks > binDef.timeStart && m.time.Ticks < binDef.timeEnd;
                    break;

                case TimeMode.Year:
                    binDef.timeStart = beginTimeScope + (long)(i * (endTimeScope - beginTimeScope) / (double)binCount);
                    binDef.timeEnd   = beginTimeScope + (long)((i + 1) * (endTimeScope - beginTimeScope) / (double)binCount);

                    binDef.checker = (m) => m.timeMeasures[0] > binDef.timeStart && m.timeMeasures[0] < binDef.timeEnd;
                    break;

                case TimeMode.WeekDay:
                    binDef.timeStart = beginTimeScope + (long)(i * (endTimeScope - beginTimeScope) / (double)binCount);
                    binDef.timeEnd   = beginTimeScope + (long)((i + 1) * (endTimeScope - beginTimeScope) / (double)binCount);

                    binDef.checker = (m) => m.timeMeasures[1] > binDef.timeStart && m.timeMeasures[1] < binDef.timeEnd;
                    break;

                case TimeMode.HourMinute:
                    binDef.timeStart = beginTimeScope + (long)(i * (endTimeScope - beginTimeScope) / (double)binCount);
                    binDef.timeEnd   = beginTimeScope + (long)((i + 1) * (endTimeScope - beginTimeScope) / (double)binCount);

                    binDef.checker = (m) => m.timeMeasures[2] > binDef.timeStart && m.timeMeasures[2] < binDef.timeEnd;
                    break;
                }
            }

            //Synchronize data measures and output data structures
            if (plotsData.Count != measures.Count)
            {
                int diff = measures.Count - plotsData.Count;
                if (diff > 0)
                {
                    while (measures.Count != plotsData.Count)
                    {
                        plotsData.Add(new PlotData());
                    }
                }
                else
                {
                    while (measures.Count != plotsData.Count)
                    {
                        plotsData.RemoveAt(0);
                    }
                }
            }
            //Synchronize self data measures and output data structures
            if (selfSplitMode)
            {
                if (selfPlotsData.Count != measures.Count)
                {
                    int diff = measures.Count - selfPlotsData.Count;
                    if (diff > 0)
                    {
                        while (measures.Count != selfPlotsData.Count)
                        {
                            selfPlotsData.Add(new PlotData());
                        }
                    }
                    else
                    {
                        while (measures.Count != selfPlotsData.Count)
                        {
                            selfPlotsData.RemoveAt(0);
                        }
                    }
                }
            }

            //Reset data
            for (int i = 0; i < measures.Count; i++)
            {
                PlotData plotData = plotsData[i];

                plotData.measure = measures[i];

                if (plotData.binValues == null)
                {
                    plotData.binValues = new double[binCount];
                }
                if (plotData.binValues.Length != binCount)
                {
                    plotData.binValues = new double[binCount];
                }

                //Clear previous data
                for (int k = 0; k < plotData.binValues.Length; k++)
                {
                    plotData.binValues[k] = 0;
                }

                //Reset maximum value
                plotData.max = double.MinValue;


                //Reset self data
                if (selfSplitMode)
                {
                    plotData = selfPlotsData[i];

                    plotData.measure = measures[i];

                    if (plotData.binValues == null)
                    {
                        plotData.binValues = new double[binCount];
                    }
                    if (plotData.binValues.Length != binCount)
                    {
                        plotData.binValues = new double[binCount];
                    }

                    //Clear previous data
                    for (int k = 0; k < plotData.binValues.Length; k++)
                    {
                        plotData.binValues[k] = 0;
                    }

                    //Reset maximum value
                    plotData.max = double.MinValue;
                }
            }

            //process messsages
            Message       msg;
            LexicPresence presence;
            int           bin = 0;

            for (int k = 0; k < baseMessages.Count; k++)
            {
                msg = baseMessages[k];

                //Skip message if author not on people filter
                if (peopleFilter != null)
                {
                    if (!peopleFilter.Contains(msg.author))
                    {
                        continue;
                    }
                }


                //Skip message if outside time bounds
                if (!boundChecker(msg))
                {
                    continue;
                }

                //Compute Full scope measures
                if (msg.author == owner)
                {
                    ownerCharCount += (int)msg.measures[0];
                    ownerWordCount += (int)msg.measures[1];
                    ownerMessageCount++;
                    ownerCommaCount       += (int)msg.measures[5];
                    ownerQuestionCount    += (int)msg.measures[2];
                    ownerExclamationCount += (int)msg.measures[3];
                    ownerLinkCount        += (int)msg.measures[6];
                }
                else
                {
                    otherCharCount += (int)msg.measures[0];
                    otherWordCount += (int)msg.measures[1];
                    otherMessageCount++;
                    otherCommaCount       += (int)msg.measures[5];
                    otherQuestionCount    += (int)msg.measures[2];
                    otherExclamationCount += (int)msg.measures[3];
                    otherLinkCount        += (int)msg.measures[6];
                }


                //TODO Check first if bin changed optimization
                //Find aggregation bin
                for (int b = 0; b < binCount; b++)
                {
                    if (binDefinitions[b].checker(msg))
                    {
                        bin = b;
                        break;
                    }
                }

                //Compute lexic
                string[] words = msg.text.Split(' ');
                currentWordCount += words.Length;
                for (int w = 0; w < words.Length; w++)
                {
                    string word = words[w];
                    if (currentLexic.ContainsKey(word))
                    {
                        presence = currentLexic[word];
                        presence.count++;
                        presence.placement += binDefinitions[bin].AxisCenter;
                    }
                    else
                    {
                        currentLexic.Add(word, new LexicPresence(word, 1, binDefinitions[bin].AxisCenter));
                    }
                }

                //Aggregate message to measure bins
                for (int m = 0; m < measures.Count; m++)
                {
                    if (!selfSplitMode)
                    {
                        //Regular non-split mode
                        plotsData[m].binValues[bin] += msg.measures[measures[m]];
                    }
                    else
                    {
                        //Split mode
                        if (msg.author == owner)
                        {
                            //add to selfplotdata
                            selfPlotsData[m].binValues[bin] += msg.measures[measures[m]];
                        }
                        else
                        {
                            //add to regular plotdata
                            plotsData[m].binValues[bin] += msg.measures[measures[m]];
                        }
                    }
                }
            }


            //Process final results
            //Get maxims
            for (int m = 0; m < measures.Count; m++)
            {
                for (int b = 0; b < binCount; b++)
                {
                    if (plotsData[m].binValues[b] > plotsData[m].max)
                    {
                        plotsData[m].max = plotsData[m].binValues[b];
                    }

                    if (selfSplitMode)
                    {
                        if (selfPlotsData[m].binValues[b] > selfPlotsData[m].max)
                        {
                            selfPlotsData[m].max = selfPlotsData[m].binValues[b];
                        }
                    }
                }
            }

            ComputeLexicalAnomalies();
        }