Miscellaneous
0
Views
0
Downloads
0
Favorites
#PNN_ARTIFICAL_N2
//+------------------------------------------------------------------+
//| #PNN_ARIFICAL.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property library
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
void Normalize(double & Examples[][], double & Test[])
{
int Size = ArrayRange(Examples,0);
int MAX_INPUT = ArrayRange(Examples,1);
double XMax[]; ArrayResize(XMax, MAX_INPUT);
double XMin[]; ArrayResize(XMin, MAX_INPUT);
double YMin=-1;
double YMax=1;
// Èùåì Ìàêñèìóì è ìèíèìóì Examples
for(int input = 0; input < MAX_INPUT; input++)
{
for(int example = 0; example<Size; example++)
{
if(Examples[example][input]>XMax[input]) XMax[input]=Examples[example][input];
if(Examples[example][input]<XMin[input]) XMin[input]=Examples[example][input];
}
if(Test[input]>XMax[input]) XMax[input]=Test[input];
if(Test[input]<XMin[input]) XMin[input]=Test[input];
}
double coeff;
//Íîðìàëèçóåì
for(input = 0; input < MAX_INPUT; input++)
{
double range=XMax[input]-XMin[input];
for(example = 0; example<Size; example++)
{
if( range==0 ) { Examples[example][input] = 0;}
else
Examples[example][input] = 2*(Examples[example][input]-XMin[input])/range-1;
}
if( range==0 ) { Test[input] = 0;}
else
Test[input] = 2*(Test[input]-XMin[input])/range-1;
}
}
// double range=(rmax-rmin);
// aa[i]=2*(aa[i]-rmin)/range-1;
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//Âûçûâàåòñÿ îòäåëüíî äëÿ êàæäîãî êëàññà
// Ðàññ÷èòûâàåì âûõîä äëÿ êëàññà
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
double PNN(double sigma,double test_example[], double Examples[][])
{
int Nk=ArrayRange(Examples,0);
int d=ArrayRange(Examples,1);
double sum;
sum = 0;
// The SUMMATION layer which accumulates the pdf
// for each example from the particular class k
Normalize(Examples, test_example);
for ( int i=0; i<Nk; i++ )
{
double product = 0;
// The PATTERN layer that multiplies the test example by the weights
for ( int j=0; j<d; j++ )
product += MathPow(test_example[j] - Examples[i][j],2.0);
product = product/MathPow( sigma ,2.0);
product = MathExp( -product );
sum += product;
}
sum /=Nk;
return (sum);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//Äîáàâèòü ïðèìåð â êëàññ
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
int ADD_EXAMPLE(double test_example[],double & Examples[][])
{
int Nk=ArrayRange(Examples,0);
int d=ArrayRange(Examples,1);
ArrayResize(Examples,Nk+1);
for(int i=0;i<d;i++)
Examples[Nk][i] = test_example[i];
return (Nk+1);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//Ñ÷èòûâàåì äàííûå èç ôàéëà
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
int PNN_Read_Class(string fname,double & Class_Example[][],int Nk)
{
int d=ArrayRange(Class_Example,1);
int numDataRead=0;
int handle=FileOpen(fname+".net",FILE_CSV|FILE_READ);
if(handle>0)
{
numDataRead = FileReadArray(handle, Class_Example, 0, Nk*d);
FileClose(handle);
if(numDataRead != Nk*d) return (false);
return (true);
}
return (false);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//Ñîõðàíÿåì äàííûå â ôàéë
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
int PNN_Write_Class(string fname,double Class_Example[][])
{
int Nk=ArrayRange(Class_Example,0);
int d=ArrayRange(Class_Example,1);
int handle=FileOpen(fname+".net", FILE_CSV |FILE_WRITE);
if(handle>0)
{
//FileWriteArray(handle, Class_Example, 0, Nk*d); // çàïèñü ïîñëåäíèõ 7 ýëåìåíòîâ
string str = "";
for(int i=0; i < Nk; i++)
{
for(int j=0; j < d; j++)
{
str =str + Class_Example[i][j]+";";
}
FileWrite(handle,str);
str="";
}
FileClose(handle);
return (true);
}
return (false);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---