public static Texture2D imageFromNet(NN.Net net) { List <Vector3> path = simulateNet(net); Texture2D imageRes = new Texture2D(128, 128, TextureFormat.Alpha8, false); //imageRes.alphaIsTransparency = true; float scale = 5.0f; Vector2 zeroPoint = new Vector2(64, 64); for (int i = 0; i < path.Count - 1; i++) { Vector2 path1 = new Vector2(path[i].x, path[i].z) * scale; Vector2 path2 = new Vector2(path[i + 1].x, path[i + 1].z) * scale; Color32 color = Color.HSVToRGB((float)i / path.Count, 1f, 1f); DrawLine(imageRes, zeroPoint + path1, zeroPoint + path2, color, 6); } imageRes.Apply(); //File.WriteAllBytes(Application.dataPath + Path.DirectorySeparatorChar + "AvatarData.png", imageRes.EncodeToPNG()); return(imageRes); }
public static List <Vector3> simulateNet(NN.Net net) { float dt = Time.fixedDeltaTime; List <Vector3> path = new List <Vector3>(100); path.Add(new Vector3(0f, 0f, 0f)); List <float> inputs = new List <float>() { 0f, 0f, 0f, 1f }; for (int i = 0; i < 50; ++i) { List <float> res = net.evaluate(inputs); Vector3 v = new Vector3(50 * res[1], 0f, 50 * res[0]); path.Add(path[path.Count - 1] + v * dt); inputs[0] = path[path.Count - 1].z; inputs[1] = path[path.Count - 1].x; inputs[2] = Vector3.Distance(Vector3.zero, path[path.Count - 1]); } return(path); }
public void buildModel() { network = new NN.Net(node_gene, node_connect); }