⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilities.cpp

📁 amygdata的神经网络算法源代码
💻 CPP
字号:
/***************************************************************************                          utilities.cpp  -  description                             -------------------    begin                : Wed May 22 2002    copyright            : (C) 2002 by Rdiger Koch    email                : rkoch@rkoch.org ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/using namespace std;#include "utilities.h"#include <cmath>#include <stdlib.h>#include <sstream>#include <string>#include <stdexcept>#include <sys/types.h>#include <sys/stat.h>float Utilities::GaussRand(float mean, float sigma){    // Based on code from the GNU Scientific Library    // and _Numerical Recipes in C_	float randVal, xuniRand, yuniRand;    float x, y, r2;  	do {      	// choose x,y in uniform square (-1,-1) to (+1,+1)		xuniRand = float(rand()) / float(RAND_MAX);		yuniRand = float(rand()) / float(RAND_MAX);		x = -1 + 2 * xuniRand;      	y = -1 + 2 * yuniRand;      	// see if it is in the unit circle       	r2 = x * x + y * y;    } while (r2 > 1.0 || r2 == 0);  	// Box-Muller transform  	randVal = sigma * y * sqrt(-2.0 * log(r2) / r2);	return (randVal + mean);}float Utilities::RandPercent(){    return ( float(rand()) / float(RAND_MAX) ) * 100.0;}string Utilities::itostr(int val){    ostringstream o;    if (o << val)        return o.str();    else        throw runtime_error("cannot convert integer to string");    return "";}string Utilities::ftostr(float val){    ostringstream o;    if (o << val)        return o.str();    else        throw runtime_error("cannot convert float to string");    return "";}void Utilities::RoundTime(AmTimeInt& time, const AmTimeInt& stepSize){    double tmpTime;    double roundTime;    tmpTime = (double)time / stepSize;    tmpTime = modf(tmpTime, &roundTime);    if (tmpTime > 0.5) {        time = ((AmTimeInt)roundTime * stepSize) + stepSize;    }    else {        time = (AmTimeInt)roundTime * stepSize;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -