Exemplo n.º 1
0
 /// <summary>
 /// Deep copy constructor
 /// </summary>
 public SimpleAnn(SimpleAnn original)
 {
     hidden_count = original.hidden_count;
     input_count  = original.input_count;
     fow          = original.fow;
     fb           = original.fb;
     parameters   = new double[hidden_count * (input_count + 2) + 1];
     n1           = new double[hidden_count];
     a1           = new double[hidden_count];
     // copy values of arrays
     original.parameters.CopyTo(parameters, 0);
     //original.n1.CopyTo(n1, 0);
     //original.a1.CopyTo(a1, 0);
 }
        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);
        }