Пример #1
0
void backprop(TYPE weights[NUM_LAYERS - 1][MAX_ROWS][MAX_COLS],
        TYPE inputs[NUM_TRAIN][SIZE_IN],
        TYPE targets[NUM_TRAIN][SIZE_OUT]){

    int ee, rows, cols, jj;
    TYPE error;
    error = 0.0;

    TYPE changeMat[NUM_LAYERS][MAX_ROWS][MAX_COLS];
    TYPE activations[NUM_LAYERS][MAX_ROWS];

    bp_1 : for(ee = 0; ee < NUM_LAYERS; ee++){
        bp_2 : for(rows = 0; rows < MAX_ROWS; rows++){
            activations[ee][rows]= 1.0;
            bp_3 : for(cols = 0; cols < MAX_COLS; cols++){
                changeMat[ee][rows][cols] = 0.0;
            }
        }
    }

    epochs_l : for(ee = 0; ee < EPOCS; ee++){
        error = 0.0;
        init_1 : for(jj = 0; jj < NUM_TRAIN; jj++){
            init_2 : for(cols = 0; cols < NUM_LAYERS; cols++){
                init_3 : for(rows = 0; rows < MAX_ROWS; rows++){
                    activations[cols][rows]= 1.0;
                }
            }

            //Run forward pass of the training data through the network
            //get activations input stimulated
            update(weights, inputs[jj], activations);

            //Adjust weights based on deltas between generated output and
            //known answer
            propagate_errors(weights, activations, targets[jj], changeMat);

            //Currently using synthetic I/O
            //error rate is irrelivant
            error += comp_error(targets[jj], activations[NUM_LAYERS - 1]);
        }
    }
}
Пример #2
0
// Call this when compiling process definition part of source code.
// Reads the process structure definition from cstate.scode.
// Depending on the compiler mode, may discard process structure (but always processes structure to test it and to declare classes)
// Updates cstate with e.g. new scode_pos.
// returns 1 on success, 0 on failure
int	parse_process_definition(void)
{

/*fpr("\n A sc_pos %i src_line %i", cstate.scode_pos, cstate.src_line);

int k;

for (k = 0; k < 100; k ++)
{
	fpr("\n scode_pos %i src_line %i", k, cstate.scode.src_line [k]);
}
*/

	fstate.target_templ = cstate.templ;

 init_procdef();
//fpr("\n template %i A(%i,%i) ", cstate.templ->template_index, procdef.buffer [15],procdef.buffer [16]);
 init_template_for_design(fstate.target_templ);
//fpr("B(%i,%i) ", procdef.buffer [15],procdef.buffer [16]);

 struct ctokenstruct ctoken;

// the first thing in the scode should be #process
//  (deal with naming processes later)
	if (!accept_next(&ctoken, CTOKEN_TYPE_PUNCTUATION, CTOKEN_SUBTYPE_HASH))
	{
//		fpr("\n # token type %i found", ctoken.type);
		return comp_error(CERR_FIXER_EXPECTED_PROCESS_HEADER, &ctoken);
	}

	if (!accept_next(&ctoken, CTOKEN_TYPE_IDENTIFIER_NON_C_KEYWORD, KEYWORD_C_PROCESS))
	{
//		fpr("\n pr token type %i found", ctoken.type);
		return comp_error(CERR_FIXER_EXPECTED_PROCESS_HEADER, &ctoken);
	}

// accept template name
//  (this should be on the same line as #process, but technically doesn't have to be)
 if (accept_next(&ctoken, CTOKEN_TYPE_PUNCTUATION, CTOKEN_SUBTYPE_QUOTES))
	{
  char template_name_string [TEMPLATE_NAME_LENGTH];
  template_name_string [0] = '\0';

	 int read_char;
	 int template_name_length = 0;

	 while(TRUE)
	 {
 		read_char = c_get_next_char_from_scode();
		 if (read_char == REACHED_END_OF_SCODE)
  		return comp_error_text("reached end of source inside string", NULL);
		 if (read_char == 0)
  		return comp_error_text("found null character inside string?", NULL);

   if (template_name_length >= TEMPLATE_NAME_LENGTH - 2)
  		return comp_error_text("template name too long", NULL);

 	 if (read_char == '"')
  	 break;
 	 template_name_string [template_name_length] = read_char;
   template_name_length++;
	 };

  template_name_string [template_name_length] = '\0';

  strcpy(procdef.template_name, template_name_string);

	}
//fpr("C(%i,%i) ", procdef.buffer [15],procdef.buffer [16]);

// accept classes
 while(accept_next(&ctoken, CTOKEN_TYPE_IDENTIFIER_NON_C_KEYWORD, KEYWORD_C_CLASS))
	{
		if (!read_next(&ctoken))
			return 0;
		while (TRUE)
		{
		 if (ctoken.type != CTOKEN_TYPE_IDENTIFIER_NEW)
 			return comp_error_text("expected new class name after class (word already in use?)", &ctoken);
 		if (!procdef_declare_new_class(&ctoken))
				return 0;
		 if (accept_next(&ctoken, CTOKEN_TYPE_PUNCTUATION, CTOKEN_SUBTYPE_SEMICOLON))
				break;
			if (!accept_next(&ctoken, CTOKEN_TYPE_PUNCTUATION, CTOKEN_SUBTYPE_COMMA))
				return comp_error_text("expected ; or , after class declaration", &ctoken);
		};
	};
//fpr("D(%i,%i) ", procdef.buffer [15],procdef.buffer [16]);

// expect open brace:
//	if (!accept_next(&ctoken, CTOKEN_TYPE_PUNCTUATION, CTOKEN_SUBTYPE_BRACE_OPEN))
//		return comp_error_text("expected open brace at start of process structure definition", &ctoken);

// now read in core shape:
//  (check for non-core shapes first because this is an obvious mistake to make)
	if (accept_next(&ctoken, CTOKEN_TYPE_IDENTIFIER_SHAPE, -1))
		return comp_error_text("the process core must be a core shape", &ctoken);
	if (!accept_next(&ctoken, CTOKEN_TYPE_IDENTIFIER_CORE_SHAPE, -1))
		return comp_error_text("expected a core shape", &ctoken);
//	fstate.target_templ->member[0].shape = identifier[ctoken.identifier_index].value;
 int core_shape = identifier[ctoken.identifier_index].value;
 write_to_procdef(core_shape);
#ifdef TEST_PROCDEF
 fpr("\nwrite core_shape %i (%i)", core_shape, procdef.buffer_length);
#endif
	if (!accept_next(&ctoken, CTOKEN_TYPE_PUNCTUATION, CTOKEN_SUBTYPE_COMMA))
		return comp_error_text("expected comma after core shape", &ctoken);
// Core angle offset
 if (!expect_angle(&ctoken))
		return comp_error_text("core angle not a constant number?", &ctoken);
 write_to_procdef(ctoken.number_value);
#ifdef TEST_PROCDEF
 fpr("\nwrite core_angle %i (%i)", ctoken.number_value, procdef.buffer_length);
#endif

	if (!accept_next(&ctoken, CTOKEN_TYPE_PUNCTUATION, CTOKEN_SUBTYPE_COMMA))
		return comp_error_text("expected comma after core angle", &ctoken);
// read objects:
 if (!procdef_read_member_objects_recursively(core_shape))
		return 0;

// expect close brace:
//  * actually read_member_objects_recursively should have read this.
	//if (!accept_next(&ctoken, CTOKEN_TYPE_PUNCTUATION, CTOKEN_SUBTYPE_BRACE_CLOSE))
		//return comp_error_text("expected open brace at start of process structure definition", &ctoken);

// Finish by checking for #code directive
	if (!accept_next(&ctoken, CTOKEN_TYPE_PUNCTUATION, CTOKEN_SUBTYPE_HASH))
		return comp_error(CERR_FIXER_EXPECTED_CODE_HEADER, &ctoken);
	if (!accept_next(&ctoken, CTOKEN_TYPE_IDENTIFIER_NON_C_KEYWORD, KEYWORD_C_CODE))
		return comp_error(CERR_FIXER_EXPECTED_CODE_HEADER, &ctoken);
//fpr("E(%i,%i) ", procdef.buffer [15],procdef.buffer [16]);

 return 1;

}