private void Init(Rect buttonRect, ITreeBuilder treeBuilder, Action <Element> callback) { m_callback = callback; buttonRect = UnityHelper.GUIToScreenRect(buttonRect); var tree = treeBuilder.Build(); InsertTree(tree); ShowAsDropDown(buttonRect, new Vector2(buttonRect.width, 320)); Focus(); wantsMouseMove = true; }
public override void Resolve() { var canonicList = _excelReader.Read(_excelPath); _treeBuilder = new TreeBuilder(canonicList); _treeBuilder.Build(); _codePad = new CodePad(_treeBuilder.CanonicTree); _codePad.Write(); var activityCode = _codePad.Code; }
public void Run(SiteForParsing siteForParsing) { try { Log = LogManager.GetCurrentClassLogger(); var site = new Site { Url = siteForParsing.Url, ExternalLinks = siteForParsing.ExternalLinks, Depth = siteForParsing.Depth, LastUpdate = DateTime.Now }; SaveSiteToDb(site); Log.Info($"Run parsing: {site.Url}"); var time = new Stopwatch(); time.Start(); IsParsing = true; _parser.Start(site, siteForParsing.NumberOfThreads); var save = new Task(SavePagesToDb); save.Start(); Task.WaitAll(_parser.Tasks); IsParsing = false; Log.Info("Parsing Complete"); Task.WaitAll(save); time.Stop(); Log.Info($"Total time: {time.ElapsedMilliseconds}"); Console.WriteLine($@"Total Pages: {_parser.MainSite.Pages.Count} Time: {time.ElapsedMilliseconds}"); if (!siteForParsing.Tree) { return; } _treeBuilder.Build(_parser.MainSite); Log.Info("Tree was successfully builded"); } catch (Exception e) { Log.Error(e.Message); } }
/// <summary> /// Learns a decision tree from the provided observations and targets but limited to the observation indices provided by indices. /// Indices can contain the same index multiple times. Weights can be provided in order to weight each sample individually /// </summary> /// <param name="observations"></param> /// <param name="targets"></param> /// <param name="indices"></param> /// <param name="weights">Provide weights inorder to weigh each sample separetely</param> /// <returns></returns> public BinaryTree Learn(F64MatrixView observations, double[] targets, int[] indices, double[] weights) { Checks.VerifyObservationsAndTargets(observations, targets); Checks.VerifyIndices(indices, observations, targets); // Verify weights dimensions. Currently sample weights is supported by DecisionTreeLearner. // Hence, the check is not added to the general checks. if (weights.Length != 0) { if (weights.Length != targets.Length || weights.Length != observations.RowCount) { throw new ArgumentException($"Weights length differ from observation row count and target length. Weights: {weights.Length}, observation: {observations.RowCount}, targets: {targets.Length}"); } } return(m_treeBuilder.Build(observations, targets, indices, weights)); }
public async Task Write(Arguments arguments, CancellationToken cancellationToken) { var profiles = await profileReader.ReadFiles(arguments.Inputs, cancellationToken); var input = profiles.Concat(profileReader.ReadVariables(arguments.Variables)); var schemes = await profileReader.ReadFiles(arguments.Schemes, cancellationToken); var usedNames = input.OfType <Payload>() .Select(p => p.Name) .Distinct() .ToList(); await Task.WhenAll( from scheme in treeBuilder.BuildScheme(schemes, usedNames).AsParallel() from tree in treeBuilder.Build(input, scheme.GetSubstituteTypes()) from alteredScheme in treeBuilder.BuildScheme( scheme.WithImplicitHiddenKeys(tree), usedNames) from pair in formatterBuilder.Build(alteredScheme) from subTree in tree.GetSubTrees(pair.prefix) // RK TODO: Logging if no suitable subtrees. select pair.formatter.Write(subTree, cancellationToken)); }
public GRMResult ExecuteGRM(Stream dataSetStream, bool dataContainsHeaders, int?decisionAttributeIndex, int minimumSupport) { var progressTracker = ProgressTrackerContainer.CurrentProgressTracker; progressTracker.BeginTask(); progressTracker.BeginStep("Creating data set representation"); var representation = _dataSetRepresentationBuilder.Build(dataSetStream, dataContainsHeaders, decisionAttributeIndex); progressTracker.EndStep(); progressTracker.BeginStep("Selecting frequent items"); var frequentItems = _frequentItemsSelector.SelectFrequentItems(representation.ItemInfos.Values, minimumSupport); progressTracker.EndStep(); progressTracker.BeginStep("Sorting frequent items"); var sortedFrequentItems = _sortingStrategy.Apply(frequentItems); progressTracker.EndStep(); progressTracker.BeginStep("Building GRM tree"); var root = _treeBuilder.Build(sortedFrequentItems, representation.DecisionIDs.Values, representation.TransactionDecisions); progressTracker.EndStep(); progressTracker.BeginStep("Running GARM procedure"); _garmProcedure.Execute(root, representation.TransactionDecisions, minimumSupport); progressTracker.EndStep(); progressTracker.BeginStep("Building result"); var decisionsGenerators = _decisionGeneratorsCollector.GetDecisionsGenerators(); var result = _grmResultBuilder.GetResult(representation.AttributesCount, representation.DecisionAttributeIndex, representation.AttributeNames, representation.DecisionIDs, representation.ItemIDs, decisionsGenerators); progressTracker.EndStep(); progressTracker.EndTask(); return(result); }
protected override void RunInternal() { // Get the immutable repository information. IRepositoryData repositoryData = _loader.LoadFrom(_repositoryDir.FullName); // Pick the remote to work on. IRemote remoteToUse = _remoteHelper.PickRemote(repositoryData, Options.RemoteToUse); // Create the tree. IBranchingStrategy strategy = _strategyProvider.GetStrategy(Options.LesserBranchesRegex); IBranch[] allBranches = repositoryData.Branches.GetFor(remoteToUse).ToArray(); IBranchesKnowledge branchesKnowledge = strategy.CreateKnowledge(allBranches); // Options for building the tree. ITagPickingOptions tagPickingOptions = TagPickingOptions.Set( Options.TagPickingMode, Options.TagCount, Options.IncludeOrphanedTags); IBranchPickingOptions branchPickingOptions = BranchPickingOptions.Set( Options.IncludeBranchesRegices, Options.ExcludeBranchesRegices); ITree tree = _treeBuilder.Build( repositoryData, remoteToUse, branchesKnowledge, branchPickingOptions, tagPickingOptions); SimplifyTree(tree); string tempPath = _fileSystem.Path.GetTempFileName(); tempPath = _fileSystem.Path.ChangeExtension(tempPath, "gv"); // Rendering options. TreeRenderingOptions renderingOptions = TreeRenderingOptions.Default; renderingOptions.ForceTreatAsGitHub = Options.ForceTreatAsGitHub; // ReSharper disable once AssignNullToNotNullAttribute using (IFileStream fileStream = _fileSystem.File.OpenWrite(tempPath)) { using (IStreamWriter textWriter = _textWriterFactory.CreateStreamWriter(fileStream)) { IGraphVizWriter graphVizWriter = _graphVizFactory.CreateGraphVizWriter(textWriter); ITreeRenderer treeRenderer = _treeRendererFactory.CreateRenderer(graphVizWriter); treeRenderer.Render(tree, remoteToUse, branchesKnowledge, renderingOptions); } } string targetPath = PrepareTargetPath(); string graphVizCommand = _appPathProvider.GetProperAppPath(ExternalApp.GraphViz); string graphVizArgs = $@"""{tempPath}"" -T{_outputFormat} -o""{targetPath}"""; Log.Debug($"Starting GraphViz with arguments: [{graphVizArgs}]."); int code = _processRunner.Execute(graphVizCommand, graphVizArgs); if (code != 0) { Log.Fatal("GraphViz execution failed."); } else { Log.Info("GraphViz execution succeeded."); Log.Info($"Saved to {targetPath}."); } }
/// <summary> /// Learns a decision tree from the provided observations and targets but limited to the observation indices provided by indices. /// Indices can contain the same index multiple times. Weights can be provided in order to weight each sample individually /// </summary> /// <param name="observations"></param> /// <param name="targets"></param> /// <param name="indices"></param> /// <param name="weights">Provide weights inorder to weigh each sample separetely</param> /// <returns></returns> public BinaryTree Learn(F64MatrixView observations, double[] targets, int[] indices, double[] weights) { return(m_treeBuilder.Build(observations, targets, indices, weights)); }