public void ProvideExerciseResults(EvaluationResults results)
 {
     if (OnExecutionStepEvaluated != null)
     {
         OnExecutionStepEvaluated(results);
     }
 }
示例#2
0
        // GET: Result
        public ActionResult Sample(string ar_resultfolder_name)
        {
            //===read the file result found in ar_workingfolder
            string ls_resultfile_path_and_name = ConfigurationManager.AppSettings["pathforuploadingvideos"] + "/" + ar_resultfolder_name + "/Results.txt";

            EvaluationResults l_evaluationResults = new EvaluationResults();
            List <DataResult> l_list_DataResult   = new List <DataResult>();
            List <string>     l_list_BrandNames   = new List <string>();

            using (StreamReader r = new StreamReader(ls_resultfile_path_and_name))
            {
                string l_json = r.ReadToEnd();
                l_list_DataResult = (List <DataResult>)JsonConvert.DeserializeObject <IEnumerable <DataResult> >(l_json);
            }

            string l_domainnamefordownloadingresults = ConfigurationManager.AppSettings["domainnamefordownloadingresults"];
            string l_ResultPathURL = l_domainnamefordownloadingresults + "/" + ar_resultfolder_name;

            l_evaluationResults.ResultPathURL = l_ResultPathURL;

            l_evaluationResults.BrandIndexToShow = 0;
            l_evaluationResults.array_DataResult = l_list_DataResult.ToArray();

            //===getting distinct BrandNames
            foreach (DataResult l_dataresult in l_evaluationResults.array_DataResult)
            {
                l_list_BrandNames.Add(l_dataresult.BrandName);
            }
            l_evaluationResults.BrandNames = l_list_BrandNames.ToArray().Distinct().ToArray();


            HttpContext.Session["results"] = l_evaluationResults;

            return(RedirectToAction("Result", "Result", new { ar_brandindextoshow = 0 }));
        }
示例#3
0
        public static EvaluationResults PrintRegressionFoldsAverageMetrics(IEnumerable <TrainCatalogBase.CrossValidationResult <RegressionMetrics> > crossValidationResults)
        {
            var results = new EvaluationResults()
            {
                L1           = crossValidationResults.Select(r => r.Metrics.MeanAbsoluteError).Average(),
                L2           = crossValidationResults.Select(r => r.Metrics.MeanSquaredError).Average(),
                RMS          = crossValidationResults.Select(r => r.Metrics.RootMeanSquaredError).Average(),
                LossFunction = crossValidationResults.Select(r => r.Metrics.LossFunction).Average(),
                R2           = crossValidationResults.Select(r => r.Metrics.RSquared).Average(),
                DateTrained  = DateTime.Now
            };


            Console.WriteLine($"*************************************************************************************************************");
            Console.WriteLine($"*       Metrics for Recommendation model      ");
            Console.WriteLine($"*------------------------------------------------------------------------------------------------------------");
            Console.WriteLine($"*       Average L1 Loss:       {results.L1:0.###} ");
            Console.WriteLine($"*       Average L2 Loss:       {results.L2:0.###}  ");
            Console.WriteLine($"*       Average RMS:           {results.RMS:0.###}  ");
            Console.WriteLine($"*       Average Loss Function: {results.LossFunction:0.###}  ");
            Console.WriteLine($"*       Average R-squared:     {results.R2:0.###}  ");
            Console.WriteLine($"*************************************************************************************************************");

            return(results);
        }
示例#4
0
 private HandleSample GetExecutionSamplerHandlerForExercise(int exID)
 {
     return((Sample sample) =>
     {
         LimbExercise ex = _exercises[exID];
         EvaluationResults results = (ex.exerciseConfig.isRealTimeSampling) ?
                                     ex.aiManager.EvaluateExerciseStep(sample.sampleDataForExercise[exID].UnwrapFromSensors(), sample.idealDataForExercise[exID].UnwrapFromSensors()) :
                                     ex.aiManager.EvaluateExerciseStep(sample.sampleDataForExercise[exID].UnwrapFromSensors());
         ex.exerciseConfig.ProvideExerciseResults(results);
     });
 }
示例#5
0
        // Token: 0x06000C07 RID: 3079 RVA: 0x0004E2A4 File Offset: 0x0004C4A4
        public static void LogEntry(MailboxSession session, MessageItem message, EvaluationResults state)
        {
            string entry = string.Format("Action:{0}, Sender: {1}, From: {2}, Subject :{3} Internet Message Id: {4}", new object[]
            {
                state,
                (message.Sender != null) ? message.Sender.EmailAddress : "null",
                (message.From != null) ? message.From.EmailAddress : "null",
                message.Subject,
                message.InternetMessageId
            });

            RbaLog.Logger.AppendFormatLogEntry(session, entry, new object[0]);
        }
示例#6
0
        private EvaluationResults <T, R> ComputeEvaluationResults(string MeasureName, List <Shape <T, R> > visitedShapes)
        {
            EvaluationResults <T, R> results   = new EvaluationResults <T, R>();
            Shape <T, R>             lastShape = visitedShapes[visitedShapes.Count - 1];

            results.MeasureName    = MeasureName;
            results.Result         = lastShape.Result;
            results.RequiredFields = visitedShapes.Where(s => s.RequiredField != null)
                                     .Select(s => s.RequiredField)
                                     .Distinct(PropertySpecifier <T> .Comparer)
                                     .ToList();
            return(results);
        }
示例#7
0
        public EvaluationResults VerifySqlData(Parameters parms)
        {
            var results = new EvaluationResults();

            parms.Fix(Config);
            try
            {
                var context = new SqlContext(parms);
                results = context.VerifyDocumentStatus();
            }
            catch (Exception ex)
            {
                results.Code    = ex.HResult;
                results.Message = $"Error: {ex.Message}";
                results.Passed  = false;
            }
            return(results);
        }
