カタベログ

IT技術に関するブログを書きたい.食べ物関連はInstagramをご参照の事.

テスト

綺麗に表示されるかのテスト.
個人的には端を折り返してくれるだけで充分ですが.
将来的には,もっとEmacsとかで編集した時のように色付けできるといいよね.
ちなみに,このコードは人工ニューロンクラスです.

#include <ctime>
#include <boost/random.hpp>
#include <boost/numeric/ublas/vector.hpp>

typedef boost::numeric::ublas::vector<double> dvect;

class neuron{
private:
	int coord;
	dvect weight;
	double net;
	double sigma;

public:
	neuron(int, int);
	void setWeight(dvect);
	void setWeight(double, int);
	void setNet(double);	
	void setSigma(double);
	int getCoord();
	double getNet();
	double getSigma();
	double getWeight(int);
	dvect getWeight();
};

neuron::neuron(int order, int coord){
	boost::mt19937 gen(static_cast<unsigned long>(std::time(0)));
	boost::uniform_real<> dst(0, 1);
	boost::variate_generator<boost::mt19937, boost::uniform_real<>> rand(gen, dst);

	this->coord = coord;
	this->net = 0.0;
	weight.resize(order);
	for(int i = 0; i < order; ++i){
		weight(i) = rand();
	}
}
void neuron::setWeight(dvect new_weight){
	weight = new_weight;
}
void neuron::setWeight(double new_weight, int index){
	weight(index) = new_weight;
}
void neuron::setNet(double new_net){
	net = new_net;
}
void neuron::setSigma(double new_sigma){
	sigma = new_sigma;
}
int neuron::getCoord(){
	return coord;
}
double neuron::getNet(){
	return net;
}
double neuron::getSigma(){
	return sigma;
}
dvect neuron::getWeight(){
	return weight;
}
double neuron::getWeight(int num){
	return weight(num);
}

Amebaよりも良いかもしれん.