public OnlineLinTrainer(int imm_buf_size, double[] gen_triggers, int[] gen_buf_sizes,
                         Action <Vector> input_method, Func <double> output_method, params LinApproxTask[] tasks)
 {
     foreach (var t in tasks)
     {
         this.tasks.Add(t);
     }
     input_count          = tasks[0].linmodel.input_count;
     linearity_check_task = tasks[0];
     // Immediate and gradient buffer initialization
     imm_buf_inputs        = new CircularBufferAA <Vector>(imm_buf_size, true);
     imm_buf_vectors       = new VectorArray(input_count, imm_buf_size);
     imm_training_inputs   = new CircularBufferAA <Vector>(imm_buf_size, true);
     imm_training_vectors  = new VectorArray(input_count, imm_buf_size);
     grad_training         = new CircularBufferAA <GenStruct>(imm_buf_size / 2, true);
     grad_training_vectors = new VectorArray(input_count, imm_buf_size / 2);
     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];
         if (i < imm_buf_size / 2)
         {
             grad_training[i] = new GenStruct(0.0, 0, grad_training_vectors[i]);
         }
     }
     // Generalization space initialization
     this.gen_triggers = gen_triggers;
     gen_space_size    = 0;
     gen_buffers       = new CircularBufferAA <GenStruct> [input_count];
     for (int i = 0; i < input_count; i++)
     {
         gen_buffers[i]  = new CircularBufferAA <GenStruct>(gen_buf_sizes[i], true);
         gen_space_size += gen_buf_sizes[i];
         VectorArray gen_array = new VectorArray(input_count, gen_buf_sizes[i]);
         for (int j = 0; j < gen_buf_sizes[i]; j++)
         {
             gen_buffers[i][j] = new GenStruct(0.0, 0, gen_array[j]);
         }
     }
     // Delegates assignment
     input_update_dlg  = input_method;
     output_update_dlg = output_method;
     // Preallocate buffers for matrix operations in linear approximator
     foreach (var t in tasks)
     {
         t.linmodel.preallocate((int)(imm_buf_size * 1.5) + gen_buf_sizes.Sum());
     }
     // Misc
     inputs_changed  = new bool[input_count];
     nothing_changed = new bool[input_count];
     reassigned      = new bool[input_count];
 }
        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);
        }
Exemplo n.º 3
0
 public Vector(VectorArray binding, int index)
 {
     source     = binding;
     this.index = index;
 }
Exemplo n.º 4
0
 public Vector(int size)
 {
     source = new VectorArray(size, 1);
     index  = 0;
 }