pyerualjetwork 5.47b0__py3-none-any.whl → 5.48a0__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.
@@ -42,7 +42,7 @@ PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welco
42
42
  - Contact: tchasancan@gmail.com
43
43
  """
44
44
 
45
- __version__ = "5.47b0"
45
+ __version__ = "5.48a0"
46
46
  __update__ = """* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES
47
47
  * PyerualJetwork Homepage: https://github.com/HCB06/PyerualJetwork/tree/main
48
48
  * PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
@@ -200,6 +200,18 @@ def sine_offset(x, beta=0.0):
200
200
  return np.sin(x + beta)
201
201
 
202
202
 
203
+ def apply_activation_derivative(x, name):
204
+ if name == 'sigmoid':
205
+ s = apply_activation(x, 'sigmoid')
206
+ return s * (1 - s)
207
+ elif name == 'relu':
208
+ return (x > 0).astype(float)
209
+ elif name == 'tanh':
210
+ return 1 - np.tanh(x) ** 2
211
+ else:
212
+ raise ValueError(f"Unknown activation derivative: {name}")
213
+
214
+
203
215
  def apply_activation(Input, activation_list):
204
216
  """
205
217
  Applies activation functions for inputs
@@ -251,4 +263,5 @@ def apply_activation(Input, activation_list):
251
263
 
252
264
  except Exception as e:
253
265
  warnings.warn(f"Error in activation processing: {str(e)}", RuntimeWarning)
254
- return Input
266
+ return Input
267
+
@@ -18,4 +18,14 @@ def binary_crossentropy(y_true_batch, y_pred_batch):
18
18
  losses = -np.mean(y_true_batch * np.log(y_pred_batch) + (1 - y_true_batch) * np.log(1 - y_pred_batch), axis=1)
19
19
 
20
20
  mean_loss = np.mean(losses)
21
- return mean_loss
21
+ return mean_loss
22
+
23
+ def categorical_crossentropy_derivative(y_true, y_pred):
24
+ epsilon = 1e-7
25
+ y_pred = np.clip(y_pred, epsilon, 1. - epsilon)
26
+ return - (y_true / y_pred)
27
+
28
+ def binary_crossentropy_derivative(y_true, y_pred):
29
+ epsilon = 1e-7
30
+ y_pred = np.clip(y_pred, epsilon, 1. - epsilon)
31
+ return (y_pred - y_true) / (y_pred * (1 - y_pred))
pyerualjetwork/nn.py CHANGED
@@ -95,14 +95,13 @@ def plan_fit(
95
95
  Returns:
96
96
  numpyarray: (Weight matrix).
97
97
  """
98
-
98
+
99
+ from .cpu.data_ops import normalization
99
100
  if not cuda:
100
- from .cpu.data_ops import normalization
101
- from .cpu.activation_functions import apply_activation
101
+ from cpu.activation_functions import apply_activation
102
102
  array_type = np
103
103
 
104
104
  else:
105
- from .cuda.data_ops import normalization
106
105
  from .cuda.activation_functions import apply_activation
107
106
  array_type = cp
108
107
 
