pyerualjetwork 4.8__py3-none-any.whl → 5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyerualjetwork/__init__.py +41 -1
- pyerualjetwork/data_operations.py +31 -1
- pyerualjetwork/data_operations_cuda.py +30 -0
- pyerualjetwork/{planeat.py → ene.py} +48 -31
- pyerualjetwork/{planeat_cuda.py → ene_cuda.py} +45 -28
- pyerualjetwork/help.py +2 -2
- pyerualjetwork/memory_operations.py +26 -0
- pyerualjetwork/model_operations.py +83 -38
- pyerualjetwork/model_operations_cuda.py +79 -33
- pyerualjetwork/{plan.py → neu.py} +67 -52
- pyerualjetwork/{plan_cuda.py → neu_cuda.py} +74 -59
- pyerualjetwork/visualizations.py +10 -10
- pyerualjetwork/visualizations_cuda.py +10 -10
- {pyerualjetwork-4.8.dist-info → pyerualjetwork-5.dist-info}/METADATA +19 -16
- pyerualjetwork-5.dist-info/RECORD +25 -0
- pyerualjetwork-4.8.dist-info/RECORD +0 -25
- {pyerualjetwork-4.8.dist-info → pyerualjetwork-5.dist-info}/WHEEL +0 -0
- {pyerualjetwork-4.8.dist-info → pyerualjetwork-5.dist-info}/top_level.txt +0 -0
pyerualjetwork/__init__.py
CHANGED
@@ -1,4 +1,44 @@
|
|
1
|
-
|
1
|
+
"""
|
2
|
+
|
3
|
+
PyerualJetwork
|
4
|
+
==============
|
5
|
+
PyereualJetwork is a large, GPU-accelerated machine learning library in Python designed for professionals and researchers.
|
6
|
+
It features PLAN, MLP, and Deep Learning training, as well as ENE (Eugenic NeuroEvolution) for genetic optimization,
|
7
|
+
which can also be applied to genetic algorithms or Reinforcement Learning (RL) problems.
|
8
|
+
The library includes functions for data pre-processing, visualizations, model saving and loading, prediction and evaluation,
|
9
|
+
training, and both detailed and simplified memory management.
|
10
|
+
|
11
|
+
|
12
|
+
Library (CPU) Main Modules:
|
13
|
+
---------------------------
|
14
|
+
- neu
|
15
|
+
- ene
|
16
|
+
- data_operations
|
17
|
+
- model_operations
|
18
|
+
|
19
|
+
Library (GPU) Main Modules:
|
20
|
+
---------------------------
|
21
|
+
- neu_cuda
|
22
|
+
- ene_cuda
|
23
|
+
- data_operations_cuda
|
24
|
+
- model_operations_cuda
|
25
|
+
|
26
|
+
Memory Module:
|
27
|
+
--------------
|
28
|
+
- memory_operations
|
29
|
+
|
30
|
+
Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJetwork/ExampleCodes
|
31
|
+
|
32
|
+
PyerualJetwork document: https://github.com/HCB06/Anaplan/blob/main/Welcome_to_Anaplan/ANAPLAN_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
|
33
|
+
|
34
|
+
- Author: Hasan Can Beydili
|
35
|
+
- YouTube: https://www.youtube.com/@HasanCanBeydili
|
36
|
+
- Linkedin: https://www.linkedin.com/in/hasan-can-beydili-77a1b9270/
|
37
|
+
- Instagram: https://www.instagram.com/canbeydilj
|
38
|
+
- Contact: tchasancan@gmail.com
|
39
|
+
"""
|
40
|
+
|
41
|
+
__version__ = "5"
|
2
42
|
__update__ = """* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES
|
3
43
|
* PyerualJetwork Homepage: https://github.com/HCB06/PyerualJetwork/tree/main
|
4
44
|
* PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
|
@@ -1,3 +1,33 @@
|
|
1
|
+
"""
|
2
|
+
|
3
|
+
|
4
|
+
Data Operations
|
5
|
+
===============
|
6
|
+
This module contains functions for handling all operational processes related to data and datasets.
|
7
|
+
|
8
|
+
Module functions:
|
9
|
+
-----------------
|
10
|
+
- encode_one_hot()
|
11
|
+
- decode_one_hot()
|
12
|
+
- split()
|
13
|
+
- manuel_balancer()
|
14
|
+
- auto_balancer()
|
15
|
+
- synthetic_augmentation()
|
16
|
+
- non_neg_normalization()
|
17
|
+
- normalization()
|
18
|
+
- standard_scaler()
|
19
|
+
|
20
|
+
Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJetwork/ExampleCodes
|
21
|
+
|
22
|
+
PyerualJetwork document: https://github.com/HCB06/Anaplan/blob/main/Welcome_to_Anaplan/ANAPLAN_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
|
23
|
+
|
24
|
+
- Author: Hasan Can Beydili
|
25
|
+
- YouTube: https://www.youtube.com/@HasanCanBeydili
|
26
|
+
- Linkedin: https://www.linkedin.com/in/hasan-can-beydili-77a1b9270/
|
27
|
+
- Instagram: https://www.instagram.com/canbeydilj
|
28
|
+
- Contact: tchasancan@gmail.com
|
29
|
+
"""
|
30
|
+
|
1
31
|
from tqdm import tqdm
|
2
32
|
import numpy as np
|
3
33
|
from colorama import Fore, Style
|
@@ -383,7 +413,7 @@ def non_neg_normalization(
|
|
383
413
|
dtype=np.float32
|
384
414
|
):
|
385
415
|
"""
|
386
|
-
Normalizes the input data [0-1] range.
|
416
|
+
Normalizes the input data [0-1] range using max-abs normalization but non negative number.
|
387
417
|
Args:
|
388
418
|
Input (numpy): Input data to be normalized.
|
389
419
|
dtype (numpy.dtype): Data type for the arrays. np.float32 by default. Example: np.float64 or np.float16.
|
@@ -1,3 +1,33 @@
|
|
1
|
+
"""
|
2
|
+
|
3
|
+
|
4
|
+
Data Operations on GPU (CUDA)
|
5
|
+
=============================
|
6
|
+
This module contains functions for handling all operational processes related to data and datasets on GPU memory.
|
7
|
+
|
8
|
+
Module functions:
|
9
|
+
---------------
|
10
|
+
- encode_one_hot()
|
11
|
+
- decode_one_hot()
|
12
|
+
- split()
|
13
|
+
- manuel_balancer()
|
14
|
+
- auto_balancer()
|
15
|
+
- synthetic_augmentation()
|
16
|
+
- non_neg_normalization()
|
17
|
+
- normalization()
|
18
|
+
- standard_scaler()
|
19
|
+
|
20
|
+
Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJetwork/ExampleCodes
|
21
|
+
|
22
|
+
PyerualJetwork document: https://github.com/HCB06/Anaplan/blob/main/Welcome_to_Anaplan/ANAPLAN_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
|
23
|
+
|
24
|
+
- Author: Hasan Can Beydili
|
25
|
+
- YouTube: https://www.youtube.com/@HasanCanBeydili
|
26
|
+
- Linkedin: https://www.linkedin.com/in/hasan-can-beydili-77a1b9270/
|
27
|
+
- Instagram: https://www.instagram.com/canbeydilj
|
28
|
+
- Contact: tchasancan@gmail.com
|
29
|
+
"""
|
30
|
+
|
1
31
|
from tqdm import tqdm
|
2
32
|
import cupy as cp
|
3
33
|
from colorama import Fore, Style
|
@@ -1,15 +1,31 @@
|
|
1
1
|
"""
|
2
|
-
|
2
|
+
|
3
|
+
|
4
|
+
ENE (Eugenic NeuroEvolution)
|
5
|
+
============================
|
6
|
+
|
7
|
+
This module contains all the functions necessary for implementing and testing the ENE (Eugenic NeuroEvolution) algorithm.
|
8
|
+
For more information about the ENE algorithm: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PLAN/PLAN.pdf
|
9
|
+
|
10
|
+
Module functions:
|
11
|
+
-----------------
|
12
|
+
- evolver()
|
13
|
+
- define_genomes()
|
14
|
+
- evaluate()
|
15
|
+
- cross_over()
|
16
|
+
- mutation()
|
17
|
+
- dominant_parent_selection()
|
18
|
+
- second_parent_selection()
|
3
19
|
|
4
20
|
Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJetwork/ExampleCodes
|
5
21
|
|
6
22
|
PyerualJetwork document: https://github.com/HCB06/Anaplan/blob/main/Welcome_to_Anaplan/ANAPLAN_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
|
7
23
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
24
|
+
- Author: Hasan Can Beydili
|
25
|
+
- YouTube: https://www.youtube.com/@HasanCanBeydili
|
26
|
+
- Linkedin: https://www.linkedin.com/in/hasan-can-beydili-77a1b9270/
|
27
|
+
- Instagram: https://www.instagram.com/canbeydilj
|
28
|
+
- Contact: tchasancan@gmail.com
|
13
29
|
"""
|
14
30
|
|
15
31
|
import numpy as np
|
@@ -22,7 +38,7 @@ from .data_operations import normalization, non_neg_normalization
|
|
22
38
|
from .ui import loading_bars, initialize_loading_bar
|
23
39
|
from .activation_functions import apply_activation, all_activations
|
24
40
|
|
25
|
-
def define_genomes(input_shape, output_shape, population_size,
|
41
|
+
def define_genomes(input_shape, output_shape, population_size, neurons=[], activation_functions=[], dtype=np.float32):
|
26
42
|
"""
|
27
43
|
Initializes a population of genomes, where each genome is represented by a set of weights
|
28
44
|
and an associated activation function. Each genome is created with random weights and activation
|
@@ -36,17 +52,15 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
|
|
36
52
|
|
37
53
|
population_size (int): The number of genomes (individuals) in the population.
|
38
54
|
|
39
|
-
|
55
|
+
neurons (list[int], optional): If you dont want train PLAN model this parameter represents neuron count of each hidden layer for MLP. Default: [] (PLAN)
|
40
56
|
|
41
|
-
|
42
|
-
|
43
|
-
activation_functions (list[str], optional): If you dont want train PLAN model this parameter represents activation function of each hidden layer for MLP. Default: None (PLAN) NOTE: THIS EFFECTS HIDDEN LAYERS OUTPUT. NOT OUTPUT LAYER!
|
57
|
+
activation_functions (list[str], optional): If you dont want train PLAN model this parameter represents activation function of each hidden layer for MLP. Default: [] (PLAN) NOTE: THIS EFFECTS HIDDEN LAYERS OUTPUT. NOT OUTPUT LAYER!
|
44
58
|
|
45
59
|
dtype (numpy.dtype): Data type for the arrays. np.float32 by default. Example: np.float64 or np.float16.
|
46
60
|
|
47
61
|
Returns:
|
48
62
|
tuple: A tuple containing:
|
49
|
-
- population_weights (numpy.ndarray):
|
63
|
+
- population_weights (numpy.ndarray[numpy.ndarray]): representing the
|
50
64
|
weight matrices for each genome.
|
51
65
|
- population_activations (list): A list of activation functions applied to each genome.
|
52
66
|
|
@@ -56,6 +70,9 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
|
|
56
70
|
The weights for each genome are then modified by applying the corresponding activation function
|
57
71
|
and normalized using the `normalization()` function. (Max abs normalization.)
|
58
72
|
"""
|
73
|
+
|
74
|
+
hidden = len(neurons)
|
75
|
+
|
59
76
|
if hidden > 0:
|
60
77
|
population_weights = np.empty((population_size, hidden + 1), dtype=object)
|
61
78
|
population_activations = [[0] * (hidden) for _ in range(population_size)]
|
@@ -112,7 +129,7 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
|
|
112
129
|
|
113
130
|
|
114
131
|
def evolver(weights,
|
115
|
-
|
132
|
+
activations,
|
116
133
|
what_gen,
|
117
134
|
fitness,
|
118
135
|
weight_evolve=True,
|
@@ -148,7 +165,7 @@ def evolver(weights,
|
|
148
165
|
weights (numpy.ndarray): Array of weights for each genome.
|
149
166
|
(first returned value of define_genomes function)
|
150
167
|
|
151
|
-
|
168
|
+
activations (list[str]): A list of activation functions for each genome.
|
152
169
|
(second returned value of define_genomes function) NOTE!: 'activation potentiations' for PLAN 'activation functions' for MLP.
|
153
170
|
|
154
171
|
what_gen (int): The current generation number, used for informational purposes or logging.
|
@@ -242,7 +259,7 @@ def evolver(weights,
|
|
242
259
|
tuple: A tuple containing:
|
243
260
|
- weights (numpy.ndarray): The updated weights for the population after selection, crossover, and mutation.
|
244
261
|
The shape is (population_size, output_shape, input_shape).
|
245
|
-
-
|
262
|
+
- activations (list): The updated list of activation functions for the population.
|
246
263
|
|
247
264
|
Notes:
|
248
265
|
- **Selection Process**:
|
@@ -263,7 +280,7 @@ def evolver(weights,
|
|
263
280
|
|
264
281
|
Example:
|
265
282
|
```python
|
266
|
-
weights,
|
283
|
+
weights, activations = ene.evolver(weights, activations, 1, fitness, show_info=True, strategy='normal_selective', policy='aggressive')
|
267
284
|
```
|
268
285
|
|
269
286
|
- The function returns the updated weights and activations after processing based on the chosen strategy, policy, and mutation parameters.
|
@@ -327,7 +344,7 @@ def evolver(weights,
|
|
327
344
|
fitness = fitness[sort_indices]
|
328
345
|
weights = weights[sort_indices]
|
329
346
|
|
330
|
-
|
347
|
+
activations = [activations[i] for i in sort_indices]
|
331
348
|
|
332
349
|
### GENOMES ARE DIVIDED INTO TWO GROUPS: GOOD GENOMES AND BAD GENOMES:
|
333
350
|
|
@@ -335,8 +352,8 @@ def evolver(weights,
|
|
335
352
|
bad_weights = weights[:slice_center]
|
336
353
|
best_weight = np.copy(good_weights[-1]) if is_mlp is False else copy.deepcopy(good_weights[-1])
|
337
354
|
|
338
|
-
good_activations = list(
|
339
|
-
bad_activations = list(
|
355
|
+
good_activations = list(activations[slice_center:])
|
356
|
+
bad_activations = list(activations[:slice_center])
|
340
357
|
best_activations = good_activations[-1].copy() if isinstance(good_activations[-1], list) else good_activations[-1]
|
341
358
|
|
342
359
|
|
@@ -469,11 +486,11 @@ def evolver(weights,
|
|
469
486
|
else:
|
470
487
|
weights = np.vstack((child_W, mutated_W), dtype=dtype)
|
471
488
|
|
472
|
-
|
489
|
+
activations = child_act + mutated_act
|
473
490
|
|
474
491
|
if save_best_genome:
|
475
492
|
weights[0] = best_weight
|
476
|
-
|
493
|
+
activations[0] = best_activations
|
477
494
|
|
478
495
|
### INFO PRINTING CONSOLE
|
479
496
|
|
@@ -512,10 +529,10 @@ def evolver(weights,
|
|
512
529
|
|
513
530
|
if weight_evolve is False: weights = origin_weights
|
514
531
|
|
515
|
-
return weights,
|
532
|
+
return weights, activations
|
516
533
|
|
517
534
|
|
518
|
-
def evaluate(Input, weights,
|
535
|
+
def evaluate(Input, weights, activations, is_mlp=False):
|
519
536
|
"""
|
520
537
|
Evaluates the performance of a population of genomes, applying different activation functions
|
521
538
|
and weights depending on whether reinforcement learning mode is enabled or not.
|
@@ -525,7 +542,7 @@ def evaluate(Input, weights, activation_potentiations, is_mlp=False):
|
|
525
542
|
a genome (A list of input features for each genome, or a single set of input features for one genome).
|
526
543
|
weights (list or numpy.ndarray): A list or 2D numpy array of weights corresponding to each genome
|
527
544
|
in `x_population`. This determines the strength of connections.
|
528
|
-
|
545
|
+
activations (list or str): A list where each entry represents an activation function
|
529
546
|
or a potentiation strategy applied to each genome. If only one
|
530
547
|
activation function is used, this can be a single string.
|
531
548
|
is_mlp (bool, optional): Evaluate PLAN model or MLP model ? Default: False (PLAN)
|
@@ -536,7 +553,7 @@ def evaluate(Input, weights, activation_potentiations, is_mlp=False):
|
|
536
553
|
|
537
554
|
Example:
|
538
555
|
```python
|
539
|
-
outputs = evaluate(Input, weights,
|
556
|
+
outputs = evaluate(Input, weights, activations)
|
540
557
|
```
|
541
558
|
|
542
559
|
- The function returns a list of outputs after processing the population, where each element corresponds to
|
@@ -544,16 +561,16 @@ def evaluate(Input, weights, activation_potentiations, is_mlp=False):
|
|
544
561
|
"""
|
545
562
|
### THE OUTPUTS ARE RETURNED, WHERE EACH GENOME'S OUTPUT MATCHES ITS INDEX:
|
546
563
|
|
547
|
-
if isinstance(
|
548
|
-
|
549
|
-
elif isinstance(
|
550
|
-
|
564
|
+
if isinstance(activations, str):
|
565
|
+
activations = [activations]
|
566
|
+
elif isinstance(activations, list):
|
567
|
+
activations = [item if isinstance(item, list) or isinstance(item, str) else [item] for item in activations]
|
551
568
|
|
552
569
|
|
553
570
|
if is_mlp:
|
554
571
|
layer = Input
|
555
572
|
for i in range(len(weights)):
|
556
|
-
if i != len(weights) - 1 and i != 0: layer = apply_activation(layer,
|
573
|
+
if i != len(weights) - 1 and i != 0: layer = apply_activation(layer, activations[i])
|
557
574
|
|
558
575
|
layer = layer @ weights[i].T
|
559
576
|
|
@@ -561,7 +578,7 @@ def evaluate(Input, weights, activation_potentiations, is_mlp=False):
|
|
561
578
|
|
562
579
|
else:
|
563
580
|
|
564
|
-
Input = apply_activation(Input,
|
581
|
+
Input = apply_activation(Input, activations)
|
565
582
|
result = Input @ weights.T
|
566
583
|
|
567
584
|
return result
|
@@ -1,15 +1,31 @@
|
|
1
1
|
"""
|
2
|
-
|
2
|
+
|
3
|
+
|
4
|
+
ENE (Eugenic NeuroEvolution) on CUDA
|
5
|
+
======================================
|
6
|
+
|
7
|
+
This module contains all the functions necessary for implementing and testing the ENE (Eugenic NeuroEvolution) algorithm on CUDA GPU.
|
8
|
+
For more information about the ENE algorithm: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PLAN/PLAN.pdf
|
9
|
+
|
10
|
+
Module functions:
|
11
|
+
-----------------
|
12
|
+
- evolver()
|
13
|
+
- define_genomes()
|
14
|
+
- evaluate()
|
15
|
+
- cross_over()
|
16
|
+
- mutation()
|
17
|
+
- dominant_parent_selection()
|
18
|
+
- second_parent_selection()
|
3
19
|
|
4
20
|
Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJetwork/ExampleCodes
|
5
21
|
|
6
22
|
PyerualJetwork document: https://github.com/HCB06/Anaplan/blob/main/Welcome_to_Anaplan/ANAPLAN_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
|
7
23
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
24
|
+
- Author: Hasan Can Beydili
|
25
|
+
- YouTube: https://www.youtube.com/@HasanCanBeydili
|
26
|
+
- Linkedin: https://www.linkedin.com/in/hasan-can-beydili-77a1b9270/
|
27
|
+
- Instagram: https://www.instagram.com/canbeydilj
|
28
|
+
- Contact: tchasancan@gmail.com
|
13
29
|
"""
|
14
30
|
|
15
31
|
import cupy as cp
|
@@ -23,7 +39,7 @@ from .data_operations_cuda import normalization, non_neg_normalization
|
|
23
39
|
from .ui import loading_bars, initialize_loading_bar
|
24
40
|
from .activation_functions_cuda import apply_activation, all_activations
|
25
41
|
|
26
|
-
def define_genomes(input_shape, output_shape, population_size,
|
42
|
+
def define_genomes(input_shape, output_shape, population_size, neurons=[], activation_functions=[], dtype=cp.float32):
|
27
43
|
"""
|
28
44
|
Initializes a population of genomes, where each genome is represented by a set of weights
|
29
45
|
and an associated activation function. Each genome is created with random weights and activation
|
@@ -36,8 +52,6 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
|
|
36
52
|
output_shape (int): The number of output features for the neural network.
|
37
53
|
|
38
54
|
population_size (int): The number of genomes (individuals) in the population.
|
39
|
-
|
40
|
-
hidden (int, optional): If you dont want train PLAN model this parameter represents a hidden layer count for MLP model. Default: 0 (PLAN)
|
41
55
|
|
42
56
|
neurons (list[int], optional): If you dont want train PLAN model this parameter represents neuron count of each hidden layer for MLP. Default: None (PLAN)
|
43
57
|
|
@@ -47,7 +61,7 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
|
|
47
61
|
|
48
62
|
Returns:
|
49
63
|
tuple: A tuple containing:
|
50
|
-
- population_weights (cupy.ndarray):
|
64
|
+
- population_weights (list[cupy.ndarray]): representing the
|
51
65
|
weight matrices for each genome.
|
52
66
|
- population_activations (list): A list of activation functions applied to each genome.
|
53
67
|
|
@@ -57,6 +71,9 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
|
|
57
71
|
The weights for each genome are then modified by applying the corresponding activation function
|
58
72
|
and normalized using the `normalization()` function. (Max abs normalization.)
|
59
73
|
"""
|
74
|
+
|
75
|
+
hidden = len(neurons)
|
76
|
+
|
60
77
|
if hidden > 0:
|
61
78
|
population_weights = [[0] * (hidden + 1) for _ in range(population_size)]
|
62
79
|
population_activations = [[0] * (hidden) for _ in range(population_size)]
|
@@ -112,7 +129,7 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
|
|
112
129
|
return cp.array(population_weights, dtype=dtype), population_activations
|
113
130
|
|
114
131
|
def evolver(weights,
|
115
|
-
|
132
|
+
activations,
|
116
133
|
what_gen,
|
117
134
|
fitness,
|
118
135
|
weight_evolve=True,
|
@@ -148,7 +165,7 @@ def evolver(weights,
|
|
148
165
|
weights (cupy.ndarray): Array of weights for each genome.
|
149
166
|
(first returned value of define_genomes function)
|
150
167
|
|
151
|
-
|
168
|
+
activations (list[str]): A list of activation functions for each genome.
|
152
169
|
(second returned value of define_genomes function) NOTE!: 'activation potentiations' for PLAN 'activation functions' for MLP.
|
153
170
|
|
154
171
|
what_gen (int): The current generation number, used for informational purposes or logging.
|
@@ -242,7 +259,7 @@ def evolver(weights,
|
|
242
259
|
tuple: A tuple containing:
|
243
260
|
- weights (numpy.ndarray): The updated weights for the population after selection, crossover, and mutation.
|
244
261
|
The shape is (population_size, output_shape, input_shape).
|
245
|
-
-
|
262
|
+
- activations (list): The updated list of activation functions for the population.
|
246
263
|
|
247
264
|
Notes:
|
248
265
|
- **Selection Process**:
|
@@ -263,7 +280,7 @@ def evolver(weights,
|
|
263
280
|
|
264
281
|
Example:
|
265
282
|
```python
|
266
|
-
weights,
|
283
|
+
weights, activations = ene_cuda.evolver(weights, activations, 1, fitness, show_info=True, strategy='normal_selective', policy='aggressive')
|
267
284
|
```
|
268
285
|
|
269
286
|
- The function returns the updated weights and activations after processing based on the chosen strategy, policy, and mutation parameters.
|
@@ -336,7 +353,7 @@ def evolver(weights,
|
|
336
353
|
fitness = fitness[sort_indices]
|
337
354
|
weights = weights[sort_indices]
|
338
355
|
|
339
|
-
|
356
|
+
activations = [activations[int(i)] for i in sort_indices]
|
340
357
|
|
341
358
|
### GENOMES ARE DIVIDED INTO TWO GROUPS: GOOD GENOMES AND BAD GENOMES:
|
342
359
|
|
@@ -344,8 +361,8 @@ def evolver(weights,
|
|
344
361
|
bad_weights = weights[:slice_center]
|
345
362
|
best_weight = cp.copy(good_weights[-1])
|
346
363
|
|
347
|
-
good_activations = list(
|
348
|
-
bad_activations = list(
|
364
|
+
good_activations = list(activations[slice_center:])
|
365
|
+
bad_activations = list(activations[:slice_center])
|
349
366
|
best_activations = good_activations[-1].copy() if isinstance(good_activations[-1], list) else good_activations[-1]
|
350
367
|
|
351
368
|
|
@@ -487,11 +504,11 @@ def evolver(weights,
|
|
487
504
|
else:
|
488
505
|
weights = cp.vstack((child_W, mutated_W), dtype=dtype)
|
489
506
|
|
490
|
-
|
507
|
+
activations = child_act + mutated_act
|
491
508
|
|
492
509
|
if save_best_genome:
|
493
510
|
weights[0] = best_weight
|
494
|
-
|
511
|
+
activations[0] = best_activations
|
495
512
|
|
496
513
|
### INFO PRINTING CONSOLE
|
497
514
|
|
@@ -529,10 +546,10 @@ def evolver(weights,
|
|
529
546
|
|
530
547
|
if weight_evolve is False: weights = origin_weights
|
531
548
|
|
532
|
-
return weights,
|
549
|
+
return weights, activations
|
533
550
|
|
534
551
|
|
535
|
-
def evaluate(Input, weights,
|
552
|
+
def evaluate(Input, weights, activations, is_mlp=False):
|
536
553
|
"""
|
537
554
|
Evaluates the performance of a population of genomes, applying different activation functions
|
538
555
|
and weights depending on whether reinforcement learning mode is enabled or not.
|
@@ -544,7 +561,7 @@ def evaluate(Input, weights, activation_potentiations, is_mlp=False):
|
|
544
561
|
weights (list or cupy.ndarray): A list or 2D numpy array of weights corresponding to each genome
|
545
562
|
in `x_population`. This determines the strength of connections.
|
546
563
|
|
547
|
-
|
564
|
+
activations (list or str): A list where each entry represents an activation function
|
548
565
|
or a potentiation strategy applied to each genome. If only one
|
549
566
|
activation function is used, this can be a single string.
|
550
567
|
is_mlp (bool, optional): Evaluate PLAN model or MLP model ? Default: False (PLAN)
|
@@ -555,7 +572,7 @@ def evaluate(Input, weights, activation_potentiations, is_mlp=False):
|
|
555
572
|
|
556
573
|
Example:
|
557
574
|
```python
|
558
|
-
outputs = evaluate(Input, weights,
|
575
|
+
outputs = evaluate(Input, weights, activations)
|
559
576
|
```
|
560
577
|
|
561
578
|
- The function returns a list of outputs after processing the population, where each element corresponds to
|
@@ -563,23 +580,23 @@ def evaluate(Input, weights, activation_potentiations, is_mlp=False):
|
|
563
580
|
"""
|
564
581
|
### THE OUTPUTS ARE RETURNED WHERE EACH GENOME'S OUTPUT MATCHES ITS INDEX:
|
565
582
|
|
566
|
-
if isinstance(
|
567
|
-
|
583
|
+
if isinstance(activations, str):
|
584
|
+
activations = [activations]
|
568
585
|
else:
|
569
|
-
|
586
|
+
activations = [item if isinstance(item, list) else [item] for item in activations]
|
570
587
|
|
571
588
|
if is_mlp:
|
572
589
|
|
573
590
|
layer = Input
|
574
591
|
for i in range(len(weights)):
|
575
|
-
if i != len(weights) - 1: layer = apply_activation(layer,
|
592
|
+
if i != len(weights) - 1: layer = apply_activation(layer, activations[i])
|
576
593
|
layer = layer @ weights[i].T
|
577
594
|
|
578
595
|
return layer
|
579
596
|
|
580
597
|
else:
|
581
598
|
|
582
|
-
Input = apply_activation(Input,
|
599
|
+
Input = apply_activation(Input, activations)
|
583
600
|
result = Input @ weights.T
|
584
601
|
|
585
602
|
return result
|
pyerualjetwork/help.py
CHANGED
@@ -12,6 +12,6 @@ def activation_potentiation():
|
|
12
12
|
def docs_and_examples():
|
13
13
|
|
14
14
|
print('PLAN document: https://github.com/HCB06/Anaplan/tree/main/Welcome_to_PLAN\n')
|
15
|
-
print('PLAN examples: https://github.com/HCB06/Anaplan/tree/main/
|
16
|
-
print('PLANEAT examples: https://github.com/HCB06/Anaplan/tree/main/
|
15
|
+
print('PLAN examples: https://github.com/HCB06/Anaplan/tree/main/Welcome_to_PyerualJetwork/ExampleCodes\n')
|
16
|
+
print('PLANEAT examples: https://github.com/HCB06/Anaplan/tree/main/Welcome_to_PyerualJetwork/ExampleCodes/ENE\n')
|
17
17
|
print('Anaplan document and examples: https://github.com/HCB06/Anaplan/tree/main/Welcome_to_Anaplan')
|
@@ -1,3 +1,29 @@
|
|
1
|
+
"""
|
2
|
+
|
3
|
+
|
4
|
+
Memory Operations
|
5
|
+
=================
|
6
|
+
This module hosts functions for managing all operational processes related to memory management,
|
7
|
+
including transferring data between CPU and GPU memory and retrieving memory information.
|
8
|
+
|
9
|
+
Module functions:
|
10
|
+
-----------------
|
11
|
+
- get_available_cpu_memory()
|
12
|
+
- transfer_to_cpu()
|
13
|
+
- transfer_to_gpu()
|
14
|
+
- optimize_labels()
|
15
|
+
|
16
|
+
Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJetwork/ExampleCodes
|
17
|
+
|
18
|
+
PyerualJetwork document: https://github.com/HCB06/Anaplan/blob/main/Welcome_to_Anaplan/ANAPLAN_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
|
19
|
+
|
20
|
+
- Author: Hasan Can Beydili
|
21
|
+
- YouTube: https://www.youtube.com/@HasanCanBeydili
|
22
|
+
- Linkedin: https://www.linkedin.com/in/hasan-can-beydili-77a1b9270/
|
23
|
+
- Instagram: https://www.instagram.com/canbeydilj
|
24
|
+
- Contact: tchasancan@gmail.com
|
25
|
+
"""
|
26
|
+
|
1
27
|
import psutil
|
2
28
|
import numpy as np
|
3
29
|
import cupy as cp
|