ANN_Policy::~ANN_Policy() { delete [] ps; delete [] delta_vector; if (separate_actions) { for (int i=0; i<n_actions; i++) { DeleteANN(Ja[i]); } delete [] Ja; } else { //ANN_ShowWeights(J); DeleteANN (J); } }
/// Call this function after you have added all the layers. /// It adds an extra output layer. int ANN_Init(ANN * ann) { // Add output layer LISTITEM *item = LastListItem(ann->c); Layer *l = NULL; #ifdef ANN_DBUG message("Initialising"); #endif if (item) { Layer *p = (Layer *) item->obj; l = ANN_AddLayer(ann, p->n_outputs, ann->n_outputs, p->y); } else { l = ANN_AddLayer(ann, ann->n_inputs, ann->n_outputs, ann->x); } if (l == NULL) { Serror("Could not create final layer\n"); DeleteANN(ann); return -1; } ann->y = l->y; l->f = &linear; l->f_d = &linear_d; // ann->t = l->t; return 0; }
//========================================================== // NewANN //---------------------------------------------------------- /// Create a new ANN ANN *NewANN(int n_inputs, int n_outputs) { ANN *ann = NULL; if (!(ann = AllocM(ANN, 1))) { Serror("Could not allocate ANN\n"); return NULL; } ann->x = NULL; ann->y = NULL; ann->t = NULL; ann->d = NULL; ann->error = NULL; ann->c = NULL; ann->a = 0.1f; ann->lambda = 0.9f; ann->zeta = 0.9f; ann->n_inputs = n_inputs; ann->n_outputs = n_outputs; ann->batch_mode = false; /* outputs are not allocated */ //logmsg ("Creating ANN with %d inputs and %d outputs\n", n_inputs, n_outputs); if (!(ann->error = AllocM(real, n_outputs))) { Serror("Could not allocate errors\n"); DeleteANN(ann); return NULL; } if (!(ann->d = AllocM(real, n_outputs))) { Serror("Could not allocate derivatives\n"); DeleteANN(ann); return NULL; } if (!(ann->c = List())) { Serror("Could not allocate list\n"); DeleteANN(ann); return NULL; } #ifdef ANN_DBUG message("Creating ANN with %d inputs and %d outputs", n_inputs, n_outputs); #endif return ann; }