pyerualjetwork 4.1.0__tar.gz → 4.1.1__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/PKG-INFO +1 -1
  2. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/__init__.py +1 -1
  3. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/activation_functions_cuda.py +2 -2
  4. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/data_operations_cuda.py +93 -46
  5. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/model_operations_cuda.py +4 -2
  6. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/plan.py +1 -1
  7. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/plan_cuda.py +3 -3
  8. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/planeat.py +4 -4
  9. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/planeat_cuda.py +4 -4
  10. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork.egg-info/PKG-INFO +1 -1
  11. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/setup.py +1 -1
  12. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/README.md +0 -0
  13. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/activation_functions.py +0 -0
  14. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/data_operations.py +0 -0
  15. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/help.py +0 -0
  16. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/loss_functions.py +0 -0
  17. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/loss_functions_cuda.py +0 -0
  18. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/metrics.py +0 -0
  19. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/metrics_cuda.py +0 -0
  20. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/model_operations.py +0 -0
  21. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/ui.py +0 -0
  22. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/visualizations.py +0 -0
  23. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork/visualizations_cuda.py +0 -0
  24. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork.egg-info/SOURCES.txt +0 -0
  25. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork.egg-info/dependency_links.txt +0 -0
  26. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/pyerualjetwork.egg-info/top_level.txt +0 -0
  27. {pyerualjetwork-4.1.0 → pyerualjetwork-4.1.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 4.1.0
3
+ Version: 4.1.1
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
@@ -47,7 +47,7 @@ for package_name in package_names:
47
47
 
48
48
  print(f"PyerualJetwork is ready to use with {err} errors")
49
49
 
50
- __version__ = "4.1.0"
50
+ __version__ = "4.1.1"
51
51
  __update__ = "* Note: CUDA modules need cupy. Enter this command in your terminal: 'pip install cupy-cuda12x' or your cuda version.\n* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES\n* PyerualJetwork document: https://github.com/HCB06/Anaplan/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf\n* YouTube tutorials: https://www.youtube.com/@HasanCanBeydili"
52
52
 
53
53
  def print_version(__version__):
@@ -18,9 +18,9 @@ def spiral_activation(x):
18
18
 
19
19
  spiral_x = r * cp.cos(theta + r)
20
20
  spiral_y = r * cp.sin(theta + r)
21
-
22
21
 
23
- spiral_output = cp.concatenate(([spiral_x[0]], spiral_y))
22
+
23
+ spiral_output = cp.concatenate([cp.array([spiral_x[0]]), spiral_y])
24
24
 
25
25
  return spiral_output
26
26
 
@@ -81,17 +81,22 @@ def decode_one_hot(encoded_data):
81
81
  return decoded_labels
82
82
 
83
83
 
84
- def split(X, y, test_size, random_state, dtype=cp.float32):
84
+ def split(X, y, test_size, random_state=42, dtype=cp.float32, use_cpu=False):
85
85
  """
86
86
  Splits the given X (features) and y (labels) data into training and testing subsets.
87
87
 
88
88
  Args:
89
89
  X (cupy.ndarray): Features data.
90
+
90
91
  y (cupy.ndarray): Labels data.
92
+
91
93
  test_size (float or int): Proportion or number of samples for the test subset.
92
- random_state (int or None): Seed for random state.
94
+
95
+ random_state (int or None): Seed for random state. Default: 42.
96
+
93
97
  dtype (cupy.dtype): Data type for the arrays. np.float32 by default. Example: cp.float64 or cp.float16. [fp32 for balanced devices, fp64 for strong devices, fp16 for weak devices: not reccomended!] (optional)
94
-
98
+
99
+ use_cpu (bool): If True, output will be same cpu's split function. Default: False.
95
100
  Returns:
96
101
  tuple: x_train, x_test, y_train, y_test as ordered training and testing data subsets.
97
102
  """
@@ -118,11 +123,17 @@ def split(X, y, test_size, random_state, dtype=cp.float32):
118
123
  else:
119
124
  raise ValueError("test_size should be float or int.")
120
125
 
121
- if random_state is not None:
122
- cp.random.seed(random_state)
126
+ if use_cpu:
127
+ indices = np.arange(num_samples)
128
+ np.random.seed(random_state)
129
+ np.random.shuffle(indices)
130
+ indices = cp.array(indices)
131
+ else:
132
+ if random_state is not None:
133
+ cp.random.seed(random_state)
123
134
 
124
- indices = cp.arange(num_samples)
125
- cp.random.shuffle(indices)
135
+ indices = cp.arange(num_samples)
136
+ cp.random.shuffle(indices)
126
137
 
127
138
  test_indices = indices[:test_size]
128
139
  train_indices = indices[test_size:]
@@ -133,16 +144,22 @@ def split(X, y, test_size, random_state, dtype=cp.float32):
133
144
  return x_train, x_test, y_train, y_test
134
145
 
135
146
 
136
- def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32):
147
+ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32, use_cpu=False):
137
148
  """
138
149
  Generates synthetic examples to balance classes to the specified number of examples per class.
139
150
 
140
151
  Arguments:
152
+
141
153
  x_train -- Input dataset (examples) - cupy array format
154
+
142
155
  y_train -- Class labels (one-hot encoded) - cupy array format
156
+
143
157
  target_samples_per_class -- Desired number of samples per class
158
+
144
159
  dtype (cupy.dtype): Data type for the arrays. np.float32 by default. Example: cp.float64 or cp.float16. [fp32 for balanced devices, fp64 for strong devices, fp16 for weak devices: not reccomended!] (optional)
145
160
 
161
+ use_cpu (bool): If True, output will be same cpu's manuel_balancer function. Default: False.
162
+
146
163
  Returns:
147
164
  x_balanced -- Balanced input dataset (cupy array format)
148
165
  y_balanced -- Balanced class labels (one-hot encoded, cupy array format)
@@ -176,8 +193,13 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
176
193
  num_samples = len(class_indices)
177
194
 
178
195
  if num_samples > target_samples_per_class:
179
-
180
- selected_indices = cp.random.choice(class_indices, target_samples_per_class, replace=False)
196
+
197
+ if use_cpu:
198
+ selected_indices = np.random.choice(
199
+ class_indices, target_samples_per_class, replace=False)
200
+ else:
201
+ selected_indices = cp.random.choice(class_indices, target_samples_per_class, replace=False)
202
+
181
203
  x_balanced.append(x_train[selected_indices])
182
204
  y_balanced.append(y_train[selected_indices])
183
205
 
@@ -193,13 +215,19 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
193
215
  additional_labels = cp.zeros((samples_to_add, y_train.shape[1]))
194
216
 
195
217
  for i in range(samples_to_add):
218
+
219
+ if use_cpu:
220
+ random_indices = np.random.choice(class_indices.get(), 2, replace=False)
221
+ else:
222
+ random_indices = cp.random.choice(class_indices, 2, replace=False)
196
223
 
197
- random_indices = cp.random.choice(class_indices, 2, replace=False)
198
224
  sample1 = x_train[random_indices[0]]
199
225
  sample2 = x_train[random_indices[1]]
200
226
 
201
-
202
- synthetic_sample = sample1 + (sample2 - sample1) * cp.random.rand()
227
+ if use_cpu:
228
+ synthetic_sample = sample1 + (sample2 - sample1) * np.random.rand()
229
+ else:
230
+ synthetic_sample = sample1 + (sample2 - sample1) * cp.random.rand()
203
231
 
204
232
  additional_samples[i] = synthetic_sample
205
233
  additional_labels[i] = y_train[class_indices[0]]
@@ -214,7 +242,7 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
214
242
  return x_balanced, y_balanced
215
243
 
216
244
 
217
- def auto_balancer(x_train, y_train, dtype=cp.float32):
245
+ def auto_balancer(x_train, y_train, dtype=cp.float32, use_cpu=False):
218
246
 
219
247
  """