示例#8
0
        public async Task <EvaluationResults> VerifyQueue(Parameters parms)
        {
            var results = new EvaluationResults();

            parms.Fix(Config);
            try
            {
                var context = new StorageContext(parms);
                results = await context.CheckQueue("process");
            }
            catch (Exception ex)
            {
                results.Code    = ex.HResult;
                results.Message = $"Error: {ex.Message}";
                results.Passed  = false;
            }
            return(results);
        }
示例#9
0
        public EvaluationResults CreateSqlTable(Parameters parms)
        {
            var results = new EvaluationResults();

            parms.Fix(Config);
            try
            {
                var context = new SqlContext(parms);
                context.CreateTable();
            }
            catch (Exception ex)
            {
                results.Code    = ex.HResult;
                results.Message = $"Error: {ex.Message}";
                results.Passed  = false;
            }
            return(results);
        }
    public void generateMap(Config conf)
    {
        Random.InitState(conf.seed);

        var points  = PointsGenerator.getPoints(conf);
        var voronoi = new Delaunay.Voronoi(points, null, new Rect(0, 0, conf.meshSize, conf.meshSize), conf.relaxationIterations);

        var elevationMap = ElevationMapGenerator.generate(conf);

        var mapGraph = new MapGraph(voronoi, elevationMap);

        BiomeMapGenerator.generate(mapGraph, conf);

        updateMesh(MapMeshGenerator.generate(mapGraph, meshSize));
        updateTexture(MapTextureGenerator.generate(mapGraph, conf));

        EvaluationResults evaluation = Evaluation.assessmentResultsToString(mapGraph, conf);

        beachFunction    = evaluation.beachFunction;
        mountainFunction = evaluation.mountainFunction;
        lowlandFunction  = evaluation.lowlandFunction;
        Debug.Log(evaluation.result);
    }
示例#11
0
    public static EvaluationResults assessmentResultsToString(MapGraph graph, Config conf)
    {
        float beachCoverage = getPercentageOfBeach(graph);
        float beachScore    = triangularFunction(beachCoverage, conf.beachScoreCoefA, conf.beachScoreCoefB);

        float mountainCoverage = getPercentageOfHighMountains(graph);
        float mountainScore    = triangularFunction(mountainCoverage, conf.mountainScoreCoefA, conf.mountainScoreCoefB);

        float lowlandCoverage = getPercentageOfLowland(graph);
        float lowlandScore    = triangularFunction(lowlandCoverage, conf.lowlandScoreCoefA, conf.lowlandScoreCoefB);

        int jointComponents = countDisjointComponents(graph);

        float maxScore = Mathf.Max(beachScore, Mathf.Max(mountainScore, lowlandScore));

        string result = string.Format(
            "Max Score: {6:F2} Number of Components: {7}\n" +
            "Coastline Beach Coverage: {0:F2} Beach Score: {1:F2}\n" +
            "Mountain Cover Percentage: {2:F2} Mountain Score: {3:F2}\n" +
            "Lowland Cover Percentage: {4:F2} Lowland Score: {5:F2}\n",
            beachCoverage, beachScore, mountainCoverage, mountainScore,
            lowlandCoverage, lowlandScore, maxScore, jointComponents);

        AnimationCurve beachFunction    = getAnimationCurve(conf.beachScoreCoefA, conf.beachScoreCoefB);
        AnimationCurve mountainFunction = getAnimationCurve(conf.mountainScoreCoefA, conf.mountainScoreCoefB);
        AnimationCurve lowlandFunction  = getAnimationCurve(conf.lowlandScoreCoefA, conf.lowlandScoreCoefB);

        EvaluationResults evaluation = new EvaluationResults();

        evaluation.result           = result;
        evaluation.beachFunction    = beachFunction;
        evaluation.mountainFunction = mountainFunction;
        evaluation.lowlandFunction  = lowlandFunction;

        return(evaluation);
    }
