Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #13 from ThinkingTransistor/development
Browse files Browse the repository at this point in the history
Merge development into master
  • Loading branch information
flotothemoon authored Apr 28, 2017
2 parents b7a17d4 + 15d16e1 commit b4153d0
Show file tree
Hide file tree
Showing 90 changed files with 4,675 additions and 2,357 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Short overview about why anyone would use this, how it came to be (even shorter)
The recommended way to use the latest version of Sigma is adding the NuGet package to your project.
You can either include the core framework (command line only) [![Nuget (PreRelease)](https://img.shields.io/nuget/vpre/Sigma.Core.svg?style=flat-square)](https://www.nuget.org/packages/Sigma.Core) or the WPF visualiser (only works on Windows) which also references the core framework [![Nuget (PreRelease WPF)](https://img.shields.io/nuget/vpre/Sigma.Core.Monitors.WPF.svg?style=flat-square)](https://www.nuget.org/packages/Sigma.Core.Monitors.WPF).

In both cases, you can use any project with a main (ConsoleApplication) but you have to change the project settings to x64 since **Sigma only supports 64bit mode**.

In both cases, you can use any project with a main (e.g. ConsoleApplication) but you have to change the project settings to x64 (since **Sigma only supports 64bit mode**) and change the target framework to **.NET 4.6** before installing the NuGet packages.

### From source

Expand Down
20 changes: 18 additions & 2 deletions Sigma.Core.Monitors.WPF/Panels/Charts/AccuracyPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ MIT License
For full license see LICENSE in the root directory of this project.
*/

using System;
using System.Collections.Generic;
using LiveCharts;
using LiveCharts.Wpf;
Expand Down Expand Up @@ -42,15 +43,30 @@ public AccuracyPanel(string title, ITrainer trainer, object headerContent = null
/// <param name="headerContent">The content for the header. If <c>null</c> is passed,
/// the title will be used.</param>
/// <param name="tops"></param>
public AccuracyPanel(string title, ITrainer trainer, object headerContent = null, params int[] tops) : base(title, headerContent)
public AccuracyPanel(string title, ITrainer trainer, object headerContent = null, params int[] tops) : this(title, trainer, TimeStep.Every(1, TimeScale.Epoch), headerContent, tops)
{
}

/// <summary>
/// Create an AccuracyPanel with a given title. It displays given accuracies per epoch.
/// If a title is not sufficient modify <see cref="SigmaPanel.Header" />.
/// </summary>
/// <param name="title">The given tile.</param>
/// <param name="trainer"></param>
/// <param name="headerContent">The content for the header. If <c>null</c> is passed,
/// the title will be used.</param>
/// <param name="tops"></param>
public AccuracyPanel(string title, ITrainer trainer, ITimeStep timeStep, object headerContent = null, params int[] tops) : base(title, headerContent)
{
if (timeStep == null) throw new ArgumentNullException(nameof(timeStep));

// skip the first since its automatically generated
for (int i = 1; i < tops.Length; i++)
{
AddSeries(new LineSeries());
}

trainer.AddHook(new ChartValidationAccuracyReport(this, "validation", TimeStep.Every(1, TimeScale.Epoch), tops));
trainer.AddHook(new ChartValidationAccuracyReport(this, "validation", timeStep, tops));

AxisY.MinValue = 0;
AxisY.MaxValue = 100;
Expand Down
15 changes: 9 additions & 6 deletions Sigma.Core.Monitors.WPF/Panels/Charts/TrainerChartPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ namespace Sigma.Core.Monitors.WPF.Panels.Charts
/// <param name="timestep">The <see cref="TimeStep"/> for the hook.</param>
/// <param name="headerContent">The content for the header. If <c>null</c> is passed,
/// the title will be used.</param>
public TrainerChartPanel(string title, ITrainer trainer, string hookedValue, ITimeStep timestep, object headerContent = null) : base(title, headerContent)
public TrainerChartPanel(string title, ITrainer trainer, string hookedValue, ITimeStep timestep, bool averageMode = false, object headerContent = null) : base(title, headerContent)
{
VisualValueReporterHook hook = new VisualValueReporterHook(this, new[] { hookedValue }, timestep);
VisualValueReporterHook hook = new VisualValueReporterHook(this, new[] { hookedValue }, timestep, averageMode);
Init(trainer, hook);
}

Expand All @@ -65,9 +65,9 @@ public TrainerChartPanel(string title, ITrainer trainer, string hookedValue, ITi
/// <param name="timestep">The <see cref="TimeStep"/> for the hook.</param>
/// <param name="headerContent">The content for the header. If <c>null</c> is passed,
/// the title will be used.</param>
public TrainerChartPanel(string title, ITrainer trainer, ITimeStep timestep, object headerContent = null, params string[] hookedValues) : base(title, headerContent)
public TrainerChartPanel(string title, ITrainer trainer, ITimeStep timestep, bool averageMode = false, object headerContent = null, params string[] hookedValues) : base(title, headerContent)
{
VisualValueReporterHook hook = new VisualValueReporterHook(this, hookedValues, timestep);
VisualValueReporterHook hook = new VisualValueReporterHook(this, hookedValues, timestep, averageMode);
Init(trainer, hook);
}

Expand Down Expand Up @@ -118,7 +118,7 @@ protected class VisualValueReporterHook : ValueReporterHook
/// <param name="chartPanel">The chartpanel to which points will get added.</param>
/// <param name="valueIdentifiers">The identifiers for the <see cref="ValueReporterHook"/>; these values will get plotted.</param>
/// <param name="timestep">The <see cref="TimeStep"/> for the hook (i.e. execution definition).</param>
public VisualValueReporterHook(ChartPanel<TChart, TSeries, TChartValues, TData> chartPanel, string[] valueIdentifiers, ITimeStep timestep) : base(valueIdentifiers, timestep)
public VisualValueReporterHook(ChartPanel<TChart, TSeries, TChartValues, TData> chartPanel, string[] valueIdentifiers, ITimeStep timestep, bool averageMode = false) : base(valueIdentifiers, timestep, averageMode, false)
{
ParameterRegistry[ChartPanelIdentifier] = chartPanel;
}
Expand All @@ -127,7 +127,10 @@ public VisualValueReporterHook(ChartPanel<TChart, TSeries, TChartValues, TData>
/// Report the values for a certain epoch / iteration to a passed ChartPanel.
/// </summary>
/// <param name="valuesByIdentifier">The values by their identifier.</param>
protected override void ReportValues(IDictionary<string, object> valuesByIdentifier)
/// <param name="reportEpochIteration">A boolean indicating whether or not to report the current epoch / iteration.</param>
/// <param name="epoch">The current epoch.</param>
/// <param name="iteration">The current iteration.</param>
protected override void ReportValues(IDictionary<string, object> valuesByIdentifier, bool reportEpochIteration, int epoch, int iteration)
{
ChartPanel<TChart, TSeries, TChartValues, TData> chartPanel = (ChartPanel<TChart, TSeries, TChartValues, TData>) ParameterRegistry[ChartPanelIdentifier];
chartPanel.Add((TData) valuesByIdentifier.Values.First());
Expand Down
79 changes: 75 additions & 4 deletions Sigma.Core.Monitors.WPF/Panels/Controls/ControlPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ MIT License
For full license see LICENSE in the root directory of this project.
*/

using System.Windows;
using System.Windows.Controls;
using Sigma.Core.Monitors.WPF.View.CustomControls.Panels.Control;
using Sigma.Core.Monitors.WPF.View.Parameterisation;
using Sigma.Core.Monitors.WPF.View.Parameterisation.Defaults;
using Sigma.Core.Monitors.WPF.View.Windows;
using Sigma.Core.Training;
using Sigma.Core.Training.Hooks.Reporters;
using Sigma.Core.Utils;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace Sigma.Core.Monitors.WPF.Panels.Controls
{
Expand All @@ -19,7 +26,8 @@ namespace Sigma.Core.Monitors.WPF.Panels.Controls
/// </summary>
public class ControlPanel : GenericPanel<StackPanel>
{
private readonly SigmaPlaybackControl _playbackControl;
private SigmaPlaybackControl _playbackControl;
private ParameterView _parameterView;

private ITrainer _trainer;

Expand All @@ -36,6 +44,18 @@ public ITrainer Trainer
}
}

/// <summary>
/// This list stores all trainers that have been initialised.
/// Required to only add one hook per trainer.
/// </summary>
private static readonly IList<ITrainer> Trainers;

static ControlPanel()
{
Trainers = new List<ITrainer>();
}


public ControlPanel(string title, object content = null) : this(title, null, content) { }

public ControlPanel(string title, ITrainer trainer, object content = null) : base(title, content)
Expand All @@ -49,10 +69,61 @@ public ControlPanel(string title, ITrainer trainer, object content = null) : bas
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(0, 20, 0, 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(WPFWindow window)
{
throw new InvalidOperationException($"{nameof(ControlPanel)} is only compatible with {nameof(SigmaWindow)}s.");
}

_playbackControl = new SigmaPlaybackControl { Trainer = Trainer };
/// <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))
{
ValueSourceReporterHook valueHook = new ValueSourceReporterHook(TimeStep.Every(1, TimeScale.Epoch), "runtime_millis");
_trainer.AddGlobalHook(valueHook);
Monitor.Sigma.SynchronisationHandler.AddSynchronisationSource(valueHook);
Trainers.Add(Trainer);

valueHook = new ValueSourceReporterHook(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);

//TODO: language support

SigmaTextBlock timeBox = (SigmaTextBlock) _parameterView.Add("Running time", typeof(object), _trainer.Operator.Registry, "runtime_millis");
timeBox.AutoPollValues(_trainer, TimeStep.Every(1, TimeScale.Epoch));
timeBox.Postfix = " ms";

UserControlParameterVisualiser epochBox = (UserControlParameterVisualiser) _parameterView.Add("Current epoch", typeof(object), _trainer.Operator.Registry, "epoch");
epochBox.AutoPollValues(_trainer, TimeStep.Every(1, TimeScale.Epoch));

UserControlParameterVisualiser iterationBox = (UserControlParameterVisualiser) _parameterView.Add("Current iteration", typeof(object), _trainer.Operator.Registry, "iteration");
iterationBox.AutoPollValues(_trainer, TimeStep.Every(1, TimeScale.Iteration));

IRegistry registry = new Registry
{
{ "op", Trainer.Operator.GetType().Name }
};
_parameterView.Add("Current operator", typeof(object), registry, "op");

Content.Children.Add(_parameterView);
}
}
}
2 changes: 1 addition & 1 deletion Sigma.Core.Monitors.WPF/Panels/Controls/DrawPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public override void SubInvoke(IRegistry registry, IRegistryResolver resolver)
});

DataProviderUtils.ProvideExternalInputData(provider, network, block);
network.Run(Operator.Handler, false);
network.Run(Operator.Handler, trainingPass: false);
DataProviderUtils.ProvideExternalOutputData(provider, network, block);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ For full license see LICENSE in the root directory of this project.
using System;
using Sigma.Core.Monitors.Synchronisation;
using Sigma.Core.Monitors.WPF.View.Parameterisation;
using Sigma.Core.Monitors.WPF.View.Windows;
using Sigma.Core.Monitors.WPF.ViewModel.Parameterisation;
using Sigma.Core.Utils;

Expand All @@ -27,6 +28,7 @@ public ParameterPanel(string title, IParameterVisualiserManager visualiserManage
{
Content = new ParameterView(visualiserManager, synchronisationHandler);
}
public ParameterPanel(string title, SigmaEnvironment environment, SigmaWindow window, object headerContent = null) : this(title, window.ParameterVisualiser, environment.SynchronisationHandler, headerContent) { }

public void Add(string name, Type type, IRegistry registry, string key)
{
Expand Down
55 changes: 48 additions & 7 deletions Sigma.Core.Monitors.WPF/Panels/SigmaPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ For full license see LICENSE in the root directory of this project.
using System.Windows;
using System.Windows.Controls;
using MaterialDesignThemes.Wpf;
using Sigma.Core.Monitors.WPF.View.Windows;

// ReSharper disable VirtualMemberCallInConstructor

Expand Down Expand Up @@ -38,6 +39,11 @@ public abstract class SigmaPanel : Card
/// </summary>
private UIElement _content;

/// <summary>
/// Currently responsible monitor - it will be automatically set when adding a new panel. (<c>null</c> until <see cref="Initialise"/>)
/// </summary>
public WPFMonitor Monitor { get; set; }

/// <summary>
/// Create a SigmaPanel with a given title.
/// If a title is not sufficient modify <see cref="Header" />.
Expand Down Expand Up @@ -99,7 +105,7 @@ protected SigmaPanel(string title, object content = null)
}
else
{
_content = value as UIElement ?? new Label { Content = value.ToString() };
_content = value as UIElement ?? new Label {Content = value.ToString()};
ContentGrid.Children.Add(_content);
}
}
Expand Down Expand Up @@ -143,10 +149,10 @@ protected virtual Grid CreateHeader(object content)
{
Grid header = new Grid();

header.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
header.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) });
header.RowDefinitions.Add(new RowDefinition {Height = new GridLength(1, GridUnitType.Auto)});
header.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(1, GridUnitType.Auto)});