220
248
  Function to balance the training data across different classes.
@@ -226,6 +254,8 @@ def auto_balancer(x_train, y_train, dtype=cp.float32):
226
254
 
227
255
  dtype (cupy.dtype): Data type for the arrays. np.float32 by default. Example: cp.float64 or cp.float16. [fp32 for balanced devices, fp64 for strong devices, fp16 for weak devices: not reccomended!] (optional)
228
256
 
257
+ use_cpu (bool): If True, output will be same cpu's auto_balancer function. Default: False.
258
+
229
259
  Returns:
230
260
  tuple: A tuple containing balanced input data and labels.
231
261
  """
@@ -248,44 +278,50 @@ def auto_balancer(x_train, y_train, dtype=cp.float32):
248
278
  classes = cp.arange(y_train.shape[1])
249
279
  class_count = len(classes)
250
280
 
251
- try:
252
- ClassIndices = {i: cp.where(cp.array(y_train)[:, i] == 1)[
253
- 0] for i in range(class_count)}
254
- classes = [len(ClassIndices[i]) for i in range(class_count)]
255
-
256
- if len(set(classes)) == 1:
257
- print(Fore.WHITE + "INFO: Data have already balanced. from: auto_balancer" + Style.RESET_ALL)
258
- return x_train, y_train
259
-
260
- MinCount = min(classes)
261
-
262
- BalancedIndices = []
263
- for i in tqdm(range(class_count),leave=False, ascii="▱▰",
264
- bar_format= bar_format, desc='Balancing Data',ncols=70):
265
- if len(ClassIndices[i]) > MinCount:
281
+
282
+ ClassIndices = {i: cp.where(cp.array(y_train)[:, i] == 1)[
283
+ 0] for i in range(class_count)}
284
+ classes = [len(ClassIndices[i]) for i in range(class_count)]
285
+
286
+ if len(set(classes)) == 1:
287
+ print(Fore.WHITE + "INFO: Data have already balanced. from: auto_balancer" + Style.RESET_ALL)
288
+ return x_train, y_train
289
+
290
+ MinCount = min(classes)
291
+
292
+ BalancedIndices = []
293
+ for i in tqdm(range(class_count),leave=False, ascii="▱▰",
294
+ bar_format= bar_format, desc='Balancing Data',ncols=70):
295
+ if len(ClassIndices[i]) > MinCount:
296
+ if use_cpu:
297
+ SelectedIndices = np.random.choice(
298
+ ClassIndices[i].get(), MinCount, replace=False)
299
+ else:
266
300
  SelectedIndices = cp.random.choice(
267
301
  ClassIndices[i], MinCount, replace=False)
268
- else:
269
- SelectedIndices = ClassIndices[i]
270
- BalancedIndices.extend(SelectedIndices)
271
-
272
- BalancedInputs = [x_train[idx] for idx in BalancedIndices]
273
- BalancedLabels = [y_train[idx] for idx in BalancedIndices]
302
+ else:
303
+ SelectedIndices = ClassIndices[i]
304
+ BalancedIndices.extend(SelectedIndices)
305
+
306
+ BalancedInputs = [x_train[idx] for idx in BalancedIndices]
307
+ BalancedLabels = [y_train[idx] for idx in BalancedIndices]
274
308
 
309
+ if use_cpu:
310
+ permutation = np.random.permutation(len(BalancedInputs))
311
+ else:
275
312
  permutation = cp.random.permutation(len(BalancedInputs))
276
- BalancedInputs = cp.array(BalancedInputs)[permutation]
277
- BalancedLabels = cp.array(BalancedLabels)[permutation]
278
313
 
279
- print(Fore.GREEN + "Data Succesfully Balanced from: " + str(len(x_train)
280
- ) + " to: " + str(len(BalancedInputs)) + ". from: auto_balancer " + Style.RESET_ALL)
281
- except:
282
- print(Fore.RED + "ERROR: Inputs and labels must be same length check parameters")
283
- sys.exit()
314
+ BalancedInputs = cp.array(BalancedInputs)[permutation]
315
+ BalancedLabels = cp.array(BalancedLabels)[permutation]
284
316
 
317
+ print(Fore.GREEN + "Data Succesfully Balanced from: " + str(len(x_train)
318
+ ) + " to: " + str(len(BalancedInputs)) + ". from: auto_balancer " + Style.RESET_ALL)
319
+
320
+
285
321
  return BalancedInputs, BalancedLabels
286
322
 
287
323
 
288
- def synthetic_augmentation(x_train, y_train, dtype=cp.float32):
324
+ def synthetic_augmentation(x_train, y_train, dtype=cp.float32, use_cpu=False):
289
325
  """
