简体   繁体   中英

Deep q-learning program exited with code -1073741819

I'm writing a Deep q-learning algorithm in c. I got as far as to write two functions, one that initializes the prediction network, and the other that initializes the target network by copying the weights and biases of the prediction network. I tried testing the function by printing out the weights of the initialized function, and this was the console:

hello
memory successfully allocated
(process 12600) exited with code -1073741819.
Press any key to close this window . . .

The code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define RAND_MAX 1

typedef struct neuron_t {
 float activation;
 float* outputWeights;
 float bias;
 float z;
 
}Neuron;

typedef struct layer_t {
 int numberOfNeurons;
 Neuron* neu;
}Layer;

int main() {
 
 Layer* test = NULL;
 int neus[] = { 3, 8, 8, 8, 4 };
 createPredictionArchitecture(test, 5, neus);

 for (int i = 0; i < 5; i++) {
     for (int j = 0; i < test[i].numberOfNeurons; i++) {
         for (int k = 0; k < test[i].neu[j].outputWeights[k]; i++) {
             printf("\n%fl", test[i].neu[j].outputWeights[k]);
         }
     }
 }
 return 0;
}

int createPredictionArchitecture(Layer* lay, int numberOfLayers, int* neuronsInEachLayer) {
 printf("hello\n");
 lay = (Layer*)malloc(numberOfLayers * sizeof(Layer));
 
 if (lay == NULL) {
     printf("Failed to allocate memory in line 41\n");
     exit(0);
 }
 else
 {
     printf("memory successfully allocated");
 }
 for (int i = 0; i < numberOfLayers; i++) {

     lay[i].numberOfNeurons = neuronsInEachLayer[i]; 

     for (int j = 0; j < lay[i].numberOfNeurons; i++) {
         lay[i].neu[j].bias = 0.01; // initializes the biases
         if ((i + 1) < (sizeof(neuronsInEachLayer)-1)) {

             for (int k = 0; k < lay[i+1].numberOfNeurons; k++) {
                 double a = rand() / (double)((RAND_MAX)) * 2 - 1;
                 double b = sqrt((2 / (lay[i].numberOfNeurons)));
                 lay[i].neu[j].outputWeights[k] = a * b; // initializes the weights
             }
         }
     }
 }
 free(neuronsInEachLayer);
 free(&numberOfLayers);
 return 0;
}

int createTargetArchitecture(Layer* predictionNetwork, Layer* targetNetwork) {

 targetNetwork = (Layer*)malloc(sizeof(predictionNetwork));

 *targetNetwork = *predictionNetwork;

 return 0;
}


It would be great if someone could help me solve this problem. Thanks

The exit code -1073741819 in hex is 0xC0000005. If you look up this code in Microsoft's documentation ( NTSTATUS Values ) you will see that it indicates that your program was terminated due to an access violation. This error can occur for a variety of reasons, including de-referencing a NULL pointer or referencing an invalid address.

You should step through your code in the debugger line by line to determine where the access violation happens. That should enable you to analyze the situation and identify the cause.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM