public void LoadInputImage(int n) { string filename = inputNames[n]; int numY = (int)Mathf.Sqrt(numInputs); Texture2D texture = Resources.Load <Texture2D>(filename); int inputLayer = 0; for (int nx = 0; nx < texture.width; nx++) { for (int ny = 0; ny < texture.height; ny++) { Color color = texture.GetPixel(nx, ny); int index = nx * numY + ny; NNnode node = nodeLayers[inputLayer][index]; node.output = 1f - color.grayscale; node.Update(); } } string lastChar = filename.Substring(filename.Length - 1, 1); string possibilites = "0123456789"; if (possibilites.Contains(lastChar)) { float correctAnswer = float.Parse(lastChar); UpdateOutputLayerWithCorrectAnswer(correctAnswer); } }
public void CreateNodesLayer(int layer, int numNodes) { nodeLayers[layer] = new List <NNnode>(); for (int n = 0; n < numNodes; n++) { NNnode node = new NNnode(layer, this); } }
public void UpdateNodes() { for (int layer = 0; layer < nodeLayers.Length; layer++) { for (int n = 0; n < nodeLayers[layer].Count; n++) { NNnode node = nodeLayers[layer][n]; node.Update(); } } }
public void CreateLinks() { for (int layer = 0; layer < layerCounts.Count; layer++) { for (int n = 0; n < nodeLayers[layer].Count; n++) { NNnode node = nodeLayers[layer][n]; CreateLinksForNode(node); } } }
public void CreateLinksForNode(NNnode nodeFrom) { if (nodeFrom.layer > 0) { List <NNnode> nodeLayerBelow = nodeLayers[nodeFrom.layer - 1]; for (int n = 0; n < nodeLayerBelow.Count; n++) { NNnode nodeTo = nodeLayerBelow[n]; CreateLink(nodeFrom, nodeTo); } } }
public void CreateLink(NNnode nodeFrom, NNnode nodeTo) { Vector3 posFrom = nodeFrom.go.transform.position; Vector3 posTo = nodeTo.go.transform.position; GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.transform.parent = parentLinks.transform; go.transform.position = (posFrom + posTo) / 2; float dist = Vector3.Distance(posFrom, posTo); go.transform.LookAt(posTo); go.transform.localScale = new Vector3(.1f, .1f, dist); go.GetComponent <Renderer>().material.color = new Color(0, 0, .125f); cntWeights++; CreateLinkInputAndWeight(nodeFrom, nodeTo, go); }
public void ScaleWeights(NNnode nodeOutput, float scaleFactor) { Color color = Random.ColorHSV(); for (int layer = 1; layer < nodeLayers.Length; layer++) { for (int n = 0; n < nodeLayers[layer].Count; n++) { NNnode node = nodeLayers[layer][n]; if (node != nodeOutput) { for (int w = 0; w < node.weights.Count; w++) { node.weights[w] *= scaleFactor; node.links[w].GetComponent <Renderer>().material.color = color; } } } } }
public void CreateLinkInputAndWeight(NNnode nodeFrom, NNnode nodeTo, GameObject goLink) { nodeFrom.inputNodes.Add(nodeTo); nodeFrom.weights.Add(Random.Range(0f, 1f)); nodeFrom.links.Add(goLink); }