290
326
  Generates synthetic examples to balance classes with fewer examples using CuPy.
291
327
  Arguments:
@@ -296,6 +332,8 @@ def synthetic_augmentation(x_train, y_train, dtype=cp.float32):
296
332
 
297
333
  dtype (cupy.dtype): Data type for the arrays. np.float32 by default. Example: cp.float64 or cp.float16. [fp32 for balanced devices, fp64 for strong devices, fp16 for weak devices: not reccomended!] (optional)
298
334
 
335
+ use_cpu (bool): If True, output will be same cpu's synthetic_augmentation function. Default: False.
336
+
299
337
  Returns:
300
338
  x_train_balanced -- Balanced input dataset (cupy array format)
301
339
  y_train_balanced -- Balanced class labels (one-hot encoded, cupy array format)
@@ -336,13 +374,21 @@ def synthetic_augmentation(x_train, y_train, dtype=cp.float32):
336
374
 
337
375
  if num_samples < max_class_count:
338
376
  while num_samples < max_class_count:
339
- random_indices = cp.random.choice(
377
+ if use_cpu:
378
+ random_indices = np.random.choice(
379
+ class_indices, 2, replace=False)
380
+ else:
381
+ random_indices = cp.random.choice(
340
382
  cp.array(class_indices), 2, replace=False)
341
383
  sample1 = x[random_indices[0]]
342
384
  sample2 = x[random_indices[1]]
343
385
 
344
- synthetic_sample = sample1 + \
345
- (sample2 - sample1) * cp.random.rand()
386
+ if use_cpu:
387
+ synthetic_sample = sample1 + \
388
+ (sample2 - sample1) * np.random.rand()
389
+ else:
390
+ synthetic_sample = sample1 + \
391
+ (sample2 - sample1) * cp.random.rand()
346
392
 
347
393
  x_balanced.append(synthetic_sample)
348
394
  y_balanced.append(y[class_indices[0]])
@@ -353,6 +399,7 @@ def synthetic_augmentation(x_train, y_train, dtype=cp.float32):
353
399
 
354
400
  return x_balanced, y_balanced
355
401
 
402
+
356
403
  def standard_scaler(x_train=None, x_test=None, scaler_params=None, dtype=cp.float32):
357
404
  """
358
405
  Standardizes training and test datasets. x_test may be None.
@@ -56,7 +56,7 @@ def save_model(model_name,
56
56
 
57
57
  class_count = W.shape[0]
58
58
 
59
- if test_acc != None:
59
+ if test_acc is not None:
60
60
  test_acc= float(test_acc)
61
61
 
62
62
  if weights_type != 'txt' and weights_type != 'npy' and weights_type != 'mat' and weights_type != 'pkl':
@@ -70,7 +70,6 @@ def save_model(model_name,
70
70
  NeuronCount = 0
71
71
  SynapseCount = 0
72
72
 
73
-
74
73
  try:
75
74
  NeuronCount += cp.shape(W)[0] + cp.shape(W)[1]
76
75
  SynapseCount += cp.shape(W)[0] * cp.shape(W)[1]
@@ -91,6 +90,9 @@ def save_model(model_name,
91
90
 
92
91
  scaler_params.append(' ')
93
92
 
93
+ scaler_params[0] = scaler_params[0].get()
94
+ scaler_params[1] = scaler_params[1].get()
95
+
94
96
  data = {'MODEL NAME': model_name,
95
97
  'MODEL TYPE': model_type,
96
98
  'CLASS COUNT': class_count,
@@ -145,7 +145,7 @@ def fit(
145
145
 
146
146
  # Training process
147
147
  for index, inp in enumerate(x_train):
148
- inp = np.array(inp, copy=False, dtype=dtype).ravel()
148
+ inp = np.array(inp, copy=False).ravel()
149
149
  y_decoded = decode_one_hot(y_train)
150
150
  # Weight updates
151
151
  STPW = feed_forward(inp, STPW, is_training=True, Class=y_decoded[index], activation_potentiation=activation_potentiation, LTD=LTD)
@@ -146,7 +146,7 @@ def fit(
146
146
 
147
147
  # Training process
148
148
  for index, inp in enumerate(x_train):
149
- inp = cp.array(inp).ravel()
149
+ inp = cp.array(inp, copy=False).ravel()
150
150
  y_decoded = decode_one_hot(y_train)
151
151
  # Weight updates
152
152
  STPW = feed_forward(inp, STPW, is_training=True, Class=y_decoded[index], activation_potentiation=activation_potentiation, LTD=LTD)
@@ -297,9 +297,9 @@ def learner(x_train, y_train, x_test=None, y_test=None, strategy='accuracy', bat
297
297
 
298
298
  # Initialize progress bar
299
299
  if batch_size == 1:
300
- ncols = 90
300
+ ncols = 85
301
301
  else:
302
- ncols = 103
302
+ ncols = 98
303
303
  progress = initialize_loading_bar(total=len(activation_potentiation), desc="", ncols=ncols, bar_format=bar_format_learner)
304
304
 
305
305
  # Initialize variables
@@ -15,10 +15,10 @@ import random
15
15
  from tqdm import tqdm
16
16
 
17
17
  ### LIBRARY IMPORTS ###
18
- from plan import feed_forward
19
- from data_operations import normalization
20
- from ui import loading_bars
21
- from activation_functions import apply_activation, all_activations
18
+ from .plan import feed_forward
19
+ from .data_operations import normalization
20
+ from .ui import loading_bars
21
+ from .activation_functions import apply_activation, all_activations
22
22
 
23
23
  def define_genomes(input_shape, output_shape, population_size, dtype=np.float32):
24
24
  """
@@ -16,10 +16,10 @@ import random
16
16
  from tqdm import tqdm
17
17
 
18
18
  ### LIBRARY IMPORTS ###
19
- from plan_cuda import feed_forward
20
- from data_operations_cuda import normalization
21
- from ui import loading_bars
22
- from activation_functions_cuda import apply_activation, all_activations
19
+ from .plan_cuda import feed_forward
20
+ from .data_operations_cuda import normalization
21
+ from .ui import loading_bars
22
+ from .activation_functions_cuda import apply_activation, all_activations
23
23
 
24
24
  def define_genomes(input_shape, output_shape, population_size, dtype=cp.float32):
25
25
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 4.1.0
3
+ Version: 4.1.1
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.0",
9
+ version="4.1.1",
10
10
  author="Hasan Can Beydili",
11
11
  author_email="tchasancan@gmail.com",
12
12
  description=(
File without changes
File without changes