protected override IGraphData _Backpropagate(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var matrix = errorSignal.GetMatrix(); return(errorSignal.ReplaceWith(matrix.Transpose())); }
protected override IGraphData _Backpropagate(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { using (var od = _input.ReluDerivative()) { var delta = errorSignal.GetMatrix().PointwiseMultiply(od); return(errorSignal.ReplaceWith(delta)); } }
public IGraphData Execute(IGraphData input, IContext context) { var output = input.GetMatrix(); if (context.IsTraining) { if (context.LearningContext.ErrorMetric == null) { context.LearningContext.ErrorMetric = _errorMetric; } var target = context.BatchSequence.Target?.GetMatrix(); if (target == null) { context.LearningContext.DeferBackpropagation(null, signal => context.Backpropagate(signal)); } else { var gradient = _errorMetric.CalculateGradient(context, output, target); context.LearningContext.DeferBackpropagation(input.ReplaceWith(gradient), signal => context.Backpropagate(signal)); } } return(input); }
public override void _Backward(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var matrix = errorSignal.GetMatrix(); (IMatrix left, IMatrix right) = matrix.SplitAtColumn(matrix.ColumnCount - _reverseSize); context.AddBackward(errorSignal.ReplaceWith(left), parents[0], _source); var batch = context.BatchSequence.MiniBatch; var sequenceIndex = context.BatchSequence.SequenceIndex; var reversedSequenceIndex = batch.SequenceCount - sequenceIndex - 1; _source._reverseBackpropagation.Add(reversedSequenceIndex, (parents[1], errorSignal.ReplaceWith(right))); _source._contextTable.Add(sequenceIndex, context); if (sequenceIndex == 0) { // process in order as we are pushing onto a stack (so will be read in reverse order) for (var i = 0; i < batch.SequenceCount; i++) { var data = _source._reverseBackpropagation[i]; var reverseContext = _source._contextTable[i]; reverseContext.AddBackward(data.Item2, data.Item1, _source); } _source._reverseBackpropagation.Clear(); _source._contextTable.Clear(); } }
public SingleRowMiniBatch(IDataSource dataSource, IGraphData data, bool isSequential, MiniBatchSequenceType sequenceType, int sequenceIndex) { CurrentSequence = new Sequence(new[] { data }, this, sequenceType, sequenceIndex); DataSource = dataSource; IsSequential = isSequential; }
void _TestAction(IAction action, IGraphData input, IGraphData expectedOutput) { var context = new TestingContext(_cpu); var output = action.Execute(input, context); FloatingPointHelper.AssertEqual(output.GetMatrix().AsIndexable(), expectedOutput.GetMatrix().AsIndexable()); }
protected override IGraphData _Backpropagate(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var es = errorSignal.GetMatrix(); es.Multiply(2f); return(errorSignal.ReplaceWith(es)); }
internal PathfindingContext(IGraphData <T> graphData, Algorithms algorithm) { this.graphData = graphData; this.algorithm = algorithm; this.openList = new UniquePriorityQueue <NodeWrapper <T> >(Comparer <NodeWrapper <T> > .Create((o1, o2) => o2.CompareTo(o1))); this.nodeMapping = new Dictionary <T, NodeWrapper <T> >(); }
private void InitializeData(IGraphData graphData) { GraphData = graphData; //restart lifetime _lifeTime = _lifeTime ?? new LifeTimeDefinition(); _commands = _commands ?? new List <ILifeTimeCommand>(); }
public IGraphData Execute(IGraphData input, IContext context) { var matrix = input.GetMatrix(); matrix.Constrain(_min, _max); return(input); }
protected override IGraphData _Backpropagate(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var es = errorSignal.GetMatrix(); using (var ones = context.LinearAlgebraProvider.CreateMatrix(es.RowCount, es.ColumnCount, 1f / _rowCount)) return(errorSignal.ReplaceWith(ones.PointwiseMultiply(es))); }
private void UpdateElements() { IGraphData <Tile> data = cachedContext.GetGraphData(); SquareTileMapData sData = data as SquareTileMapData; if (tiles == null || tiles.Length == 0) { tiles = new UISquareTileElement[sData.RangeX, sData.RangeY]; for (int i = 0; i < sData.RangeX; ++i) { for (int j = 0; j < sData.RangeY; ++j) { UISquareTileElement tile = Instantiate <UISquareTileElement>(template, this.tilesRoot); tile.Init(i, j, cachedContext); (tile.transform as RectTransform).anchoredPosition = new Vector2((i + 0.5f) * 60f, (j + 0.5f) * 60f); tiles[i, j] = tile; tile.UpdateView(); } } } else { foreach (var cord in dirtyElements) { UISquareTileElement tile = this.tiles[cord.x, cord.y]; tile.UpdateView(); } dirtyElements.Clear(); } }
public override void _Backward(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { Debug.Assert(_source._children.Contains(fromNode)); _signalTable[fromNode] = errorSignal; if (_signalTable.All(s => s.Value != null) && parents?.Any() == true) { var firstSignal = _signalTable[_source._children.First()]; var otherSignals = _signalTable .Where(s => s.Value != firstSignal && s.Value.Columns == firstSignal.Columns && s.Value.Rows == firstSignal.Rows) .ToList() ; if (otherSignals.Any()) { var matrix = firstSignal.GetMatrix(); foreach (var item in otherSignals) { matrix.AddInPlace(item.Value.GetMatrix()); } firstSignal = firstSignal.ReplaceWith(matrix); } foreach (var parent in parents) { context.AddBackward(firstSignal, parent, _source); } _source._onBackpropagation?.Invoke(_signalTable); } }
protected override IGraphData _Backpropagate(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var output = errorSignal.GetMatrix().PointwiseMultiply(_filter); return(errorSignal.ReplaceWith(output)); }
private void UpdateTileCost(int x, int y, float cost) { IGraphData <Tile> data = cachedContext.GetGraphData(); SquareTileMapData sData = data as SquareTileMapData; sData.SetCost(x, y, cost); SetTileDirty(x, y); }
public void SwitchDiagram(IGraphData data) { if (data != null) { Designer.OpenTab(data); LoadDiagram(Workspace.CurrentGraph); } }
public DiagramViewModel(IGraphData diagram) { if (diagram == null) { throw new Exception("Diagram not found"); } CurrentRepository = diagram.Repository; }
public GraphRuntime(IDialogueController dialogue, IGraphData data) { _dataToRuntime = data.Nodes.ToDictionary( k => k, v => v.GetRuntime(this, dialogue)); Root = GetCopy(data.Root); }
public IGraphData Execute(IGraphData input, IContext context) { var ec = context.ExecutionContext; var memory = ec.GetMemory(_readFrom); ec.SetMemory(_writeTo, memory); return(input); }
protected override IGraphData _Backpropagate(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var es = errorSignal.GetMatrix(); using (var oneHalf = context.LinearAlgebraProvider.CreateMatrix(es.RowCount, es.ColumnCount, 0.5f)) using (var sqrt = es.Sqrt(1e-8f)) using (var delta = oneHalf.PointwiseMultiply(sqrt)) return(errorSignal.ReplaceWith(delta)); }
public override void _Backward(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var es = errorSignal.GetMatrix(); var delta1 = es.PointwiseMultiply(_input2); var delta2 = es.PointwiseMultiply(_input1); context.AddBackward(errorSignal.ReplaceWith(delta1), parents.First(), _source); context.AddBackward(errorSignal.ReplaceWith(delta2), parents.Last(), _source); }
protected override IGraphData _Backpropagate(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var error = errorSignal.GetMatrix(); using (var columnSums = error.ColumnSums()) { columnSums.Multiply(1f / error.RowCount); _source._param.AddInPlace(columnSums, 1f, context.LearningContext.BatchLearningRate); } return(errorSignal); }
protected override void ApplyConnection(IGraphData graph, IConnectable output, IConnectable input) { //base.ApplyConnection(graph, output, input); var typedItem = output as ITypedItem; if (typedItem != null) { typedItem.RelatedType = input.Identifier; } }
protected override IGraphData _Backpropagate(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var es = errorSignal.GetMatrix(); using (var minusOne = context.LinearAlgebraProvider.CreateMatrix(es.RowCount, es.ColumnCount, -1f)) using (var inputSquared = _input.PointwiseMultiply(_input)) using (var delta = minusOne.PointwiseDivide(inputSquared)) { return(errorSignal.ReplaceWith(delta.PointwiseMultiply(es))); } }
internal static ISolver <T> Create <T>(IGraphData <T> graphData, Algorithms algorithm) where T : IGraphNode { switch (graphData) { case ITileMapData tileMapData: return(CreateForTileData(tileMapData, algorithm) as ISolver <T>); } throw new NotImplementedException(); }
/// <summary> /// Sends a backpropagation signal further up the graph /// </summary> /// <param name="errorSignal">The backpropagating error</param> /// <param name="context">Graph context</param> /// <param name="parents">Parents of the current node</param> protected void _SendErrorTo(IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { if (parents?.Any() == true) { foreach (var parent in parents) { context.AddBackward(errorSignal, parent, _source); } } }
public async static ValueTask <string> CreateGraphAsync(IJSRuntime jsRuntime, string containerId, IGraphData data, IGraphOptions options) { return(await jsRuntime.InvokeAsync <string>("graphComponents.createGraph", containerId, data, options)); }
public override void _Backward(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var es = errorSignal.GetMatrix(); var negative = es.Clone(); negative.Multiply(-1f); context.AddBackward(errorSignal, parents.First(), _source); context.AddBackward(errorSignal.ReplaceWith(negative), parents.Last(), _source); }
protected IContext _Process(IExecutionContext executionContext, IGraphData data) { var context = new TrainingEngineContext(executionContext, data, _learningContext); _input.ExecuteForward(context, 0); while (context.HasNext) { context.ExecuteNext(); } return(context); }
protected override IGraphData _Backpropagate(INode fromNode, IGraphData errorSignal, IContext context, IReadOnlyList <INode> parents) { var error = errorSignal.GetMatrix(); var delta = error.ColumnSums(); delta.Multiply(1f / error.RowCount); var delta2 = delta.Average(); _source._param += delta2 * context.LearningContext.BatchLearningRate; return(errorSignal); }
public void AddGraph(IGraphData data) { if (Graphs.All(p => p.Identifier != data.Identifier)) { var workspaceGraph = new WorkspaceGraph { GraphId = data.Identifier, WorkspaceId = Identifier }; Repository.Add(workspaceGraph); } }
public void Reload(IGraphData graphData) { // TODO 2.0: Filter Stacks? //if (_persistedFilterStack.Count < 1) return; //if (_persistedFilterStack.Count != (FilterStack.Count)) //{ // foreach (var filterName in _persistedFilterStack) // { // var filter = graphData.Repository.GetFilters().FirstOrDefault(p => p.Identifier == filterName); // if (filter == null) // { // _persistedFilterStack.Clear(); // FilterStack.Clear(); // break; // } // //FilterStack.Push(filter); // graphData.PushFilter(filter); // } //} }
public DiagramViewModel(IGraphData diagram) { if (diagram == null) throw new Exception("Diagram not found"); CurrentRepository = diagram.Repository; DataObject = diagram; }
public void PreCompile(INodeRepository repository, IGraphData diagramData) { }
public void PostCompile(INodeRepository repository, IGraphData diagramData) { EditorApplication.ExecuteMenuItem("Visual Studio Tools/Generate Project Files"); }
public void ConnectionApplied(IGraphData g, IConnectable output, IConnectable input) { //#if UNITY_EDITOR //var projectService = InvertApplication.Container.Resolve<WorkspaceService>(); //foreach (var graph in projectService.CurrentWorkspace.Graphs) //{ // if (graph.Identifier == g.Identifier) // { // UnityEditor.EditorUtility.SetDirty(graph as UnityEngine.Object); // } //} //#endif }
public void ConnectionApplying(IGraphData graph, IConnectable output, IConnectable input) { }
public void LoadDiagram(IGraphData diagram) { InvertGraphEditor.DesignerWindow = this; if (diagram == null) return; try { DiagramDrawer = new DiagramDrawer(new DiagramViewModel(diagram)); DiagramDrawer.Dirty = true; //DiagramDrawer.Data.ApplyFilter(); DiagramDrawer.Refresh(InvertGraphEditor.PlatformDrawer); } catch (Exception ex) { InvertApplication.LogException(ex); InvertApplication.Log("Either a plugin isn't installed or the file could no longer be found. See Exception error"); } }