Label headerContent = new Label { Content = content };
Label headerContent = new Label {Content = content};
header.Children.Add(headerContent);

header.SetResourceReference(BackgroundProperty, "SigmaPanelHeaderBackground");
Expand Down Expand Up @@ -174,19 +180,54 @@ protected virtual Grid CreateContentGrid()
{
Grid grid = new Grid();

grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(1, GridUnitType.Star)});
grid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)});

return grid;
}

/// <summary>
/// This method invokes the initialisation of the panel (after it has been addded).
/// </summary>
public void Initialise(WPFWindow window)
{
if (window is SigmaWindow)
{
OnInitialise((SigmaWindow)window);
}
else
{
OnInitialise(window);
}
}

/// <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(WPFWindow window)
{

}

/// <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)
{

}

/// <summary>
/// Create the default panel in which every other element is contained.
/// </summary>
/// <returns>The newly create <see cref="DockPanel" />.</returns>
protected virtual DockPanel CreateDockPanel()
{
return new DockPanel { LastChildFill = true, Margin = new Thickness(-1, 0, 0, 0) };
return new DockPanel {LastChildFill = true, Margin = new Thickness(-1, 0, 0, 0)};
}
}
}
4 changes: 4 additions & 0 deletions Sigma.Core.Monitors.WPF/Sigma.Core.Monitors.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<Compile Include="Utils\AttributeUtils.cs" />
<Compile Include="Utils\ChartPanelPerformance.cs" />
<Compile Include="Utils\Converters\InverseBooleanConverter.cs" />
<Compile Include="ViewModel\Parameterisation\PollParameterHook.cs" />
<Compile Include="Utils\WindowUtils.cs" />
<Compile Include="ViewModel\Parameterisation\IParameterVisualiserManager.cs" />
<Compile Include="ViewModel\Parameterisation\ParameterVisualiserManager.cs" />
Expand Down Expand Up @@ -222,6 +223,8 @@
<Compile Include="View\Parameterisation\Defaults\SigmaComboBox.xaml.cs">
<DependentUpon>SigmaComboBox.xaml</DependentUpon>
</Compile>
<Compile Include="View\Parameterisation\Defaults\SigmaDynamicGenericBox.cs" />
<Compile Include="View\Parameterisation\Defaults\SigmaGenericBox.cs" />
<Compile Include="View\Parameterisation\Defaults\SigmaSlider.xaml.cs">
<DependentUpon>SigmaSlider.xaml</DependentUpon>
</Compile>
Expand All @@ -233,6 +236,7 @@
</Compile>
<Compile Include="ViewModel\Parameterisation\IParameterLabel.cs" />
<Compile Include="ViewModel\Parameterisation\IParameterVisualiserInfo.cs" />
<Compile Include="View\Parameterisation\Defaults\SigmaTimeBlock.cs" />
<Compile Include="View\Parameterisation\ParameterLabel.cs" />
<Compile Include="View\Parameterisation\ParameterView.xaml.cs">
<DependentUpon>ParameterView.xaml</DependentUpon>
Expand Down
Loading

0 comments on commit b4153d0

Please sign in to comment.