private void Init() { //Init classes scalingFunction = new ScalingFunction(); weightsGenerator = new WeightsGeneratorRNGCSP(); activationFunctions = new ActivationFunctions(); geneticAlgorithm = new GeneticAlgorithm(weightsGenerator); neuralNetwork = new List <NeuralNetwork>(); perceptron = new Perceptron(); //Init Lists keyStore = new List <BTCKeyStore>(); dataSet = new List <DataSet>(); valkeyStore = new List <BTCKeyStore>(); valdataSet = new List <DataSet>(); neuralNetwork = new List <NeuralNetwork>(); deathRate = 10; //If too high, then chance plays an increasing role and skews the result. cb = new CircularBuffer(deathRate); oldMetric = double.MaxValue; attemptstats = new double[32]; GenerateValidationDataset(); }
/// <summary> /// /// </summary> /// <param name="lData"></param> /// <param name="lError"></param> /// <returns></returns> public static unsafe Texture2D CreateTexture2DFromWebP(byte[] lData, bool lMipmaps, bool lLinear, out Error lError, ScalingFunction scalingFunction = null ) { lError = 0; Texture2D lTexture2D = null; int lWidth = 0, lHeight = 0; GetWebPDimensions(lData, out lWidth, out lHeight); byte[] lRawData = LoadRGBAFromWebP(lData, ref lWidth, ref lHeight, lMipmaps, out lError, scalingFunction); if (lError == Error.Success) { lTexture2D = new Texture2D(lWidth, lHeight, TextureFormat.RGBA32, lMipmaps, lLinear); lTexture2D.LoadRawTextureData(lRawData); lTexture2D.Apply(lMipmaps, true); } return lTexture2D; }
private void Init() { //Init classes scalingFunction = new ScalingFunction(); activationFunctions = new ActivationFunctions(); neuralNetwork = new List <NeuralNetwork>(); perceptron = new Perceptron(); analyserEntry = new AnalyserEntry(); //Init Lists neuralNetwork = new List <NeuralNetwork>(); rowCountsPerByte = new int[32]; byteNum = 0; rowSkipCount = 0; votes = new double[32, 256]; publicAddressDouble = new double[20]; prob = 40; }
private void Init() { //Init classes scalingFunction = new ScalingFunction(); activationFunctions = new ActivationFunctions(); geneticAlgorithm = new GeneticAlgorithm(); neuralNetwork = new NeuralNetwork(); weightsGenerator = new WeightsGenerator(); //Init Lists keyStore = new List <BTCKeyStore>(); dataSet = new List <DataSet>(); valkeyStore = new List <BTCKeyStore>(); valdataSet = new List <DataSet>(); nnld = new List <NeuralNetworkLayerDesign>(); currentMaxBytes = 0; deathRate = 10; //If too high, then chance plays an increasing role and skews the result. }
private byte ExecuteNetwork(double[] exampleAddressDbl) { NeuralNetwork nn = new NeuralNetwork(); ScalingFunction sf = new ScalingFunction(); ActivationFunctions af = new ActivationFunctions(); double[][] networkWeights = new double[5][]; double[][] networkBias = new double[5][]; WeightsGenerator wg = new WeightsGenerator(); int[] networks1 = new int[] { 8, 6, 4, 2, 1 }; networkWeights[0] = wg.CreateWeights(3, networks1[0] * 32); networkWeights[1] = wg.CreateWeights(3, networks1[1] * 8); networkWeights[2] = wg.CreateWeights(3, networks1[2] * 6); networkWeights[3] = wg.CreateWeights(3, networks1[3] * 4); networkWeights[4] = wg.CreateWeights(3, networks1[4] * 2); networkBias[0] = Enumerable.Repeat(0.00, networks1[0] * 32).ToArray(); networkBias[1] = Enumerable.Repeat(0.00, networks1[1] * 8).ToArray(); networkBias[2] = Enumerable.Repeat(0.00, networks1[2] * 6).ToArray(); networkBias[3] = Enumerable.Repeat(0.00, networks1[3] * 4).ToArray(); networkBias[4] = Enumerable.Repeat(0.00, networks1[4] * 2).ToArray(); double[] layerOneOutput = nn.PerceptronLayer(networks1[0], exampleAddressDbl, networkWeights[0], exampleAddressDbl.Length, networkBias[0]); layerOneOutput = af.TanSigmoid(layerOneOutput); double[] layerTwoOutput = nn.PerceptronLayer(networks1[1], layerOneOutput, networkWeights[1], layerOneOutput.Length, networkBias[1]); layerTwoOutput = af.TanSigmoid(layerTwoOutput); double[] layerThreeOutput = nn.PerceptronLayer(networks1[2], layerTwoOutput, networkWeights[2], layerTwoOutput.Length, networkBias[2]); layerThreeOutput = af.TanSigmoid(layerThreeOutput); double[] layerFourOutput = nn.PerceptronLayer(networks1[3], layerThreeOutput, networkWeights[3], layerThreeOutput.Length, networkBias[3]); layerFourOutput = af.TanSigmoid(layerFourOutput); double[] layerOutput = nn.PerceptronLayer(networks1[4], layerFourOutput, networkWeights[4], layerFourOutput.Length, networkBias[4]); layerOutput = af.TanSigmoid(layerOutput); return((byte)(255.0 * layerOutput[0])); }
private void Init() { //Init classes scalingFunction = new ScalingFunction(); weightsGenerator = new WeightsGeneratorURNGFibonacci(); //inject a different weight generator //weightsGenerator = new WeightsGeneratorRNGCSP(); //weightsGenerator = new WeightsGeneratorPRNGSHA512(); activationFunctions = new ActivationFunctions(); geneticAlgorithm = new GeneticAlgorithm(weightsGenerator); neuralNetwork = new List <NeuralNetwork>(); perceptron = new Perceptron(); //Init Lists keyStore = new List <BTCKeyStore>(); dataSet = new List <DataSet>(); valkeyStore = new List <BTCKeyStore>(); valdataSet = new List <DataSet>(); neuralNetwork = new List <NeuralNetwork>(); currentMaxBytes = 0; deathRate = 100; //If too high, then chance plays an increasing role and skews the result. }
public static unsafe void LoadTexture2DFromWebP(byte[] webpBytes, Texture2D texture, bool lMipmaps, bool lLinear, byte[] bytePool, int numBytesRequired, ScalingFunction scalingFunction = null) { Debug.Assert(bytePool.Length >= numBytesRequired); Array.Clear(bytePool, 0, numBytesRequired); int width = texture.width; int height = texture.height; fixed(byte *lDataPtr = webpBytes) { fixed(byte *lRawDataPtr = bytePool) { int lStride = 4 * width; // As we have to reverse the y order of the data, we pass through a negative stride and // pass through a pointer to the last line of the data. byte *lTmpDataPtr = lRawDataPtr + (height - 1) * lStride; WebPDecoderConfig config = new WebPDecoderConfig(); if (NativeLibwebp.WebPInitDecoderConfig(&config) == 0) { throw new Exception("WebPInitDecoderConfig failed. Wrong version?"); } // Set up decode options config.options.use_threads = 1; if (scalingFunction != null) { config.options.use_scaling = 1; } config.options.scaled_width = width; config.options.scaled_height = height; // read the .webp input file information VP8StatusCode result = NativeLibwebp.WebPGetFeatures(lDataPtr, (UIntPtr)webpBytes.Length, &config.input); if (result != VP8StatusCode.VP8_STATUS_OK) { throw new Exception(string.Format("Failed WebPGetFeatures with error {0}.", result.ToString())); } // specify the output format config.output.colorspace = WEBP_CSP_MODE.MODE_RGBA; config.output.u.RGBA.rgba = lTmpDataPtr; config.output.u.RGBA.stride = -lStride; config.output.u.RGBA.size = (UIntPtr)(height * lStride); config.output.height = height; config.output.width = width; config.output.is_external_memory = 1; // Decode result = NativeLibwebp.WebPDecode(lDataPtr, (UIntPtr)webpBytes.Length, &config); if (result != VP8StatusCode.VP8_STATUS_OK) { throw new Exception(string.Format("Failed WebPDecode with error {0}.", result.ToString())); } texture.LoadRawTextureData((IntPtr)lRawDataPtr, numBytesRequired); texture.Apply(lMipmaps, true); } } }
/// <summary> /// /// </summary> /// <param name="lTexture2D"></param> /// <param name="lData"></param> /// <param name="lError"></param> public static unsafe void LoadWebP(this Texture2D lTexture2D, byte[] lData, out Error lError, ScalingFunction scalingFunction = null, bool makeNoLongerReadable = true) { lError = 0; bool lMipmaps = lTexture2D.mipmapCount != 1; int lWidth = 0, lHeight = 0; GetWebPDimensions(lData, out lWidth, out lHeight); byte[] lRawData = LoadRGBAFromWebP(lData, ref lWidth, ref lHeight, lMipmaps, out lError, scalingFunction); if (lError == Error.Success) { lTexture2D.LoadRawTextureData(lRawData); lTexture2D.Apply(lMipmaps, makeNoLongerReadable); } }
/// <summary> /// /// </summary> /// <param name="lData"></param> /// <param name="lError"></param> /// <returns></returns> public static unsafe Texture2D CreateTexture2DFromWebP(byte[] lData, bool lMipmaps, bool lLinear, out Error lError, ScalingFunction scalingFunction = null, bool makeNoLongerReadable = true) { Texture2D lTexture2D = null; int lWidth; int lHeight; GetWebPDimensions(lData, out lWidth, out lHeight); byte[] lRawData = LoadRGBAFromWebP(lData, ref lWidth, ref lHeight, lMipmaps, out lError, scalingFunction); if (lError == Error.Success) { lTexture2D = CreateWebpTexture2D(lWidth, lHeight, lMipmaps, lLinear); lTexture2D.LoadRawTextureData(lRawData); lTexture2D.Apply(lMipmaps, makeNoLongerReadable); } return(lTexture2D); }
/// <summary> /// Loads an image from webp into a byte array in RGBA format. /// </summary> /// <returns>The RGBA from web p.</returns> /// <param name="lData">L data.</param> /// <param name="lWidth">L width.</param> /// <param name="lHeight">L height.</param> /// <param name="lMipmaps">If set to <c>true</c> l mipmaps.</param> /// <param name="lError">L error.</param> /// <param name="scalingFunction">Scaling function.</param> public static unsafe byte[] LoadRGBAFromWebP(byte[] lData, ref int lWidth, ref int lHeight, bool lMipmaps, out Error lError, ScalingFunction scalingFunction = null) { lError = 0; byte[] lRawData = null; int lLength = lData.Length; fixed(byte *lDataPtr = lData) { // If we've been supplied a function to alter the width and height, use that now. scalingFunction?.Invoke(ref lWidth, ref lHeight); // If mipmaps are requested we need to create 1/3 more memory for the mipmaps to be generated in. int numBytesRequired = lWidth * lHeight * 4; if (lMipmaps) { numBytesRequired = Mathf.CeilToInt((numBytesRequired * 4.0f) / 3.0f); } lRawData = new byte[numBytesRequired]; fixed(byte *lRawDataPtr = lRawData) { int lStride = 4 * lWidth; // As we have to reverse the y order of the data, we pass through a negative stride and // pass through a pointer to the last line of the data. byte *lTmpDataPtr = lRawDataPtr + (lHeight - 1) * lStride; WebPDecoderConfig config = new WebPDecoderConfig(); if (NativeLibwebp.WebPInitDecoderConfig(&config) == 0) { throw new Exception("WebPInitDecoderConfig failed. Wrong version?"); } // Set up decode options config.options.use_threads = 1; if (scalingFunction != null) { config.options.use_scaling = 1; } config.options.scaled_width = lWidth; config.options.scaled_height = lHeight; // read the .webp input file information VP8StatusCode result = NativeLibwebp.WebPGetFeatures(lDataPtr, (UIntPtr)lLength, &config.input); if (result != VP8StatusCode.VP8_STATUS_OK) { throw new Exception(string.Format("Failed WebPGetFeatures with error {0}.", result.ToString())); } // specify the output format config.output.colorspace = WEBP_CSP_MODE.MODE_RGBA; config.output.u.RGBA.rgba = lTmpDataPtr; config.output.u.RGBA.stride = -lStride; config.output.u.RGBA.size = (UIntPtr)(lHeight * lStride); config.output.height = lHeight; config.output.width = lWidth; config.output.is_external_memory = 1; // Decode result = NativeLibwebp.WebPDecode(lDataPtr, (UIntPtr)lLength, &config); if (result != VP8StatusCode.VP8_STATUS_OK) { throw new Exception(string.Format("Failed WebPDecode with error {0}.", result.ToString())); } } lError = Error.Success; } return(lRawData); }
/// <summary> /// /// </summary> /// <param name="lTexture2D"></param> /// <param name="lData"></param> /// <param name="lError"></param> public static unsafe void LoadWebP(this Texture2D lTexture2D, byte[] lData, out Status lError, ScalingFunction scalingFunction = null) { lError = 0; bool lMipmaps = lTexture2D.mipmapCount != 1; int lWidth = 0, lHeight = 0; GetWebPDimensions(lData, out lWidth, out lHeight); byte[] lRawData = LoadRGBAFromWebP(lData, ref lWidth, ref lHeight, lMipmaps, out lError, scalingFunction); if (lError == Status.SUCCESS) { lTexture2D.LoadRawTextureData(lRawData); lTexture2D.Apply(lMipmaps, true); } }
/// <summary> /// /// </summary> /// <param name="lData"></param> /// <param name="lError"></param> /// <returns></returns> public static unsafe Texture2D CreateTexture2DFromWebP(byte[] lData, bool lMipmaps, bool lLinear, out Status lError, ScalingFunction scalingFunction = null) { lError = 0; Texture2D lTexture2D = null; int lWidth = 0, lHeight = 0; GetWebPDimensions(lData, out lWidth, out lHeight); byte[] lRawData = LoadRGBAFromWebP(lData, ref lWidth, ref lHeight, lMipmaps, out lError, scalingFunction); if (lError == Status.SUCCESS) { lTexture2D = new Texture2D(lWidth, lHeight, TextureFormat.RGBA32, lMipmaps, lLinear); lTexture2D.LoadRawTextureData(lRawData); lTexture2D.Apply(lMipmaps, true); } return(lTexture2D); }
public static unsafe Texture2D[] CreateTextures2DFromWebP(byte[] lData, bool lMipmaps, bool lLinear, out Error lError, ScalingFunction scalingFunction = null) { lError = 0; List <Texture2D> lTexture2Ds = new List <Texture2D>(); int lWidth = 0, lHeight = 0; GetWebPDimensions(lData, out lWidth, out lHeight); Debug.Log($"{lWidth} {lHeight}"); List <byte[]> lRawDatas = LoadRGBAsFromWebP(lData, ref lWidth, ref lHeight, lMipmaps, out lError, scalingFunction); //if (lError == Error.Success) //{ // Texture2D lTexture2D= new Texture2D(lWidth, lHeight, TextureFormat.RGBA32, lMipmaps, lLinear); // lTexture2D.LoadRawTextureData(lRawData); // lTexture2D.Apply(lMipmaps, true); // lTexture2Ds.Add(lTexture2D); //} return(lTexture2Ds.ToArray()); }
public static unsafe List <byte[]> LoadRGBAsFromWebP(byte[] lData, ref int lWidth, ref int lHeight, bool lMipmaps, out Error lError, ScalingFunction scalingFunction = null) { List <byte[]> bytes_list = new List <byte[]>(); lError = 0; byte[] lRawData = null; int lLength = lData.Length; WebPAnimDecoderOptions config = new WebPAnimDecoderOptions(); fixed(byte *p = lData) { IntPtr ptr = (IntPtr)p; var webpdata = new WebPData { bytes = ptr, size = new UIntPtr((uint)lLength) }; //NativeBindings.WebPDataInit(ref webpdata); } return(bytes_list); }
/// <summary> /// /// </summary> /// <param name="lTexture2D"></param> /// <param name="lData"></param> /// <param name="lError"></param> public static unsafe void LoadWebP(this Texture2D lTexture2D, byte[] lData, out Error lError, ScalingFunction scalingFunction = null) { lError = 0; bool lMipmaps = lTexture2D.mipmapCount != 1; int lWidth = 0, lHeight = 0; GetWebPDimensions(lData, out lWidth, out lHeight); byte[] lRawData = LoadRGBAFromWebP(lData, ref lWidth, ref lHeight, lMipmaps, out lError, scalingFunction); if (lError == Error.Success) { lTexture2D.LoadRawTextureData(lRawData); lTexture2D.Apply(lMipmaps, true); } }
/// <summary> /// Loads an image from webp into a byte array in RGBA format. /// </summary> /// <returns>The RGBA from web p.</returns> /// <param name="lData">L data.</param> /// <param name="lWidth">L width.</param> /// <param name="lHeight">L height.</param> /// <param name="lMipmaps">If set to <c>true</c> l mipmaps.</param> /// <param name="lError">L error.</param> /// <param name="scalingFunction">Scaling function.</param> public static unsafe byte[] LoadRGBAFromWebP(byte[] lData, ref int lWidth, ref int lHeight, bool lMipmaps, out Error lError, ScalingFunction scalingFunction = null) { lError = 0; byte[] lRawData = null; int lLength = lData.Length; fixed (byte* lDataPtr = lData) { // If we've been supplied a function to alter the width and height, use that now. if (scalingFunction != null) { scalingFunction(ref lWidth, ref lHeight); } // If mipmaps are requested we need to create 1/3 more memory for the mipmaps to be generated in. int numBytesRequired = lWidth * lHeight * 4; if (lMipmaps) { numBytesRequired = Mathf.CeilToInt((numBytesRequired * 4.0f) / 3.0f); } lRawData = new byte[numBytesRequired]; fixed (byte* lRawDataPtr = lRawData) { int lStride = 4 * lWidth; // As we have to reverse the y order of the data, we pass through a negative stride and // pass through a pointer to the last line of the data. byte* lTmpDataPtr = lRawDataPtr + (lHeight - 1) * lStride; WebPDecoderConfig config = new WebPDecoderConfig(); if (NativeBindings.WebPInitDecoderConfig(ref config) == 0) { throw new Exception("WebPInitDecoderConfig failed. Wrong version?"); } // Set up decode options config.options.use_threads = 1; if (scalingFunction != null) { config.options.use_scaling = 1; } config.options.scaled_width = lWidth; config.options.scaled_height = lHeight; // read the .webp input file information VP8StatusCode result = NativeBindings.WebPGetFeatures((IntPtr)lDataPtr, (UIntPtr)lLength, ref config.input); if (result != VP8StatusCode.VP8_STATUS_OK) { throw new Exception(string.Format("Failed WebPGetFeatures with error {0}.", result.ToString())); } // specify the output format config.output.colorspace = WEBP_CSP_MODE.MODE_RGBA; config.output.u.RGBA.rgba = (IntPtr)lTmpDataPtr; config.output.u.RGBA.stride = -lStride; config.output.u.RGBA.size = (UIntPtr)(lHeight * lStride); config.output.height = lHeight; config.output.width = lWidth; config.output.is_external_memory = 1; // Decode result = NativeBindings.WebPDecode((IntPtr)lDataPtr, (UIntPtr)lLength, ref config); if (result != VP8StatusCode.VP8_STATUS_OK) { throw new Exception(string.Format("Failed WebPDecode with error {0}.", result.ToString())); } } lError = Error.Success; } return lRawData; }