Last active
December 19, 2015 09:09
-
-
Save bartolsthoorn/5930817 to your computer and use it in GitHub Desktop.
Hopfield networks; checks errors in current state vs patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static VALUE hopfield_calculate_state_errors(VALUE self, VALUE state, VALUE patterns) { | |
// Compare state to patterns and calculate errors for each pattern | |
int patterns_count = (int) RARRAY_LEN(patterns); | |
int pattern_length = (int) RARRAY_LEN(state); | |
VALUE errors = rb_ary_new2(patterns_count); | |
for(int p = 0; p < patterns_count; p++) { | |
int sum = 0; | |
for(int c = 0; c < pattern_length; c++) { | |
int state_value = FIX2INT(rb_ary_entry(state, c)); | |
int pattern_value = FIX2INT(rb_ary_entry(rb_ary_entry(patterns, p), c)); | |
if (pattern_value != state_value) | |
sum++; | |
} | |
rb_ary_push(errors, INT2FIX(sum)); | |
} | |
return errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment