void GenerateCPPN() { foreach (NodeGene node in cppnTest.Nodes) { node.fTYPE = ActivationFunctions.RandomFTYPE(); } cppn = new TWEANN(cppnTest); }
/// <summary> /// Create a new sculpture from a geno /// </summary> /// <param name="geno">TWEANNGenotype</param> public void NewSculpture(TWEANNGenotype geno) { backupGeno = geno.Copy(); this.geno = geno; cppn = new TWEANN(geno); if (cppn.Running) { geno = backupGeno; } // GenerateCPPN(); DrawSculpture(); }
public void Start() { dotProdTest = new TWEANN(2, 1, false, FTYPE.ID, 0); inputs = new float[] { 3, 5 }; Debug.Log("Starting test using inputs"); foreach (float d in inputs) { Debug.Log(d); } float[] results = dotProdTest.Process(inputs); foreach (float sum in results) { Debug.Log("Ending test: result = " + sum); } }
private void GenerateImageFromCPPN() { processingCPPN = true; if (debug) { Debug.Log("CPPN Imgage generation started..."); } if (debug) { Debug.Log("NETWORK OUTPUT : BEFORE CPPN : Building TWEANN from geno " + geno.ToString()); } cppn = new TWEANN(geno); if (debug) { Debug.Log("NETWORK OUTPUT : AFTER CPPN : Building TWEANN from geno " + geno.ToString()); } Vector3[] hsvArr = new Vector3[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float scaledX = Scale(x, width); float scaledY = Scale(y, height); float distCenter = GetDistFromCenter(scaledX, scaledY); float[] hsv = ProcessCPPNInput(scaledX, scaledY, distCenter, BIAS); // This initial hue is in the range [-1,1] as in the MM-NEAT code // However, C Sharp's Colors do not automatically map negative numbers to the proper hue range as in Java, so an additional step is needed Color colorHSV = Color.HSVToRGB( hsv[TWO_DIMENSIONAL_HUE_INDEX], hsv[TWO_DIMENSIONAL_SATURATION_INDEX], hsv[TWO_DIMENSIONAL_BRIGHTNESS_INDEX], false); //Debug.Log(hsv[0] + ", " + hsv[1] + ", " + hsv[2]); /*Color colorHSV = Color.HSVToRGB( * Mathf.Abs(ActivationFunctions.Activation(FTYPE.PIECEWISE, hsv[TWO_DIMENSIONAL_HUE_INDEX])), * Mathf.Abs(ActivationFunctions.Activation(FTYPE.HLPIECEWISE, hsv[TWO_DIMENSIONAL_SATURATION_INDEX])), * Mathf.Abs(ActivationFunctions.Activation(FTYPE.PIECEWISE, hsv[TWO_DIMENSIONAL_BRIGHTNESS_INDEX])), * true * ); */ MaxValue = Mathf.Max(MaxValue, hsv[TWO_DIMENSIONAL_HUE_INDEX]); MinValue = Mathf.Min(MinValue, hsv[TWO_DIMENSIONAL_HUE_INDEX]); //Debug.Log(finalColor[0] + ", " + finalColor[1] + ", " + finalColor[2]); //pixels[x + y * width] = colorHSV; hsvArr[x + y * width] = new Vector3(hsv[TWO_DIMENSIONAL_HUE_INDEX], hsv[TWO_DIMENSIONAL_SATURATION_INDEX], hsv[TWO_DIMENSIONAL_BRIGHTNESS_INDEX]); } } for (int i = 0; i < hsvArr.Length; i++) { float[] v = FormatHSV(new float[] { hsvArr[i][TWO_DIMENSIONAL_HUE_INDEX], hsvArr[i][TWO_DIMENSIONAL_SATURATION_INDEX], hsvArr[i][TWO_DIMENSIONAL_BRIGHTNESS_INDEX] }); pixels[i] = Color.HSVToRGB(v[TWO_DIMENSIONAL_HUE_INDEX], v[TWO_DIMENSIONAL_SATURATION_INDEX], v[TWO_DIMENSIONAL_BRIGHTNESS_INDEX], true); } //Debug.Log("MaxValue: " + MaxValue + ", MinValue: " + MinValue); processingCPPN = false; needsRedraw = true; //img.SetPixels(pixels); //img.Apply(); if (ArtGallery.DEBUG_LEVEL > ArtGallery.DEBUG.NONE) { Debug.Log("CPPN Imgage generation complete"); } }
/// <summary> /// Change voxels in sculpture based on CPPN outputs /// </summary> private void DrawSculpture() { processingCPPN = true; float halfVoxelSize = voxelSize / 2; cppn = new TWEANN(geno); Vector4[] outArr = new Vector4[SCULP_X * SCULP_Z * SCULP_Y]; voxArray = new Color[SCULP_X, SCULP_Z, SCULP_Y]; for (int x = 0; x < SCULP_X; x++) { for (int z = 0; z < SCULP_Z; z++) { for (int y = 0; y < SCULP_Y; y++) { float actualX = -(halfVoxelSize * SCULP_X / 2.0f) + halfVoxelSize + x * halfVoxelSize; float actualZ = -(halfVoxelSize * SCULP_Z / 2.0f) + halfVoxelSize + z * halfVoxelSize; float actualY = -(halfVoxelSize * SCULP_Y / 2.0f) + halfVoxelSize + y * halfVoxelSize; float distFromCenter = GetDistFromCenter(actualX, actualZ, actualY); float distFromCenterXZ = GetDistFromCenterXY(actualX, actualZ); float distfromCenterYZ = GetDistFromCenterZY(actualY, actualZ); float distfromCenterZY = GetDistFromCenterZY(actualX, actualZ); //float[] outputs = cppn.Process(new float[] { actualX, actualY, actualZ, distFromCenter, BIAS}); float[] outputs = cppn.Process(new float[] { actualX, actualY, actualZ, distFromCenter, distFromCenterXZ, distfromCenterYZ, distfromCenterZY, BIAS }); //TODO move all of the CPPN render out of the draw function if (MaxValue < outputs[THREE_DIMENSIONAL_HUE_INDEX]) { MaxValue = outputs[THREE_DIMENSIONAL_HUE_INDEX]; } if (MinValue > outputs[THREE_DIMENSIONAL_HUE_INDEX]) { MinValue = outputs[THREE_DIMENSIONAL_HUE_INDEX]; } outArr[x + (SCULP_Z * z) + (SCULP_Y * y)] = new Vector4(outputs[THREE_DIMENSIONAL_HUE_INDEX], outputs[THREE_DIMENSIONAL_SATURATION_INDEX], outputs[THREE_DIMENSIONAL_BRIGHTNESS_INDEX], outputs[THREE_DIMENSIONAL_VOXEL_INDEX]); } } } for (int x = 0; x < SCULP_X; x++) { for (int z = 0; z < SCULP_Z; z++) { for (int y = 0; y < SCULP_Y; y++) { float[] o = FixHue(outArr[x + (SCULP_Z * z) + (SCULP_Y * y)]); if (o[THREE_DIMENSIONAL_VOXEL_INDEX] > PRESENCE_THRESHOLD) { Color colorHSV = Color.HSVToRGB( o[THREE_DIMENSIONAL_HUE_INDEX], o[THREE_DIMENSIONAL_SATURATION_INDEX], o[THREE_DIMENSIONAL_BRIGHTNESS_INDEX], true ); float alpha = 1f; if (transparent) { alpha = ActivationFunctions.Activation(FTYPE.HLPIECEWISE, o[THREE_DIMENSIONAL_VOXEL_INDEX]); } //float alpha = -1.0f; Color color = new Color(colorHSV.r, colorHSV.g, colorHSV.b, alpha); voxArray[x, z, y] = color; } else { // This option will make the voxel turn off (requires matching = true statement above) voxArray[x, z, y] = new Color(0f, 0f, 0f, 0f); // This option will enable the "glass block" effect //rend.material.SetColor("_Color", new Color(0f, 0f, 0f, 0f)); } } } } processingCPPN = false; needsRedraw = true; }
public void Start() { xorTest = new TWEANNGenotype(2, 1, 0); List <NodeGene> nodes = xorTest.Nodes; /* Quick test for dotProduct */ float[] dotProdTestInputs = new float[] { 3, 5 }; Debug.Log("Staring test: dotproduct using inputs 3, 5"); float[] dotProdTestResults = new TWEANN(xorTest).Process(dotProdTestInputs); foreach (float sum in dotProdTestResults) { Debug.Log("Ending test: dotproduct = " + sum); } xorTest.SpliceNode(FTYPE.TANH, 2158, -1, -3, -0.3964445706032944f, -0.4269614531487551f, 100, 101); xorTest.AddLink(-1, -3, -0.5081867337293002f, 106); xorTest.SpliceNode(FTYPE.TANH, 150, -2, -3, -3.275181751309399f, -0.9183280870360113f, 102, 103); xorTest.AddLink(-1, 150, -2.202539496376981f, 104); xorTest.AddLink(-2, 2158, 0.9295958853236486f, 105); // Set activation function of output node xorTest.GetNodeByInnovationID(-1).fTYPE = FTYPE.TANH; xorTest.GetNodeByInnovationID(-2).fTYPE = FTYPE.TANH; xorTest.GetNodeByInnovationID(-3).fTYPE = FTYPE.TANH; // Set bias manually // Set weights manually /* List all nodes to output to verify network */ foreach (NodeGene ng in xorTest.Nodes) { Debug.Log(ng.ToString()); } foreach (LinkGene lg in xorTest.Links) { Debug.Log(lg.ToString()); } /* XOR test */ List <float[]> inputs = new List <float[]>(); inputs.Add(new float[] { 0, 0 }); inputs.Add(new float[] { 0, 1 }); inputs.Add(new float[] { 1, 0 }); inputs.Add(new float[] { 1, 1 }); TWEANN XORNetwork = new TWEANN(xorTest); for (int test = 0; test < inputs.Count; test++) { Debug.Log(""); string debugString = "Starting test using inputs "; foreach (float f in inputs[test]) { debugString += f + ", "; } Debug.Log(debugString); float[] results = XORNetwork.Process(inputs[test]); foreach (float sum in results) { Debug.Log("Ending test: result = " + sum); } } }