示例#12
0
    protected override void Run(string[] args)
    {
        if (file_format == RatingFileFormat.KDDCUP_2011)
        {
            user_mapping = new IdentityMapping();
            item_mapping = new IdentityMapping();
        }
        base.Run(args);

        bool do_eval = false;

        if (test_ratio > 0 || chronological_split != null)
        {
            do_eval = true;
        }
        if (test_file != null && !test_no_ratings)
        {
            do_eval = true;
        }

        Console.Error.WriteLine(
            string.Format(CultureInfo.InvariantCulture,
                          "ratings range: [{0}, {1}]", recommender.MinRating, recommender.MaxRating));

        if (test_ratio > 0)
        {
            var split = new RatingsSimpleSplit(training_data, test_ratio);
            recommender.Ratings = training_data = split.Train[0];
            test_data           = split.Test[0];
            Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "test ratio {0}", test_ratio));
        }
        if (chronological_split != null)
        {
            var split = chronological_split_ratio != -1
                                                        ? new RatingsChronologicalSplit((ITimedRatings)training_data, chronological_split_ratio)
                                                        : new RatingsChronologicalSplit((ITimedRatings)training_data, chronological_split_time);
            recommender.Ratings = training_data = split.Train[0];
            test_data           = split.Test[0];
            if (test_ratio != -1)
            {
                Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "test ratio (chronological) {0}", chronological_split_ratio));
            }
            else
            {
                Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "split time {0}", chronological_split_time));
            }
        }

        Console.Write(training_data.Statistics(test_data, user_attributes, item_attributes));

        if (find_iter != 0)
        {
            if (!(recommender is IIterativeModel))
            {
                Abort("Only iterative recommenders (interface IIterativeModel) support --find-iter=N.");
            }

            var iterative_recommender = recommender as IIterativeModel;
            iterative_recommender.NumIter = num_iter;
            Console.WriteLine(recommender);

            if (cross_validation > 1)
            {
                recommender.DoIterativeCrossValidation(cross_validation, max_iter, find_iter);
            }
            else
            {
                var eval_stats = new List <double>();

                if (load_model_file == null)
                {
                    recommender.Train();
                }

                if (compute_fit)
                {
                    Console.WriteLine("fit {0} iteration {1}", Render(recommender.Evaluate(training_data)), iterative_recommender.NumIter);
                }

                Console.WriteLine("{0} iteration {1}", Render(Evaluate()), iterative_recommender.NumIter);

                for (int it = (int)iterative_recommender.NumIter + 1; it <= max_iter; it++)
                {
                    TimeSpan time = Wrap.MeasureTime(delegate() {
                        iterative_recommender.Iterate();
                    });
                    training_time_stats.Add(time.TotalSeconds);

                    if (it % find_iter == 0)
                    {
                        if (compute_fit)
                        {
                            time = Wrap.MeasureTime(delegate() {
                                Console.WriteLine("fit {0} iteration {1}", recommender.Evaluate(training_data), it);
                            });
                            fit_time_stats.Add(time.TotalSeconds);
                        }

                        EvaluationResults results = null;
                        time = Wrap.MeasureTime(delegate() { results = Evaluate(); });
                        eval_time_stats.Add(time.TotalSeconds);
                        eval_stats.Add(results[eval_measures[0]]);
                        Console.WriteLine("{0} iteration {1}", Render(results), it);

                        Model.Save(recommender, save_model_file, it);
                        if (prediction_file != null)
                        {
                            recommender.WritePredictions(test_data, prediction_file + "-it-" + it, user_mapping, item_mapping, prediction_line, prediction_header);
                        }

                        if (epsilon > 0.0 && results[eval_measures[0]] - eval_stats.Min() > epsilon)
                        {
                            Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} >> {1}", results[eval_measures[0]], eval_stats.Min()));
                            Console.Error.WriteLine("Reached convergence on training/validation data after {0} iterations.", it);
                            break;
                        }
                        if (results[eval_measures[0]] > cutoff)
                        {
                            Console.Error.WriteLine("Reached cutoff after {0} iterations.", it);
                            break;
                        }
                    }
                }                 // for
                if (max_iter % find_iter != 0)
                {
                    recommender.WritePredictions(test_data, prediction_file, user_mapping, item_mapping, prediction_line, prediction_header);
                }
            }
        }
        else
        {
            TimeSpan seconds;

            Console.Write(recommender + " ");

            if (load_model_file == null)
            {
                if (cross_validation > 1)
                {
                    Console.WriteLine();
                    var results = DoCrossValidation();
                    Console.Write(Render(results));
                    do_eval = false;
                }
                else
                {
                    if (search_hp)
                    {
                        double result = NelderMead.FindMinimum("RMSE", recommender);
                        Console.Error.WriteLine("estimated quality (on split) {0}", result.ToString(CultureInfo.InvariantCulture));
                    }

                    seconds = Wrap.MeasureTime(delegate() { recommender.Train(); });
                    Console.Write(" training_time " + seconds + " ");
                }
            }

            if (do_eval)
            {
                if (online_eval)
                {
                    seconds = Wrap.MeasureTime(delegate() { Console.Write(Render(recommender.EvaluateOnline(test_data))); });
                }
                else
                {
                    seconds = Wrap.MeasureTime(delegate() { Console.Write(Render(Evaluate())); });
                }

                Console.Write(" testing_time " + seconds);

                if (compute_fit)
                {
                    Console.Write("\nfit ");
                    seconds = Wrap.MeasureTime(delegate() {
                        Console.Write(Render(recommender.Evaluate(training_data)));
                    });
                    Console.Write(" fit_time " + seconds);
                }
            }

            if (prediction_file != null)
            {
                Console.WriteLine();
                seconds = Wrap.MeasureTime(delegate() {
                    recommender.WritePredictions(test_data, prediction_file, user_mapping, item_mapping, prediction_line, prediction_header);
                });
                Console.Error.WriteLine("prediction_time " + seconds);
            }

            Console.WriteLine();
        }
        Model.Save(recommender, save_model_file);
        DisplayStats();
    }
示例#13
0
 public ArticolationError UnwrapFromResults(string id, EvaluationResults results, List <string> limbIds)
 {
     return(results.Corrections[GetIndexOf(id, limbIds)]);
 }
        public static void f_main(String ar_path_for_uploading_videos, String ar_working_folder_name, String ar_uploaded_video_name, String[] ar_brand_names, double ar_cost_of_1_second)
        {
            //===initializing google API key
            string ls_google_app_credentials_path_and_filename = HostingEnvironment.MapPath("~/CloudVision/google_cloud_credential_for_logo_detection-nowting-bd7886019869.json");

            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", ls_google_app_credentials_path_and_filename);

            VideoCapture l_capture   = VideoCapture.FromFile(Path.Combine(ar_path_for_uploading_videos, ar_working_folder_name, ar_uploaded_video_name));
            Double       l_framerate = l_capture.Get(5);
            Double       l_frameid;
            int          li_counter             = 0;
            Mat          l_frame                = new Mat();
            Mat          l_frame_with_boundarie = new Mat();

            String ls_result_folder_path = Path.Combine(ar_path_for_uploading_videos, ar_working_folder_name);

            Directory.CreateDirectory(ls_result_folder_path);

            List <DataResult> l_list_DataResult = new List <DataResult>();

            while (true)
            {
                l_capture.Read(l_frame);
                if (l_frame.Empty())
                {
                    break;
                }

                l_frameid = l_capture.Get(1);
                if (l_frameid % l_framerate != 0)
                {
                    continue;                               //===getting 1 frame per second
                }
                //======================================================================================================
                //======================================================================================================
                li_counter++;
                if (li_counter != 1 && li_counter != 2 && li_counter != 3)
                {
                    continue;
                }                                                                        //=== temp code to process only the first 3 frames
                //======================================================================================================
                //======================================================================================================

                //===find all texts in frame
                AnnotateImageResponse l_response = f_find_brand_by_DetectDocumentText_in(l_frame);

                //===set a rectangle over each corresponding brand-text and save the frame
                foreach (string l_brand_name in ar_brand_names)
                {
                    if (String.IsNullOrEmpty(l_brand_name.Trim()))
                    {
                        continue;
                    }

                    DataResult l_current_data_result = f_hilight_brand_and_save_frame(l_frame, l_response, l_brand_name, ar_cost_of_1_second, ls_result_folder_path, "pic_" + li_counter.ToString(), li_counter);
                    l_list_DataResult.Add(l_current_data_result);
                }
            }

            //===write result into file
            using (StreamWriter l_file = File.AppendText(Path.Combine(ls_result_folder_path, "Results.txt")))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(l_file, l_list_DataResult);
            }


            string l_domainnamefordownloadingresults = ConfigurationManager.AppSettings["domainnamefordownloadingresults"];

            EvaluationResults l_EvaluationResults = new EvaluationResults();

            l_EvaluationResults.ResultPathURL    = l_domainnamefordownloadingresults + "/" + ar_working_folder_name;
            l_EvaluationResults.BrandNames       = ar_brand_names;
            l_EvaluationResults.BrandIndexToShow = 0;
            l_EvaluationResults.array_DataResult = l_list_DataResult.ToArray();

            HttpContext.Current.Session["results"] = l_EvaluationResults;

            return;
        }
