-
Notifications
You must be signed in to change notification settings - Fork 1
/
HarrixMathLibrary.h
3774 lines (3637 loc) · 165 KB
/
HarrixMathLibrary.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef HARRIXMATHLIBRARY_H
#define HARRIXMATHLIBRARY_H
#include <stdlib.h>
#include <time.h>
#include <math.h>
// КОНСТАНТЫ
const double HML_TAU=0.61803398874989484820;
const double HML_E=2.71828182845904523536;
const double HML_LOG2E=1.44269504088896340736;
const double HML_LOG10E=0.434294481903251827651;
const double HML_LN2=0.693147180559945309417;
const double HML_LN10=2.30258509299404568402;
const double HML_PI=3.14159265358979323846;
const double HML_PI_2=1.57079632679489661923;
const double HML_PI_4=0.785398163397448309616;
const double HML_1_PI=0.318309886183790671538;
const double HML_2_PI=0.636619772367581343076;
const double HML_1_SQRTPI=0.564189583547756286948;
const double HML_2_SQRTPI=1.12837916709551257390;
const double HML_SQRT2=1.41421356237309504880;
const double HML_SQRT_2=0.707106781186547524401;
const double HML_INFINITY=1.7E308;//Машинная бесконечность
const double HML_MINFINITY=-1.7E308;//Минус машинная бесконечность
const double HML_MEANINGOFLIFE=42;//Смысл жизни
const double HML_G=9.80665;//Ускорение свободного падения
const double HML_GM=9.8156;//Ускорение свободного падения в Москве
//ДЛЯ ГЕНЕРАТОРОВ СЛУЧАЙНЫХ ЧИСЕЛ
enum TypeOfRandomNumberGenerator { StandardRandomNumberGenerator, MersenneTwisterRandomNumberGenerator };//тип генератора случайных чисел: стандартный или MersenneTwister:
void HML_SeedRandom(void);//Инициализатор генератора случайных чисел
double HML_RandomNumber(void);//Генерирует вещественное случайное число из интервала (0;1)
void HML_SetRandomNumberGenerator(TypeOfRandomNumberGenerator T);//Переназначить генератор случайных чисел на другой
//ПЕРЕМЕННЫЕ ПЕРЕЧИСЛЯЕМОГО ТИПА
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ОБЪЯВЛЕНИЯ ФУНКЦИЙ
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Вектора (Одномерные массивы)
template <class T> void HML_AcceptanceLimits(T *VHML_ResultVector, T *Left, T *Right, int VHML_N);
template <class T> void HML_AcceptanceLimits(T *VHML_ResultVector, T Left, T Right, int VHML_N);
template <class T> void HML_AcceptanceLimitsLeft(T *VHML_ResultVector, T *Left, int VHML_N);
template <class T> void HML_AcceptanceLimitsLeft(T *VHML_ResultVector, T Left, int VHML_N);
template <class T> void HML_AcceptanceLimitsRight(T *VHML_ResultVector, T *Right, int VHML_N);
template <class T> void HML_AcceptanceLimitsRight(T *VHML_ResultVector, T Right, int VHML_N);
template <class T> void HML_ChangeOrderInVector(T *VHML_Vector, T *VHML_ResultVector, int *Order, int VHML_N);
template <class T> void HML_ChangeOrderInVector(T *VHML_Vector, int *Order, int VHML_N);
template <class T> int HML_CheckElementInVector(T *x, int VHML_N, T a);
template <class T> int HML_CompareMeanOfVectors(T *a, T *b, int VHML_N);
template <class T> int HML_CompareMeanOfVectors(T *a, T *b, int VHML_N1, int VHML_N2);
void HML_DependentNoiseInVector(double *VHML_ResultVector, double percent, int VHML_N);
template <class T> bool HML_EqualityOfVectors(T *a, T *b, int VHML_N);
double HML_EuclidNorma(double *a,int VHML_N);
template <class T> void HML_FibonacciNumbersVector(T *VHML_ResultVector, int VHML_N);
template <class T> void HML_FillVector(T *VHML_ResultVector, int VHML_N, T x);
template <class T> T HML_MaximumOfVector(T *VHML_Vector, int VHML_N);
template <class T> T HML_MinimumOfVector(T *VHML_Vector, int VHML_N);
template <class T> void HML_MixingVector(T *VHML_ResultVector, double P, int VHML_N);
template <class T, class T2> void HML_MixingVectorWithConjugateVector(T *VHML_ResultVector, T2 *VHML_ResultVector2, double P, int VHML_N);
void HML_NoiseInVector(double *VHML_ResultVector, double percent, int VHML_N);
template <class T> int HML_NumberOfDifferentValuesInVector(T *a, int VHML_N);
template <class T> int HML_NumberOfMaximumOfVector(T *a, int VHML_N);
template <class T> int HML_NumberOfMinimumOfVector(T *a, int VHML_N);
template <class T> int HML_NumberOfNegativeValues(T *a, int VHML_N);
template <class T> int HML_NumberOfPositiveValues(T *a, int VHML_N);
template <class T> int HML_NumberOfZeroValues(T *a, int VHML_N);
template <class T> void HML_OrdinalVector(T *VHML_ResultVector, int VHML_N);
template <class T> void HML_OrdinalVectorZero(T *VHML_ResultVector, int VHML_N);
template <class T> T HML_ProductOfElementsOfVector(T *VHML_Vector,int VHML_N);
template <class T> void HML_ReverseVector(T *VHML_ResultVector, int VHML_N);
template <class T> int HML_SearchElementInVector (T *X, T x, int VHML_N);
template <class T> int HML_SearchFirstNotZero(T *x, int VHML_N);
template <class T> int HML_SearchFirstZero(T *x, int VHML_N);
int HML_SeparateVectorLimitOnProductElements(int *VHML_Vector, int *Order, int Limit, int VHML_N);
int HML_SeparateVectorLimitOnProductElementsTwo(int *VHML_Vector, int *Order, int Limit, int VHML_N);
template <class T> void HML_ShiftLeftVector(T *VHML_Vector, int VHML_N);
template <class T> void HML_ShiftRightVector(T *VHML_Vector, int VHML_N);
template <class T> T HML_SumSquareVector(T *VHML_Vector,int VHML_N);
template <class T> T HML_SumVector(T *VHML_Vector,int VHML_N);
template <class T> void HML_VectorMinusVector(T *a, T *b, T *VHML_ResultVector, int VHML_N);
template <class T> void HML_VectorMinusVector(T *VHML_ResultVector, T *b, int VHML_N);
template <class T> void HML_VectorMultiplyNumber(T *VHML_ResultVector, int VHML_N, T Number);
template <class T> void HML_VectorPlusVector(T *a, T *b, T *VHML_ResultVector, int VHML_N);
template <class T> void HML_VectorPlusVector(T *VHML_ResultVector, T *b, int VHML_N);
template <class T> void HML_VectorToVector(T *VHML_Vector, T *VHML_ResultVector, int VHML_N);
template <class T> void HML_ZeroVector(T *VHML_ResultVector,int VHML_N);
//Генетические алгоритмы
void HML_ArithmeticalCrossoverForReal(double *Parent1, double *Parent2, double *VHML_ResultVector, double w, int VHML_N);
void HML_BLXCrossoverForReal(double *Parent1, double *Parent2, double *VHML_ResultVector, double alpha, int VHML_N);
double HML_BinaryFitnessFunction(int*x, int VHML_N);
void HML_ExtendedLineForReal(double *Parent1, double *Parent2, double *VHML_ResultVector, double w, int VHML_N);
void HML_FlatCrossoverForReal(double *Parent1, double *Parent2, double *VHML_ResultVector, int VHML_N);
void HML_GeometricalCrossoverForReal(double *Parent1, double *Parent2, double *VHML_ResultVector, double w, int VHML_N);
void HML_LinearCrossoverForReal(double *Parent1, double *Parent2, double *VHML_ResultVector, int VHML_N);
void HML_MakeVectorOfProbabilityForProportionalSelectionV2(double *Fitness, double *VHML_ResultVector, int VHML_N);
void HML_MakeVectorOfProbabilityForRanklSelection(double *Rank, double *VHML_ResultVector, int VHML_N);
void HML_MakeVectorOfRankForRankSelection(double *Fitness, double *VHML_ResultVector, int VHML_N);
void HML_MakeVectorOfRankZeroForRankSelection(double *Fitness, double *VHML_ResultVector, int VHML_N);
template <class T> void HML_MutationBinaryMatrix(T **VHML_ResultMatrix, double ProbabilityOfMutation, int VHML_N,int VHML_M);
template <class T> void HML_MutationBinaryVector(T *VHML_ResultVector, double ProbabilityOfMutation, int VHML_N);
void HML_NormalizationVectorAll(double *x,int VHML_N);
void HML_NormalizationVectorMaxMin(double *VHML_ResultVector,int VHML_N);
void HML_NormalizationVectorOne(double *VHML_ResultVector,int VHML_N);
double HML_ProbabilityOfTournamentSelection(double *Fitness, double *VHML_ResultVector_Probability, int T, int VHML_N);
int HML_ProportionalSelection(double *Fitness, int VHML_N);
int HML_ProportionalSelectionV2(double *VectorOfProbability, int VHML_N);
int HML_ProportionalSelectionV3(double *Fitness, int VHML_N);
int HML_RankSelection(double *VectorOfProbability, int VHML_N);
int HML_SelectItemOnProbability(double *P, int VHML_N);
template <class T> void HML_SinglepointCrossover(T *Parent1, T *Parent2, T *VHML_ResultVector, int VHML_N);
void HML_SinglepointCrossoverForReal(double *Parent1, double *Parent2, double *VHML_ResultVector, int VHML_N);
template <class T> void HML_SinglepointCrossoverWithCopying(T *Parent1, T *Parent2, T *VHML_ResultVector, int VHML_N);
int HML_StandartBinaryGeneticAlgorithm(int *Parameters, double (*FitnessFunction)(int*,int), int *VHML_ResultVector, double *VHML_Result);
int HML_StandartGeneticAlgorithm(int *Parameters, int *NumberOfParts, double *Left, double *Right, double (*FitnessFunction)(double*,int), double *VHML_ResultVector, double *VHML_Result);
int HML_StandartGeneticAlgorithm(int *Parameters, double (*FitnessFunction)(int*,int), int *VHML_ResultVector, double *VHML_Result);
int HML_StandartRealGeneticAlgorithm(int *Parameters, int *NumberOfParts, double *Left, double *Right, double (*FitnessFunction)(double*,int), double *VHML_ResultVector, double *VHML_Result);
int HML_TournamentSelection(double *Fitness, int SizeTournament, int VHML_N);
int HML_TournamentSelection(double *Fitness, int SizeTournament, int *Taken, int VHML_N);
int HML_TournamentSelectionWithReturn(double *Fitness, int SizeTournament, int VHML_N);
template <class T> void HML_TwopointCrossover(T *Parent1, T *Parent2, T *VHML_ResultVector, int VHML_N);
void HML_TwopointCrossoverForReal(double *Parent1, double *Parent2, double *VHML_ResultVector, int VHML_N);
template <class T> void HML_TwopointCrossoverWithCopying(T *Parent1, T *Parent2, T *VHML_ResultVector, int VHML_N);
template <class T> void HML_UniformCrossover(T *Parent1, T *Parent2, T *VHML_ResultVector, int VHML_N);
void HML_UniformCrossoverForReal(double*Parent1, double *Parent2, double *VHML_ResultVector, int VHML_N);
//Геометрия
template <class T> int HML_BoolCrossingTwoSegment(T b1,T c1,T b2,T c2);
double HML_LineGeneralForm(double x, double A, double B, double C, int *solutionis);
double HML_LineGeneralForm(double x, double A, double B, double C);
double HML_LineSlopeInterceptForm(double x, double k, double b);
double HML_LineTwoPoint(double x, double x1, double y1, double x2, double y2, int *solutionis);
double HML_LineTwoPoint(double x, double x1, double y1, double x2, double y2);
double HML_Parabola(double x, double a, double b, double c);
//Гиперболические функции
double HML_Cosech(double x);
double HML_Cosh(double x);
double HML_Cotanh(double x);
double HML_Sech(double x);
double HML_Sinh(double x);
double HML_Tanh(double x);
//Дифференцирование
double HML_CenterDerivative(double x, double h, double (*Function)(double));
double HML_LeftDerivative(double x, double h, double (*Function)(double));
double HML_RightDerivative(double x, double h, double (*Function)(double));
//Интегрирование
double HML_IntegralOfRectangle(double a, double b, double Epsilon,double (*Function)(double));
double HML_IntegralOfSimpson(double a, double b, double Epsilon,double (*Function)(double));
double HML_IntegralOfTrapezium(double a, double b, double Epsilon,double (*Function)(double));
//Кодирование и декодирование
void HML_BinaryGrayVectorToRealVector(int *x, int n, double *VHML_ResultVector, double *Left, double *Right, int *Lengthi, int VHML_N);
void HML_BinaryGrayVectorToRealVector(int *x, double *VHML_ResultVector,int *TempBinaryVector, double *Left, double *Right, int *Lengthi, int VHML_N);
template <class T> T HML_BinaryToDecimal(T *a, int VHML_N);
template <class T> T HML_BinaryToDecimalFromPart(T *a, int Begin, int n);
void HML_BinaryVectorToRealVector(int *x, double *VHML_ResultVector, double *Left, double *Right, int *Lengthi, int VHML_N);
template <class T> void HML_GrayCodeToBinary(T *a,int *VHML_ResultVector, int VHML_N);
template <class T> void HML_GrayCodeToBinaryFromPart(T *a, T *VHML_ResultVector, int Begin, int n);
//Комбинаторика
template <class T> T HML_KCombinations(T k, T n);
//Математические функции
template <class T> T HML_Abs(T x);
template <class T> T HML_AcceptanceLimitsNumber(T Number, T Left, T Right);
template <class T> T HML_AcceptanceLimitsNumberLeft(T Number, T Left);
template <class T> T HML_AcceptanceLimitsNumberRight(T Number, T Right);
template <class T> bool HML_AlmostEqual(T x, T y);
template <class T> bool HML_AlmostEqual(T x, T y, double epsilon);
template <class T> bool HML_AlmostZero(T x);
template <class T> bool HML_AlmostZero(T x, double epsilon);
double HML_AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything();
double HML_ArithmeticalProgression(double a1,double d,int n);
double HML_ExpMSxD2(double x);
template <class T> T HML_Factorial(T x);
template <class T> T HML_FibonacciNumber(T n);
double HML_GeometricSeries(double u1,double q,int n);
int HML_GreatestCommonDivisorEuclid(int A,int B);
template <class T> T HML_HeavisideFunction(T x);
int HML_HowManyPowersOfTwo(int x);
double HML_InverseNormalizationNumberAll(double x);
int HML_LeastCommonMultipleEuclid(int A,int B);
template <class T> T HML_LogFactorial(T x);
template <class T> T HML_Max(T a, T b);
template <class T> T HML_Max(T a, T b, T c);
template <class T> T HML_Max(T a, T b, T c, T d);
template <class T> T HML_Max(T a, T b, T c, T d, T e);
template <class T> T HML_Max(T a, T b, T c, T d, T e, T f);
template <class T> T HML_Max(T a, T b, T c, T d, T e, T f, T g);
template <class T> T HML_Max(T a, T b, T c, T d, T e, T f, T g, T h);
template <class T> T HML_Max(T a, T b, T c, T d, T e, T f, T g, T h, T i);
template <class T> T HML_Max(T a, T b, T c, T d, T e, T f, T g, T h, T i, T j);
double HML_MeaningOfLife();
template <class T> T HML_Min(T a, T b);
template <class T> T HML_Min(T a, T b, T c);
template <class T> T HML_Min(T a, T b, T c, T d);
template <class T> T HML_Min(T a, T b, T c, T d, T e);
template <class T> T HML_Min(T a, T b, T c, T d, T e, T f);
template <class T> T HML_Min(T a, T b, T c, T d, T e, T f, T g);
template <class T> T HML_Min(T a, T b, T c, T d, T e, T f, T g, T h);
template <class T> T HML_Min(T a, T b, T c, T d, T e, T f, T g, T h, T i);
template <class T> T HML_Min(T a, T b, T c, T d, T e, T f, T g, T h, T i, T j);
void HML_MixedMultiLogicVectorOfFullSearch(int *VHML_Vector, int I, int *HowMuchInElements, int VHML_N);
double HML_NormalizationNumberAll(double x);
template <class T> void HML_NumberInterchange(T *a, T *b);
template <class T> void HML_NumberInterchange(T &a, T &b);
int HML_Parity(int a);
template <class T> T HML_PowerOf(T x, int n);
double HML_ProbabilityDensityFunctionOfInverseGaussianDistribution (double x, double mu, double lambda);
template <class T> int HML_Sign(T a);
template <class T> int HML_SignNull(T a);
double HML_SumGeometricSeries(double u1,double q,int n);
double HML_SumOfArithmeticalProgression(double a1,double d,int n);
int HML_SumOfDigits(int a);
template <class T> void HML_Swap(T &a, T &b);
//Матрицы
template <class T> bool HML_CheckForIdenticalColsInMatrix(T **VHML_ResultMatrix, int VHML_N, int VHML_M);
template <class T> bool HML_CheckForIdenticalRowsInMatrix(T **VHML_ResultMatrix, int VHML_N, int VHML_M);
template <class T> void HML_ColInMatrixMultiplyNumber(T **VHML_ResultMatrix, int k, int VHML_N, T Number);
template <class T> void HML_ColInterchange(T **VHML_ResultMatrix, int VHML_N, int k, int l);
template <class T> void HML_ColToMatrix(T **VHML_ResultMatrix, T *b, int VHML_N, int k);
template <class T> void HML_DeleteColInMatrix(T **VHML_ResultMatrix, int k, int VHML_N, int VHML_M);
template <class T> void HML_DeleteRowInMatrix(T **VHML_ResultMatrix, int k, int VHML_N, int VHML_M);
template <class T> bool HML_EqualityOfMatrixes (T **a, T **b,int VHML_N,int VHML_M);
template <class T> void HML_FillMatrix(T **VHML_ResultMatrix, int VHML_N, int VHML_M, T x);
template <class T> void HML_IdentityMatrix(T **VHML_ResultMatrix,int VHML_N);
template <class T> void HML_MatrixMinusMatrix(T **a, T **b, T **VHML_ResultMatrix, int VHML_N, int VHML_M);
template <class T> void HML_MatrixMinusMatrix(T **VHML_ResultMatrix, T **b, int VHML_N, int VHML_M);
template <class T> void HML_MatrixMultiplyMatrix(T **a, T **b, T **VHML_ResultMatrix, int VHML_N, int VHML_M, int VHML_S);
template <class T> void HML_MatrixMultiplyMatrixT(T **a, T **b, T **VHML_ResultMatrix, int VHML_N, int VHML_M, int VHML_S);
template <class T> void HML_MatrixMultiplyNumber(T **VHML_ResultMatrix, int VHML_N, int VHML_M, T Number);
template <class T> void HML_MatrixPlusMatrix(T **a, T **b, T **VHML_ResultMatrix, int VHML_N, int VHML_M);
template <class T> void HML_MatrixPlusMatrix(T **VHML_ResultMatrix, T **b, int VHML_N, int VHML_M);
template <class T> void HML_MatrixT(T **a, T **VHML_ResultMatrix, int VHML_N, int VHML_M);
template <class T> void HML_MatrixTMultiplyMatrix(T **a, T **b, T **VHML_ResultMatrix, int VHML_N, int VHML_M, int VHML_S);
template <class T> void HML_MatrixToCol(T **a, T *VHML_ResultVector, int VHML_N, int k);
template <class T> void HML_MatrixToMatrix(T **a, T **VHML_ResultMatrix, int VHML_N, int VHML_M);
template <class T> void HML_MatrixToRow(T **a, T *VHML_ResultVector, int k, int VHML_M);
template <class T> T HML_MaximumOfMatrix(T **a, int VHML_N, int VHML_M);
template <class T> T HML_MinimumOfMatrix(T **a, int VHML_N, int VHML_M);
template <class T> void HML_MixingRowsInOrder(T **VHML_ResultMatrix, int *b, int VHML_N, int VHML_M);
template <class T> int HML_NumberOfDifferentValuesInMatrix(T **a, int VHML_N, int VHML_M);
template <class T> void HML_RowInMatrixMultiplyNumber(T **VHML_ResultMatrix, int k, int VHML_M, T Number);
template <class T> void HML_MatrixToRow(T **a, T *VHML_ResultVector, int k, int VHML_M);
template <class T> void HML_RowToMatrix(T **VHML_ResultMatrix, T *b, int k, int VHML_M);
template <class T> T HML_SumMatrix(T **a,int VHML_N,int VHML_M);
template <class T> void HML_ZeroMatrix(T **VHML_ResultMatrix,int VHML_N,int VHML_M);
//Метрика
template <class T> T HML_Chebychev(T *x, T *y, int VHML_N);
template <class T> T HML_CityBlock(T *x, T *y, int VHML_N);
template <class T> T HML_Euclid(T *x, T *y, int VHML_N);
template <class T> T HML_Minkovski(T *x, T *y, int r, int VHML_N);
//Модели
int HML_PendulumOfMaxwell(double *Data);
//Непараметрика
double HML_BellShapedKernelExp(double z);
double HML_BellShapedKernelParabola(double z);
double HML_BellShapedKernelRectangle(double z);
double HML_BellShapedKernelTriangle(double z);
double HML_DerivativeOfBellShapedKernelExp(double z);
double HML_DerivativeOfBellShapedKernelParabola(double z);
double HML_DerivativeOfBellShapedKernelRectangle(double z);
double HML_DerivativeOfBellShapedKernelTriangle(double z);
void HML_MakingVectorForNonparametricEstimatorOfDerivative3(double *VHML_ResultVector, double *X, double *Y, int VHML_N, double C, int V);
void HML_MakingVectorForNonparametricEstimatorOfDerivative6(double *VHML_ResultVector, double *X, double *Y, int VHML_N, double C, int V);
double HML_NonparametricEstimatorOfDerivative(double x, double *X, double *Y, int VHML_N, double C, int V, bool *b);
double HML_NonparametricEstimatorOfDerivative(double x, double *X, double *Y, int VHML_N, double C, int V);
double HML_NonparametricEstimatorOfDerivative2(double x, double *X, double *Y, int VHML_N, double C, int V, bool *b);
double HML_NonparametricEstimatorOfDerivative2(double x, double *X, double *Y, int VHML_N, double C, int V);
double HML_NonparametricEstimatorOfDerivative3(double x, double *X, double *dY, int VHML_N, double C, int V, bool *b);
double HML_NonparametricEstimatorOfDerivative3(double x, double *X, double *dY, int VHML_N, double C, int V);
double HML_NonparametricEstimatorOfDerivative4(double x, double *X, double *Y, int VHML_N, double C, int V, bool *b);
double HML_NonparametricEstimatorOfDerivative4(double x, double *X, double *Y, int VHML_N, double C, int V);
double HML_NonparametricEstimatorOfDerivative5(double x, double *X, double *Y, int VHML_N, double C, int V, bool *b);
double HML_NonparametricEstimatorOfDerivative5(double x, double *X, double *Y, int VHML_N, double C, int V);
double HML_NonparametricEstimatorOfDerivative6(double x, double *X, double *dY, int VHML_N, double C, int V, bool *b);
double HML_NonparametricEstimatorOfDerivative6(double x, double *X, double *dY, int VHML_N, double C, int V);
double HML_NonparametricEstimatorOfRegression(double x, double *X, double *Y, int VHML_N, double C, int V, bool *b);
double HML_NonparametricEstimatorOfRegression(double x, double *X, double *Y, int VHML_N, double C, int V);
//Нечеткие системы
double HML_CentroidOfTrapeziformFuzzyNumber(double a,double b,double c,double d);
double HML_MaxiMinTrapeziformFuzzyNumbers (double *Data);
double HML_TrapeziformFuzzyNumber(double x,double a,double b,double c,double d);
double HML_TrapeziformTruncatedFuzzyNumber(double x, double a, double b, double c, double d, double m);
//Оптимизация
int HML_BinaryMonteCarloAlgorithm(int *Parameters, double (*FitnessFunction)(int*,int), int *VHML_ResultVector, double *VHML_Result);
void HML_DichotomyOptimization (double Left, double Right, double (*Function)(double), double Interval, double Epsilon, double *VHML_Result_X,double *VHML_Result_Y);
void HML_FibonacciOptimization (double Left, double Right, double (*Function)(double), int Count, double *VHML_Result_X,double *VHML_Result_Y);
void HML_GoldenSectionOptimization (double Left, double Right, double (*Function)(double), double Interval, double *VHML_Result_X,double *VHML_Result_Y);
void HML_QuadraticFitOptimization (double Left, double Right, double (*Function)(double), double Epsilon, double Epsilon2, double *VHML_Result_X,double *VHML_Result_Y);
int HML_RealMonteCarloAlgorithm(int *Parameters, double *Left, double *Right, double (*FitnessFunction)(double*,int), double *VHML_ResultVector, double *VHML_Result);
void HML_RealMonteCarloOptimization (double Left, double Right, double (*Function)(double), int Count, double *VHML_Result_X,double *VHML_Result_Y);
void HML_UniformSearchOptimization (double Left, double Right, double (*Function)(double), double Interval, double *VHML_Result_X,double *VHML_Result_Y);
void HML_UniformSearchOptimizationN (double Left, double Right, double (*Function)(double), int Count, double *VHML_Result_X,double *VHML_Result_Y);
//Оптимизация - свалка алгоритмов
int HML_BinaryGeneticAlgorithmTournamentSelectionWithReturn(double *Parameters, double (*FitnessFunction)(int*,int), int *VHML_ResultVector, double *VHML_Result);
int HML_BinaryGeneticAlgorithmTwiceGenerations(int *Parameters, double (*FitnessFunction)(int*,int), int *VHML_ResultVector, double *VHML_Result);
int HML_BinaryGeneticAlgorithmWCC(int *Parameters, double (*FitnessFunction)(int*,int), int *VHML_ResultVector, double *VHML_Result);
int HML_BinaryGeneticAlgorithmWDPOfNOfGPS(double *Parameters, double (*FitnessFunction)(int*,int), int *VHML_ResultVector, double *VHML_Result);
int HML_BinaryGeneticAlgorithmWDTS(double *Parameters, double (*FitnessFunction)(int*,int), int *VHML_ResultVector, double *VHML_Result);
int HML_RealGeneticAlgorithmTournamentSelectionWithReturn(double *Parameters, int *NumberOfParts, double *Left, double *Right, double (*FitnessFunction)(double*,int), double *VHML_ResultVector, double *VHML_Result);
int HML_RealGeneticAlgorithmTwiceGenerations(int *Parameters, int *NumberOfParts, double *Left, double *Right, double (*FitnessFunction)(double*,int), double *VHML_ResultVector, double *VHML_Result);
int HML_RealGeneticAlgorithmWCC(int *Parameters, int *NumberOfParts, double *Left, double *Right, double (*FitnessFunction)(double*,int), double *VHML_ResultVector, double *VHML_Result);
int HML_RealGeneticAlgorithmWDPOfNOfGPS(double *Parameters, int *NumberOfParts, double *Left, double *Right, double (*FitnessFunction)(double*,int), double *VHML_ResultVector, double *VHML_Result);
int HML_RealGeneticAlgorithmWDTS(double *Parameters, int *NumberOfParts, double *Left, double *Right, double (*FitnessFunction)(double*,int), double *VHML_ResultVector, double *VHML_Result);
//Перевод единиц измерений
double HML_DegToRad(double VHML_X);
double HML_RadToDeg(double VHML_X);
//Случайные объекты
template <class T> void HML_BernulliVector(T *VHML_ResultVector, int VHML_N);
int HML_BitNumber(double P);
int HML_BitNumber();
template <class T> void HML_RandomArrangingObjectsIntoBaskets(T *VHML_ResultVector, int N, int VHML_N);
template <class T> void HML_RandomBinaryMatrix(T **VHML_ResultMatrix,int VHML_N,int VHML_M);
template <class T> void HML_RandomBinaryVector(T *VHML_ResultVector,int VHML_N);
template <class T> void HML_RandomIntMatrix(T **VHML_ResultMatrix, T n, T m, int VHML_N, int VHML_M);
template <class T> void HML_RandomIntMatrixInCols(T **VHML_ResultMatrix, T *n, T *m, int VHML_N, int VHML_M);
template <class T> void HML_RandomIntMatrixInElements(T **VHML_ResultMatrix, T **n, T **m, int VHML_N, int VHML_M);
template <class T> void HML_RandomIntMatrixInRows(T **VHML_ResultMatrix, T *n, T *m, int VHML_N, int VHML_M);
template <class T> void HML_RandomIntVector(T *VHML_ResultVector, T n, T m, int VHML_N);
template <class T> void HML_RandomIntVectorInElements(T *VHML_ResultVector, T *n, T *m, int VHML_N);
template <class T> void HML_RandomMatrixOfPermutation(T **VHML_ResultMatrix, int VHML_N, int VHML_M);
void HML_RandomRealMatrix(double **VHML_ResultMatrix, double Left, double Right, int VHML_N, int VHML_M);
void HML_RandomRealMatrixInCols(double **VHML_ResultMatrix, double *Left, double *Right, int VHML_N, int VHML_M);
void HML_RandomRealMatrixInElements(double **VHML_ResultMatrix, double **Left, double **Right, int VHML_N, int VHML_M);
void HML_RandomRealMatrixInRows(double **VHML_ResultMatrix, double *Left, double *Right, int VHML_N, int VHML_M);
void HML_RandomRealVector(double *VHML_ResultVector, double Left, double Right, int VHML_N);
void HML_RandomRealVectorInElements(double *VHML_ResultVector, double *Left, double *Right, int VHML_N);
template <class T> void HML_RandomVectorOfPermutation(T *VHML_ResultVector, int VHML_N);
void HML_RandomVectorOfProbability(double *VHML_ResultVector, int VHML_N);
//Случайные числа
double HML_RandomNormal(double Mean, double StdDev);
double HML_RandomUniform(double a, double b);
int HML_RandomUniformInt(int n, int m);
int HML_RandomUniformIntIncluding(int n, int m);
//Сортировка
template <class T> void HML_BubbleDescendingSort(T *VHML_ResultVector, int VHML_N);
template <class T> void HML_BubbleSort(T *VHML_ResultVector, int VHML_N);
template <class T> void HML_BubbleSortColWithOtherConjugateColsInMatrix(T **VHML_ResultMatrix,int Col, int VHML_N, int VHML_M);
template <class T> void HML_BubbleSortEveryColInMatrix(T **VHML_ResultMatrix,int VHML_N, int VHML_M);
template <class T> void HML_BubbleSortEveryRowInMatrix(T **VHML_ResultMatrix,int VHML_N, int VHML_M);
template <class T> void HML_BubbleSortInGroups(T *VHML_ResultVector, int VHML_N, int m);
template <class T> void HML_BubbleSortRowWithOtherConjugateRowsInMatrix(T **VHML_ResultMatrix,int Row, int VHML_N, int VHML_M);
template <class T, class T2> void HML_BubbleSortWithConjugateVector(T *VHML_ResultVector, T2 *VHML_ResultVector2, int VHML_N);
template <class T, class T2, class T3> void HML_BubbleSortWithTwoConjugateVectors(T *VHML_ResultVector, T2 *VHML_ResultVector2, T3 *VHML_ResultVector3, int VHML_N);
//Статистика и теория вероятности
double HML_DensityOfDistributionOfNormalizedCenteredNormalDistribution(double x);
double HML_DistributionFunctionOfNormalDistribution(double x, double mu, double sigma, double Epsilon);
double HML_DistributionFunctionOfNormalizedCenteredNormalDistribution(double x, double Epsilon);
double HML_LeftBorderOfWilcoxonWFromTable(int m, int n, double Q);
template <class T> T HML_Mean(T *x, int VHML_N);
template <class T> T HML_MeanOfFilter(T *x, int VHML_N, T UpperFilter, T LowerFilter);
template <class T> T HML_MeanOfLowerFilter(T *x, int VHML_N, T LowerFilter);
template <class T> T HML_MeanOfUpperFilter(T *x, int VHML_N, T UpperFilter);
template <class T> T HML_Median(T *x, int VHML_N);
double HML_RightBorderOfWilcoxonWFromTable(int m, int n, double Q);
template <class T> T HML_SampleCovariance(T *x, T *y, int VHML_N);
double HML_StdDevToVariance(double StdDev);
template <class T> T HML_UncorrectedVariance(T *x, int VHML_N);
template <class T> T HML_Variance(T *x, int VHML_N);
double HML_VarianceToStdDev(double Variance);
int HML_WilcoxonW(double *a, double *b, int VHML_N1, int VHML_N2, double Q);
int HML_WilcoxonW(double *a, double *b, int VHML_N1, int VHML_N2, double Q, double *Lr, double *Rr, double *Wr);
//Тестовые функции для оптимизации
double HML_TestFunction_Ackley(double *x, int VHML_N);
double HML_TestFunction_AdditivePotential(double x, double y);
double HML_TestFunction_Bosom(double x, double y);
double HML_TestFunction_EggHolder(double x, double y);
double HML_TestFunction_GaussianQuartic(double *x, int VHML_N);
double HML_TestFunction_Griewangk(double *x, int VHML_N);
double HML_TestFunction_Himmelblau(double x, double y);
double HML_TestFunction_HyperEllipsoid(double *x, int VHML_N);
double HML_TestFunction_InvertedRosenbrock(double x, double y);
double HML_TestFunction_Katnikov(double x, double y);
double HML_TestFunction_Multiextremal(double x);
double HML_TestFunction_Multiextremal2(double x);
double HML_TestFunction_Multiextremal3(double x, double y);
double HML_TestFunction_Multiextremal4(double x, double y);
double HML_TestFunction_MultiplicativePotential(double x, double y);
double HML_TestFunction_ParaboloidOfRevolution(double *x, int VHML_N);
double HML_TestFunction_Rana(double x, double y);
double HML_TestFunction_Rastrigin(double *x, int VHML_N);
double HML_TestFunction_RastriginNovgorod(double *x, int VHML_N);
double HML_TestFunction_RastriginWithChange(double x, double y);
double HML_TestFunction_RastriginWithTurning(double x, double y);
double HML_TestFunction_ReverseGriewank(double x, double y);
double HML_TestFunction_Rosenbrock(double *x, int VHML_N);
double HML_TestFunction_RotatedHyperEllipsoid(double *x, int VHML_N);
double HML_TestFunction_Schwefel(double *x, int VHML_N);
double HML_TestFunction_ShekelsFoxholes(double x, double y);
double HML_TestFunction_Sombrero(double x, double y);
double HML_TestFunction_StepFunction(double *x, int VHML_N);
double HML_TestFunction_SumVector(int *x, int VHML_N);
double HML_TestFunction_Wave(double x);
//Тригонометрические функции
double HML_Cos(double x);
double HML_CosDeg(double x);
double HML_Cosec(double x);
double HML_CosecDeg(double x);
double HML_Cotan(double x);
double HML_CotanDeg(double x);
double HML_Sec(double x);
double HML_SecDeg(double x);
double HML_Sin(double x);
double HML_SinDeg(double x);
double HML_Tan(double x);
double HML_TanDeg(double x);
//Уравнения
int HML_QuadraticEquation(double a, double b, double c, double *x1, double *x2);
int HML_QuadraticEquationCount(double a, double b, double c, double *x1, double *x2);
//Физика
double HML_NewtonSecondLawAcceleration(double F, double m);
double HML_NewtonSecondLawForce(double a, double m);
//Цвет
int HML_AddColorB(int R, int G, int B, double p);
int HML_AddColorG(int R, int G, int B, double p);
int HML_AddColorR(int R, int G, int B, double p);
int HML_AlphaBlendingColorToColorB(double alpha, int R1, int G1, int B1, int R2, int G2, int B2);
int HML_AlphaBlendingColorToColorG(double alpha, int R1, int G1, int B1, int R2, int G2, int B2);
int HML_AlphaBlendingColorToColorR(double alpha, int R1, int G1, int B1, int R2, int G2, int B2);
int HML_ColorFromGradientB(double position, int R1, int G1, int B1, int R2, int G2, int B2);
int HML_ColorFromGradientG(double position, int R1, int G1, int B1, int R2, int G2, int B2);
int HML_ColorFromGradientR(double position, int R1, int G1, int B1, int R2, int G2, int B2);
int HML_DivideColorB(int R, int G, int B, double p);
int HML_DivideColorG(int R, int G, int B, double p);
int HML_DivideColorR(int R, int G, int B, double p);
int HML_GiveRainbowColorB(double position);
int HML_GiveRainbowColorG(double position);
int HML_GiveRainbowColorR(double position);
int HML_GreyscaleB(int R, int G, int B);
int HML_GreyscaleG(int R, int G, int B);
int HML_GreyscaleR(int R, int G, int B);
int HML_MultiplyColorB(int R, int G, int B, double p);
int HML_MultiplyColorG(int R, int G, int B, double p);
int HML_MultiplyColorR(int R, int G, int B, double p);
int HML_NegativeColorB(int R, int G, int B);
int HML_NegativeColorG(int R, int G, int B);
int HML_NegativeColorR(int R, int G, int B);
int HML_SubtractColorB(int R, int G, int B, double p);
int HML_SubtractColorG(int R, int G, int B, double p);
int HML_SubtractColorR(int R, int G, int B, double p);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// РЕАЛИЗАЦИЯ ШАБЛОНОВ
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//*****************************************************************
//Вектора (Одномерные массивы)
//*****************************************************************
template <class T> void HML_AcceptanceLimits(T *VHML_ResultVector, T *Left, T *Right, int VHML_N)
{
/*
Функция вмещает вектор VHML_ResultVector в прямоугольную многомерной области,
определяемой левыми границами и правыми границами. Если какая-то координата
вектора выходит за границу, то значение этой координаты принимает граничное значение.
Входные параметры:
VHML_ResultVector - указатель на вектор (в него же записывается "исправленный вектор");
Left - вектор левых границ;
Right - вектор правых границ;
VHML_N - размерность вектора.
Возвращаемое значение:
Отсутствует.
*/
for (int i=0;i<VHML_N;i++)
{
if (VHML_ResultVector[i]<Left[i]) VHML_ResultVector[i]=Left[i];//принятие граничного левого условия
if (VHML_ResultVector[i]>Right[i]) VHML_ResultVector[i]=Right[i];//принятие граничного правого условия
}
}
//---------------------------------------------------------------------------
template <class T> void HML_AcceptanceLimits(T *VHML_ResultVector, T Left, T Right, int VHML_N)
{
/*
Функция вмещает вектор VHML_ResultVector в прямоугольную многомерной области,
определяемой левыми границами и правыми границами. Если какая-то координата
вектора выходит за границу, то значение этой координаты принимает граничное значение.
Входные параметры:
VHML_ResultVector - указатель на вектор (в него же записывается "исправленный вектор");
Left - левая граница;
Right - правая граница;
VHML_N - размерность вектора.
Возвращаемое значение:
Отсутствует.
*/
for (int i=0;i<VHML_N;i++)
{
if (VHML_ResultVector[i]<Left) VHML_ResultVector[i]=Left;//принятие граничного левого условия
if (VHML_ResultVector[i]>Right) VHML_ResultVector[i]=Right;//принятие граничного правого условия
}
}
//---------------------------------------------------------------------------
template <class T> void HML_AcceptanceLimitsLeft(T *VHML_ResultVector, T *Left, int VHML_N)
{
/*
Если значения вектора VHML_ResultVector[i] слева выходят за Left[i], то она ограничивается Left[i].
Входные параметры:
VHML_ResultVector - указатель на вектор (в него же записывается "исправленный вектор");
Left - вектор левых границ;
VHML_N - размерность вектора.
Возвращаемое значение:
Отсутствует.
*/
for (int i=0;i<VHML_N;i++)
{
if (VHML_ResultVector[i]<Left[i]) VHML_ResultVector[i]=Left[i];//принятие граничного левого условия
}
}
//---------------------------------------------------------------------------
template <class T> void HML_AcceptanceLimitsLeft(T *VHML_ResultVector, T Left, int VHML_N)
{
/*
Если значения вектора VHML_ResultVector[i] слева выходят за Left, то она ограничивается Left.
Входные параметры:
VHML_ResultVector - указатель на вектор (в него же записывается "исправленный вектор");
Left - левая граница;
VHML_N - размерность вектора.
Возвращаемое значение:
Отсутствует.
*/
for (int i=0;i<VHML_N;i++)
{
if (VHML_ResultVector[i]<Left) VHML_ResultVector[i]=Left;//принятие граничного левого условия
}
}
//---------------------------------------------------------------------------
template <class T> void HML_AcceptanceLimitsRight(T *VHML_ResultVector, T *Right, int VHML_N)
{
/*
Если значения вектора VHML_ResultVector[i] справа выходят за Right[i], то она ограничивается Right[i].
Входные параметры:
VHML_ResultVector - указатель на вектор (в него же записывается "исправленный вектор");
Right - вектор правых границ;
VHML_N - размерность вектора.
Возвращаемое значение:
Отсутствует.
*/
for (int i=0;i<VHML_N;i++)
{
if (VHML_ResultVector[i]>Right[i]) VHML_ResultVector[i]=Right[i];//принятие граничного правого условия
}
}
//---------------------------------------------------------------------------
template <class T> void HML_AcceptanceLimitsRight(T *VHML_ResultVector, T Right, int VHML_N)
{
/*
Если значения вектора VHML_ResultVector[i] справа выходят за Right, то она ограничивается Right.
Входные параметры:
VHML_ResultVector - указатель на вектор (в него же записывается "исправленный вектор");
Right - правая граница;
VHML_N - размерность вектора.
Возвращаемое значение:
Отсутствует.
*/
for (int i=0;i<VHML_N;i++)
{
if (VHML_ResultVector[i]>Right) VHML_ResultVector[i]=Right;//принятие граничного правого условия
}
}
//---------------------------------------------------------------------------
template <class T> void HML_ChangeOrderInVector(T *VHML_Vector, T *VHML_ResultVector, int *Order, int VHML_N)
{
/*
Функция меняет порядок элементов в массиве VHML_Vector и сохраняет в другой VHML_ResultVector согласно массиву
Order, в котором записан новый порядок элементов.
Входные параметры:
VHML_Vector - указатель на массив;
VHML_ResultVector - указатель на массив, куда сохраняем данные;
Order - указатель на массив, в котором хранится порядок элементов;
VHML_N - количество элементов в массиве.
Возвращаемое значение:
Отсутствует.
*/
for (int i=0;i<VHML_N;i++)
VHML_ResultVector[i]=VHML_Vector[Order[i]];
}
//---------------------------------------------------------------------------
template <class T> void HML_ChangeOrderInVector(T *VHML_Vector, int *Order, int VHML_N)
{
/*
Функция меняет порядок элементов в массиве VHML_Vector согласно массиву
Order, в котором записан новый порядок элементов.
Входные параметры:
VHML_Vector - указатель на массив;
Order - указатель на массив, в котором хранится порядок элементов;
VHML_N - количество элементов в массиве.
Возвращаемое значение:
Отсутствует.
*/
T *TempVector;
TempVector = new T [VHML_N];
HML_VectorToVector(VHML_Vector,TempVector,VHML_N);
for (int i=0;i<VHML_N;i++)
VHML_Vector[i]=TempVector[Order[i]];
delete [] TempVector;
}
//---------------------------------------------------------------------------
template <class T> int HML_CheckElementInVector(T *x, int VHML_N, T a)
{
/*
Функция проверяет наличие элемента а в векторе x.
Входные параметры:
x - указатель на вектор;
VHML_N - размер массива;
a - проверяемый элемент.
Возвращаемое значение:
Номер (начиная с нуля) первого элемента, равного искомому. Если такого элемента нет, то возвращается -1.
*/
int VHML_Result=-1;
int i=0;
while ((i<VHML_N)&&(VHML_Result==-1))
{
if (x[i]==a) VHML_Result=i;//нашли
i++;
}
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> int HML_CompareMeanOfVectors(T *a, T *b, int VHML_N)
{
/*
Функция проверяет, какой вектор по среднему арифметическому больше.
Входные параметры:
a - первый вектор;
b - вторый вектор;
VHML_N - размер векторов.
Возвращаемое значение:
0 - вектора совпадают или совпадает среднее арифметическое;
1 - первый вектор имеет большее значение арифметического среднего;
2 - второй вектор имеет большее значение арифметического среднего.
Примечание:
Данную функцию удобно использовать вкупе с функцией HML_WilcoxonW.
*/
int VHML_Result=0;
for (int i=0;i<VHML_N;i++)
if (a[i]!=b[i]) VHML_Result=-1;
if (VHML_Result==-1)
{
double Ma=HML_SumVector(a,VHML_N)/double(VHML_N);
double Mb=HML_SumVector(b,VHML_N)/double(VHML_N);
if (Ma>Mb)
VHML_Result=1;
else
VHML_Result=2;
if (Ma==Mb) VHML_Result=0;
}
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> int HML_CompareMeanOfVectors(T *a, T *b, int VHML_N1, int VHML_N2)
{
/*
Функция проверяет, какой вектор по среднему арифметическому больше.
Входные параметры:
a - первый вектор;
b - вторый вектор;
VHML_N1 - размер вектора a;
VHML_N2 - размер вектора b.
Возвращаемое значение:
0 - вектора совпадают или совпадает среднее арифметическое;
1 - первый вектор имеет большее значение арифметического среднего;
2 - второй вектор имеет большее значение арифметического среднего.
Примечание:
Данную функцию удобно использовать вкупе с функцией HML_WilcoxonW.
*/
int VHML_Result=0;
if (VHML_N1==VHML_N2)
for (int i=0;i<VHML_N1;i++)
if (a[i]!=b[i]) VHML_Result=-1;
else
VHML_Result=-1;
if (VHML_Result==-1)
{
double Ma=HML_SumVector(a,VHML_N1)/double(VHML_N1);
double Mb=HML_SumVector(b,VHML_N2)/double(VHML_N2);
if (Ma>Mb)
VHML_Result=1;
else
VHML_Result=2;
if (Ma==Mb) VHML_Result=0;
}
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> bool HML_EqualityOfVectors(T *a, T *b, int VHML_N)
{
/*
Функция проверяет равенство векторов.
Входные параметры:
a - первый вектор;
b - вторый вектор;
VHML_N - размер векторов.
Возвращаемое значение:
true - вектора совпадают;
false - вектора не совпадают.
*/
bool VHML_Result=true;
for (int i=0;i<VHML_N;i++)
if (a[i]!=b[i]) VHML_Result=false;
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> void HML_FibonacciNumbersVector(T *VHML_ResultVector, int VHML_N)
{
/*
Функция заполняет массив числами Фибоначчи.
Входные параметры:
VHML_ResultVector - указатель на массив, в который записывается результат;
VHML_N - размер массива.
Возвращаемое значение:
Отсутствует.
*/
if (VHML_N>=1) VHML_ResultVector[0]=1;
if (VHML_N>=2) VHML_ResultVector[1]=1;
if (VHML_N>2)
{
for (int i=2;i<VHML_N;i++)
VHML_ResultVector[i]=VHML_ResultVector[i-1]+VHML_ResultVector[i-2];
}
}
//---------------------------------------------------------------------------
template <class T> void HML_FillVector(T *VHML_ResultVector, int VHML_N, T x)
{
/*
Функция заполняет вектор значениями, равных x.
Входные параметры:
VHML_ResultVector - указатель на преобразуемый массив;
VHML_N - количество элементов в массиве;
x - число, которым заполняется вектор.
Возвращаемое значение:
Отсутствует.
*/
for (int i=0;i<VHML_N;i++) VHML_ResultVector[i]=x;
}
//---------------------------------------------------------------------------
template <class T> T HML_MaximumOfVector(T *VHML_Vector, int VHML_N)
{
/*
Функция ищет максимальный элемент в векторе (одномерном массиве).
Входные параметры:
VHML_Vector - указатель на вектор (одномерный массив);
VHML_N - размер массива.
Возвращаемое значение:
Максимальный элемент.
*/
T VHML_Result;
VHML_Result=VHML_Vector[0];
for (int i=1;i<VHML_N;i++)
if (VHML_Vector[i]>VHML_Result)
VHML_Result=VHML_Vector[i];
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> T HML_MinimumOfVector(T *VHML_Vector, int VHML_N)
{
/*
Функция ищет минимальный элемент в векторе (одномерном массиве).
Входные параметры:
VHML_Vector - указатель на вектор (одномерный массив);
VHML_N - размер массива.
Возвращаемое значение:
Минимальный элемент.
*/
T VHML_Result;
VHML_Result=VHML_Vector[0];
for (int i=1;i<VHML_N;i++)
if (VHML_Vector[i]<VHML_Result)
VHML_Result=VHML_Vector[i];
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> void HML_MixingVector(T *VHML_ResultVector, double P, int VHML_N)
{
/*
Функция перемешивает массив. Поочередно рассматриваются номера элементов массивов.
С некоторой вероятностью рассматриваемый элемент массива меняется местами со
случайным элементом массива.
Входные параметры:
VHML_ResultVector - указатель на исходный массив;
P - вероятность того, что элемент массива под рассматриваемым номером поменяется
местами с каким-нибудь другим элементов (не включая самого себя);
VHML_N - размер массива.
Возвращаемое значение:
Отсутствует.
*/
int i,j;
for (i=0;i<VHML_N;i++)
{
if (HML_RandomNumber()<=P)
{
j=HML_RandomUniformInt(0,VHML_N-1);
if (j>=i) j++;
HML_NumberInterchange (&VHML_ResultVector[i],&VHML_ResultVector[j]); //меняем местами элементы массива
}
}
}
//---------------------------------------------------------------------------
template <class T, class T2> void HML_MixingVectorWithConjugateVector(T *VHML_ResultVector, T2 *VHML_ResultVector2, double P, int VHML_N)
{
/*
Функция перемешивает массив вместе со сопряженным массивом. Поочередно
рассматриваются номера элементов массивов. С некоторой вероятностью
рассматриваемый элемент массива меняется местами со случайным элементом массива.
Пары элементов первого массива и сопряженного остаются без изменения.
Входные параметры:
VHML_ResultVector - указатель на исходный массив;
VHML_ResultVector2 - указатель на сопряженный массив;
P - вероятность того, что элемент массива под рассматриваемым номером поменяется
местами с каким-нибудь другим элементов (не включая самого себя);
VHML_N - количество элементов в массивах.
Возвращаемое значение:
Отсутствует.
*/
int i,j;
for (i=0;i<VHML_N;i++)
{
if (HML_RandomNumber()<P)
{
j=HML_RandomUniformInt(0,VHML_N-1);
if (j>=i) j++;
HML_NumberInterchange (&VHML_ResultVector[i],&VHML_ResultVector[j]);//меняем местами элементы массива
HML_NumberInterchange (&VHML_ResultVector2[i],&VHML_ResultVector2[j]);//меняем местами элементы сопряженного массива
}
}
}
//---------------------------------------------------------------------------
template <class T> int HML_NumberOfDifferentValuesInVector(T *a, int VHML_N)
{
/*
Функция подсчитывает число различных значений в векторе (одномерном массиве).
Входные параметры:
a - указатель на вектор;
VHML_N - размер массива a.
Возвращаемое значение:
Число различных значений в векторе.
Примечание:
Алгоритм очень топорный и медленный.
*/
T *b;
b=new T[VHML_N];
int VHML_Result=0;
for (int i=0;i<VHML_N;i++)
if (HML_CheckElementInVector(b,VHML_Result,a[i])==-1)
{
b[VHML_Result]=a[i];
VHML_Result++;
}
delete [] b;
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> int HML_NumberOfMaximumOfVector(T *a, int VHML_N)
{
/*
Функция ищет номер максимального элемента в векторе (одномерном массиве).
Входные параметры:
a - указатель на вектор (одномерный массив);
VHML_N - размер массива.
Возвращаемое значение:
Номер максимального элемента.
*/
T Max;
Max=a[0];
int VHML_Result=0;
for (int i=1;i<VHML_N;i++)
if (a[i]>Max)
{
Max=a[i];
VHML_Result=i;
}
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> int HML_NumberOfMinimumOfVector(T *a, int VHML_N)
{
/*
Функция ищет номер минимального элемента в векторе (одномерном массиве).
Входные параметры:
a - указатель на вектор (одномерный массив);
VHML_N - размер массива.
Возвращаемое значение:
Номер минимального элемента.
*/
T Min;
Min=a[0];
int VHML_Result=0;
for (int i=1;i<VHML_N;i++)
if (a[i]<Min)
{
Min=a[i];
VHML_Result=i;
}
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> int HML_NumberOfNegativeValues(T *a, int VHML_N)
{
/*
Функция подсчитывает число отрицательных значений в векторе (одномерном массиве).
Входные параметры:
a - указатель на исходный массив;
VHML_N - количество элементов в массиве.
Выходной параметр:
Число отрицательных значений в массиве.
*/
int VHML_Result=0;
for (int i=0;i<VHML_N;i++)
if (a[i]<0)
VHML_Result++;
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> int HML_NumberOfPositiveValues(T *a, int VHML_N)
{
/*
Функция подсчитывает число положительных значений в векторе (одномерном массиве).
Входные параметры:
a - указатель на исходный массив;
VHML_N - количество элементов в массиве.
Выходной параметр:
Число положительных значений в массиве.
*/
int VHML_Result=0;
for (int i=0;i<VHML_N;i++)
if (a[i]>0)
VHML_Result++;
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> int HML_NumberOfZeroValues(T *a, int VHML_N)
{
/*
Функция подсчитывает число нулевых значений в векторе (одномерном массиве).
Входные параметры:
a - указатель на исходный массив;
VHML_N - количество элементов в массиве.
Выходной параметр:
Число нулевых значений в массиве.
*/
int VHML_Result=0;
for (int i=0;i<VHML_N;i++)
if (a[i]==0)
VHML_Result++;
return VHML_Result;
}
//---------------------------------------------------------------------------
template <class T> void HML_OrdinalVector(T *VHML_ResultVector, int VHML_N)
{
/*
Функция заполняет вектор значениями, равные номеру элемента, начиная с единицы.
Входные параметры:
VHML_ResultVector - указатель на вектор (одномерный массив), который и заполняется;
VHML_N - размер массива.
Возвращаемое значение:
Отсутствует.
*/
for (int i=0;i<VHML_N;i++)
VHML_ResultVector[i]=i+1;
}
//---------------------------------------------------------------------------
template <class T> void HML_OrdinalVectorZero(T *VHML_ResultVector, int VHML_N)
{
/*
Функция заполняет вектор значениями, равные номеру элемента, начиная с нуля.
Входные параметры:
VHML_ResultVector - указатель на вектор (одномерный массив), который и заполняется;
VHML_N - размер массива.