示例#1
0
        /// <summary>
        /// This method will be called after the panel has been added (window, monitor set...)
        /// </summary>
        protected override void OnInitialise(SigmaWindow window)
        {
            if (!Trainers.Contains(Trainer))
            {
                ValueSourceReporter valueHook = new ValueSourceReporter(TimeStep.Every(1, TimeScale.Epoch), "runtime_millis");
                _trainer.AddGlobalHook(valueHook);
                Monitor.Sigma.SynchronisationHandler.AddSynchronisationSource(valueHook);
                Trainers.Add(Trainer);

                valueHook = new ValueSourceReporter(TimeStep.Every(1, TimeScale.Iteration), "iteration");
                _trainer.AddLocalHook(valueHook);
                Monitor.Sigma.SynchronisationHandler.AddSynchronisationSource(valueHook);
            }

            //TODO: style?
            _playbackControl = new SigmaPlaybackControl {
                Trainer = Trainer, Margin = new Thickness(0, 0, 0, 20), HorizontalAlignment = HorizontalAlignment.Center
            };

            Content.Children.Add(_playbackControl);

            _parameterView = new ParameterView(Monitor.Sigma, window);

            SigmaTextBlock timeBox = (SigmaTextBlock)_parameterView.Add(Properties.Resources.RunningTime, typeof(object), _trainer.Operator.Registry, "runtime_millis");

            timeBox.AutoPollValues(_trainer, TimeStep.Every(1, TimeScale.Epoch));
            timeBox.Postfix = " ms";

            UserControlParameterVisualiser epochBox = (UserControlParameterVisualiser)_parameterView.Add(Properties.Resources.CurrentEpoch, typeof(object), _trainer.Operator.Registry, "epoch");

            epochBox.AutoPollValues(_trainer, TimeStep.Every(1, TimeScale.Epoch));

            UserControlParameterVisualiser iterationBox = (UserControlParameterVisualiser)_parameterView.Add(Properties.Resources.CurrentIteration, typeof(object), _trainer.Operator.Registry, "iteration");

            iterationBox.AutoPollValues(_trainer, TimeStep.Every(1, TimeScale.Iteration));

            IRegistry registry = new Registry
            {
                { "operator", Trainer.Operator.GetType().Name },
                { "optimiser", Trainer.Optimiser.GetType().Name }
            };

            _parameterView.Add(Properties.Resources.CurrentOperator, typeof(object), registry, "operator");
            _parameterView.Add(Properties.Resources.CurrentOptimiser, typeof(object), registry, "optimiser");
            //TODO: completely hardcoded activation function
            UserControlParameterVisualiser activationBox = (UserControlParameterVisualiser)_parameterView.Add(Properties.Resources.CurrentActivationFunction, typeof(object), _trainer.Operator.Registry, "network.layers.2-fullyconnected.activation");

            activationBox.AutoPollValues(_trainer, TimeStep.Every(1, TimeScale.Start));

            Trainer.AddGlobalHook(new LambdaHook(TimeStep.Every(1, TimeScale.Reset), (registry1, resolver) =>
            {
                epochBox.Read();
                iterationBox.Read();
            }));

            Content.Children.Add(_parameterView);
        }
示例#2
0
        private static void PrintWindow(SigmaWindow window)
        {
            Debug.WriteLine("window: " + window + " parent: " + window.ParentWindow + $" children:{window.ChildrenReadOnly.Count}\n================");
            foreach (SigmaWindow child in window.ChildrenReadOnly)
            {
                PrintWindow(child);
            }

            Debug.WriteLine("================");
        }
示例#3
0
        /// <summary>
        ///     This method ensures that the passed window is a <see cref="SigmaWindow" />.
        /// </summary>
        /// <param name="function">The function that will be executed, when a <see cref="TitleBarItem" /> is clicked. </param>
        /// <exception cref="ArgumentException">
        ///     If the passed window is not a <see cref="SigmaWindow" />, an exception will be
        ///     thrown.
        /// </exception>
        protected void AddSigmaFunction(Func <Application, SigmaWindow, TitleBarItem> function)
        {
            TitleBarFuncs.Add((app, window) =>
            {
                SigmaWindow sigmaWindow = window as SigmaWindow;

                if (sigmaWindow == null)
                {
                    throw new ArgumentException(
                        $@"Unfortunately, the default {nameof(TitleBarFactory)} only works with a {nameof(SigmaWindow)}.", nameof(window));
                }

                return(function(app, sigmaWindow));
            });
        }
示例#4
0
        public void SetIndex(int row, int column, TicTacToePlayer move)
        {
            if (move == NextTicTacToePlayer)
            {
                SetIndexFast(row, column, move);

                TicTacToePlayer winner;
                if (GameOver(row, column, out winner))
                {
                    //TODO: fix cast
                    SigmaWindow window = (SigmaWindow)_monitor.Window;

                    if (winner == TicTacToePlayer.None)
                    {
                        Task.Factory.StartNew(() => window.SnackbarMessageQueue.Enqueue("It's a tie!", "Got it", null));
                    }
                    else
                    {
                        Task.Factory.StartNew(() => window.SnackbarMessageQueue.Enqueue($"Player: {winner} has won the game!", "Got it", null));
                    }

                    _gameOver = true;

                    foreach (TicTacToeButton ticTacToeButton in _buttons)
                    {
                        ticTacToeButton.IsEnabled = false;
                    }
                }

                NextTicTacToePlayer = NextTicTacToePlayer.TogglePlayer();

                Field.SetValue(MapToInt(move), 0, row * _field.GetLength(0) + column);
                OnFieldChange(row, column, move, _gameOver);

                if (Autoplay)
                {
                    if (NextTicTacToePlayer == AiTicTacToePlayer)
                    {
                        OnAiMove();
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// This method will be called once the window is initialising (after it has been added).
        /// Do not store a reference of the window unless you properly dispose it (remove reference once not required).
        /// </summary>
        /// <param name="window">The wpf window this panel will be added to.</param>
        protected override void OnInitialise(SigmaWindow window)
        {
            Content = new TicTacToeField(Handler, Monitor);

            _moveOrder = new List <int>(9);

            Block           = new Dictionary <string, INDArray>();
            PassNetworkHook = new PassNetworkHook(this, Block, TimeStep.Every(1, TimeScale.Epoch));
            PassNetworkHook.On(new ExternalCriteria(registerHoldFunc: action => InvokePass = action));

            UpdateBlock();

            Content.AiMove += AIMoveRequest;

            Trainer.AddGlobalHook(PassNetworkHook);

            //Content.FieldChange += FieldChange;
            IsReady = true;
        }
示例#6
0
        /// <summary>
        /// The default item generation that will be called if no other title bar item is specified (i.e. <see cref="TitleBarFuncs"/> is empty).
        /// </summary>
        public virtual void InitialiseDefaultItems()
        {
            _log.Info("Creating default title bar items because no others have been specified.");

            AddSigmaFunction((app, window) =>
                             new TitleBarItem(Properties.Resources.ButtonEnvironment,
                                              Properties.Resources.MenuButtonLoad, (Action)(() =>
            {
                SigmaEnvironment sigma = window.Monitor.Sigma;
                ITrainer activeTrainer = sigma.RunningOperatorsByTrainer.Keys.FirstOrDefault();

                if (activeTrainer != null)
                {
                    OpenFileDialog fileDialog = new OpenFileDialog();
                    fileDialog.Title = "Open Network";
                    fileDialog.Multiselect = false;
                    fileDialog.Filter = "Sigma Network Files (*.sgnet)|*.sgnet";
                    fileDialog.InitialDirectory = new FileInfo(SigmaEnvironment.Globals.Get <string>("storage_path")).FullName;

                    if (fileDialog.ShowDialog() == true)
                    {
                        try
                        {
                            INetwork network = Serialisation.Read <INetwork>(Target.FileByPath(fileDialog.FileName), Serialisers.BinarySerialiser, false);

                            if (!Network.AreNetworkExternalsCompatible(network, activeTrainer.Network))
                            {
                                throw new InvalidOperationException($"Unable to switch to network \"{network.Name}\" with incompatible internals (from {fileDialog.FileName}).");
                            }

                            activeTrainer.Reset();

                            bool forceInitialisationBefore = activeTrainer.ForceInitialisation;
                            activeTrainer.ForceInitialisation = false;
                            activeTrainer.Network = network;
                            activeTrainer.Initialise(activeTrainer.Operator.Handler);

                            activeTrainer.ForceInitialisation = forceInitialisationBefore;

                            Task.Factory.StartNew(() => window.SnackbarMessageQueue.Enqueue(
                                                      $"Switched network \"{network.Name}\", reset training (now using \"{fileDialog.FileName}\")", "Got it", null));
                        }
                        catch (Exception e)
                        {
                            _log.Error($"Error while switching to network \"{fileDialog.FileName}\": {e.GetType()} ({e.Message})", e);
                        }
                    }
                }
                else
                {
                    _log.Warn($"Unable to load new network because no trainer is active.");
                }
            }),
                                              Properties.Resources.MenuButtonSave, new TitleBarItem("Extras", "Extra1", "Extra2", new TitleBarItem("More", "Extra 3"))));

#if DEBUG
            AddSigmaFunction((app, window) => new TitleBarItem(Properties.Resources.ButtonDebug,
                                                               "5 second indeterminate task",
                                                               (Action)(() =>
            {
                new Thread(() =>
                {
                    ITaskObserver task = null;
                    try
                    {
                        task = SigmaEnvironment.TaskManager.BeginTask(TaskType.Preprocess, "Indeterminate task");
                        Thread.Sleep(5000);
                    }
                    catch (Exception)
                    {
                        // ignore
                    }
                    finally
                    {
                        SigmaEnvironment.TaskManager.EndTask(task);
                    }
                }).Start();
            }), "Flood", (Action)(() =>
            {
                ILog log = LogManager.GetLogger(typeof(TitleBarFactory));
                new Thread(() =>
                {
                    for (int i = 1; i <= 1; i++)
                    {
                        log.Debug($"Flood {i}: debug");
                        log.Info($"Flood {i}: info");
                        log.Warn($"Flood {i}: warn");
                        log.Error($"Flood {i}: error");
                        log.Fatal($"Flood {i}: fatal");
                    }
                }).Start();
            }), "Print Hierarchy", (Action)(() =>
            {
                SigmaWindow root = window;
                while (!root.IsRoot)
                {
                    root = root.ParentWindow;
                }

                PrintWindow(root);
            })
                                                               ));
#endif

            AddSigmaFunction((app, window) => new TitleBarItem(Properties.Resources.ButtonSettings, new TitleBarItem(Properties.Resources.MenuButtonStyle, Properties.Resources.MenuButtonToggleDark,
                                                                                                                     (Action)(() => window.Monitor.ColourManager.Dark = !window.Monitor.ColourManager.Dark),
                                                                                                                     Properties.Resources.MenuButtonToggleAlternate, (Action)(() => window.Monitor.ColourManager.Alternate = !window.Monitor.ColourManager.Alternate) /*,
                                                                                                                                                                                                                                                                       * Properties.Resources.MenuButtonLanguage, (Action< Application, Window, TitleBarItem>) ((application, genericWindow, item) =>
                                                                                                                                                                                                                                                                       * {
                                                                                                                                                                                                                                                                       * WPFMonitor monitor = window.Monitor;
                                                                                                                                                                                                                                                                       * monitor.UiCultureInfo = CultureInfo.GetCultureInfo("de-DE");
                                                                                                                                                                                                                                                                       * monitor.Reload();
                                                                                                                                                                                                                                                                       * })*/)));

            AddSigmaFunction((app, window) =>
            {
                IUIFactory <UIElement> aboutFactory = (IUIFactory <UIElement>)Registry.TryGetValue(AboutFactoryIdentifier, () => new AboutFactory(window.DialogHost));
                object aboutContent = aboutFactory.CreateElement(app, window);

                TitleBarItem about = new TitleBarItem(Properties.Resources.ButtonHelp, new TitleBarItem(Properties.Resources.MenuButtonAbout, (Action)(async() =>
                {
                    window.DialogHost.IsOpen = false;
                    await DialogHost.Show(aboutContent, window.DialogHostIdentifier);
                })));

                return(about);
            });
        }
示例#7
0
 /// <summary>
 /// This method will be called once the window is initialising (after it has been added).
 /// Do not store a reference of the window unless you properly dispose it (remove reference once not required).
 /// </summary>
 /// <param name="window">The wpf window this panel will be added to.</param>
 protected virtual void OnInitialise(SigmaWindow window)
 {
 }
示例#8
0
 /// <summary>
 /// Generate a new parameter view with the manager and synchronisation handler assigned in the environment / window.
 /// <param name="environment">The currently active environment.</param>
 /// <param name="window">The currently active window (i.e. root window).</param>
 /// </summary>
 public ParameterView(SigmaEnvironment environment, SigmaWindow window) : this(window.ParameterVisualiser, environment.SynchronisationHandler)
 {
 }
示例#9
0
 public ParameterPanel(string title, SigmaEnvironment environment, SigmaWindow window, object headerContent = null) : this(title, window.ParameterVisualiser, environment.SynchronisationHandler, headerContent)
 {
 }
示例#10
0
 /// <summary>
 /// Create a new <see cref="AboutFactory"/> with the <see cref="DialogHost"/> from <see cref="SigmaWindow"/>.
 /// </summary>
 /// <param name="window">The <see cref="SigmaWindow"/>, the <see cref="AboutFactory"/> will produce in. </param>
 public AboutFactory(SigmaWindow window) : this(window.DialogHost)
 {
 }