static void GenBufPutCriteria(GridSpace <GenStruct> .CellValue oldvalue, GenStruct newdata, Vector new_coord, Vector cell_center, double[] cell_sizes) { if (newdata.birth - oldvalue.data.birth > 200) { new_coord.DeepCopy(oldvalue.coord); oldvalue.data = newdata; return; } if (Vector.SqrLength(oldvalue.coord, cell_center) > Vector.SqrLength(new_coord, cell_center)) { new_coord.DeepCopy(oldvalue.coord); oldvalue.data = newdata; return; } }
public OnlineAnnTrainer(SimpleAnn ann, int imm_buf_size, int[] gen_cells, double[] l_gen_bound, double[] u_gen_bound, Action <Vector> input_method, Func <double> output_method) { this.ann = ann; // Immediate buffer initialization imm_buf_inputs = new CircularBufferAA <Vector>(imm_buf_size, true); imm_buf_vectors = new VectorArray(ann.input_count, imm_buf_size); imm_training_inputs = new CircularBufferAA <Vector>(imm_buf_size, true); imm_training_vectors = new VectorArray(ann.input_count, imm_buf_size); imm_buf_outputs = new CircularBufferAA <double>(imm_buf_size, true); imm_training_outputs = new CircularBufferAA <double>(imm_buf_size, true); // bind vectors in circular buffers to vector arrays for (int i = 0; i < imm_buf_size; i++) { imm_buf_inputs[i] = imm_buf_vectors[i]; imm_training_inputs[i] = imm_training_vectors[i]; } // Generalization space initialization gen_space = new GridSpace <GenStruct>(ann.input_count, gen_cells, l_gen_bound, u_gen_bound); linear_gen_buff = gen_space.Linearized; gen_space.put_method = GenBufPutCriteria; // Delegates assignment input_update_dlg = input_method; output_update_dlg = output_method; // Preallocate buffers for ann int supercell_size = gen_cells[0]; for (int i = 1; i < ann.input_count; i++) { supercell_size *= gen_cells[i]; } ann.preallocate(imm_buf_size + supercell_size); // Misc batch_size = imm_buf_size; coord_vector = new Vector(ann.input_count); }