static bool _sml_ann_bridge_calculate_confidence_interval(struct sml_ann_bridge *iann, struct sml_variables_list *inputs, unsigned int observations) { unsigned int i, j, inputs_len; float mean, sd, value; struct sml_variable *var; Confidence_Interval *ci; char var_name[SML_VARIABLE_NAME_MAX_LEN + 1]; sml_debug("Calculating confidence interval"); inputs_len = sml_ann_variables_list_get_length(inputs); for (i = 0; i < inputs_len; i++) { mean = sd = 0.0; var = sml_ann_variables_list_index(inputs, i); ci = sol_vector_append(&iann->confidence_intervals); if (!ci) { sml_critical("Could not alloc the Confidence_Interval"); goto err_exit; } for (j = 0; j < observations; j++) { value = sml_ann_variable_get_value_by_index(var, j); if (isnan(value)) sml_ann_variable_get_range(var, &value, NULL); mean += value; } mean /= observations; //Now the standard deviation for (j = 0; j < observations; j++) { value = sml_ann_variable_get_value_by_index(var, j); if (isnan(value)) sml_ann_variable_get_range(var, &value, NULL); sd += pow(value - mean, 2.0); } sd /= observations; sd = sqrt(sd); //Confidence interval of 95% ci->lower_limit = mean - (1.96 * (sd / sqrt(observations))); ci->upper_limit = mean + (1.96 * (sd / sqrt(observations))); iann->ci_length_sum += (ci->upper_limit - ci->lower_limit); if (sml_ann_variable_get_name(var, var_name, sizeof(var_name))) { sml_warning("Failed to get variable name for %p", var); continue; } sml_debug("Variable:%s mean:%f sd:%f lower:%f upper:%f", var_name, mean, sd, ci->lower_limit, ci->upper_limit); } return true; err_exit: sol_vector_clear(&iann->confidence_intervals); return false; }
static void _debug_variables(struct sml_variables_list *list) { float val; struct sml_variable *var; struct sml_fuzzy_term *term; char var_name[SML_VARIABLE_NAME_MAX_LEN + 1]; char term_name[SML_TERM_NAME_MAX_LEN + 1]; uint16_t i, len, j, len_j; len = sml_fuzzy_variables_list_get_length(list); for (i = 0; i < len; i++) { var = sml_fuzzy_variables_list_index(list, i); val = sml_fuzzy_variable_get_value(var); if (sml_fuzzy_variable_get_name(var, var_name, sizeof(var_name))) sml_warning("Failed to get name of variable %p", var); else sml_debug("\t\t%s: %g", var_name, val); len_j = sml_fuzzy_variable_terms_count(var); for (j = 0; j < len_j; j++) { term = sml_fuzzy_variable_get_term(var, j); if (sml_fuzzy_term_get_name(term, term_name, sizeof(term_name))) { sml_warning("Failed to get name of term %p", term); continue; } sml_debug("\t\t\t%s: %g", term_name, ((fl::Term *)term)->membership(val)); } } }
/* for debug */ void sml_heap_dump() { unsigned int i; struct subheap *subheap; struct alloc_ptr *ptr; struct segment *seg; for (i = BLOCKSIZE_MIN_LOG2; i <= BLOCKSIZE_MAX_LOG2; i++) { subheap = &global_subheaps[i]; ptr = &ALLOC_PTR_SET()->alloc_ptr[i]; if (BITPTR_EQUAL(ptr->freebit, dummy_bitptr)) { sml_debug("ptr[%u] (%u): dummy bitptr\n", i, ptr->blocksize_bytes); } else { seg = ALLOC_PTR_TO_SEGMENT(ptr); sml_debug("ptr[%u] (%u): free=%p, bit %u\n", i, ptr->blocksize_bytes, ptr->free, BITPTR_INDEX(ptr->freebit, BITMAP0_BASE(seg))); } sml_debug(" segments:\n"); dump_segment_list(subheap->seglist, *subheap->unreserved); } sml_debug("freelist:\n"); dump_segment_list(heap_space.freelist, NULL); }
void sml_measure_debug(struct sml_measure *measure, sml_matrix_convert_cb convert) { sml_debug("\tInputs:"); sml_matrix_debug(&measure->inputs, convert); sml_debug("\tOutputs:"); sml_matrix_debug(&measure->outputs, convert); }
/* for debug */ static void obj_dump__(int indent, void *obj) { unsigned int i; unsigned int *bitmap; void **field = obj; char *buf; if (obj == NULL) { sml_debug("%*sNULL\n", indent, ""); return; } switch (OBJ_TYPE(obj)) { case OBJTYPE_UNBOXED_ARRAY: case OBJTYPE_UNBOXED_VECTOR: sml_debug("%*s%p:%u:%s\n", indent, "", obj, OBJ_SIZE(obj), (OBJ_TYPE(obj) == OBJTYPE_UNBOXED_ARRAY) ? "UNBOXED_ARRAY" : "UNBOXED_VECTOR"); for (i = 0; i < OBJ_SIZE(obj) / sizeof(unsigned int); i++) sml_debug("%*s0x%08x\n", indent + 2, "", ((unsigned int *)field)[i]); for (i = i * sizeof(unsigned int); i < OBJ_SIZE(obj); i++) sml_debug("%*s0x%02x\n", indent + 2, "", ((unsigned char*)field)[i]); break; case OBJTYPE_BOXED_ARRAY: case OBJTYPE_BOXED_VECTOR: sml_debug("%*s%p:%u:%s\n", indent, "", obj, OBJ_SIZE(obj), (OBJ_TYPE(obj) == OBJTYPE_BOXED_ARRAY) ? "BOXED_ARRAY" : "BOXED_VECTOR"); for (i = 0; i < OBJ_SIZE(obj) / sizeof(void*); i++) obj_dump__(indent + 2, field[i]); for (i = i * sizeof(void*); i < OBJ_SIZE(obj); i++) sml_debug("%*s0x%02x\n", indent + 2, "", ((char*)field)[i]); break; case OBJTYPE_RECORD: sml_debug("%*s%p:%u:RECORD\n", indent, "", obj, OBJ_SIZE(obj)); bitmap = OBJ_BITMAP(obj); for (i = 0; i < OBJ_SIZE(obj) / sizeof(void*); i++) { if (BITMAP_BIT(bitmap, i) != TAG_UNBOXED) obj_dump__(indent + 2, field[i]); else sml_debug("%*s%p\n", indent + 2, "", field[i]); } break; default: sml_debug("%*s%p:%u:unknown type %u", indent, "", obj, OBJ_SIZE(obj), OBJ_TYPE(obj)); break; } }
void sml_fuzzy_debug(struct sml_fuzzy *fuzzy) { sml_debug("Fuzzy Bridge:"); sml_debug("\tInputs(%d) {", sml_fuzzy_variables_list_get_length(fuzzy->input_list)); _debug_variables(fuzzy->input_list); sml_debug("\t}"); sml_debug("\tOutputs(%d) {", sml_fuzzy_variables_list_get_length(fuzzy->output_list)); _debug_variables(fuzzy->output_list); sml_debug("\t}"); }
void sml_matrix_debug(struct sml_matrix *m, sml_matrix_convert_cb convert) { struct sml_string *str = sml_string_new("\t"); uint16_t i, len_i, j, len_j; struct sol_vector *vec; char buf[BUF_LEN]; sml_string_append(str, "{"); len_i = m->data.len; for (i = 0; i < len_i; i++) { vec = sol_vector_get(&m->data, i); if (i > 0) sml_string_append(str, ", "); sml_string_append(str, "{"); len_j = vec ? vec->len : 0; for (j = 0; j < len_j; j++) { if (j > 0) sml_string_append(str, ", "); convert(buf, BUF_LEN, sml_matrix_get(m, i, j)); sml_string_append_printf(str, "%s", buf); } sml_string_append(str, "}"); } sml_string_append(str, "}"); sml_debug("%s", sml_string_get_string(str)); sml_string_free(str); }
void sml_fuzzy_variable_set_enabled(struct sml_variable *variable, bool enabled) { fl::Variable *fl_var = (fl::Variable*) variable; fl_var->setEnabled(enabled); sml_debug("Variable %s %s", fl_var->getName().c_str(), enabled ? "enabled" : "disabled"); }
/* for debug */ static void dump_segment_list(struct segment *seg, struct segment *cur) { size_t filled, count; while (seg) { count = segment_filled(seg, 0, &filled); sml_debug(" segment %p:%s\n", seg, seg == cur ? " UNRESERVED" : ""); sml_debug(" blocksize = %u, " "%lu blocks, %lu blocks used, %lu bytes filled\n", BLOCK_SIZE(seg), (unsigned long)seg->layout->num_blocks, (unsigned long)count, (unsigned long)filled); seg = seg->next; } }
static void bitmap_dump(struct bitmap_info_space *b_info) { unsigned int *tmp = (unsigned int *)b_info->base; sml_debug("bitmap dump start %p %u\n",b_info,b_info->block_size_log); while((char *)tmp < (char *)b_info->tree[0]) { sml_debug("%x",*tmp); tmp++; } sml_debug("tree dump\n"); while((char *)tmp < (char *)b_info->end) { sml_debug("%x",*tmp); tmp++; } sml_debug("bitmap dump end\n"); return; }
/* for debug */ void sml_heap_dump() { char *cur; unsigned int size, allocsize; sml_debug("from space : %p - %p\n", HEAP_START(sml_heap_from_space), sml_heap_from_space.limit); cur = HEAP_START(sml_heap_from_space); while (cur < sml_heap_from_space.free) { size = OBJ_TOTAL_SIZE(cur); allocsize = HEAP_ROUND_SIZE(size); sml_debug("%p : type=%08x, size=%u, total=%u, alloc=%u\n", cur, OBJ_TYPE(cur), OBJ_SIZE(cur), size, allocsize); cur += allocsize; } }
static fl::SNorm * _get_snorm(enum sml_fuzzy_snorm norm) { fl::SNorm *fl_norm; switch (norm) { case SML_FUZZY_SNORM_ALGEBRAIC_SUM: sml_debug("SNorm is algebraic sum"); fl_norm = new (std::nothrow) fl::AlgebraicSum(); break; case SML_FUZZY_SNORM_BOUNDED_SUM: sml_debug("SNorm is bounded sum"); fl_norm = new (std::nothrow) fl::BoundedSum(); break; case SML_FUZZY_SNORM_DRASTIC_SUM: sml_debug("SNorm is drastic sum"); fl_norm = new (std::nothrow) fl::DrasticSum(); break; case SML_FUZZY_SNORM_EINSTEIN_SUM: sml_debug("SNorm is einstein sum"); fl_norm = new (std::nothrow) fl::EinsteinSum(); break; case SML_FUZZY_SNORM_HAMACHER_SUM: sml_debug("SNorm is hamacher sum"); fl_norm = new (std::nothrow) fl::HamacherSum(); break; case SML_FUZZY_SNORM_MAXIMUM: sml_debug("SNorm is maximum"); fl_norm = new (std::nothrow) fl::Maximum(); break; case SML_FUZZY_SNORM_NILPOTENT_MAXIMUM: sml_debug("SNorm is nilpotent maximum"); fl_norm = new (std::nothrow) fl::NilpotentMaximum(); break; case SML_FUZZY_SNORM_NORMALIZED_SUM: sml_debug("SNorm is normalized sum"); fl_norm = new (std::nothrow) fl::NormalizedSum(); break; default: sml_critical("Unknown SNorm %d", norm); return NULL; } if (!fl_norm) sml_critical("Could not alloc the snorm"); return fl_norm; }
/* remove all the rules from the first rule block and remove all the other ruleblocks, since all the rules we'll be added on the first one */ static void _remove_rule_blocks(fl::Engine *engine) { uint16_t rule_blocks_size, rules_size, i; fl::RuleBlock *rule_block; sml_debug("Removing rules"); rule_blocks_size = engine->numberOfRuleBlocks(); if (rule_blocks_size == 0) return; rule_block = engine->getRuleBlock(0); rules_size = rule_block->numberOfRules(); for (i = 0; i < rules_size; i++) delete rule_block->removeRule(0); for (i = 1; i < rule_blocks_size; i++) delete engine->removeRuleBlock(1); }
static fl::TNorm * _get_tnorm(enum sml_fuzzy_tnorm norm) { fl::TNorm *fl_norm; switch (norm) { case SML_FUZZY_TNORM_ALGEBRAIC_PRODUCT: sml_debug("Conjunction set to algebraic product"); fl_norm = new (std::nothrow) fl::AlgebraicProduct(); break; case SML_FUZZY_TNORM_BOUNDED_DIFFERENCE: sml_debug("Conjunction set to bounded difference"); fl_norm = new (std::nothrow) fl::BoundedDifference(); break; case SML_FUZZY_TNORM_DRASTIC_PRODUCT: sml_debug("Conjunction set to drastic product"); fl_norm = new (std::nothrow) fl::DrasticProduct(); break; case SML_FUZZY_TNORM_EINSTEIN_PRODUCT: sml_debug("Conjunction set to einstein product"); fl_norm = new (std::nothrow) fl::EinsteinProduct(); break; case SML_FUZZY_TNORM_HAMACHER_PRODUCT: sml_debug("Conjunction set to hamacher product"); fl_norm = new (std::nothrow) fl::HamacherProduct(); break; case SML_FUZZY_TNORM_MINIMUM: sml_debug("Conjunction set to minimum"); fl_norm = new (std::nothrow) fl::Minimum(); break; case SML_FUZZY_TNORM_NILPOTENT_MINIMUM: sml_debug("Conjunction set to nilpotent minimum"); fl_norm = new (std::nothrow) fl::NilpotentMinimum(); break; default: sml_critical("Unknown TNorm %d", norm); return NULL; } if (!fl_norm) sml_critical("Could not alloc the tnorm"); return fl_norm; }