static float testNetwork(NeuralNetwork& neuralNetwork, const Image& image, float noiseMagnitude, size_t iterations, size_t batchSize, std::default_random_engine& engine) { float accuracy = 0.0f; iterations = std::max(iterations, 1UL); lucius::util::log("TestVisualization") << "Testing the accuracy of the trained network.\n"; for(size_t i = 0; i != iterations; ++i) { lucius::util::log("TestVisualization") << " Iteration " << i << " out of " << iterations << "\n"; ImageVector batch = generateBatch(image, noiseMagnitude, batchSize, engine); Matrix input = batch.convertToStandardizedMatrix( neuralNetwork.getInputCount(), neuralNetwork.getInputBlockingFactor(), image.colorComponents()); Matrix reference = generateReference(batch); lucius::util::log("TestVisualization") << " Input: " << input.toString(); lucius::util::log("TestVisualization") << " Reference: " << reference.toString(); accuracy += neuralNetwork.computeAccuracy(input, reference); } return accuracy * 100.0f / iterations; }
xmlNode * create_request_adv(const char *task, xmlNode *msg_data, const char *host_to, const char *sys_to, const char *sys_from, const char *uuid_from, const char *origin) { char *true_from = NULL; xmlNode *request = NULL; char *reference = generateReference(task, sys_from); if (uuid_from != NULL) { true_from = generate_hash_key(sys_from, uuid_from); } else if(sys_from != NULL) { true_from = crm_strdup(sys_from); } else { crm_err("No sys from specified"); } /* host_from will get set for us if necessary by CRMd when routed */ request = create_xml_node(NULL, __FUNCTION__); crm_xml_add(request, F_CRM_ORIGIN, origin); crm_xml_add(request, F_TYPE, T_CRM); crm_xml_add(request, F_CRM_VERSION, CRM_FEATURE_SET); crm_xml_add(request, F_CRM_MSG_TYPE, XML_ATTR_REQUEST); crm_xml_add(request, XML_ATTR_REFERENCE, reference); crm_xml_add(request, F_CRM_TASK, task); crm_xml_add(request, F_CRM_SYS_TO, sys_to); crm_xml_add(request, F_CRM_SYS_FROM, true_from); /* HOSTTO will be ignored if it is to the DC anyway. */ if(host_to != NULL && strlen(host_to) > 0) { crm_xml_add(request, F_CRM_HOST_TO, host_to); } if (msg_data != NULL) { add_message_xml(request, F_CRM_DATA, msg_data); } crm_free(reference); crm_free(true_from); return request; }
ScriptEngine::ScriptEngine() : m_engine(asCreateScriptEngine()) { if (!m_engine) return; // Set the message callback to receive information on errors in human readable form. int r = m_engine->SetMessageCallback(asFUNCTION(MessageCallback), &m_errorString, asCALL_CDECL); assert(r >= 0); RegisterStdString(m_engine); // RegisterStdStringUtils(engine); // The scripts can directly print text r = m_engine->RegisterGlobalFunction("void print(const string &in message)", asMETHOD(ScriptEngine, print), asCALL_THISCALL_ASGLOBAL, this); assert(r >= 0); RegisterScriptMath(m_engine); aatc::RegisterAllContainers(m_engine); registerObject(m_engine); registerAllTypes(m_engine); generateReference(); }
static void trainNetwork(NeuralNetwork& neuralNetwork, const Image& image, float noiseMagnitude, size_t iterations, size_t batchSize, std::default_random_engine& engine) { lucius::util::log("TestVisualization") << "Training the network.\n"; for(size_t i = 0; i != iterations; ++i) { lucius::util::log("TestVisualization") << " Iteration " << i << " out of " << iterations << "\n"; ImageVector batch = generateBatch(image, noiseMagnitude, batchSize, engine); Matrix input = batch.convertToStandardizedMatrix( neuralNetwork.getInputCount(), neuralNetwork.getInputBlockingFactor(), image.colorComponents()); Matrix reference = generateReference(batch); lucius::util::log("TestVisualization") << " Input: " << input.toString(); lucius::util::log("TestVisualization") << " Reference: " << reference.toString(); neuralNetwork.train(input, reference); } }