pyerualjetwork 4.1.8b7__tar.gz → 4.1.9__tar.gz

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.
Files changed (28) hide show
  1. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/PKG-INFO +1 -1
  2. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/__init__.py +1 -1
  3. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/data_operations.py +1 -1
  4. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/plan.py +22 -57
  5. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/plan_cuda.py +20 -35
  6. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/planeat.py +1 -1
  7. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/planeat_cuda.py +1 -1
  8. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/visualizations_cuda.py +1 -1
  9. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork.egg-info/PKG-INFO +1 -1
  10. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/setup.py +1 -1
  11. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/README.md +0 -0
  12. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/activation_functions.py +0 -0
  13. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/activation_functions_cuda.py +0 -0
  14. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/data_operations_cuda.py +0 -0
  15. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/help.py +0 -0
  16. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/loss_functions.py +0 -0
  17. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/loss_functions_cuda.py +0 -0
  18. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/memory_operations.py +0 -0
  19. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/metrics.py +0 -0
  20. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/metrics_cuda.py +0 -0
  21. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/model_operations.py +0 -0
  22. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/model_operations_cuda.py +0 -0
  23. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/ui.py +0 -0
  24. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork/visualizations.py +0 -0
  25. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork.egg-info/SOURCES.txt +0 -0
  26. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork.egg-info/dependency_links.txt +0 -0
  27. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/pyerualjetwork.egg-info/top_level.txt +0 -0
  28. {pyerualjetwork-4.1.8b7 → pyerualjetwork-4.1.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 4.1.8b7
3
+ Version: 4.1.9
4
4
  Summary: PyerualJetwork is a machine learning library written in Python for professionals, incorporating advanced, unique, new, and modern techniques.
5
5
  Author: Hasan Can Beydili
6
6
  Author-email: tchasancan@gmail.com
@@ -48,7 +48,7 @@ for package_name in package_names:
48
48
 
49
49
  print(f"PyerualJetwork is ready to use with {err} errors")
50
50
 
51
- __version__ = "4.1.8b7"
51
+ __version__ = "4.1.9"
52
52
  __update__ = "* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES\n* PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf\n* YouTube tutorials: https://www.youtube.com/@HasanCanBeydili"
53
53
 
54
54
  def print_version(__version__):
@@ -11,7 +11,7 @@ def encode_one_hot(y_train, y_test=None, summary=False):
11
11
  Args:
12
12
  y_train (numpy.ndarray): Train label data.
13
13
  y_test (numpy.ndarray): Test label data one-hot encoded. (optional).
14
- summary (bool): If True, prints the class-to-index mapping. Default: False
14
+ summary (bool, optional): If True, prints the class-to-index mapping. Default: False
15
15
 
16
16
  Returns:
17
17
  tuple: One-hot encoded y_train and (if given) y_test.
@@ -16,6 +16,7 @@ PYERUALJETWORK document: https://github.com/HCB06/PyerualJetwork/blob/main/Welco
16
16
  import numpy as np
17
17
  from colorama import Fore
18
18
  import math
19
+ import random
19
20
 
20
21
  ### LIBRARY IMPORTS ###
21
22
  from .ui import loading_bars, initialize_loading_bar
@@ -24,6 +25,7 @@ from .loss_functions import binary_crossentropy, categorical_crossentropy
24
25
  from .activation_functions import apply_activation, Softmax, all_activations
25
26
  from .metrics import metrics
26
27
  from .model_operations import get_acc, get_preds, get_preds_softmax
28
+ from .memory_operations import optimize_labels
27
29
  from .visualizations import (
28
30
  draw_neural_web,
29
31
  update_neural_web_for_fit,
@@ -261,45 +263,30 @@ def learner(x_train, y_train, optimizer, x_test=None, y_test=None, strategy='acc
261
263
  # Pre-checks
262
264
 
263
265
  x_train = x_train.astype(dtype, copy=False)
264
-
265
- if len(y_train[0]) < 256:
266
- if y_train.dtype != np.uint8:
267
- y_train = np.array(y_train, copy=False).astype(np.uint8, copy=False)
268
- elif len(y_train[0]) <= 32767:
269
- if y_train.dtype != np.uint16:
270
- y_train = np.array(y_train, copy=False).astype(np.uint16, copy=False)
271
- else:
272
- if y_train.dtype != np.uint32:
273
- y_train = np.array(y_train, copy=False).astype(np.uint32, copy=False)
274
-
275
- if x_test is not None:
276
- x_test = x_test.astype(dtype, copy=False)
277
-
278
- if len(y_test[0]) < 256:
279
- if y_test.dtype != np.uint8:
280
- y_test = np.array(y_test, copy=False).astype(np.uint8, copy=False)
281
- elif len(y_test[0]) <= 32767:
282
- if y_test.dtype != np.uint16:
283
- y_test = np.array(y_test, copy=False).astype(np.uint16, copy=False)
284
- else:
285
- if y_test.dtype != np.uint32:
286
- y_test = np.array(y_test, copy=False).astype(np.uint32, copy=False)
266
+ y_train = optimize_labels(y_train, cuda=False)
287
267
 
288
268
  if x_test is None and y_test is None:
289
269
  x_test = x_train
290
270
  y_test = y_train
291
271
  data = 'Train'
292
272
  else:
273
+ x_test = x_test.astype(dtype, copy=False)
274
+ y_test = optimize_labels(y_test, cuda=False)
293
275
  data = 'Test'
294
276
 
295
277
  # Filter activation functions
296
- if only_this != None:
278
+ if only_this is not None:
297
279
  activation_potentiation = only_this
298
- if except_this != None:
280
+ if except_this is not None:
299
281
  activation_potentiation = [item for item in activation_potentiation if item not in except_this]
300
282
  if gen is None:
301
283
  gen = len(activation_potentiation)
302
284
 
285
+ if strategy != 'accuracy' and strategy != 'f1' and strategy != 'recall' and strategy != 'precision': raise ValueError("Strategy parameter only be 'accuracy' or 'f1' or 'recall' or 'precision'.")
286
+
287
+ if start_this_act is None and len(activation_potentiation) % 2 != 0: raise ValueError("Activation length must be even number. Please use 'except_this' parameter and except some activation. For example: except_this=['linear']")
288
+ if start_this_act is not None and len(activation_potentiation) + 1 % 2 != 0: raise ValueError("You are using start_this parameter, activation length still must be even number. Please use 'except_this' parameter and except some activation. For example: except_this=['linear']")
289
+
303
290
  # Initialize visualization components
304
291
  viz_objects = initialize_visualization_for_learner(show_history, neurons_history, neural_web_history, x_train, y_train)
305
292
 
@@ -336,34 +323,6 @@ def learner(x_train, y_train, optimizer, x_test=None, y_test=None, strategy='acc
336
323
  loss_list = []
337
324
  target_pop = []
338
325
 
339
- for i in range(len(activation_potentiation)):
340
-
341
- if i == 0 and start_this_act is not None:
342
- act_pop[0] = activation_potentiation[i]
343
-
344
- else:
345
- act_pop.append(activation_potentiation[i])
346
-
347
- x_test_batch, y_test_batch = batcher(x_test, y_test, batch_size=batch_size)
348
- W = fit(x_train, y_train, activation_potentiation=act_pop[-1], train_bar=False, auto_normalization=auto_normalization, dtype=dtype)
349
- model = evaluate(x_test_batch, y_test_batch, W=W, loading_bar_status=False, activation_potentiation=act_pop[-1], dtype=dtype)
350
-
351
- if i == 0 and start_this_W is not None:
352
- weight_pop[0] = W
353
-
354
- else:
355
- weight_pop.append(W)
356
-
357
- if strategy == 'accuracy': target_pop.append(model[get_acc()])
358
- elif strategy == 'f1' or strategy == 'precision' or strategy == 'recall':
359
- precision_score, recall_score, f1_score = metrics(y_test_batch, model[get_preds()])
360
-
361
- if strategy == 'precision': target_pop.append(precision_score)
362
- if strategy == 'recall': target_pop.append(recall_score)
363
- if strategy == 'f1': target_pop.append(f1_score)
364
-
365
- print(f"\rPre-Fit {i}/{len(activation_potentiation)}, {data} {strategy}: {target_pop[-1]}",end='')
366
-
367
326
  progress = initialize_loading_bar(total=len(activation_potentiation), desc="", ncols=ncols, bar_format=bar_format_learner)
368
327
 
369
328
  for i in range(gen):
@@ -373,16 +332,19 @@ def learner(x_train, y_train, optimizer, x_test=None, y_test=None, strategy='acc
373
332
  progress.n = 0
374
333
  progress.last_print_n = 0
375
334
  progress.update(0)
376
-
377
- weight_pop, act_pop = optimizer(np.array(weight_pop, dtype=dtype), act_pop, i, np.array(target_pop, dtype=dtype, copy=False), target_fitness=target_fitness, bar_status=False)
378
- target_pop = []
379
335
 
380
336
  for j in range(len(activation_potentiation)):
381
337
 
382
338
  x_test_batch, y_test_batch = batcher(x_test, y_test, batch_size=batch_size)
383
- model = evaluate(x_test_batch, y_test_batch, W=weight_pop[j], loading_bar_status=False, activation_potentiation=act_pop[j], dtype=dtype)
339
+
340
+ if i == 0:
341
+ act_pop.append(activation_potentiation[j])
342
+ W = fit(x_train, y_train, activation_potentiation=act_pop[-1], train_bar=False, auto_normalization=auto_normalization, dtype=dtype)
343
+ weight_pop.append(W)
384
344
 
345
+ model = evaluate(x_test_batch, y_test_batch, W=weight_pop[j], loading_bar_status=False, activation_potentiation=act_pop[j], dtype=dtype)
385
346
  acc = model[get_acc()]
347
+
386
348
  if strategy == 'accuracy': target_pop.append(acc)
387
349
 
388
350
  elif strategy == 'f1' or strategy == 'precision' or strategy == 'recall':
@@ -516,6 +478,9 @@ def learner(x_train, y_train, optimizer, x_test=None, y_test=None, strategy='acc
516
478
  best_acc_per_gen_list.append(best_acc)
517
479
  loss_list.append(best_loss)
518
480
 
481
+ weight_pop, act_pop = optimizer(np.array(weight_pop, dtype=dtype), act_pop, i, np.array(target_pop, dtype=dtype, copy=False), target_fitness=target_fitness, bar_status=False)
482
+ target_pop = []
483
+
519
484
  # Early stopping check
520
485
  if early_stop == True and i > 0:
521
486
  if best_acc_per_gen_list[i] == best_acc_per_gen_list[i-1]:
@@ -25,7 +25,7 @@ from .loss_functions_cuda import binary_crossentropy, categorical_crossentropy
25
25
  from .activation_functions_cuda import apply_activation, Softmax, all_activations
26
26
  from .metrics_cuda import metrics
27
27
  from .model_operations_cuda import get_acc, get_preds, get_preds_softmax
28
- from .memory_operations import transfer_to_gpu, transfer_to_cpu
28
+ from .memory_operations import transfer_to_gpu, transfer_to_cpu, optimize_labels
29
29
  from .visualizations_cuda import (
30
30
  draw_neural_web,
31
31
  update_neural_web_for_fit,
@@ -277,12 +277,15 @@ def learner(x_train, y_train, optimizer, x_test=None, y_test=None, strategy='acc
277
277
 
278
278
  activation_potentiation = all_activations()
279
279
 
280
+ y_train = optimize_labels(y_train, cuda=True)
281
+
280
282
  if x_test is None and y_test is None:
281
283
  x_test = x_train
282
284
  y_test = y_train
283
285
  data = 'Train'
284
286
  else:
285
287
  data = 'Test'
288
+ y_test = optimize_labels(y_test, cuda=True)
286
289
 
287
290
  if memory == 'gpu':
288
291
  x_train = transfer_to_gpu(x_train, dtype=dtype)
@@ -305,14 +308,19 @@ def learner(x_train, y_train, optimizer, x_test=None, y_test=None, strategy='acc
305
308
  else:
306
309
  raise ValueError("memory parameter must be 'cpu' or 'gpu'.")
307
310
 
311
+ if strategy != 'accuracy' and strategy != 'f1' and strategy != 'recall' and strategy != 'precision': raise ValueError("Strategy parameter only be 'accuracy' or 'f1' or 'recall' or 'precision'.")
312
+
308
313
  # Filter activation functions
309
- if only_this != None:
314
+ if only_this is not None:
310
315
  activation_potentiation = only_this
311
- if except_this != None:
316
+ if except_this is not None:
312
317
  activation_potentiation = [item for item in activation_potentiation if item not in except_this]
313
318
  if gen is None:
314
319
  gen = len(activation_potentiation)
315
320
 
321
+ if start_this_act is None and len(activation_potentiation) % 2 != 0: raise ValueError("Activation length must be even number. Please use 'except_this' parameter and except some activation. For example: except_this=['linear']")
322
+ if start_this_act is not None and len(activation_potentiation) + 1 % 2 != 0: raise ValueError("You are using start_this parameter, activation length still must be even number. Please use 'except_this' parameter and except some activation. For example: except_this=['linear']")
323
+
316
324
  # Initialize visualization components
317
325
  viz_objects = initialize_visualization_for_learner(show_history, neurons_history, neural_web_history, x_train, y_train)
318
326
 
@@ -348,34 +356,6 @@ def learner(x_train, y_train, optimizer, x_test=None, y_test=None, strategy='acc
348
356
  loss_list = []
349
357
  target_pop = []
350
358
 
351
- for i in range(len(activation_potentiation)):
352
-
353
- if i == 0 and start_this_act is not None:
354
- act_pop[0] = activation_potentiation[i]
355
-
356
- else:
357
- act_pop.append(activation_potentiation[i])
358
-
359
- x_test_batch, y_test_batch = batcher(x_test, y_test, batch_size=batch_size)
360
- W = fit(x_train, y_train, activation_potentiation=act_pop[-1], train_bar=False, auto_normalization=auto_normalization, dtype=dtype, memory=memory)
361
- model = evaluate(x_test_batch, y_test_batch, W=W, loading_bar_status=False, activation_potentiation=act_pop[-1], dtype=dtype, memory=memory)
362
-
363
- if i == 0 and start_this_W is not None:
364
- weight_pop[0] = W
365
-
366
- else:
367
- weight_pop.append(W)
368
-
369
- if strategy == 'accuracy': target_pop.append(model[get_acc()])
370
- elif strategy == 'f1' or strategy == 'precision' or strategy == 'recall':
371
- precision_score, recall_score, f1_score = metrics(y_test_batch, model[get_preds()])
372
-
373
- if strategy == 'precision': target_pop.append(precision_score)
374
- if strategy == 'recall': target_pop.append(recall_score)
375
- if strategy == 'f1': target_pop.append(f1_score)
376
-
377
- print(f"\rPre-Fit {i}/{len(activation_potentiation)}, {data} {strategy}: {target_pop[-1]}",end='')
378
-
379
359
  progress = initialize_loading_bar(total=len(activation_potentiation), desc="", ncols=ncols, bar_format=bar_format_learner)
380
360
 
381
361
  for i in range(gen):
@@ -386,12 +366,15 @@ def learner(x_train, y_train, optimizer, x_test=None, y_test=None, strategy='acc
386
366
  progress.last_print_n = 0
387
367
  progress.update(0)
388
368
 
389
- weight_pop, act_pop = optimizer(cp.array(weight_pop, dtype=dtype), act_pop, i, cp.array(target_pop, dtype=dtype, copy=False), target_fitness=target_fitness, bar_status=False)
390
- target_pop = []
391
-
392
369
  for j in range(len(activation_potentiation)):
393
370
 
394
371
  x_test_batch, y_test_batch = batcher(x_test, y_test, batch_size=batch_size)
372
+
373
+ if i == 0:
374
+ act_pop.append(activation_potentiation[j])
375
+ W = fit(x_train, y_train, activation_potentiation=act_pop[-1], train_bar=False, auto_normalization=auto_normalization, dtype=dtype)
376
+ weight_pop.append(W)
377
+
395
378
  model = evaluate(x_test_batch, y_test_batch, W=weight_pop[j], loading_bar_status=False, activation_potentiation=act_pop[j], dtype=dtype, memory=memory)
396
379
 
397
380
  acc = model[get_acc()]
@@ -527,6 +510,9 @@ def learner(x_train, y_train, optimizer, x_test=None, y_test=None, strategy='acc
527
510
 
528
511
  best_acc_per_gen_list.append(best_acc)
529
512
  loss_list.append(best_loss)
513
+
514
+ weight_pop, act_pop = optimizer(cp.array(weight_pop, dtype=dtype), act_pop, i, cp.array(target_pop, dtype=dtype, copy=False), target_fitness=target_fitness, bar_status=False)
515
+ target_pop = []
530
516
 
531
517
  # Early stopping check
532
518
  if early_stop == True and i > 0:
@@ -656,7 +642,6 @@ def evaluate(
656
642
  Returns:
657
643
  tuple: Model (list).
658
644
  """
659
- from memory_operations import transfer_to_cpu, transfer_to_gpu
660
645
 
661
646
  if memory == 'gpu':
662
647
  x_test = transfer_to_gpu(x_test, dtype=dtype)
@@ -255,7 +255,7 @@ Example:
255
255
 
256
256
  bar_format = loading_bars()[0]
257
257
 
258
- if bar_status: progress = initialize_loading_bar(len(bad_weights), desc="GENERATION: " + str(what_gen), bar_format=bar_format, ncols=50, ascii="▱▰")
258
+ if bar_status: progress = initialize_loading_bar(len(bad_weights), desc="GENERATION: " + str(what_gen), bar_format=bar_format, ncols=50)
259
259
 
260
260
  for i in range(len(bad_weights)):
261
261
 
@@ -255,7 +255,7 @@ Example:
255
255
 
256
256
  bar_format = loading_bars()[0]
257
257
 
258
- if bar_status: progress = initialize_loading_bar(len(bad_weights), desc="GENERATION: " + str(what_gen), bar_format=bar_format, ncols=50, ascii="▱▰")
258
+ if bar_status: progress = initialize_loading_bar(len(bad_weights), desc="GENERATION: " + str(what_gen), bar_format=bar_format, ncols=50)
259
259
 
260
260
  for i in range(len(bad_weights)):
261
261
 
@@ -358,7 +358,7 @@ def plot_evaluate(x_test, y_test, y_preds, acc_list, W, activation_potentiation)
358
358
  fpr, tpr, thresholds = roc_curve(y_true, y_preds)
359
359
 
360
360
  roc_auc = cp.trapz(tpr, fpr)
361
- axs[1, 0].plot(fpr, tpr, color='darkorange', lw=2, label=f'ROC curve (area = {roc_auc:.2f})')
361
+ axs[1, 0].plot(fpr.get(), tpr.get(), color='darkorange', lw=2, label=f'ROC curve (area = {roc_auc:.2f})')
362
362
  axs[1, 0].plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')
363
363
  axs[1, 0].set_xlim([0.0, 1.0])
364
364
  axs[1, 0].set_ylim([0.0, 1.05])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 4.1.8b7
3
+ Version: 4.1.9
4
4
  Summary: PyerualJetwork is a machine learning library written in Python for professionals, incorporating advanced, unique, new, and modern techniques.
5
5
  Author: Hasan Can Beydili
6
6
  Author-email: tchasancan@gmail.com
@@ -6,7 +6,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
6
6
  # Setting Up
7
7
  setup(
8
8
  name="pyerualjetwork",
9
- version="4.1.8b7",
9
+ version="4.1.9",
10
10
  author="Hasan Can Beydili",
11
11
  author_email="tchasancan@gmail.com",
12
12
  description=(