Beispiel #1
0
        /// <summary>
        /// Calculates the edge points when the slope is undefined (vertical line)
        /// </summary>
        /// <param name="factors">The factors.</param>
        /// <param name="x">The x.</param>
        /// <returns></returns>
        public static Point[] CalcUndefinedSlopeEdgePoints(ScalingFactors factors, double x)
        {
            //double maxLength = CalcMaxWidth(factors);
            double y1 = factors.WorldHeight / 2.0;
            double y2 = -factors.WorldHeight / 2.0;

            Point[] points = new Point[] { new Point(x, y1), new Point(x, y2) };
            return(points);
        }
Beispiel #2
0
        /// <summary>
        /// Calculates points on opposite ends of PlotWindow for scaling
        /// </summary>
        /// <param name="factors"></param>
        /// <param name="slope"></param>
        /// <param name="intercept"></param>
        /// <returns></returns>
        public static Point[] CalcEdgePoints(ScalingFactors factors, double slope, double intercept)
        {
            //y = mx+b
            //double maxLength = CalcMaxWidth(factors);
            double x1 = factors.WorldWidth / 2.0;
            double y1 = slope * x1 + intercept;

            double x2 = -factors.WorldWidth / 2.0;
            double y2 = slope * x2 - intercept;

            Point P1 = new Point(x1, y1);
            Point P2 = new Point(x2, y2);

            Point[] points = new Point[] { P1, P2 };

            return(points);
        }
        public PlotViewModel(DataRepository dataRepository)
        {
            scalingFactors = new ScalingFactors();
            //position = new Point3D(-40, 40, 40);
            //at = new Vector3D(40, -40, -40);
            position = new Point3D(0, 0, 1);
            at       = new Vector3D(0, 0, -1);
            up       = new Vector3D(0, 1, 0);

            scalingFactors.WorldWidth  = 10;
            scalingFactors.WorldHeight = 10;

            camera = new OrthographicCamera(position, at, up, WorldWidth);
            camera.NearPlaneDistance           = 1;
            this._dataRepository               = dataRepository;
            this._dataRepository.ShapeAdded   += this.OnShapeAddedOrRemoved;
            this._dataRepository.ShapeDeleted += this.OnShapeAddedOrRemoved;
            scalingFactors.SceneWidth          = 1;
            scalingFactors.SceneHeight         = 1;
        }
Beispiel #4
0
        /// <summary>
        /// Calculates the Y scaling factor for an individual (Model3D) plot object based on the rotation angle
        /// </summary>
        /// <param name="factors"></param>
        /// <param name="rotationAngle"></param>
        /// <returns></returns>
        public static double CalcYObjectScaleFactor(ScalingFactors factors, double rotationAngle)
        {
            double yScale = CalcYHeightScaleFactor(factors);

            //Max scale
            double wMax = factors.SegmentScale;
            //Min scale
            double wMin = wMax * factors.SceneScalingRatio;

            //if (wMin > wMin * yScale)
            //{
            //    wMin = wMax * factors.SceneScalingRatio * yScale;
            //}
            //else
            //{
            //    wMax = wMax / yScale;
            //}

            //return Math.Min(Math.Max(wMin, wMax), (((wMax - wMin) * Math.Max(0, Math.Cos(rotationAngle)) + wMin) + .01));
            return(((wMax - wMin) * Math.Cos(rotationAngle) + wMin) + .01);
        }
Beispiel #5
0
        object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            /*
             * values[0] = MouseCoordinate (pixels)
             * values[1] = SceneWidth (pixels)
             * values[2] = SceneHeight (pixels)
             * values[3] = CameraWidth (world width)
             */

            //Convert to [-1, 1] range
            //double worldCoord = (2 * (double)values[0]) / (double)values[1] - 1;
            ////Convert To World Coordinates
            //worldCoord = (worldCoord * (double)values[3]) / 2.0;
            //return worldCoord.ToString();
            if (values[1].GetType().Equals(typeof(ScalingFactors)))
            {
                bool           isY            = (bool)values[2];
                double         mouseCoord     = (double)values[0];
                ScalingFactors scalingFactors = (ScalingFactors)values[1];

                //
                double worldCoord = 0;
                //Convert to [-1, 1] range, then To World Coordinates
                if (isY)
                {
                    worldCoord = (2 * mouseCoord) / scalingFactors.SceneHeight - 1;
                    worldCoord = (worldCoord * scalingFactors.WorldHeight) / 2.0;
                    worldCoord = -worldCoord;
                }
                else
                {
                    worldCoord = (2 * mouseCoord) / scalingFactors.SceneWidth - 1;
                    worldCoord = (worldCoord * scalingFactors.WorldWidth) / 2.0;
                }
                return(worldCoord.ToString());
            }
            return(0.ToString());
        }
