public double[] GetDenseWeights(double[] weights) { if (!prepared) { Prepare(); } int rows = maps * Corners.Length; int columns = InputShape.Aggregate(1, (acc, val) => acc * val); int kernelSize = KernelShape.Aggregate(1, (acc, val) => acc * val); Matrix <double> mat = Matrix <double> .Build.Dense(rows, columns); for (int m = 0; m < maps; m++) { for (int i = 0; i < Corners.Length; i++) { var c = Corners[i]; foreach (var o in Offsets) { var l = Location(c, o, InputShape); if (l < 0) { continue; } var k = Location(null, o, KernelShape); mat[m * Corners.Length + i, l] = weights[k + m * kernelSize]; } } } return(mat.ToRowMajorArray()); }
public void SetInputPopup(Enum popup) { if (inputKind == InputKind.Terrain) { inputTerrain = (InputTerrain)popup; } else if (inputKind == InputKind.Noise) { inputNoise = (InputNoise)popup; } else if (inputKind == InputKind.Shape) { inputShape = (InputShape)popup; } else if (inputKind == InputKind.File) { inputFile = (InputFile)popup; } else if (inputKind == InputKind.Current) { inputCurrent = (InputCurrent)popup; } else if (inputKind == InputKind.Portal) { inputPortal = (InputPortal)popup; } }
public void ApplyInput() { // If the ID changed the image layouts must change as well if (!LedLayout.Id.Equals(InputId)) { foreach (var imageLayout in Model.DeviceLayout.LedImageLayouts) { foreach (var ledImage in imageLayout.LedImages.Where(l => l.Id.Equals(LedLayout.Id))) { ledImage.Id = InputId; } } } LedLayout.Id = InputId; LedLayout.DescriptiveX = InputX; LedLayout.DescriptiveY = InputY; LedLayout.DescriptiveWidth = InputWidth; LedLayout.DescriptiveHeight = InputHeight; // Apply custom shape data if (InputShape == Shape.Custom) { LedLayout.DescriptiveShape = InputShapeData; } else { LedLayout.DescriptiveShape = InputShape.ToString(); } // If LED image exists, update it if (_ledImage != null) { _ledImage.Image = InputImage; NotifyOfPropertyChange(() => LedImagePath); } // Create a new LED image and add it to the layout else { var ledImage = new LedImage { Id = LedLayout.Id, Image = InputImage }; // Find the current layout var layout = Model.DeviceLayout.LedImageLayouts.FirstOrDefault(l => l.Layout != null && l.Layout.Equals(_layoutViewModel.EditorViewModel.SelectedImageLayout)); // If missing, create it if (layout == null) { layout = new LedImageLayout { Layout = _layoutViewModel.EditorViewModel.SelectedImageLayout }; Model.DeviceLayout.LedImageLayouts.Add(layout); } layout.LedImages.Add(ledImage); UpdateLedImage(ledImage); } _layoutViewModel.UpdateLeds(); }
public void SetDefaultSettings() { size = TC_Settings.instance.global.defaultTerrainSize; if (transform.parent.GetSiblingIndex() == 0) { inputKind = InputKind.Shape; inputShape = InputShape.Circle; wrapMode = ImageWrapMode.Clamp; } else if (outputId == TC.heightOutput) { inputKind = InputKind.File; inputFile = InputFile.RawImage; wrapMode = ImageWrapMode.Clamp; } }
public void ApplyInput() { LedLayout.Id = InputId; LedLayout.DescriptiveX = InputX; LedLayout.DescriptiveY = InputY; LedLayout.DescriptiveWidth = InputWidth; LedLayout.DescriptiveHeight = InputHeight; // Apply custom shape data if (InputShape == Shape.Custom) { LedLayout.DescriptiveShape = InputShapeData; } else { LedLayout.DescriptiveShape = InputShape.ToString(); } // If LED image exists, update it _layoutViewModel.UpdateLeds(); }
static public void ClickMenuInput(object obj) { int instanceID; string command = TD.ObjectToCommandAndInstanceID(obj, out instanceID); TC_Node node = EditorUtility.InstanceIDToObject(instanceID) as TC_Node; if (node != null) { int index = command.IndexOf("/"); string inputKind = command.Substring(0, index); string input = command.Substring(index + 1); bool changed = false; InputKind oldInputKind = node.inputKind; node.inputKind = (InputKind)Enum.Parse(typeof(InputKind), inputKind); if (node.inputKind != oldInputKind) { changed = true; } if (inputKind == "Terrain") { InputTerrain oldInputTerrain = node.inputTerrain; node.inputTerrain = (InputTerrain)Enum.Parse(typeof(InputTerrain), input); if (node.inputTerrain != oldInputTerrain) { changed = true; } } else if (inputKind == "Noise") { InputNoise oldInputNoise = node.inputNoise; node.inputNoise = (InputNoise)Enum.Parse(typeof(InputNoise), input); if (node.inputNoise != oldInputNoise) { changed = true; } } else if (inputKind == "Shape") { InputShape oldInputShape = node.inputShape; node.inputShape = (InputShape)Enum.Parse(typeof(InputShape), input); if (node.inputShape != oldInputShape) { changed = true; } } else if (inputKind == "File") { InputFile oldInputFile = node.inputFile; node.inputFile = (InputFile)Enum.Parse(typeof(InputFile), input); if (node.inputFile != oldInputFile) { changed = true; } } else if (inputKind == "Current") { InputCurrent oldInputCurrent = node.inputCurrent; node.inputCurrent = (InputCurrent)Enum.Parse(typeof(InputCurrent), input); if (node.inputCurrent != oldInputCurrent) { changed = true; } } if (changed) { node.Init(); EditorUtility.SetDirty(node); TC.RefreshOutputReferences(node.outputId, true); } } }
public override void Prepare() { if (!layerPrepared) { convolutionEngine.Prepare(); if (UseAxisForBlocks == null) { UseAxisForBlocks = InputShape.Select(x => true).ToArray(); } var len = convolutionEngine.Offsets.Length; int dim = convolutionEngine.InputShape.Aggregate((a, b) => a * b); var blockOffsets = BlockOffset().ToArray(); var CornersProjections = convolutionEngine.Corners.Select(x => x[0]).Distinct().ToArray(); var expectedBlockSize = CornersProjections.Length / (double)blockOffsets.Length; var smallBlockSize = (int)Math.Floor(expectedBlockSize); var largeBlockSize = (int)Math.Ceiling(expectedBlockSize); var numberOfLargeBlocks = CornersProjections.Length - blockOffsets.Length * smallBlockSize; CornersMap = Enumerable.Range(0, convolutionEngine.Corners.Length).Select(x => - 1).ToArray(); masks = new IVector[len][]; shifts = new int[len][]; for (int i = 0; i < len; i++) { List <int>[] selections = Enumerable.Range(0, blockOffsets.Length).Select(t => new List <int>()).ToArray(); masks[i] = new IVector[blockOffsets.Length]; shifts[i] = new int[blockOffsets.Length]; for (int j = 0; j < shifts[i].Length; j++) { var thisBlockSize = (j > numberOfLargeBlocks) ? smallBlockSize : largeBlockSize; shifts[i][j] = (j == 0) ? convolutionEngine.Location(null, convolutionEngine.Offsets[i], convolutionEngine.InputShape) : shifts[i][j - 1] + blockOffsets[j - 1] - blockOffsets[j] + thisBlockSize * Stride[0] * dim / InputShape[0]; } for (int j = 0; j < convolutionEngine.Corners.Length; j++) { var location = convolutionEngine.Location(convolutionEngine.Corners[j], convolutionEngine.Offsets[i], convolutionEngine.InputShape); var CornerID = (convolutionEngine.Corners[j][0] - convolutionEngine.Corners[0][0]) / Stride[0]; var block = (CornerID < largeBlockSize * numberOfLargeBlocks) ? CornerID / largeBlockSize : numberOfLargeBlocks + ((CornerID - largeBlockSize * numberOfLargeBlocks) / smallBlockSize); if (location >= 0) { selections[block].Add(location); var map = location - shifts[i][block]; if (CornersMap[j] >= 0 && CornersMap[j] != map) { throw new Exception("Internal Error"); } CornersMap[j] = map; } } ParallelProcessInEnv(masks[i].Length, (env, id, j) => { if (selections[j].Any()) { var v = Vector <double> .Build.SparseOfIndexed(dim, selections[j].Select(l => new Tuple <int, double>(l, 1.0))); masks[i][j] = Factory.GetPlainVector(v, EVectorFormat.dense, 1); } else { masks[i][j] = null; } }); } // calculate output dimension var largeBlockMaxDim = (numberOfLargeBlocks == 0) ? 0 : (dim / InputShape[0]) * (1 + Stride[0] * (largeBlockSize - 1)) + blockOffsets[numberOfLargeBlocks - 1]; var smallBlockMaxDim = (dim / InputShape[0]) * (1 + Stride[0] * (smallBlockSize - 1)) + blockOffsets[blockOffsets.Length - 1]; outputDim = (largeBlockMaxDim > smallBlockMaxDim) ? largeBlockMaxDim : smallBlockMaxDim; HotIndices = Vector <double> .Build.DenseOfIndexed(outputDim, CornersMap.Select(x => new Tuple <int, double>(x, 1))); layerPrepared = true; } }