本文整理汇总了C++中FileObject::ref方法的典型用法代码示例。如果您正苦于以下问题:C++ FileObject::ref方法的具体用法?C++ FileObject::ref怎么用?C++ FileObject::ref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileObject
的用法示例。
在下文中一共展示了FileObject::ref方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestANN_SingleClassificationPSO
bool TestANN_SingleClassificationPSO(){
// File Object to save data
FileObject file;
// define random number generator instance
RandomNumberGenerator rng;
// define number of data values
const int N = 100;
// set training data
std::vector<double> x(N*N), y(N*N), z(N*N);
for(int i = 0; i < N; i++){
for( int j = 0; j < N; j++ ){
int k = i+N*j;
x[k] = i/static_cast<double>(N);
y[k] = j/static_cast<double>(N);
z[k] = binaryField(x[k],y[k]);
}
}
// set the layers
std::vector<int> layers { 2, 3, 3, 1 };
// create classifier
NeuralNet classifier( layers );
classifier.setActivationFunc(1, NeuralPrototypes::prototypes.getFunction(NeuralPrototypes::Poly) );
classifier.setActivationFunc(layers.size()-1, NeuralPrototypes::prototypes.getFunction(NeuralPrototypes::Sigmoid) );
la::Mat<double> guess(classifier.numWeights(),1,0);
la::Mat<double> lb(classifier.numWeights(),1,0), ub(classifier.numWeights(),1,0);
// Try to classify given inputs
for( int i = 0; i < classifier.numWeights(); i++ ){
lb[i] = -3; ub[i] = 3;
}
PSO gd;
gd.setMaxIter(100);
gd.setdims(lb, ub);
gd.setLocalStep(0.1);
gd.setGlobalStep(0.01);
gd.setNumParticles(5);
gd.func.net = &classifier;
gd.func.x = &x;
gd.func.y = &y;
gd.func.z = &z;
gd.func.init();
gd.showStatus();
gd.solve();
la::Mat<double> in(2,1,0), out(2,1,0);
gd.soln().print();
for( int i = 0; i < classifier.numWeights(); i++ ){
classifier.weightAt(i) = gd.soln()[i];
}
// save truth data
file.openFile("/Users/christianjhoward/truth.csv", FileObject::Write);
if( file.isOpen() ){
for( int i = 0; i < x.size(); i++ ){
fprintf(file.ref(), "%0.6lf, %0.6lf, %0.6lf\n",x[i],y[i],z[i]);
}
}
// save results
file.openFile("/Users/christianjhoward/approx.csv", FileObject::Write);
if( file.isOpen() ){
for( int i = 0; i < x.size(); i++ ){
in[0] = x[i];
in[1] = y[i];
classifier(in,out);
fprintf(file.ref(), "%0.6lf, %0.6lf, %0.6lf\n",x[i],y[i],out[0]);
}
}
return true;
}