株式会社MITECH
Machine
Imagination Technologies
エム・アイ・テク

 

Useful Sample Codes Using Spice-SOM and Spice-MLP Neural Networks

 

Example of using Spice-MLP Neural Networks

  ============
// MLP_Data_Modeling.cpp : Defines the entry point for the console application.

#include "mlpsom_include/spice_mlp_lib.h"
using namespace std;
using namespace SpiceNeuro;

void InitMlpDataSet(MlpTrainingSet *DataSets, int nTrainingDataSet, int nInputs, int nOutputs);
void FreeDataSet(MlpTrainingSet *DataSets);
int findMaxIndex(double *data, const int nData);

More ...

 

Activated functions in Spice-MLP Neural Network

  ============
AF_Linear,    //  1. y = a*x
AF_Identity,  //  2. y = x
AF_Sigmoid,   //  3. y = (1.0 / (1.0 + exp(-x)))
AF_HyperTanh, //  4. y = (3.432 / (1 + exp(-0.667 * x)) - 1.716)
AF_Tanh,      //  5. y = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
AF_ArcTan,    //  6. y = atan(x)
AF_ArcCotan,  //  7. y = pi/2 - atan(x)
AF_ArcSinh,   //  8. y = log(x + sqr(x * x + 1))
AF_InvertAbs, //  9. y = x/(1+abs(x))
AF_Scah,      // 10. y = scah Hyperbolic Secant, ex. scah(x)
AF_Sin,       // 11. y = sin(x)
AF_Cos,       // 12. y = cos(x)
AF_ExpMinusX, // 13. y = exp (-x)
AF_ExpX,      // 14. y = exp (x)
AF_Cubic,             // 15. y = x*x*x
AF_Quadratic,         // 16. y = x*x

AF_SinXoverX,         // 17. y = sin(x)/x
AF_AtanXoverX,        // 18. y = atan(x)/x
AF_XoverEpx,          // 19. y = x/exp(x) == x *exp(-1.0 * x)
AF_Gaussian,          // 20. y = exp(-x*x)
AF_SinGaussian,       // 21. y = 3*sin(x)*exp(-x*x)
AF_CosGaussian,       // 22. y = cos(x)*exp(-x*x)
AF_LinearGaussian,    // 23. y = 2.5*x*exp(-x*x)
AF_QuadraticGaussian, // 24. y = x*x*exp(-x*x)
AF_CubicGaussian,     // 25. y = 3*x*x*x*exp(-x*x)
AF_XsinX,             // 26. y = x*sin(x)
AF_XcosX,             // 27. y = x*cos(x)
   

 

Example of using Spice-SOM to organize face data
Here is output video

  // Spice_SOM_For_Face_Data.cpp

using namespace std;
using namespace cv;
using namespace SpiceNeuro;

Size bsize = Size(32,45); // 40,54 size for face

// create an image of a neuron weight
// chanel = 1 or 3
Mat neuronImage(float *weight, int chanel)
{
...
}

// weight_image = 1: create an image in that each neuron is average of its weights
// weight_image = 0: create an image in that each neuron is average of samples on it
Mat som_map_image(SpiceS *som, int weight_image, int chanel)
{
    // start the som
    const int nxNodes = som->GetCols();
    const int nyNodes = som->GetRows();
 ...
    return som_img;
}

More ...
 

Example of using Spice-SOM to organize iris data

  #include "include/spice_som_lib.h"
using namespace SpiceNeuro;

int main()
{
    const int nxNodes = 10;
    const int nyNodes = 10;
    const int iDataLength = 4;
    const int nDataSets   = 150;

    SpiceS *som = new SpiceS(nxNodes, nyNodes, iDataLength, nDataSets);
    som->LoadTrainingData("iris_for_som_150_data_4_inputs.txt.dat");

    som->ResetRandomWeight();
    som->Training(NF_Linear, 10);

    som->BuildingWinnerTable();
    som->SaveWinnerTable2CsvFile("iris_map_after_training.csv");
    som->saveWeight("iris_weight.dat");

    ...
}

More ...

 

 

Copyright©2016 Machine Imagination Technologies. All rights reserved.