Beispiel #6
0
        private void Level1Classification(List <DocumentData> TrainData, List <DocumentData> TestData)
        {
            var selectedFeatures = AppDataCenter.Singleton.FeaturesSelected.Select((a, i) => new { item = a, index = i })
                                   .Where(a => a.item.IsSelected).Select(a => a.index).ToArray();

            //  selectedFeatures = new int[] {  37 };



            ClassifierService.Service.InitSelectFeatures(selectedFeatures);



            ScalingFactors scales = null;

            //  if(AppDataCenter.Singleton.PathToScale != null)
            // {
            //      scales = FeatureListHolder.loadScalesFromFile(ClassifierService.Service.LocalFeatures, AppDataCenter.Singleton.PathToScale);


            // }
            // AppDataCenter.Singleton.AddConsoleMessage("Building Model");
            AppDataCenter.Singleton.ChosenFeatures = ClassifierService.Service.LocalFeatures;
            AppDataCenter.Singleton.UpdateFeatureVertHorzSelection();
            AppDataCenter.Singleton.EntireModelStats = ClassifierService.Service.CreateModel(AppDataCenter.Singleton.ChosenFields
                                                                                             , TrainData, TestData, Configuration, m_featuresCalculate, AppDataCenter.Singleton.AddConsoleMessage, TuneScale, AppDataCenter.Singleton.PathToScale);


            //  if (AppDataCenter.Singleton.PathToScale != null)
            // {


            //  FeatureListHolder.SaveScalesToFile(ClassifierService.Service.LocalFeatures, AppDataCenter.Singleton.PathToScale,scales);
            // }


            double[] confidenceOut;

            List <ReportResultItem> ReoprtResults = new List <ReportResultItem>();

            Array.ForEach(AppDataCenter.Singleton.ChosenFields,
                          new Action <string>(a =>
            {
                ReoprtResults.Add(new ReportResultItem(a));
            }));
            ReportResultItem NullResult = new ReportResultItem("");

            ReoprtResults.Add(NullResult);

            AppDataCenter.Singleton.RejectedFields.Clear();

            ClassifierService.Service.level1RunTestForLevel2(TrainData, AppDataCenter.Singleton.ChosenFields, AppDataCenter.Singleton.AddConsoleMessage);


            // add printing of train data sucss

            ConcurrentBag <FieldReportItem> fieldBag = new ConcurrentBag <FieldReportItem>();


            AppDataCenter.Singleton.AddConsoleMessage("Running Test on  : " + TestData.Count + " Pages");
            int index = 0;

            // int result;
            foreach (DocumentData doc1 in TestData)
            {
                var startTimeFeatures = DateTime.Now;

                //     AppDataCenter.Singleton.AddConsoleMessage("Testing Page : " + docnum++);

                //  List<FieldData> fields = ClassifierService.Service.GetFieldsOfDoc(FieldsToTest, doc1);
                TimeSpan FeatureCalcSpan = new TimeSpan(0);

                /* foreach (CandidateData field in doc1.Candidates)
                 * {
                 *   result = 0;
                 *   startTimeFeatures = DateTime.Now;
                 *   if (m_useLastRuntimeData == true)
                 *   {
                 *       foreach (var featureIndex in ClassifierService.Service.LocalFeatures
                 *                                       .Select((x, i) => AppDataCenter.Singleton.IsFeatureCalculate(x.Name) == true ? i : -1)
                 *                                       .Where(x => x >= 0))
                 *       {
                 *           field.Features[featureIndex] = ClassifierService.Service.GetFieldFeature(doc1, field, featureIndex);
                 *       }
                 *   }
                 *   else
                 *   {
                 *       field.Features = ClassifierService.Service.GetFieldFeatures(doc1, field);
                 *   }
                 *   FeatureCalcSpan += (DateTime.Now - startTimeFeatures);
                 *   result = ClassifierService.Service.GetDescition(field.Features, out confidenceOut);
                 *
                 *
                 * //  field.AccordConfidance = (ClassifierService.Service.NormalizaedConfidence(confidenceOut));
                 *   field.AccordConfidance = (confidenceOut);
                 * }*/
                List <int> featursIndexFilter = new List <int>();
                // Get the index of the feature we need to calculate - all other features will be use the value already exist in the field

                ClassifierService.Service.getDocFeatures(doc1, null, null, AppDataCenter.Singleton.ChosenFields, featursIndexFilter, false, null, true, true);

                double NumGolden  = 0;
                double NumMatched = 0;

                foreach (var r in AppDataCenter.Singleton.ChosenFields.Select((x, i) => new { Value = x, Index = i }))
                {
                    //  if (doc1.Candidates.Where(a => a.NameFromTypist == r.Value).ToList().Count() <= 0) continue;
                    NumGolden++;

                    CandidateData fieldCandidate = doc1.Candidates.OrderByDescending(a => a.AccordConfidance[r.Index]).FirstOrDefault();

                    FieldReportItem fieldReportItem = new FieldReportItem(r.Value, r.Index, fieldCandidate, doc1);


                    if (fieldReportItem.IsMatch)
                    {
                        NumMatched++;
                    }

                    /*  }
                     * else
                     * {
                     *    fieldReportItem.isRejected = true;
                     *
                     * }*/
                    if (!fieldReportItem.IsMatch)
                    {
                        Trace.WriteLine("Doc : " + doc1.DocumentName + " ,Confidance : " + fieldCandidate.AccordConfidance[r.Index] + ",Field : " + r.Value + " ,Recognized : " + fieldCandidate.NameFromTypist + " content : " + fieldCandidate.Content + (fieldReportItem.IsMatch ? " True" : " False"));
                    }



                    fieldBag.Add(fieldReportItem);
                }

                AppDataCenter.Singleton.AddConsoleMessage(index++ + " Page : " + doc1.DocumentName + " Getting Features (sec) : " + FeatureCalcSpan.TotalSeconds + " success : " + Math.Round(NumMatched / NumGolden * 100) + "%");
            }



            AppDataCenter.Singleton.AddConsoleMessage("Update results");


            AppDataCenter.Singleton.EntireModelStats.testresults = fieldBag.ToList();


            ReportData.noOfFields  = fieldBag.Count();
            ReportData.NoOfPages   = TestData.Count;
            ReportData.fpCount     = fieldBag.Where(a => a.IsFP).Count();
            ReportData.matchCount  = fieldBag.Where(a => a.IsMatch).Count();
            ReportData.rejectCount = fieldBag.Where(a => a.IsRejected).Count();

            foreach (FieldReportItem fieldresult in fieldBag.Where(a => a.IsMatch))
            {
                ReportData.QualityMatch.Add(fieldresult.MatchQuality);
            }

            List <FieldReportItem> FPList = fieldBag.Where(a => a.IsFP).ToList().OrderBy(b => b.Field.NameFromTypist ?? "").ThenByDescending(a => a.Field.AccordConfidance.Max()).ToList();


            foreach (var r in AppDataCenter.Singleton.ChosenFields)
            {
                List <FieldReportItem> FPfromGolden    = FPList.Where(a => a.ExpectedField.NameFromTypist == r).ToList();
                List <FieldReportItem> FPnotFromGolden = FPList.Where(a => a.ExpectedField.NameFromTypist != r && a.MatchedName == r).ToList();
                double success  = (double)fieldBag.Where(a => a.Field.NameFromTypist == r && a.IsMatch).Count() / (double)fieldBag.Where(a => a.Field.NameFromTypist == r).Count() * 100;
                int    countNum = fieldBag.Where(a => a.Field.NameFromTypist == r).Count();
                Trace.WriteLine("*********** The field : " + r + " success : " + Math.Round(success, 1) + "%   Count : " + countNum + "         *************");
            }
            AppDataCenter.Singleton.NotifyChange(NotifyGroup.ScatterData);
        }
Beispiel #7
0
 /// <summary>
 /// Calculates the Y scaling factor for the entire collection of plot objects (ModelGroup3D) based on the WorldHeight
 /// </summary>
 /// <param name="factors"></param>
 /// <returns></returns>
 public static double CalcYHeightScaleFactor(ScalingFactors factors)
 {
     return((factors.SceneHeight / factors.WorldHeight) / (factors.SceneWidth / factors.WorldWidth)); // * 1 / factors.SceneScalingRatio;
     //Multiplying the return value by 1/sceneScaleRatio would treat the Y and X range the same (if the WorldWidth == WorldHeight (always))
     //* 1 / scalingFactors.sceneScalingRatio
 }
Beispiel #8
0
 public static double CalcMaxWidth(ScalingFactors factors)
 {
     return(Math.Max(factors.WorldWidth, factors.WorldHeight));
 }