@@ -119,7 +118,7 @@ def plan_fit(
119
118
 
120
119
  weight += y_train.T @ x_train if not cuda else cp.array(y_train).T @ cp.array(x_train)
121
120
 
122
- return normalization(weight, dtype=dtype)
121
+ return normalization(weight.get() if cuda else weight,dtype=dtype)
123
122
 
124
123
 
125
124
  def learn(x_train, y_train, optimizer, template_model, gen, pop_size, fit_start=True, batch_size=1,
@@ -199,7 +198,8 @@ def learn(x_train, y_train, optimizer, template_model, gen, pop_size, fit_start=
199
198
  tuple: A list for model parameters: [Weight matrix, Train Preds, Train Accuracy, [Activations functions]].
200
199
  """
201
200
 
202
- from .ene import define_genomes
201
+ from .optimizers.ene import define_genomes
202
+ from .optimizers.backprop import backprop_update_general
203
203
  from .cpu.visualizations import display_decision_boundary_history, create_decision_boundary_hist, plot_decision_boundary
204
204
 
205
205
  if cuda is False:
@@ -315,16 +315,11 @@ def learn(x_train, y_train, optimizer, template_model, gen, pop_size, fit_start=
315
315
  if model_type == 'PLAN' and transfer_learning:
316
316
  if i == gen_copy[0]:
317
317
 
318
- if cuda:
319
- array_type = cp
320
- else:
321
- array_type = np
322
-
323
318
  model_type = 'PTNN'
324
319
  neurons = neurons_copy
325
320
 
326
321
  for individual in range(len(weight_pop)):
327
- weight_pop[individual] = array_type.copy(best_weight)
322
+ weight_pop[individual] = np.copy(best_weight)
328
323
  activation_potentiations[individual] = final_activations.copy() if isinstance(final_activations, list) else final_activations
329
324
 
330
325
  activation_potentiation = activation_potentiations[0]
@@ -338,13 +333,13 @@ def learn(x_train, y_train, optimizer, template_model, gen, pop_size, fit_start=
338
333
  for l in range(1, len(weight_pop[0])):
339
334
  original_shape = weight_pop[0][l].shape
340
335
 
341
- identity_matrix = array_type.eye(original_shape[0], original_shape[1], dtype=weight_pop[0][l].dtype)
336
+ identity_matrix = np.eye(original_shape[0], original_shape[1], dtype=weight_pop[0][l].dtype)
342
337
  weight_pop[0][l] = identity_matrix
343
338
 
344
339
  for l in range(len(weight_pop)):
345
- weight_pop[l][0] = array_type.copy(best_weight)
340
+ weight_pop[l][0] = np.copy(best_weight)
346
341
 
347
- best_weight = array_type.array(weight_pop[0], dtype=object)
342
+ best_weight = np.array(weight_pop[0], dtype=object)
348
343
  final_activations = act_pop[0]
349
344
  is_mlp = True
350
345
  fit_start = False
@@ -359,6 +354,9 @@ def learn(x_train, y_train, optimizer, template_model, gen, pop_size, fit_start=
359
354
 
360
355
  x_train_batch, y_train_batch = batcher(x_train, y_train, batch_size=batch_size)
361
356
 
357
+ if optimizer == 'backprop':
358
+ pop_size = 1
359
+
362
360
  for j in range(pop_size):
363
361
 
364
362
  if fit_start is True and i == 0:
@@ -375,6 +373,12 @@ def learn(x_train, y_train, optimizer, template_model, gen, pop_size, fit_start=
375
373
  weight_pop[j] = plan_fit(x_train_batch, y_train_batch, activations=act_pop[j], cuda=cuda, auto_normalization=auto_normalization, dtype=dtype)
376
374
 
377
375
 
376
+ if optimizer == 'backprop':
377
+ weight_pop[0], current_loss = backprop_update_general(
378
+ x_train_batch, y_train_batch, weight_pop[0], act_pop[0],
379
+ learning_rate=0.01
380
+ )
381
+
378
382
  model = evaluate(x_train_batch, y_train_batch, W=weight_pop[j], activations=act_pop[j], activation_potentiations=activation_potentiations[j], auto_normalization=auto_normalization, cuda=cuda, model_type=model_type)
379
383
  acc = model[get_acc()]
380
384
 
@@ -535,8 +539,9 @@ def learn(x_train, y_train, optimizer, template_model, gen, pop_size, fit_start=
535
539
  if model_type == 'PLAN': weight_pop = np.array(weight_pop, copy=False, dtype=dtype)
536
540
  else: weight_pop = np.array(weight_pop, copy=False, dtype=object)
537
541
 
538
- weight_pop, act_pop = optimizer(weight_pop, act_pop, i, np.array(target_pop, dtype=dtype, copy=False), weight_evolve=weight_evolve, is_mlp=is_mlp, bar_status=False)
539
- target_pop = []
542
+ if optimizer != 'backprop':
543
+ weight_pop, act_pop = optimizer(weight_pop, act_pop, i, np.array(target_pop, dtype=dtype, copy=False), weight_evolve=weight_evolve, is_mlp=is_mlp, bar_status=False)
544
+ target_pop = []
540
545
 
541
546
  # Early stopping check
542
547
  if early_stop == True and i > 0:
@@ -0,0 +1,43 @@
1
+ """
2
+
3
+ Optimizers
4
+ ==============
5
+ PyereualJetwork is a large wide GPU-accelerated machine learning library in Python designed for professionals and researchers.
6
+ It features PLAN, MLP Deep Learning and PTNN 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
+ PyerualJetwork Main Modules:
13
+ ----------------------------
14
+ - nn
15
+ - ene
16
+ - model_ops
17
+
18
+ CPU Main Modules:
19
+ ---------------------------
20
+ - cpu.data_ops
21
+
22
+ GPU Main Modules:
23
+ ---------------------------
24
+ - cuda.data_ops
25
+
26
+ Memory Module:
27
+ --------------
28
+ - memory_ops
29
+
30
+ Issue Solver Module:
31
+ --------------
32
+ - issue_solver
33
+
34
+ Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJetwork/ExampleCodes
35
+
36
+ PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
37
+
38
+ - Creator: Hasan Can Beydili
39
+ - YouTube: https://www.youtube.com/@HasanCanBeydili
40
+ - Linkedin: https://www.linkedin.com/in/hasan-can-beydili-77a1b9270/
41
+ - Instagram: https://www.instagram.com/canbeydilj
42
+ - Contact: tchasancan@gmail.com
43
+ """
@@ -0,0 +1,48 @@
1
+ import numpy as np
2
+
3
+ from ..cpu.loss_functions import categorical_crossentropy, categorical_crossentropy_derivative
4
+ from ..cpu.activation_functions import apply_activation, apply_activation_derivative
5
+
6
+ def backprop_update_general(
7
+ X, y, weights, activations_list,
8
+ learning_rate=0.01
9
+ ):
10
+ """
11
+ X: (batch_size, input_dim)
12
+ y: (batch_size, output_dim)
13
+ weights: numpy object array, her eleman (in_dim, out_dim) şeklinde ağırlık matrisi
14
+ activations_list: her katman için aktivasyon ismi listesi (örn: ['relu', 'sigmoid', 'softmax'])
15
+ apply_activation: x ve aktivasyon adı alır, çıktı verir
16
+ apply_activation_derivative: x ve aktivasyon adı alır, türev verir
17
+ loss_function: y_true ve y_pred alır, loss döner
18
+ loss_derivative: y_true ve y_pred alır, d_loss/d_y_pred döner
19
+ learning_rate: öğrenme oranı
20
+ """
21
+ num_layers = len(weights) + 1
22
+ activations = [X]
23
+ inputs = []
24
+
25
+ # Forward pass
26
+ for i, w in enumerate(weights):
27
+ inp = np.dot(activations[-1], w)
28
+ out = apply_activation(inp, activations_list[i])
29
+ inputs.append(inp)
30
+ activations.append(out)
31
+
32
+ y_pred = activations[-1]
33
+ loss = categorical_crossentropy(y, y_pred)
34
+
35
+ # Calculate output error (using provided derivative)
36
+ error = categorical_crossentropy_derivative(y, y_pred)
37
+ deltas = [error * apply_activation_derivative(inputs[-1], activations_list[-1])]
38
+
39
+ # Backpropagate
40
+ for i in reversed(range(len(weights) - 1)):
41
+ delta = np.dot(deltas[0], weights[i + 1].T) * apply_activation_derivative(inputs[i], activations_list[i])
42
+ deltas.insert(0, delta)
43
+
44
+ # Update weights
45
+ for i in range(len(weights)):
46
+ weights[i] += learning_rate * np.dot(activations[i].T, deltas[i])
47
+
48
+ return weights, loss
@@ -1,4 +1,4 @@
1
- """
1
+ """
2
2
 
3
3
 
4
4
  ENE (Eugenic NeuroEvolution)
@@ -33,9 +33,9 @@ import math
33
33
  import copy
34
34
 
35
35
  ### LIBRARY IMPORTS ###
36
- from .cpu.data_ops import non_neg_normalization
37
- from .ui import loading_bars, initialize_loading_bar
38
- from .cpu.activation_functions import all_activations
36
+ from ..cpu.data_ops import non_neg_normalization
37
+ from ..ui import loading_bars, initialize_loading_bar
38
+ from ..cpu.activation_functions import all_activations
39
39
 
40
40
  def define_genomes(input_shape, output_shape, population_size, neurons=[], activation_functions=[], dtype=np.float32):
41
41
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 5.47b0
3
+ Version: 5.48a0
4
4
  Summary: PyereualJetwork is a GPU-accelerated machine learning library in Python for professionals and researchers. It features PLAN, MLP, Deep Learning training, and ENE (Eugenic NeuroEvolution) for genetic optimization, applicable to genetic algorithms or Reinforcement Learning (RL). The library includes data pre-processing, visualizations, model saving/loading, prediction, evaluation, training, and detailed or simplified memory management.
5
5
  Author: Hasan Can Beydili
6
6
  Author-email: tchasancan@gmail.com
@@ -1,18 +1,17 @@
1
- pyerualjetwork/__init__.py,sha256=83JqHyw4IH4Q7UYP7dEobblHD-olA-17hUNYtN9cQkU,3022
2
- pyerualjetwork/ene.py,sha256=8g2XEPRm3NLqSaN7xihIj1xXdIjSrl8Q69zqWTIXPI4,42142
1
+ pyerualjetwork/__init__.py,sha256=80ynIu2ljiuU0i-1VfkQ9ZK7LstUGJFRTm_KFWgiKeU,3022
3
2
  pyerualjetwork/fitness_functions.py,sha256=D9JVCr9DFid_xXgBD4uCKxdW2k10MVDE5HZRSOK4Igg,1237
4
3
  pyerualjetwork/help.py,sha256=sn9jBzXkQsTZvdgsUXUpSs_BbYYIgY3whofg6dj8peI,848
5
4
  pyerualjetwork/issue_solver.py,sha256=uay_9XK6xWnLmK2P_BeyDQlyNXzg_zYffnXYd228wZk,4102
6
5
  pyerualjetwork/memory_ops.py,sha256=TUFh9SYWCKL6N-vNdWId_EwU313TuZomQCHOrltrD-4,14280
7
6
  pyerualjetwork/model_ops.py,sha256=39eUKrj0VKYiEYWKcq1U8O0TV_QMrxkuy8IhCHQsEcw,25101
8
- pyerualjetwork/nn.py,sha256=3r9lxrrUYwbrqx84AhflcPPvbaCwwkpnXF01g8s7v9w,36835
7
+ pyerualjetwork/nn.py,sha256=Ag8HEaJxsFdEcormqRgYIkdth7yI20IeqQHmKliiso8,37087
9
8
  pyerualjetwork/old_cpu_model_ops.py,sha256=1KNgjUeYCO_TsA5RtbNiuIiBJzq8-rL2dE6jxKqCBU0,21481
10
9
  pyerualjetwork/old_cuda_model_ops.py,sha256=KAscAd8e_I8Vqdd9BJaHd6-IG6fhxFglAFxys0sqmEo,23079
11
10
  pyerualjetwork/ui.py,sha256=JBTFYz5R24XwNKhA3GSW-oYAoiIBxAE3kFGXkvm5gqw,656
12
11
  pyerualjetwork/cpu/__init__.py,sha256=9apRbPqvGKLJwyI3Md6R5a478YbZ7kIq0dRRa_lqgrY,789
13
- pyerualjetwork/cpu/activation_functions.py,sha256=zZSoOQ452Ykp_RsHVxklxesJmmFgufyIB4F3WQjudEQ,6689
12
+ pyerualjetwork/cpu/activation_functions.py,sha256=NH0TDmAS9CRlviXAaC2xa4zUGU_WyZRWjCeWjXV5-N4,7054
14
13
  pyerualjetwork/cpu/data_ops.py,sha256=SPsIcjU0JPHfsnEmGjD8q-yTlpgYk-KPOPJ44dfp-nU,16143
15
- pyerualjetwork/cpu/loss_functions.py,sha256=6PyBI232SQRGuFnG3LDGvnv_PUdWzT2_2mUODJiejGI,618
14
+ pyerualjetwork/cpu/loss_functions.py,sha256=w3eQREZBPS0cnHJ4637MlLF5xUsIxZTOtCQhicVH86s,969
16
15
  pyerualjetwork/cpu/metrics.py,sha256=NF8FARAqtuGlf4omVkQT4pOQZy7uePqzuHZGX9Y_Pn4,6076
17
16
  pyerualjetwork/cpu/visualizations.py,sha256=RcEZXX-U3BStOna1-C_a7z2VpXHuLAigeg1pD4u8I9I,26923
18
17
  pyerualjetwork/cuda/__init__.py,sha256=Kja6OmNaJ0giOhRNYw9hgGkh5N4F1EUS2v94E_rmp2k,839
@@ -21,7 +20,10 @@ pyerualjetwork/cuda/data_ops.py,sha256=k7NX-ckZ6-NwvioigACUHrekG7L5lO4bzTtQbBwH1
21
20
  pyerualjetwork/cuda/loss_functions.py,sha256=C93IZJcrOpT6HMK9x1O4AHJWXYTkN5WZiqdssPbvAPk,617
22
21
  pyerualjetwork/cuda/metrics.py,sha256=PjDBoRvr6va8vRvDIJJGBO4-I4uumrk3NCM1Vz4NJTo,5054
23
22
  pyerualjetwork/cuda/visualizations.py,sha256=2mHE7iqqsN3K6xtCnemS4o_YWGS0bIV2IxF4cG6Ur9k,20090
24
- pyerualjetwork-5.47b0.dist-info/METADATA,sha256=-jbrSF5DZLdVFjMi80xETm6k8NKrbFPXgg0GW9ILqjc,7990
25
- pyerualjetwork-5.47b0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
26
- pyerualjetwork-5.47b0.dist-info/top_level.txt,sha256=BRyt62U_r3ZmJpj-wXNOoA345Bzamrj6RbaWsyW4tRg,15
27
- pyerualjetwork-5.47b0.dist-info/RECORD,,
23
+ pyerualjetwork/optimizers/__init__.py,sha256=vMHWczFD28ndwipUM4diF5-_9hV1sU4Q_Pi5q6iK9X8,1400
24
+ pyerualjetwork/optimizers/backprop.py,sha256=FoUcV_ljMSRpUp4HIt0KhC4cRY-YYeYYPyFzdRu_Fdw,1868
25
+ pyerualjetwork/optimizers/ene.py,sha256=JX8hXtd-TpsUca-YrRLbGiUl-Bn2bmBxrkQsX7q7KIo,42144
26
+ pyerualjetwork-5.48a0.dist-info/METADATA,sha256=_xHtppTJUQ3zSnUz7pY3nAByTMo5RcnFVZugDFfe1d0,7990
27
+ pyerualjetwork-5.48a0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
28
+ pyerualjetwork-5.48a0.dist-info/top_level.txt,sha256=BRyt62U_r3ZmJpj-wXNOoA345Bzamrj6RbaWsyW4tRg,15
29
+ pyerualjetwork-5.48a0.dist-info/RECORD,,