示例#15
0
 private void SaveResults(EvaluationResults results)
 {
     var r = _evalResRepo.Create(results);
 }
示例#16
0
 public bool Update(EvaluationResults entity)
 {
     throw new NotImplementedException();
 }
示例#17
0
        // Token: 0x06000B71 RID: 2929 RVA: 0x00049A1C File Offset: 0x00047C1C
        protected override void HandleEventInternal(MapiEvent mapiEvent, MailboxSession itemStore, StoreObject item, List <KeyValuePair <string, object> > customDataToLog)
        {
            ResourceBookingAssistantLogEntry resourceBookingAssistantLogEntry = new ResourceBookingAssistantLogEntry
            {
                MapiEventFlag = mapiEvent.EventMask.ToString(),
                MailboxGuid   = itemStore.MailboxGuid,
                TenantGuid    = itemStore.MailboxOwner.MailboxInfo.OrganizationId.GetTenantGuid(),
                DatabaseGuid  = itemStore.MailboxOwner.MailboxInfo.GetDatabaseGuid()
            };

            try
            {
                string text = (item != null) ? item.ClassName : mapiEvent.ObjectClass;
                resourceBookingAssistantLogEntry.ObjectClass = text;
                if (itemStore.GetDefaultFolderId(DefaultFolderType.Calendar) == null)
                {
                    ResourceBookingAssistant.Tracer.TraceDebug <object, Guid>((long)this.GetHashCode(), "{0}: Mailbox: {1} - Calendar folder does not exist. Skipping processing.", TraceContext.Get(), mapiEvent.MailboxGuid);
                    resourceBookingAssistantLogEntry.IsCalendarFolderNotAvailable = true;
                }
                else
                {
                    CachedState cachedState = AssistantsService.CachedObjectsList.GetCachedState(mapiEvent.MailboxGuid);
                    bool        flag        = ResourceCheck.DetailedCheckForAutomatedBooking(mapiEvent, itemStore, item, cachedState);
                    resourceBookingAssistantLogEntry.IsAutomatedBooking = flag;
                    if (flag)
                    {
                        if (item == null)
                        {
                            ResourceBookingAssistant.Tracer.TraceDebug((long)this.GetHashCode(), "{0}: HandleEvent was passed a null item.", new object[]
                            {
                                TraceContext.Get()
                            });
                        }
                        else
                        {
                            ResourceBookingAssistant.Tracer.TraceDebug((long)this.GetHashCode(), "{0}: Automatic Booking is on.", new object[]
                            {
                                TraceContext.Get()
                            });
                            if (item is MeetingMessage)
                            {
                                MeetingMessage meetingMessage = item as MeetingMessage;
                                resourceBookingAssistantLogEntry.MeetingSender            = meetingMessage.Sender.EmailAddress;
                                resourceBookingAssistantLogEntry.MeetingInternetMessageId = meetingMessage.InternetMessageId;
                                if (meetingMessage.IsDelegated())
                                {
                                    ResourceBookingAssistant.Tracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Deleting delegated meeting message: ID={1}", TraceContext.Get(), item.Id.ToString());
                                    itemStore.Delete(DeleteItemFlags.MoveToDeletedItems, new StoreId[]
                                    {
                                        meetingMessage.Id
                                    });
                                    RbaLog.LogEntry(itemStore, meetingMessage, EvaluationResults.Delete);
                                    resourceBookingAssistantLogEntry.IsDelegatedMeetingRequest = true;
                                    return;
                                }
                            }
                            cachedState.LockForRead();
                            CalendarConfiguration calendarConfiguration;
                            try
                            {
                                calendarConfiguration = (cachedState.State[0] as CalendarConfiguration);
                            }
                            finally
                            {
                                cachedState.ReleaseReaderLock();
                            }
                            bool flag2 = false;
                            try
                            {
                                if (item is MeetingRequest)
                                {
                                    flag2 = (item as MeetingRequest).IsOrganizer();
                                }
                                else if (item is MeetingCancellation)
                                {
                                    flag2 = (item as MeetingCancellation).IsOrganizer();
                                }
                            }
                            catch (ObjectNotFoundException innerException)
                            {
                                ResourceBookingAssistant.Tracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Object Not Found. ID={1}", TraceContext.Get(), item.Id.ToString());
                                throw new TransientMailboxException(innerException);
                            }
                            resourceBookingAssistantLogEntry.IsOrganizer = flag2;
                            if (!ObjectClass.IsOfClass(text, "IPM.Schedule.Meeting") || flag2)
                            {
                                if (calendarConfiguration.DeleteNonCalendarItems && (mapiEvent.EventMask & MapiEventTypeFlags.NewMail) != (MapiEventTypeFlags)0)
                                {
                                    ResourceBookingAssistant.Tracer.TraceError((long)this.GetHashCode(), "{0}: Deleting a non-meeting message", new object[]
                                    {
                                        TraceContext.Get()
                                    });
                                    if (item is MessageItem)
                                    {
                                        RbaLog.LogEntry(itemStore, item as MessageItem, EvaluationResults.Delete);
                                    }
                                    itemStore.Delete(DeleteItemFlags.MoveToDeletedItems, new StoreId[]
                                    {
                                        item.Id
                                    });
                                    resourceBookingAssistantLogEntry.DeleteNonMeetingMessage = true;
                                }
                            }
                            else
                            {
                                ResourceBookingAssistant.Tracer.TraceDebug((long)this.GetHashCode(), "{0}: Message is the right class", new object[]
                                {
                                    TraceContext.Get()
                                });
                                if (!(item is MeetingMessage))
                                {
                                    ResourceBookingAssistant.Tracer.TraceError((long)this.GetHashCode(), "{0}: Unexpected: Message class matched, but is not the correct object type. Ignoring message.", new object[]
                                    {
                                        TraceContext.Get()
                                    });
                                }
                                else
                                {
                                    ResourceBookingAssistant.Tracer.TraceDebug((long)this.GetHashCode(), "{0}: Message is MeetingMessage", new object[]
                                    {
                                        TraceContext.Get()
                                    });
                                    resourceBookingAssistantLogEntry.IsMeetingMessage = true;
                                    MeetingMessage   meetingMessage   = item as MeetingMessage;
                                    CalendarItemBase calendarItemBase = null;
                                    DateTime         utcNow           = DateTime.UtcNow;
                                    resourceBookingAssistantLogEntry.StartProcessingTime = utcNow;
                                    for (int i = 0; i < 2; i++)
                                    {
                                        IEnumerable <VersionedId> duplicates;
                                        Exception ex;
                                        bool      calendarItem = CalendarAssistant.GetCalendarItem(meetingMessage, ResourceBookingAssistant.Tracer, ref calendarItemBase, false, out duplicates, out ex);
                                        resourceBookingAssistantLogEntry.AddExceptionToLog(ex);
                                        if (!calendarItem)
                                        {
                                            break;
                                        }
                                        if (calendarItemBase == null)
                                        {
                                            ResourceBookingAssistant.Tracer.TraceDebug <object, VersionedId>((long)this.GetHashCode(), "{0}: Original CalendarItem for message {1} is null", TraceContext.Get(), meetingMessage.Id);
                                        }
                                        StoreObjectValidationError[] array = meetingMessage.Validate();
                                        if (array != null && array.Length > 0)
                                        {
                                            ResourceBookingAssistant.Tracer.TraceError <object, StoreObjectValidationError>((long)this.GetHashCode(), "{0}: mtgMessage did not validate, {1}", TraceContext.Get(), array[0]);
                                            resourceBookingAssistantLogEntry.IsMeetingMessageInvalid = true;
                                            throw new SkipException(Strings.descSkipExceptionFailedValidateCalItem);
                                        }
                                        string text2 = string.Empty;
                                        try
                                        {
                                            this.calProcessor.ProcessMeetingMessage(itemStore, meetingMessage, ref calendarItemBase, calendarConfiguration, duplicates, false);
                                            text2 = meetingMessage.Id.ToString();
                                            resourceBookingAssistantLogEntry.IsMeetingMessageProcessed = true;
                                            resourceBookingAssistantLogEntry.MeetingMessageId          = text2;
                                            bool flag3 = false;
                                            if (meetingMessage is MeetingRequest)
                                            {
                                                flag3 = (meetingMessage as MeetingRequest).IsOrganizer();
                                            }
                                            else if (meetingMessage is MeetingCancellation)
                                            {
                                                flag3 = (meetingMessage as MeetingCancellation).IsOrganizer();
                                            }
                                            else if (meetingMessage is MeetingResponse)
                                            {
                                                flag3 = true;
                                            }
                                            resourceBookingAssistantLogEntry.IsOrganizer = flag3;
                                            resourceBookingAssistantLogEntry.IsDelegatedMeetingRequest = meetingMessage.IsDelegated();
                                            if (calendarItemBase == null)
                                            {
                                                if (flag3)
                                                {
                                                    RbaLog.LogEntry(itemStore, meetingMessage, EvaluationResults.IgnoreOrganizer);
                                                }
                                                else if (resourceBookingAssistantLogEntry.IsDelegatedMeetingRequest)
                                                {
                                                    RbaLog.LogEntry(itemStore, meetingMessage, EvaluationResults.IgnoreDelegate);
                                                }
                                            }
                                            if (calendarItemBase == null && meetingMessage is MeetingCancellation)
                                            {
                                                ResourceBookingAssistant.Tracer.TraceDebug((long)this.GetHashCode(), "{0}: Deleting a meeting cancellation without correlated calendar item found", new object[]
                                                {
                                                    TraceContext.Get()
                                                });
                                                itemStore.Delete(DeleteItemFlags.MoveToDeletedItems, new StoreId[]
                                                {
                                                    meetingMessage.Id
                                                });
                                                RbaLog.LogEntry(itemStore, meetingMessage, EvaluationResults.Delete);
                                                resourceBookingAssistantLogEntry.DeleteCanceledMeeting = true;
                                            }
                                            if (calendarItemBase != null)
                                            {
                                                StoreObjectValidationError[] array2 = calendarItemBase.Validate();
                                                if (array2 != null && array2.Length > 0)
                                                {
                                                    ResourceBookingAssistant.Tracer.TraceError <object, StoreObjectValidationError>((long)this.GetHashCode(), "{0}: calendar item did not validate, {1}", TraceContext.Get(), array2[0]);
                                                    throw new SkipException(Strings.descSkipExceptionFailedValidateCalItem);
                                                }
                                                ResourceBookingAssistant.Tracer.TraceDebug((long)this.GetHashCode(), "{0}: About to process request", new object[]
                                                {
                                                    TraceContext.Get()
                                                });
                                                EvaluationResults evaluationResults = EvaluationResults.None;
                                                BookingRoles      bookingRoles      = BookingRoles.NoRole;
                                                ResourceBookingProcessing.ProcessRequest(mapiEvent, itemStore, meetingMessage, ref calendarItemBase, calendarConfiguration, out evaluationResults, out bookingRoles);
                                                resourceBookingAssistantLogEntry.IsResourceBookingRequestProcessed = true;
                                                resourceBookingAssistantLogEntry.EvaluationResult = evaluationResults.ToString();
                                                resourceBookingAssistantLogEntry.BookingRole      = bookingRoles.ToString();
                                            }
                                            break;
                                        }
                                        catch (CorruptDataException ex2)
                                        {
                                            ResourceBookingAssistant.Tracer.TraceDebug <object, string, CorruptDataException>((long)this.GetHashCode(), "{0}: The calendar item found was corrupted, so we could not do Resource Booking processing for message ID={1}, skipping event. Exception={2}", TraceContext.Get(), text2, ex2);
                                            throw new SkipException(ex2);
                                        }
                                        catch (ADTransientException arg)
                                        {
                                            ResourceBookingAssistant.Tracer.TraceDebug <object, string, ADTransientException>((long)this.GetHashCode(), "{0}: There was an tranisent AD error processing the calendar item during Resource Booking processing for message ID={1}, cleaning things up and retrying. Exception={2}", TraceContext.Get(), text2, arg);
                                            throw;
                                        }
                                        catch (ObjectNotFoundException innerException2)
                                        {
                                            ResourceBookingAssistant.Tracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Object Not Found. ID={1}", TraceContext.Get(), text2);
                                            throw new TransientMailboxException(innerException2);
                                        }
                                        catch (SaveConflictException ex3)
                                        {
                                            ResourceBookingAssistant.Tracer.TraceDebug <object, string, SaveConflictException>((long)this.GetHashCode(), "{0}: There was an error saving the calendar item during Resource Booking processing for message ID={1}, cleaning things up and retrying.Exception={2}", TraceContext.Get(), text2, ex3);
                                            resourceBookingAssistantLogEntry.AddExceptionToLog(ex3);
                                        }
                                        catch (OccurrenceCrossingBoundaryException ex4)
                                        {
                                            resourceBookingAssistantLogEntry.AddExceptionToLog(ex4);
                                            ResourceBookingAssistant.Tracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Found an overlapping occurrence while processing message ID={1}. Cleaning things up and retrying", TraceContext.Get(), text2);
                                            if (ex4.OccurrenceInfo == null)
                                            {
                                                ResourceBookingAssistant.Tracer.TraceError((long)this.GetHashCode(), "{0}: Unexpected: Handling OccurrenceCrossingBoundaryException, the OccurrenceInfo is null", new object[]
                                                {
                                                    TraceContext.Get()
                                                });
                                                break;
                                            }
                                            VersionedId versionedId = ex4.OccurrenceInfo.VersionedId;
                                            AggregateOperationResult aggregateOperationResult = meetingMessage.Session.Delete(DeleteItemFlags.MoveToDeletedItems, new StoreId[]
                                            {
                                                versionedId
                                            });
                                            ResourceBookingAssistant.Tracer.TraceDebug <object, OperationResult>((long)this.GetHashCode(), "{0}: Deleting the occurrence when handling an OccurrenceCrossingBoundaryException, returned:{2}", TraceContext.Get(), aggregateOperationResult.OperationResult);
                                        }
                                        finally
                                        {
                                            ResourceBookingAssistant.Tracer.TraceDebug((long)this.GetHashCode(), "{0}: In finally block.", new object[]
                                            {
                                                TraceContext.Get()
                                            });
                                            if (calendarItemBase != null)
                                            {
                                                calendarItemBase.Dispose();
                                                calendarItemBase = null;
                                            }
                                            DateTime utcNow2  = DateTime.UtcNow;
                                            TimeSpan timeSpan = utcNow2.Subtract(utcNow);
                                            ResourceBookingPerfmon.AverageResourceBookingProcessingTime.IncrementBy((long)timeSpan.TotalMilliseconds);
                                            ResourceBookingPerfmon.AverageResourceBookingProcessingTimeBase.Increment();
                                            resourceBookingAssistantLogEntry.StartProcessingTime = utcNow;
                                            resourceBookingAssistantLogEntry.StopProcessingTime  = utcNow2;
                                            ResourceBookingAssistant.TracerPfd.TracePfd <int, object, string>((long)this.GetHashCode(), "PFD IWR {0} {1}: Finished processing message. MeetingMessageID = {2}", 20247, TraceContext.Get(), text2);
                                        }
                                        i++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex5)
            {
                resourceBookingAssistantLogEntry.AddExceptionToLog(ex5);
                throw ex5;
            }
            finally
            {
                customDataToLog.AddRange(resourceBookingAssistantLogEntry.FormatCustomData());
            }
        }
示例#18
0
 public bool Create(EvaluationResults entity)
 {
     _db.EvaluationResults.Add(entity);
     return(Save());
 }
    protected override void Run(string[] args)
    {
        base.Run(args);

        Console.Write(training_data.Statistics(test_data, user_attributes, item_attributes));

        bool no_eval = true;

        if (test_ratio > 0 || test_file != null)
        {
            no_eval = false;
        }

        TimeSpan time_span;

        if (find_iter != 0)
        {
            if (!(recommender is IIterativeModel))
            {
                Abort("Only iterative recommenders (interface IIterativeModel) support --find-iter=N.");
            }

            var iterative_recommender = recommender as IIterativeModel;
            iterative_recommender.NumIter = num_iter;
            Console.WriteLine(recommender);
            var eval_stats = new List <double>();

            if (cross_validation > 1)
            {
                var repeated_events = repeated_items ? RepeatedEvents.Yes : RepeatedEvents.No;
                recommender.DoIterativeCrossValidation(
                    cross_validation,
                    test_users, candidate_items, eval_item_mode, repeated_events,
                    max_iter, find_iter);
            }
            else
            {
                if (load_model_file == null)
                {
                    Train();
                }

                if (compute_fit)
                {
                    Console.WriteLine("fit: {0} iteration {1} ", ComputeFit(), iterative_recommender.NumIter);
                }

                EvaluationResults results = null;
                if (!no_eval)
                {
                    results = Evaluate();
                    Console.WriteLine("{0} iteration {1}", Render(results), iterative_recommender.NumIter);
                }

                for (int it = (int)iterative_recommender.NumIter + 1; it <= max_iter; it++)
                {
                    TimeSpan t = Wrap.MeasureTime(delegate() {
                        iterative_recommender.Iterate();
                    });
                    training_time_stats.Add(t.TotalSeconds);

                    if (it % find_iter == 0)
                    {
                        if (compute_fit)
                        {
                            t = Wrap.MeasureTime(delegate() {
                                Console.WriteLine("fit: {0} iteration {1} ", ComputeFit(), it);
                            });
                            fit_time_stats.Add(t.TotalSeconds);
                        }

                        if (!no_eval)
                        {
                            t = Wrap.MeasureTime(delegate() { results = Evaluate(); });
                            eval_time_stats.Add(t.TotalSeconds);
                            eval_stats.Add(results[eval_measures[0]]);
                            Console.WriteLine("{0} iteration {1}", Render(results), it);
                        }

                        Model.Save(recommender, save_model_file, it);
                        Predict(prediction_file, test_users_file, it);

                        if (!no_eval)
                        {
                            if (epsilon > 0.0 && eval_stats.Max() - results[eval_measures[0]] > epsilon)
                            {
                                Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} >> {1}", results[eval_measures[0]], eval_stats.Min()));
                                Console.Error.WriteLine("Reached convergence on training/validation data after {0} iterations.", it);
                                break;
                            }
                            if (results[eval_measures[0]] < cutoff)
                            {
                                Console.Error.WriteLine("Reached cutoff after {0} iterations.", it);
                                Console.Error.WriteLine("DONE");
                                break;
                            }
                        }
                    }
                }                 // for
                if (max_iter % find_iter != 0)
                {
                    Predict(prediction_file, test_users_file);
                }
            }
        }
        else
        {
            Console.WriteLine(recommender + " ");

            if (load_model_file == null)
            {
                if (cross_validation > 1)
                {
                    var results = recommender.DoCrossValidation(cross_validation, test_users, candidate_items, eval_item_mode, compute_fit, true);
                    Console.Write(Render(results));
                    no_eval = true;
                }
                else
                {
                    time_span = Wrap.MeasureTime(delegate() { Train(); });
                    Console.Write("training_time " + time_span + " ");
                }
            }

            if (prediction_file != null)
            {
                Predict(prediction_file, test_users_file);
            }
            else if (!no_eval)
            {
                if (compute_fit)
                {
                    Console.WriteLine("fit: {0}", ComputeFit());
                }

                if (online_eval)
                {
                    time_span = Wrap.MeasureTime(delegate() {
                        var results = recommender.EvaluateOnline(test_data, training_data, test_users, candidate_items, eval_item_mode);
                        Console.Write(Render(results));
                    });
                }
                else
                {
                    time_span = Wrap.MeasureTime(delegate() { Console.Write(Render(Evaluate())); });
                }
                Console.Write(" testing_time " + time_span);
            }
            Console.WriteLine();
        }
        Model.Save(recommender, save_model_file);
        DisplayStats();
    }
 protected string Render(EvaluationResults results)
 {
     results.MeasuresToShow = eval_measures;
     return(results.ToString());
 }
示例#21
0
        static void Main(string[] args)
        {
            TopNEvaluator evaluator = new TopNEvaluator();

            var recommendersUnderTest = new List <ITrainableRecSource <MalTrainingData, MalUserListEntries, IEnumerable <IRecommendation>, IRecommendation> >();
            List <List <EvaluationResults> > resultsForEachRecommender = new List <List <EvaluationResults> >();

            const int    minEpisodesToCountIncomplete = 26;
            const double targetPercentile             = 0.25;

            //var averageScoreRecSourceWithoutDropped = new MalAverageScoreRecSource(minEpisodesToCountIncomplete, useDropped: false, minUsersToCountAnime: 50);
            //var mostPopularRecSourceWithoutDropped = new MalMostPopularRecSource(minEpisodesToCountIncomplete, useDropped: false);
            //var defaultBiasedMatrixFactorizationRecSource = new MalMyMediaLiteRatingPredictionRecSource<BiasedMatrixFactorization>
            //    (new BiasedMatrixFactorization(), minEpisodesToCountIncomplete, useDropped: true, minUsersToCountAnime: 50);
            //var biasedMatrixFactorizationRecSourceWithBoldDriver = new MalMyMediaLiteRatingPredictionRecSource<BiasedMatrixFactorization>
            //    (new BiasedMatrixFactorization() { BoldDriver = true }, minEpisodesToCountIncomplete, useDropped: true, minUsersToCountAnime: 50);
            //var biasedMatrixFactorizationRecSourceWithFactors = new MalMyMediaLiteRatingPredictionRecSource<BiasedMatrixFactorization>
            //    (new BiasedMatrixFactorization() { BoldDriver = true, FrequencyRegularization = true, NumFactors = 50 },
            //    minEpisodesToCountIncomplete, useDropped: true, minUsersToCountAnime: 50);
            //var biasedMatrixFactorizationRecSourceWithFactorsAndIters = new MalMyMediaLiteRatingPredictionRecSource<BiasedMatrixFactorization>
            //    (new BiasedMatrixFactorization() { BoldDriver = true, FrequencyRegularization = true, NumFactors = 50, NumIter = 50 },
            //    minEpisodesToCountIncomplete, useDropped: true, minUsersToCountAnime: 50);
            //var defaultMatrixFactorizationRecSource = new MalMyMediaLiteRatingPredictionRecSource<MatrixFactorization>
            //    (new MatrixFactorization(), minEpisodesToCountIncomplete, useDropped: true, minUsersToCountAnime: 50);
            var animeRecsRecSource35 = new MalAnimeRecsRecSourceWithConstantPercentTarget(
                numRecommendersToUse: 100,
                fractionConsideredRecommended: 0.35,
                targetFraction: 0.35,
                minEpisodesToClassifyIncomplete: minEpisodesToCountIncomplete
                );

            //var animeRecsRecSource25 = new MalAnimeRecsRecSourceWithConstantPercentTarget(
            //    numRecommendersToUse: 100,
            //    fractionConsideredRecommended: 0.25,
            //    targetFraction: 0.25,
            //    minEpisodesToClassifyIncomplete: minEpisodesToCountIncomplete
            //);

#if MYMEDIALITE
            var bprmfRecSource = new MalMyMediaLiteItemRecommenderRecSourceWithConstantPercentTarget <BPRMF>(
                new BPRMF()
            {
                BiasReg = .01f
            },
                fractionConsideredRecommended: 0.25,
                minEpisodesToClassifyIncomplete: minEpisodesToCountIncomplete,
                minUsersToCountAnime: 30,
                targetFraction: 0.25
                );
#endif

            //recommendersUnderTest.Add(averageScoreRecSourceWithoutDropped);
            //recommendersUnderTest.Add(mostPopularRecSourceWithoutDropped);
            //recommendersUnderTest.Add(defaultBiasedMatrixFactorizationRecSource);
            //recommendersUnderTest.Add(biasedMatrixFactorizationRecSourceWithBoldDriver);
            //recommendersUnderTest.Add(biasedMatrixFactorizationRecSourceWithFactors);
            //recommendersUnderTest.Add(biasedMatrixFactorizationRecSourceWithFactorsAndIters);
            //recommendersUnderTest.Add(defaultMatrixFactorizationRecSource);
            recommendersUnderTest.Add(animeRecsRecSource35);
            //recommendersUnderTest.Add(animeRecsRecSource25);
#if MYMEDIALITE
            recommendersUnderTest.Add(bprmfRecSource);
#endif

            for (int i = 0; i < recommendersUnderTest.Count; i++)
            {
                resultsForEachRecommender.Add(new List <EvaluationResults>());
            }

            IUserInputClassifier <MalUserListEntries> targetClassifier = new MalPercentageRatingClassifier(targetPercentile, minEpisodesToCountIncomplete);

            MalTrainingData rawData;

            IConfigurationBuilder configBuilder = new ConfigurationBuilder()
                                                  .AddXmlFile("config_base.xml")
                                                  .AddXmlFile("config_overrides.xml", optional: true);

            IConfigurationRoot rawConfig = configBuilder.Build();
            Config             config    = rawConfig.Get <Config>();

            string postgresConnectionString = config.ConnectionStrings.AnimeRecs;
            using (PgMalDataLoader loader = new PgMalDataLoader(postgresConnectionString))
                using (CancellationTokenSource timeout = new CancellationTokenSource(TimeSpan.FromSeconds(60)))
                {
                    rawData = loader.LoadMalTrainingDataAsync(timeout.Token).ConfigureAwait(false).GetAwaiter().GetResult();
                }

            const int numEvaluations = 5;
            const int numRecsToGet   = 25;

            for (int pass = 0; pass < numEvaluations; pass++)
            {
                for (int recSourceIndex = 0; recSourceIndex < recommendersUnderTest.Count; recSourceIndex++)
                {
                    ITrainableRecSource <MalTrainingData, MalUserListEntries, IEnumerable <IRecommendation>, IRecommendation> recSource = recommendersUnderTest[recSourceIndex];

                    Tuple <MalTrainingData, ICollection <MalUserListEntries> > dataForTrainingAndEvaluation = GetDataForTrainingAndEvaluation(rawData);
                    MalTrainingData trainingData = dataForTrainingAndEvaluation.Item1;
                    ICollection <MalUserListEntries> dataForEvaluation = dataForTrainingAndEvaluation.Item2;

                    recSource.Train(trainingData);

                    EvaluationResults results = evaluator.Evaluate(
                        recSource: recSource,
                        users: dataForEvaluation,
                        goodBadClassifier: targetClassifier,
                        inputDivisionFunc: MalUserListEntries.DivideClassifiedForInputAndEvaluation,
                        numRecsToTryToGet: numRecsToGet
                        );

                    resultsForEachRecommender[recSourceIndex].Add(results);
                }
            }

            for (int recSourceIndex = 0; recSourceIndex < recommendersUnderTest.Count; recSourceIndex++)
            {
                ITrainableRecSource <MalTrainingData, MalUserListEntries, IEnumerable <IRecommendation>, IRecommendation> recSource = recommendersUnderTest[recSourceIndex];
                Console.WriteLine(recSource);
                foreach (EvaluationResults resultsForPass in resultsForEachRecommender[recSourceIndex])
                {
                    Console.WriteLine("Precision: {0:P2}\tRecall: {1:P2}",
                                      resultsForPass.Precision, resultsForPass.Recall);
                }
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
            }
        }