Question for connoisseurs - page 3

 
Chris_Brown писал(а) >>

And if there is a two-dimensional array, a 4-by-9 matrix and you assign a value of 0.1 to each element, would it be something like this?

As Talex correctly pointed out, you can (and should) initialize arrays using the ArrayInitialize function

 

Help!

I can't understand how the NS learning algorithm works (with a teacher).

I'll take my NS as an example (Please don't scold me too much, I'm kind of new at this).

Help me with drawing the NS learning algorithm


//Размеры матрицы
double W[4][9];//Матрица весов размером 4 на 8
//	W					
//	W31	-0,52	-0,01	-0,08	0,35	          Выходной слой
//	W21	1,52	1,35	1,12	-1,38	
//	W22	7,05	4,75	3,25	1,45	
//	W23	7,36	4,42	3,90	2,26	          Скрытый слой 2   
//	W24	6,79	5,54	3,74	2,81	
//	W11	-4,65	13,06	7,00	4,67	0,07
//	W12	-3,25	11,92	2,66	5,98	2,41      Скрытый слой 1
//	W13	-3,31	8,93	3,32	5,57	4,20
//	W14	4,33	4,86	9,84	8,96	1,52 

//Функции активации нейронов
double NormDate(double Date,int Type,int A) {
  double x;
  if ( Type==0){     
      x= Date;
      return(MathTan(MathExp( A* x)-MathExp(- A* x)/MathExp( A* x)+MathExp(- A* x)));//гиперболический тангенс
      }
  if ( Type==1){
      x= Date;
      return(1/(1+MathExp(- A* x)));// сигмоид
     }
 } 


//+------------------------------------------------------------------+
//| Многослойная нейронная сеть.                                     |
//| Параметры сети:                                                  |
//| Входные параметры подаются во входном массиве - X                |                                   
//| Веса задаются в весовой матрице - W                              |
//| Число скрытых слоёв = V                                          |
//|                                                                  |
//+------------------------------------------------------------------+
double neuronet1(double W[][],double X[], int V){
int N=ArraySize( X);
int i, j, I;
double sum=0.0;
double Out[99][99];
double summ=0.0;
//Расчёты скрытых слоёв NC
for ( I=0; I<= V-1; I++){
  for( i= I* N; i<=( N-1+ N* I); i++){
  for( j=0; j<= N-1; j++){
  if( I==0)
        summ+=( W[ j][ i]* X[ j]);else
        summ+=( W[ j][ i]* Out[ I-1][ j]);
}
Out[ I][ i- I* N]= NormDate( summ,0,1);
summ=0;
}
}
//Расчёт выходного слоя NC
for( j=0; j<= N-1; j++){
sum+= W[ j][8]* Out[ V-1][ j];
}

sum= NormDate( sum,0,1);

return( sum);
}

int init(){
//+------------------------------------------------------------------+
//|  Инциализирование весовой матрицы случайными числами             |
//+------------------------------------------------------------------+
MathSrand(TimeLocal());
double Dia=1;//диапазон случайных чисел
ArrayInitialize( W,(MathRand()/32767.0* Dia));
}
int start(){
//+------------------------------------------------------------------+
//| Создание массива с входными данными                              |
//+------------------------------------------------------------------+
double X[4];
 X[0]=1.2447;// На первых порах пусть будут сами котировки 
 X[1]=1.2458;
 X[2]=1.2364;
 X[3]=1.2377;
 
 double Out[1];
 Out[1]=0.8;//  например в процессе обучения должно получиться значение больше 0.8
 
 //Пример обращения к функции нейросети
 Comment( neuronet1( W, X,2));
   return(0);}
//+------------------------------------------------------------------+
 

Also about the hyperbolic tangent, does it count correctly ?


return((MathExp( A* x)-MathExp(- A* x))/(MathExp( A* x)+MathExp(- A* x)));
 
Is there any way to dynamically set the range of the array?
 
Chris_Brown >> :

And about the hyperbolic tangent, does it count correctly ?

tanh(x) = sinh(x)/cosh(x) = (e^x - e^-x)/(e^x + e^-x)


By the way, the function e^x doesn't seem to be fast.

So it's better this way:

double var = A* x;

double expVar = MathExp( var);
double revExpVar = 1/ expVar;

double tanh = ( expVar - revExpVar)/( expVar + revExpVar)

It should be faster.

Chris_Brown >> :
Is there any way to dynamically set the range of the array?

What is the range of values? It's from -1 to 1. If I've got it right:

double ScaledTanh = Scale*tanh - Shift;
 

What is the value range? Is it -1 to 1 . If I understand it correctly:

double ScaledTanh = Scale*tanh - Shift;

No. That's not what I mean.

The standard array declaration:

int Mas[50]; // Here the array is defined by the range from 0 to 49


I meant dynamically, i.e. change this range when making some calculations.

 
ArrayResize() - changes the size of the array.
 
Mathemat >> :
ArrayResize() - changes the size of the array.

Aha, here's an example:

double W[3][4];

ArrayResize(W,2)


The result will change 3 to 2. How do we change the second one from 4 to 6?

--------

I have another idea: (For example.)

#define Input 4 //Number of neurons in the input layer
#define Out 1 //Number of neurons in the output layer
double W[Input][Out+1];//Weight matrix

but here appears the error of adding 1 to Out

 

Good afternoon, everyone.

Not really on the subject. Please advise -

How do I translate the text in PDF format into Word?

(The file is large, - "Twilight", D. Glukhovsky 65 mb)

 
rid писал(а) >>

Good afternoon, everyone.

Not really on the subject. Please advise -

How do I translate the text in PDF format into Word?

(The file is large, - "Twilight", D. Glukhovsky 65 mb)

I usually recognize in FineReader and convert it to Word. Although there may be other options.

But the question is definitely off topic.

Reason: