private void RadBookItem_MouseEnter(object sender, MouseEventArgs e) { if (this.dragStarted || FoldHelper.MouseWithinFoldAreas(e.GetPosition((IInputElement)this), this) || this.ParentBook != null && this.ParentBook.ShowPageFold != PageFoldVisibility.OnPageEnter) { return; } this.OnPageMouseEnter(new PageMouseEventArgs(this)); }
private void RadBookItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!this.CanBeTurned) { return; } this.mousePoint = e.GetPosition((IInputElement)this); if (!FoldHelper.MouseWithinFoldAreas(this.mousePoint, this) && this.FoldSize != new Size(0.0, 0.0)) { return; } this.draggedCorner = FoldHelper.GetQuadrant(this.mousePoint, this); this.targetCorner = RadBookItem.GetOppositeCorner(this.draggedCorner); this.UpdatePageFold(); if (this.doubleClickMode && this.PageFlipMode == PageFlipMode.DoubleClick) { if (this.mouseDoubleClick != null) { this.mouseDoubleClick((object)this, new MouseClickEventArgs(this.targetCorner)); } this.doubleClickMode = false; this.doubleClickTimer.Stop(); } else { this.singleClickMode = this.PageFlipMode == PageFlipMode.SingleClick; this.doubleClickMode = this.PageFlipMode == PageFlipMode.DoubleClick; this.dragStarted = true; if (this.PageFlipMode == PageFlipMode.SingleClick) { this.singleClickTimer.Start(); } else if (this.PageFlipMode == PageFlipMode.DoubleClick) { this.doubleClickTimer.Start(); } else { this.singleClickTimer.Stop(); this.doubleClickTimer.Stop(); } if (this.mouseDragStart == null) { return; } this.mouseDragStart((object)this, new DragStartedEventArgs(this.draggedCorner, this.mousePoint)); } }
private void UpdatePageFold() { if (this.Position == PagePosition.Right) { if (FoldHelper.MouseWithinTopRightFoldArea(this.mousePoint, this.FoldSize, this.ActualWidth)) { this.RaiseCornerEnterMove(FoldPosition.TopRight, 0.0, 0.0); this.lastEnteredCorner = FoldPosition.TopRight; } else if (FoldHelper.MouseWithinBottomRightFoldArea(this.mousePoint, this.FoldSize, this.ActualWidth, this.ActualHeight)) { this.RaiseCornerEnterMove(FoldPosition.BottomRight, 0.0, 0.0); this.lastEnteredCorner = FoldPosition.BottomRight; } else { this.RaiseCornerLeave(FoldHelper.GetQuadrant(this.mousePoint, this)); this.lastEnteredCorner = FoldPosition.None; } } else if (FoldHelper.MouseWithinTopLeftFoldArea(this.mousePoint, this.FoldSize)) { this.RaiseCornerEnterMove(FoldPosition.TopLeft, 0.0, 0.0); this.lastEnteredCorner = FoldPosition.TopLeft; } else if (FoldHelper.MouseWithinBottomLeftFoldArea(this.mousePoint, this.FoldSize, this.ActualHeight)) { this.RaiseCornerEnterMove(FoldPosition.BottomLeft, 0.0, 0.0); this.lastEnteredCorner = FoldPosition.BottomLeft; } else { this.RaiseCornerLeave(FoldHelper.GetQuadrant(this.mousePoint, this)); this.lastEnteredCorner = FoldPosition.None; } }
private void RadBookItem_MouseMove(object sender, MouseEventArgs e) { if (!this.CanBeTurned) { return; } if (this.dragStarted) { this.CaptureMouse(); } if (this.ParentBook.ShowPageFold == PageFoldVisibility.OnPageEnter && !FoldHelper.MouseWithinFoldAreas(e.GetPosition((IInputElement)this), this)) { this.OnPageMouseMove(new PageMouseEventArgs(this)); } this.mousePoint = e.GetPosition((IInputElement)this); if (this.dragStarted && this.mouseDragMove != null) { this.mouseDragMove((object)this, new DragInProgressEventArgs(this.mousePoint)); } else { this.UpdatePageFold(); } }
private void RunCore(IChannel ch, string cmd) { Host.AssertValue(ch); IPredictor inputPredictor = null; if (Args.ContinueTrain && !TrainUtils.TryLoadPredictor(ch, Host, Args.InputModelFile, out inputPredictor)) { ch.Warning("No input model file specified or model file did not contain a predictor. The model state cannot be initialized."); } ch.Trace("Constructing data pipeline"); IDataLoader loader = CreateRawLoader(); // If the per-instance results are requested and there is no name column, add a GenerateNumberTransform. var preXf = Args.PreTransform; if (!string.IsNullOrEmpty(Args.OutputDataFile)) { string name = TrainUtils.MatchNameOrDefaultOrNull(ch, loader.Schema, nameof(Args.NameColumn), Args.NameColumn, DefaultColumnNames.Name); if (name == null) { var args = new GenerateNumberTransform.Arguments(); args.Column = new[] { new GenerateNumberTransform.Column() { Name = DefaultColumnNames.Name }, }; args.UseCounter = true; var options = CmdParser.GetSettings(ch, args, new GenerateNumberTransform.Arguments()); preXf = preXf.Concat( new[] { new KeyValuePair <string, SubComponent <IDataTransform, SignatureDataTransform> >( "", new SubComponent <IDataTransform, SignatureDataTransform>( GenerateNumberTransform.LoadName, options)) }).ToArray(); } } loader = CompositeDataLoader.Create(Host, loader, preXf); ch.Trace("Binding label and features columns"); IDataView pipe = loader; var stratificationColumn = GetSplitColumn(ch, loader, ref pipe); var scorer = Args.Scorer; var evaluator = Args.Evaluator; Func <IDataView> validDataCreator = null; if (Args.ValidationFile != null) { validDataCreator = () => { // Fork the command. var impl = new CrossValidationCommand(this); return(impl.CreateRawLoader(dataFile: Args.ValidationFile)); }; } FoldHelper fold = new FoldHelper(Host, RegistrationName, pipe, stratificationColumn, Args, CreateRoleMappedData, ApplyAllTransformsToData, scorer, evaluator, validDataCreator, ApplyAllTransformsToData, inputPredictor, cmd, loader, !string.IsNullOrEmpty(Args.OutputDataFile)); var tasks = fold.GetCrossValidationTasks(); if (!evaluator.IsGood()) { evaluator = EvaluateUtils.GetEvaluatorType(ch, tasks[0].Result.ScoreSchema); } var eval = evaluator.CreateInstance(Host); // Print confusion matrix and fold results for each fold. for (int i = 0; i < tasks.Length; i++) { var dict = tasks[i].Result.Metrics; MetricWriter.PrintWarnings(ch, dict); eval.PrintFoldResults(ch, dict); } // Print the overall results. if (!TryGetOverallMetrics(tasks.Select(t => t.Result.Metrics).ToArray(), out var overallList)) { throw ch.Except("No overall metrics found"); } var overall = eval.GetOverallResults(overallList.ToArray()); MetricWriter.PrintOverallMetrics(Host, ch, Args.SummaryFilename, overall, Args.NumFolds); eval.PrintAdditionalMetrics(ch, tasks.Select(t => t.Result.Metrics).ToArray()); Dictionary <string, IDataView>[] metricValues = tasks.Select(t => t.Result.Metrics).ToArray(); SendTelemetryMetric(metricValues); // Save the per-instance results. if (!string.IsNullOrWhiteSpace(Args.OutputDataFile)) { var perInstance = EvaluateUtils.ConcatenatePerInstanceDataViews(Host, eval, Args.CollateMetrics, Args.OutputExampleFoldIndex, tasks.Select(t => t.Result.PerInstanceResults).ToArray(), out var variableSizeVectorColumnNames); if (variableSizeVectorColumnNames.Length > 0) { ch.Warning("Detected columns of variable length: {0}. Consider setting collateMetrics- for meaningful per-Folds results.", string.Join(", ", variableSizeVectorColumnNames)); } if (Args.CollateMetrics) { ch.Assert(perInstance.Length == 1); MetricWriter.SavePerInstance(Host, ch, Args.OutputDataFile, perInstance[0]); } else { int i = 0; foreach (var idv in perInstance) { MetricWriter.SavePerInstance(Host, ch, ConstructPerFoldName(Args.OutputDataFile, i), idv); i++; } } } }
private void RunCore(IChannel ch, string cmd) { Host.AssertValue(ch); IPredictor inputPredictor = null; if (Args.ContinueTrain && !TrainUtils.TryLoadPredictor(ch, Host, Args.InputModelFile, out inputPredictor)) { ch.Warning("No input model file specified or model file did not contain a predictor. The model state cannot be initialized."); } ch.Trace("Constructing data pipeline"); IDataLoader loader = CreateRawLoader(); // If the per-instance results are requested and there is no name column, add a GenerateNumberTransform. var preXf = Args.PreTransform; if (!string.IsNullOrEmpty(Args.OutputDataFile)) { string name = TrainUtils.MatchNameOrDefaultOrNull(ch, loader.Schema, nameof(Args.NameColumn), Args.NameColumn, DefaultColumnNames.Name); if (name == null) { var args = new GenerateNumberTransform.Arguments(); args.Column = new[] { new GenerateNumberTransform.Column() { Name = DefaultColumnNames.Name }, }; args.UseCounter = true; var options = CmdParser.GetSettings(ch, args, new GenerateNumberTransform.Arguments()); preXf = preXf.Concat( new[] { new KeyValuePair <string, SubComponent <IDataTransform, SignatureDataTransform> >( "", new SubComponent <IDataTransform, SignatureDataTransform>( GenerateNumberTransform.LoadName, options)) }).ToArray(); } } loader = CompositeDataLoader.Create(Host, loader, preXf); ch.Trace("Binding label and features columns"); IDataView pipe = loader; var stratificationColumn = GetSplitColumn(ch, loader, ref pipe); var scorer = Args.Scorer; var evaluator = Args.Evaluator; Func <IDataView> validDataCreator = null; if (Args.ValidationFile != null) { validDataCreator = () => { // Fork the command. var impl = new CrossValidationCommand(this); return(impl.CreateRawLoader(dataFile: Args.ValidationFile)); }; } FoldHelper fold = new FoldHelper(Host, RegistrationName, pipe, stratificationColumn, Args, CreateRoleMappedData, ApplyAllTransformsToData, scorer, evaluator, validDataCreator, ApplyAllTransformsToData, inputPredictor, cmd, loader, !string.IsNullOrEmpty(Args.OutputDataFile)); var tasks = fold.GetCrossValidationTasks(); if (!evaluator.IsGood()) { evaluator = EvaluateUtils.GetEvaluatorType(ch, tasks[0].Result.ScoreSchema); } var eval = evaluator.CreateInstance(Host); // Print confusion matrix and fold results for each fold. for (int i = 0; i < tasks.Length; i++) { var dict = tasks[i].Result.Metrics; MetricWriter.PrintWarnings(ch, dict); eval.PrintFoldResults(ch, dict); } // Print the overall results. eval.PrintOverallResults(ch, Args.SummaryFilename, tasks.Select(t => t.Result.Metrics).ToArray()); Dictionary <string, IDataView>[] metricValues = tasks.Select(t => t.Result.Metrics).ToArray(); SendTelemetryMetric(metricValues); // Save the per-instance results. if (!string.IsNullOrWhiteSpace(Args.OutputDataFile)) { Func <Task <FoldHelper.FoldResult>, int, IDataView> getPerInstance = (task, i) => { if (!Args.OutputExampleFoldIndex) { return(task.Result.PerInstanceResults); } // If the fold index is requested, add a column containing it. We use the first column in the data view // as an input column to the LambdaColumnMapper, because it must have an input. var inputColName = task.Result.PerInstanceResults.Schema.GetColumnName(0); var inputColType = task.Result.PerInstanceResults.Schema.GetColumnType(0); return(Utils.MarshalInvoke(EvaluateUtils.AddKeyColumn <int>, inputColType.RawType, Host, task.Result.PerInstanceResults, inputColName, MetricKinds.ColumnNames.FoldIndex, inputColType, Args.NumFolds, i + 1, "FoldIndex", default(ValueGetter <VBuffer <DvText> >))); }; var foldDataViews = tasks.Select(getPerInstance).ToArray(); if (Args.CollateMetrics) { var perInst = AppendPerInstanceDataViews(foldDataViews, ch); MetricWriter.SavePerInstance(Host, ch, Args.OutputDataFile, perInst); } else { int i = 0; foreach (var idv in foldDataViews) { MetricWriter.SavePerInstance(Host, ch, ConstructPerFoldName(Args.OutputDataFile, i), idv); i++; } } } }