pyerualjetwork 4.6.6__py3-none-any.whl → 4.6.8__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.
@@ -1,4 +1,4 @@
1
- __version__ = "4.6.6"
1
+ __version__ = "4.6.8"
2
2
  __update__ = """* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES
3
3
  * PyerualJetwork Homepage: https://github.com/HCB06/PyerualJetwork/tree/main
4
4
  * PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
@@ -7,7 +7,7 @@ import warnings
7
7
 
8
8
  def all_activations():
9
9
 
10
- activations_list = ['linear', 'sigmoid', 'relu', 'tanh', 'circular', 'spiral', 'swish', 'sin_plus', 'mod_circular', 'tanh_circular', 'leaky_relu', 'softplus', 'elu', 'gelu', 'selu', 'sinakt', 'p_squared', 'sglu', 'dlrelu', 'exsig', 'acos', 'gla', 'srelu', 'qelu', 'isra', 'waveakt', 'arctan', 'bent_identity', 'sech', 'softsign', 'pwl', 'cubic', 'gaussian', 'sine', 'tanh_square', 'mod_sigmoid', 'quartic', 'square_quartic', 'cubic_quadratic', 'exp_cubic', 'sine_square', 'logarithmic', 'scaled_cubic', 'sine_offset']
10
+ activations_list = ['linear', 'sigmoid', 'relu', 'tanh', 'circular', 'spiral', 'swish', 'sin_plus', 'mod_circular', 'tanh_circular', 'leaky_relu', 'softplus', 'elu', 'gelu', 'selu', 'sinakt', 'p_squared', 'sglu', 'dlrelu', 'exsig', 'acos', 'gla', 'srelu', 'qelu', 'isra', 'waveakt', 'arctan', 'bent_identity', 'sech', 'softsign', 'pwl', 'cubic', 'gaussian', 'sine', 'tanh_square', 'mod_sigmoid', 'quartic', 'square_quartic', 'cubic_quadratic', 'sine_square', 'logarithmic', 'scaled_cubic', 'sine_offset']
11
11
 
12
12
  return activations_list
13
13
 
@@ -279,7 +279,7 @@ def apply_activation(Input, activation_list):
279
279
 
280
280
  activation_outputs = np.array([activation_functions[act](origin_input) for act in valid_activations])
281
281
 
282
- return Input + np.sum(activation_outputs, axis=0)
282
+ return np.sum(activation_outputs, axis=0)
283
283
 
284
284
  except Exception as e:
285
285
  warnings.warn(f"Error in activation processing: {str(e)}", RuntimeWarning)
@@ -6,7 +6,7 @@ import warnings
6
6
 
7
7
  def all_activations():
8
8
 
9
- activations_list = ['linear', 'sigmoid', 'relu', 'tanh', 'circular', 'spiral', 'swish', 'sin_plus', 'mod_circular', 'tanh_circular', 'leaky_relu', 'softplus', 'elu', 'gelu', 'selu', 'sinakt', 'p_squared', 'sglu', 'dlrelu', 'exsig', 'acos', 'gla', 'srelu', 'qelu', 'isra', 'waveakt', 'arctan', 'bent_identity', 'sech', 'softsign', 'pwl', 'cubic', 'gaussian', 'sine', 'tanh_square', 'mod_sigmoid', 'quartic', 'square_quartic', 'cubic_quadratic', 'exp_cubic', 'sine_square', 'logarithmic', 'scaled_cubic', 'sine_offset']
9
+ activations_list = ['linear', 'sigmoid', 'relu', 'tanh', 'circular', 'spiral', 'swish', 'sin_plus', 'mod_circular', 'tanh_circular', 'leaky_relu', 'softplus', 'elu', 'gelu', 'selu', 'sinakt', 'p_squared', 'sglu', 'dlrelu', 'exsig', 'acos', 'gla', 'srelu', 'qelu', 'isra', 'waveakt', 'arctan', 'bent_identity', 'sech', 'softsign', 'pwl', 'cubic', 'gaussian', 'sine', 'tanh_square', 'mod_sigmoid', 'quartic', 'square_quartic', 'cubic_quadratic', 'sine_square', 'logarithmic', 'scaled_cubic', 'sine_offset']
10
10
 
11
11
  return activations_list
12
12
 
@@ -202,9 +202,6 @@ def square_quartic(x):
202
202
  def cubic_quadratic(x):
203
203
  return x**3 * (x**2)
204
204
 
205
- def exp_cubic(x):
206
- return cp.exp(x**3)
207
-
208
205
  def sine_square(x):
209
206
  return cp.sin(x)**2
210
207
 
@@ -266,7 +263,6 @@ def apply_activation(Input, activation_list):
266
263
  'quartic': quartic,
267
264
  'square_quartic': square_quartic,
268
265
  'cubic_quadratic': cubic_quadratic,
269
- 'exp_cubic': exp_cubic,
270
266
  'sine_square': sine_square,
271
267
  'logarithmic': logarithmic,
272
268
  'scaled_cubic': lambda x: scaled_cubic(x, 1.0),
@@ -282,7 +278,7 @@ def apply_activation(Input, activation_list):
282
278
 
283
279
  activation_outputs = cp.array([activation_functions[act](origin_input) for act in valid_activations])
284
280
 
285
- return Input + cp.sum(activation_outputs, axis=0)
281
+ return cp.sum(activation_outputs, axis=0)
286
282
 
287
283
  except Exception as e:
288
284
  warnings.warn(f"Error in activation processing: {str(e)}", RuntimeWarning)
@@ -379,22 +379,24 @@ dtype=np.float32):
379
379
 
380
380
 
381
381
  def non_neg_normalization(
382
- Input,
382
+ Input,
383
383
  dtype=np.float32
384
384
  ):
385
385
  """
386
386
  Normalizes the input data [0-1] range.
387
-
388
387
  Args:
389
388
  Input (numpy): Input data to be normalized.
390
-
391
- dtype (numpy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
392
-
389
+ dtype (numpy.dtype): Data type for the arrays. np.float32 by default. Example: np.float64 or np.float16.
393
390
  Returns:
394
391
  (numpy) Scaled input data after normalization.
395
392
  """
393
+ Input = Input.astype(dtype, copy=False)
394
+ MaxAbs = np.max(np.abs(Input))
396
395
 
397
- MaxAbs = np.max(np.abs(Input.astype(dtype, copy=False)))
396
+ if np.all(Input == Input.flat[0]):
397
+ randomization = np.random.random(Input.shape).astype(dtype)
398
+ return randomization
399
+
398
400
  return (Input + MaxAbs) / (2 * MaxAbs)
399
401
 
400
402
 
@@ -420,22 +420,24 @@ def normalization(
420
420
 
421
421
 
422
422
  def non_neg_normalization(
423
- Input,
424
- dtype=cp.float32
423
+ Input,
424
+ dtype=np.float32
425
425
  ):
426
426
  """
427
427
  Normalizes the input data [0-1] range.
428
-
429
428
  Args:
430
429
  Input (cupy): Input data to be normalized.
431
-
432
430
  dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
433
-
434
431
  Returns:
435
432
  (cupy) Scaled input data after normalization.
436
433
  """
434
+ Input = Input.astype(dtype, copy=False)
435
+ MaxAbs = cp.max(cp.abs(Input))
437
436
 
438
- MaxAbs = cp.max(cp.abs(Input.astype(dtype, copy=False)))
437
+ if cp.all(Input == Input.flat[0]):
438
+ randomization = cp.random.random(Input.shape).astype(dtype)
439
+ return randomization
440
+
439
441
  return (Input + MaxAbs) / (2 * MaxAbs)
440
442
 
441
443
 
@@ -55,6 +55,13 @@ def save_model(model_name,
55
55
  if model_type != 'PLAN' and model_type != 'MLP':
56
56
  raise ValueError("model_type parameter must be 'PLAN' or 'MLP'.")
57
57
 
58
+ if isinstance(activation_potentiation, str):
59
+ activation_potentiation = [activation_potentiation]
60
+ else:
61
+ activation_potentiation = [item if isinstance(item, list) else [item] for item in activation_potentiation]
62
+
63
+ activation = activation_potentiation.copy()
64
+
58
65
  if test_acc != None:
59
66
  test_acc= float(test_acc)
60
67
 
@@ -82,6 +89,7 @@ def save_model(model_name,
82
89
  sys.exit()
83
90
 
84
91
  elif model_type == 'MLP':
92
+
85
93
  class_count = W[-1].shape[0]
86
94
 
87
95
  NeuronCount.append(np.shape(W[0])[1])
@@ -95,33 +103,34 @@ def save_model(model_name,
95
103
  print(Fore.RED + "ERROR: Weight matrices have a problem from: save_model" + Style.RESET_ALL)
96
104
  sys.exit()
97
105
 
106
+
98
107
  SynapseCount.append(' ')
99
108
 
100
- activation_potentiation.append('')
101
- activation_potentiation.insert(0, '')
109
+ activation.append('')
110
+ activation.insert(0, '')
102
111
 
103
- if isinstance(activation_potentiation, str):
104
- activation_potentiation = [activation_potentiation]
105
- activation_potentiation.append('')
112
+ if len(activation) == 1 and model_type == 'PLAN':
113
+ activation = [activation]
114
+ activation.append('')
106
115
 
107
- if len(activation_potentiation) > len(NeuronCount):
108
- for i in range(len(activation_potentiation) - len(NeuronCount)):
116
+ if len(activation) > len(NeuronCount):
117
+ for i in range(len(activation) - len(NeuronCount)):
109
118
  NeuronCount.append('')
110
-
111
- if len(activation_potentiation) > len(SynapseCount):
112
- for i in range(len(activation_potentiation) - len(SynapseCount)):
119
+
120
+ if len(activation) > len(SynapseCount):
121
+ for i in range(len(activation) - len(SynapseCount)):
113
122
  SynapseCount.append('')
114
123
 
115
124
 
116
125
  if scaler_params != None:
117
126
 
118
- if len(scaler_params) > len(activation_potentiation):
127
+ if len(scaler_params) > len(activation):
119
128
 
120
- activation_potentiation += ['']
129
+ activation += ['']
121
130
 
122
- elif len(activation_potentiation) > len(scaler_params):
131
+ elif len(activation) > len(scaler_params):
123
132
 
124
- for i in range(len(activation_potentiation) - len(scaler_params)):
133
+ for i in range(len(activation) - len(scaler_params)):
125
134
 
126
135
  scaler_params.append(' ')
127
136
 
@@ -136,70 +145,62 @@ def save_model(model_name,
136
145
  'WEIGHTS FORMAT': weights_format,
137
146
  'MODEL PATH': model_path,
138
147
  'STANDARD SCALER': scaler_params,
139
- 'ACTIVATION POTENTIATION': activation_potentiation
148
+ 'ACTIVATION POTENTIATION': activation
140
149
  }
141
150
 
142
151
  df = pd.DataFrame(data)
143
152
  df.to_pickle(model_path + model_name + '.pkl')
144
153
 
145
- if isinstance(W, list): max_file = len(W)
146
- else: max_file = 1
147
-
148
- for i in range(max_file):
149
-
150
- if max_file > 1: weight = W[i]
151
- else: weight = W
154
+ try:
152
155
 
153
- try:
156
+ if weights_type == 'txt' and weights_format == 'f':
154
157
 
155
- if weights_type == 'txt' and weights_format == 'f':
158
+ np.savetxt(model_path + model_name + f'_weights.txt', W, fmt='%f')
156
159
 
157
- np.savetxt(model_path + model_name + f'weights{i}.txt', weight, fmt='%f')
160
+ if weights_type == 'txt' and weights_format == 'raw':
158
161
 
159
- if weights_type == 'txt' and weights_format == 'raw':
162
+ np.savetxt(model_path + model_name + f'_weights.txt', W)
160
163
 
161
- np.savetxt(model_path + model_name + f'weights{i}.txt', weight)
164
+ ###
162
165
 
163
- ###
166
+
167
+ if weights_type == 'pkl' and weights_format == 'f':
164
168
 
165
-
166
- if weights_type == 'pkl' and weights_format == 'f':
169
+ with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
170
+ pickle.dump(W.astype(float), f)
167
171
 
168
- with open(model_path + model_name + f'weights{i}.pkl', 'wb') as f:
169
- pickle.dump(weight.astype(float), f)
172
+ if weights_type == 'pkl' and weights_format =='raw':
173
+
174
+ with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
175
+ pickle.dump(W, f)
170
176
 
171
- if weights_type == 'pkl' and weights_format =='raw':
172
-
173
- with open(model_path + model_name + f'weights{i}.pkl', 'wb') as f:
174
- pickle.dump(weight, f)
177
+ ###
175
178
 
176
- ###
179
+ if weights_type == 'npy' and weights_format == 'f':
177
180
 
178
- if weights_type == 'npy' and weights_format == 'f':
181
+ np.save(model_path + model_name + f'_weights.npy', W, W.astype(float))
179
182
 
180
- np.save(model_path + model_name + f'weights{i}.npy', weight, weight.astype(float))
183
+ if weights_type == 'npy' and weights_format == 'raw':
181
184
 
182
- if weights_type == 'npy' and weights_format == 'raw':
185
+ np.save(model_path + model_name + f'_weights.npy', W)
183
186
 
184
- np.save(model_path + model_name + f'weights{i}.npy', weight)
187
+ ###
185
188
 
186
- ###
189
+ if weights_type == 'mat' and weights_format == 'f':
187
190
 
188
- if weights_type == 'mat' and weights_format == 'f':
191
+ w = {'w': W.astype(float)}
192
+ io.savemat(model_path + model_name + f'_weights.mat', w)
189
193
 
190
- w = {'w': weight.astype(float)}
191
- io.savemat(model_path + model_name + f'weights{i}.mat', w)
194
+ if weights_type == 'mat' and weights_format == 'raw':
195
+
196
+ w = {'w': W}
197
+ io.savemat(model_path + model_name + f'_weights.mat', w)
192
198
 
193
- if weights_type == 'mat' and weights_format == 'raw':
194
-
195
- w = {'w': weight}
196
- io.savemat(model_path + model_name + f'weights{i}.mat', w)
199
+ except:
197
200
 
198
- except:
201
+ print(Fore.RED + "ERROR: Model Weights not saved. Check the Weight parameters. SaveFilePath expl: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: save_model" + Style.RESET_ALL)
202
+ sys.exit()
199
203
 
200
- print(Fore.RED + "ERROR: Model Weights not saved. Check the Weight parameters. SaveFilePath expl: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: save_model" + Style.RESET_ALL)
201
- sys.exit()
202
-
203
204
  if show_info:
204
205
  print(df)
205
206
 
@@ -258,33 +259,26 @@ def load_model(model_name,
258
259
  model_name = str(df['MODEL NAME'].iloc[0])
259
260
  model_type = str(df['MODEL TYPE'].iloc[0])
260
261
  WeightType = str(df['WEIGHTS TYPE'].iloc[0])
261
- layers = list(df['NEURON COUNT'])
262
-
263
- if model_type == 'MLP': max_file = len(layers)-1
264
- else: max_file = 1
265
-
266
- W = []
267
-
268
- for i in range(max_file):
269
-
270
- if WeightType == 'txt':
271
- W.append(np.loadtxt(model_path + model_name + f'weights{i}.txt'))
272
- elif WeightType == 'npy':
273
- W.append(np.load(model_path + model_name + f'weights{i}.npy'))
274
- elif WeightType == 'mat':
275
- W.append(sio.loadmat(model_path + model_name + f'weights{i}.mat'))
276
- elif WeightType == 'pkl':
277
- with open(model_path + model_name + f'weights{i}.pkl', 'rb') as f:
278
- W = pickle.load(f)
279
- else:
280
-
281
- raise ValueError(
282
- Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
283
-
284
- if WeightType == 'mat':
285
- W[-1] = W[-1]['w']
286
262
 
287
- if model_type == 'PLAN': W = np.array(W[0], dtype=W[0].dtype)
263
+ if model_type == 'MLP': allow_pickle = True
264
+ else: allow_pickle = False
265
+
266
+ if WeightType == 'txt':
267
+ W = (np.loadtxt(model_path + model_name + f'_weights.txt'))
268
+ elif WeightType == 'npy':
269
+ W = (np.load(model_path + model_name + f'_weights.npy', allow_pickle=allow_pickle))
270
+ elif WeightType == 'mat':
271
+ W = (sio.loadmat(model_path + model_name + f'_weights.mat'))
272
+ elif WeightType == 'pkl':
273
+ with open(model_path + model_name + f'_weights.pkl', 'rb') as f:
274
+ W = pickle.load(f)
275
+ else:
276
+
277
+ raise ValueError(
278
+ Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
279
+
280
+ if WeightType == 'mat':
281
+ W = W['w']
288
282
 
289
283
  return W, None, None, activation_potentiation, scaler_params, None, model_type
290
284
 
@@ -320,6 +314,11 @@ def predict_model_ssd(Input, model_name, model_path='', dtype=np.float32):
320
314
  W = model[get_weights()]
321
315
  model_type = model[get_model_type()]
322
316
 
317
+ if isinstance(activation_potentiation, str):
318
+ activation_potentiation = [activation_potentiation]
319
+ else:
320
+ activation_potentiation = [item if isinstance(item, list) else [item] for item in activation_potentiation]
321
+
323
322
  Input = standard_scaler(None, Input, scaler_params)
324
323
 
325
324
  if model_type == 'MLP':
@@ -343,7 +342,7 @@ def predict_model_ssd(Input, model_name, model_path='', dtype=np.float32):
343
342
  sys.exit()
344
343
 
345
344
 
346
- def reverse_predict_model_ssd(output, model_name, model_path='', dtype=np.float32):
345
+ def reverse_predict_model_ssd(output, model_name, model_path=''):
347
346
 
348
347
  """
349
348
  reverse prediction function from storage
@@ -355,8 +354,6 @@ def reverse_predict_model_ssd(output, model_name, model_path='', dtype=np.float3
355
354
 
356
355
  model_path (str): Path of the model. Default: ''
357
356
 
358
- dtype (numpy.dtype): Data type for the arrays. np.float32 by default. Example: np.float64 or np.float16. [fp32 for balanced devices, fp64 for strong devices, fp16 for weak devices: not reccomended!]
359
-
360
357
  Returns:
361
358
  ndarray: Input from the model.
362
359
  """
@@ -401,6 +398,11 @@ def predict_model_ram(Input, W, scaler_params=None, activation_potentiation=['li
401
398
 
402
399
  Input = standard_scaler(None, Input, scaler_params)
403
400
 
401
+ if isinstance(activation_potentiation, str):
402
+ activation_potentiation = [activation_potentiation]
403
+ else:
404
+ activation_potentiation = [item if isinstance(item, list) else [item] for item in activation_potentiation]
405
+
404
406
  if is_mlp:
405
407
 
406
408
  layer = Input
@@ -421,7 +423,7 @@ def predict_model_ram(Input, W, scaler_params=None, activation_potentiation=['li
421
423
  print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: predict_model_ram." + Style.RESET_ALL)
422
424
  sys.exit()
423
425
 
424
- def reverse_predict_model_ram(output, W, dtype=np.float32):
426
+ def reverse_predict_model_ram(output, W):
425
427
 
426
428
  """
427
429
  reverse prediction function from memory
@@ -432,8 +434,6 @@ def reverse_predict_model_ram(output, W, dtype=np.float32):
432
434
 
433
435
  W (list of ndarrays): Weights of the model.
434
436
 
435
- dtype (numpy.dtype): Data type for the arrays. np.float32 by default. Example: np.float64 or np.float16. [fp32 for balanced devices, fp64 for strong devices, fp16 for weak devices: not reccomended!]
436
-
437
437
  Returns:
438
438
  ndarray: Input from the model.
439
439
  """
@@ -59,6 +59,19 @@ def save_model(model_name,
59
59
  if model_type != 'PLAN' and model_type != 'MLP':
60
60
  raise ValueError("model_type parameter must be 'PLAN' or 'MLP'.")
61
61
 
62
+ if isinstance(W, list):
63
+ W = W.copy()
64
+
65
+ if isinstance(W, np.ndarray):
66
+ W = np.copy(W)
67
+
68
+ if isinstance(activation_potentiation, str):
69
+ activation_potentiation = [activation_potentiation]
70
+ else:
71
+ activation_potentiation = [item if isinstance(item, list) else [item] for item in activation_potentiation]
72
+
73
+ activation = activation_potentiation.copy()
74
+
62
75
  if test_acc is not None:
63
76
  test_acc= float(test_acc)
64
77
 
@@ -86,6 +99,12 @@ def save_model(model_name,
86
99
  sys.exit()
87
100
 
88
101
  elif model_type == 'MLP':
102
+
103
+ for i in range(len(W)):
104
+ W[i] = W[i].get()
105
+
106
+ W = np.array(W, dtype=object)
107
+
89
108
  class_count = W[-1].shape[0]
90
109
 
91
110
  NeuronCount.append(cp.shape(W[0])[1])
@@ -101,30 +120,30 @@ def save_model(model_name,
101
120
 
102
121
  SynapseCount.append(' ')
103
122
 
104
- activation_potentiation.append('')
105
- activation_potentiation.insert(0, '')
123
+ activation.append('')
124
+ activation.insert(0, '')
106
125
 
107
- if isinstance(activation_potentiation, str):
108
- activation_potentiation = [activation_potentiation]
109
- activation_potentiation.append('')
126
+ if len(activation) == 1 and model_type == 'PLAN':
127
+ activation = [activation]
128
+ activation.append('')
110
129
 
111
- if len(activation_potentiation) > len(NeuronCount):
112
- for i in range(len(activation_potentiation) - len(NeuronCount)):
130
+ if len(activation) > len(NeuronCount):
131
+ for i in range(len(activation) - len(NeuronCount)):
113
132
  NeuronCount.append('')
114
133
 
115
- if len(activation_potentiation) > len(SynapseCount):
116
- for i in range(len(activation_potentiation) - len(SynapseCount)):
134
+ if len(activation) > len(SynapseCount):
135
+ for i in range(len(activation) - len(SynapseCount)):
117
136
  SynapseCount.append('')
118
137
 
119
138
  if scaler_params != None:
120
139
 
121
- if len(scaler_params) > len(activation_potentiation):
140
+ if len(scaler_params) > len(activation):
122
141
 
123
- activation_potentiation += ['']
142
+ activation += ['']
124
143
 
125
- elif len(activation_potentiation) > len(scaler_params):
144
+ elif len(activation) > len(scaler_params):
126
145
 
127
- for i in range(len(activation_potentiation) - len(scaler_params)):
146
+ for i in range(len(activation) - len(scaler_params)):
128
147
 
129
148
  scaler_params.append(' ')
130
149
 
@@ -142,70 +161,57 @@ def save_model(model_name,
142
161
  'WEIGHTS FORMAT': weights_format,
143
162
  'MODEL PATH': model_path,
144
163
  'STANDARD SCALER': scaler_params,
145
- 'ACTIVATION POTENTIATION': activation_potentiation
164
+ 'ACTIVATION POTENTIATION': activation
146
165
  }
147
166
 
148
167
  df = pd.DataFrame(data)
149
168
  df.to_pickle(model_path + model_name + '.pkl')
150
169
 
151
- if isinstance(W, list): max_file = len(W)
152
- else: max_file = 1
153
-
154
- for i in range(max_file):
155
170
 
156
- if max_file > 1: weight = W[i]
157
- else: weight = W
158
-
159
- try:
171
+ if weights_type == 'txt' and weights_format == 'f':
160
172
 
161
- if weights_type == 'txt' and weights_format == 'f':
173
+ cp.savetxt(model_path + model_name + f'_weights.txt', W, fmt='%f')
162
174
 
163
- cp.savetxt(model_path + model_name + f'weights{i}.txt', weight, fmt='%f')
175
+ if weights_type == 'txt' and weights_format == 'raw':
164
176
 
165
- if weights_type == 'txt' and weights_format == 'raw':
177
+ cp.savetxt(model_path + model_name + f'_weights.txt', W)
166
178
 
167
- cp.savetxt(model_path + model_name + f'weights{i}.txt', weight)
179
+ ###
168
180
 
169
- ###
170
-
171
-
172
- if weights_type == 'pkl' and weights_format == 'f':
181
+
182
+ if weights_type == 'pkl' and weights_format == 'f':
173
183
 
174
- with open(model_path + model_name + f'weights{i}.pkl', 'wb') as f:
175
- pickle.dump(weight.astype(float), f)
184
+ with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
185
+ pickle.dump(W.astype(float), f)
176
186
 
177
- if weights_type == 'pkl' and weights_format =='raw':
178
-
179
- with open(model_path + model_name + f'weights{i}.pkl', 'wb') as f:
180
- pickle.dump(weight, f)
187
+ if weights_type == 'pkl' and weights_format =='raw':
188
+
189
+ with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
190
+ pickle.dump(W, f)
181
191
 
182
- ###
192
+ ###
183
193
 
184
- if weights_type == 'npy' and weights_format == 'f':
194
+ if weights_type == 'npy' and weights_format == 'f':
185
195
 
186
- cp.save(model_path + model_name + f'weights{i}.npy', weight, weight.astype(float))
196
+ cp.save(model_path + model_name + f'_weights.npy', W, W.astype(float))
187
197
 
188
- if weights_type == 'npy' and weights_format == 'raw':
198
+ if weights_type == 'npy' and weights_format == 'raw':
189
199
 
190
- cp.save(model_path + model_name + f'weights{i}.npy', weight)
200
+ cp.save(model_path + model_name + f'_weights.npy', W)
191
201
 
192
- ###
202
+ ###
193
203
 
194
- if weights_type == 'mat' and weights_format == 'f':
204
+ if weights_type == 'mat' and weights_format == 'f':
195
205
 
196
- w = {'w': weight.astype(float)}
197
- io.savemat(model_path + model_name + f'weights{i}.mat', w)
206
+ w = {'w': W.astype(float)}
207
+ io.savemat(model_path + model_name + f'_weights.mat', w)
198
208
 
199
- if weights_type == 'mat' and weights_format == 'raw':
200
-
201
- w = {'w': weight}
202
- io.savemat(model_path + model_name + f'weights{i}.mat', w)
209
+ if weights_type == 'mat' and weights_format == 'raw':
210
+
211
+ w = {'w': W}
212
+ io.savemat(model_path + model_name + f'_weights.mat', w)
203
213
 
204
- except:
205
214
 
206
- print(Fore.RED + "ERROR: Model Weights not saved. Check the Weight parameters. SaveFilePath expl: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: save_model" + Style.RESET_ALL)
207
- sys.exit()
208
-
209
215
  if show_info:
210
216
  print(df)
211
217
 
@@ -266,33 +272,26 @@ def load_model(model_name,
266
272
  model_name = str(df['MODEL NAME'].iloc[0])
267
273
  model_type = str(df['MODEL TYPE'].iloc[0])
268
274
  WeightType = str(df['WEIGHTS TYPE'].iloc[0])
269
- layers = list(df['NEURON COUNT'])
270
-
271
- if model_type == 'MLP': max_file = len(layers)-1
272
- else: max_file = 1
273
-
274
- W = []
275
-
276
- for i in range(max_file):
277
-
278
- if WeightType == 'txt':
279
- W.append(cp.loadtxt(model_path + model_name + f'weights{i}.txt'))
280
- elif WeightType == 'npy':
281
- W.append(cp.load(model_path + model_name + f'weights{i}.npy'))
282
- elif WeightType == 'mat':
283
- W.append(sio.loadmat(model_path + model_name + f'weights{i}.mat'))
284
- elif WeightType == 'pkl':
285
- with open(model_path + model_name + f'weights{i}.pkl', 'rb') as f:
286
- W = pickle.load(f)
287
- else:
288
275
 
289
- raise ValueError(
290
- Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
291
-
292
- if WeightType == 'mat':
293
- W[-1] = W[-1]['w']
294
-
295
- if model_type == 'PLAN': W = cp.array(W[0], dtype=W[0].dtype)
276
+ if model_type == 'MLP': allow_pickle = True
277
+ else: allow_pickle = False
278
+
279
+ if WeightType == 'txt':
280
+ W = (cp.loadtxt(model_path + model_name + f'_weights.txt'))
281
+ elif WeightType == 'npy':
282
+ W = (cp.load(model_path + model_name + f'_weights.npy', allow_pickle=allow_pickle))
283
+ elif WeightType == 'mat':
284
+ W = (sio.loadmat(model_path + model_name + f'_weights.mat'))
285
+ elif WeightType == 'pkl':
286
+ with open(model_path + model_name + f'_weights.pkl', 'rb') as f:
287
+ W = pickle.load(f)
288
+ else:
289
+
290
+ raise ValueError(
291
+ Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
292
+
293
+ if WeightType == 'mat':
294
+ W = W['w']
296
295
 
297
296
  return W, None, None, activation_potentiation, scaler_params, None, model_type
298
297
 
@@ -330,6 +329,11 @@ def predict_model_ssd(Input, model_name, model_path='', dtype=cp.float32):
330
329
  W = model[get_weights()]
331
330
  model_type = model[get_model_type()]
332
331
 
332
+ if isinstance(activation_potentiation, str):
333
+ activation_potentiation = [activation_potentiation]
334
+ else:
335
+ activation_potentiation = [item if isinstance(item, list) else [item] for item in activation_potentiation]
336
+
333
337
  Input = standard_scaler(None, Input, scaler_params)
334
338
 
335
339
  if model_type == 'MLP':
@@ -410,7 +414,12 @@ def predict_model_ram(Input, W, scaler_params=None, activation_potentiation=['li
410
414
  from .activation_functions_cuda import apply_activation
411
415
 
412
416
  try:
413
-
417
+
418
+ if isinstance(activation_potentiation, str):
419
+ activation_potentiation = [activation_potentiation]
420
+ else:
421
+ activation_potentiation = [item if isinstance(item, list) else [item] for item in activation_potentiation]
422
+
414
423
  Input = standard_scaler(None, Input, scaler_params)
415
424
 
416
425
  if is_mlp:
pyerualjetwork/plan.py CHANGED
@@ -404,6 +404,11 @@ def evaluate(
404
404
 
405
405
  if auto_normalization: x_test = normalization(x_test, dtype=x_test.dtype)
406
406
 
407
+ if isinstance(activation_potentiation, str):
408
+ activation_potentiation = [activation_potentiation]
409
+ else:
410
+ activation_potentiation = [item if isinstance(item, list) else [item] for item in activation_potentiation]
411
+
407
412
  x_test = apply_activation(x_test, activation_potentiation)
408
413
 
409
414
  result = x_test @ W.T
@@ -413,6 +413,11 @@ def evaluate(
413
413
 
414
414
  if auto_normalization: x_test = normalization(x_test, dtype=x_test.dtype)
415
415
 
416
+ if isinstance(activation_potentiation, str):
417
+ activation_potentiation = [activation_potentiation]
418
+ else:
419
+ activation_potentiation = [item if isinstance(item, list) else [item] for item in activation_potentiation]
420
+
416
421
  x_test = apply_activation(x_test, activation_potentiation)
417
422
 
418
423
  result = x_test @ W.T
@@ -58,7 +58,7 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
58
58
  and normalized using the `normalization()` function. (Max abs normalization.)
59
59
  """
60
60
  if hidden > 0:
61
- population_weights = cp.empty((population_size, hidden + 1), dtype=object)
61
+ population_weights = [[0] * (hidden + 1) for _ in range(population_size)]
62
62
  population_activations = [[0] * (hidden) for _ in range(population_size)]
63
63
 
64
64
  if len(neurons) != hidden:
@@ -88,6 +88,8 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
88
88
  population_weights[i][l][j,:] = apply_activation(population_weights[i][l][j,:], population_activations[i])
89
89
  population_weights[i][l][j,:] = normalization(population_weights[i][l][j,:], dtype=dtype)
90
90
 
91
+ return population_weights, population_activations
92
+
91
93
  else:
92
94
  population_weights = [0] * population_size
93
95
  population_activations = [0] * population_size
@@ -107,8 +109,7 @@ def define_genomes(input_shape, output_shape, population_size, hidden=0, neurons
107
109
  population_weights[i][j,:] = apply_activation(population_weights[i][j,:], population_activations[i])
108
110
  population_weights[i][j,:] = normalization(population_weights[i][j,:], dtype=dtype)
109
111
 
110
- return population_weights, population_activations
111
-
112
+ return cp.array(population_weights, dtype=dtype), population_activations
112
113
 
113
114
  def evolver(weights,
114
115
  activation_potentiations,
@@ -313,6 +314,16 @@ def evolver(weights,
313
314
  activation_selection_add_prob = 0
314
315
  activation_mutate_delete_prob = 0
315
316
 
317
+ if isinstance(weights, list):
318
+
319
+ for i in range(len(weights)):
320
+
321
+ for j in range(len(weights[i])):
322
+
323
+ weights[i][j] = weights[i][j].get()
324
+
325
+ weights = np.array(weights, dtype=object)
326
+
316
327
  ### FITNESS LIST IS SORTED IN ASCENDING ORDER, AND THE WEIGHT AND ACTIVATIONS OF EACH GENOME ARE SORTED ACCORDING TO THIS ORDER:
317
328
 
318
329
  sort_indices = cp.argsort(fitness)
@@ -332,7 +343,7 @@ def evolver(weights,
332
343
  bad_activations = list(activation_potentiations[:slice_center])
333
344
  best_activations = good_activations[-1].copy() if isinstance(good_activations[-1], list) else good_activations[-1]
334
345
 
335
-
346
+
336
347
  ### PLANEAT IS APPLIED ACCORDING TO THE SPECIFIED POLICY, STRATEGY, AND PROBABILITY CONFIGURATION:
337
348
 
338
349
  bar_format = loading_bars()[0]
@@ -374,8 +385,8 @@ def evolver(weights,
374
385
  else:
375
386
  act_l = l - 1
376
387
 
377
- child_W[i][l], child_act[i][act_l] = cross_over(first_parent_W[l],
378
- second_parent_W[l],
388
+ child_W[i][l], child_act[i][act_l] = cross_over(cp.array(first_parent_W[l]),
389
+ cp.array(second_parent_W[l]),
379
390
  first_parent_act[act_l],
380
391
  second_parent_act[act_l],
381
392
  cross_over_mode=cross_over_mode,
@@ -389,6 +400,8 @@ def evolver(weights,
389
400
  weight_evolve=weight_evolve,
390
401
  epsilon=epsilon
391
402
  )
403
+
404
+
392
405
  else:
393
406
  child_W[i], child_act[i] = cross_over(first_parent_W,
394
407
  second_parent_W,
@@ -428,7 +441,7 @@ def evolver(weights,
428
441
  else:
429
442
  act_l = l - 1
430
443
 
431
- mutated_W[i][l], mutated_act[i][act_l] = mutation(genome_W[l],
444
+ mutated_W[i][l], mutated_act[i][act_l] = mutation(cp.array(genome_W[l]),
432
445
  genome_act[act_l],
433
446
  activation_mutate_prob=activation_mutate_prob,
434
447
  activation_add_prob=activation_mutate_add_prob,
@@ -462,7 +475,13 @@ def evolver(weights,
462
475
  child_act[0] = best_activations
463
476
 
464
477
  if is_mlp:
465
- weights = cp.vstack((child_W, mutated_W), dtype=object)
478
+ for i in range(len(child_W)):
479
+ for j in range(len(child_W[i])):
480
+ child_W[i][j] = cp.array(child_W[i][j], dtype=dtype)
481
+
482
+ child_W = list(child_W)
483
+ mutated_W = list(mutated_W)
484
+ weights = child_W + mutated_W
466
485
  else:
467
486
  weights = cp.vstack((child_W, mutated_W), dtype=dtype)
468
487
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyerualjetwork
3
- Version: 4.6.6
3
+ Version: 4.6.8
4
4
  Summary: PyerualJetwork is a machine learning library supported with GPU(CUDA) acceleration written in Python for professionals and researchers including with PLAN algorithm, PLANEAT algorithm (genetic optimization). Also includes data pre-process and memory manegament
5
5
  Author: Hasan Can Beydili
6
6
  Author-email: tchasancan@gmail.com
@@ -0,0 +1,25 @@
1
+ pyerualjetwork/__init__.py,sha256=c09JK_8RrB0Y82QOyzuVwS3OkNQz6SzjMfzbwcLtjkc,1279
2
+ pyerualjetwork/activation_functions.py,sha256=0fNOHXd490HC6gadKwb0AuBjw34dWq3GRZkg5iWO27c,7621
3
+ pyerualjetwork/activation_functions_cuda.py,sha256=X5-dtYBkGp35kyL21eLR7mbYUdttxElu-WqXmwmkV9E,7672
4
+ pyerualjetwork/data_operations.py,sha256=XKYG9-mLa3qKAXUjejuD7V8aJKjpl5PdQwKzPFjpKgs,15437
5
+ pyerualjetwork/data_operations_cuda.py,sha256=zqiHXDRtC8qDlVlN6lLoZn9uQgkm40aKFfFjWjurCxQ,17538
6
+ pyerualjetwork/fitness_functions.py,sha256=urRdeMvUhNgWxD4ZGHCRdQlIf9cTWYMvF3_aVBojRqY,1235
7
+ pyerualjetwork/help.py,sha256=nQ_YbYA2RtuafhuvkreNpX0WWL1I_nzlelwCtvei0_Y,775
8
+ pyerualjetwork/loss_functions.py,sha256=6PyBI232SQRGuFnG3LDGvnv_PUdWzT2_2mUODJiejGI,618
9
+ pyerualjetwork/loss_functions_cuda.py,sha256=C93IZJcrOpT6HMK9x1O4AHJWXYTkN5WZiqdssPbvAPk,617
10
+ pyerualjetwork/memory_operations.py,sha256=0yCOHcgiNyF4ccMcRlL1Q9F_byG4nzjhmkbpXE_yU6E,13401
11
+ pyerualjetwork/metrics.py,sha256=q7MkhnZDRbCjFBDDfUgrl8lBYnUT_1ro1LxeBq105pI,6077
12
+ pyerualjetwork/metrics_cuda.py,sha256=73h9GC7XwmnFCVzFEEiPQfF8CwHIz2wsCbxpZrJtYgw,5061
13
+ pyerualjetwork/model_operations.py,sha256=SYMXYNFFLz2YUvmp9lSKXd2L1vCwhyL_AUjL3UYCkZw,15134
14
+ pyerualjetwork/model_operations_cuda.py,sha256=VmFtzuSs37FUIWeEML229hTHeZzSFPNBleI7qDfCOV0,16096
15
+ pyerualjetwork/plan.py,sha256=cjVblo8TxTHX-GZPvgQvJZ34nOmzxSvtCrQi9K-Mhog,23268
16
+ pyerualjetwork/plan_cuda.py,sha256=ZEU_b_EoA-zPk7Gn94L_XBZz1v4mn8DOUsjTNV6fp8Q,24230
17
+ pyerualjetwork/planeat.py,sha256=prbkUIrD37Y_b7MmTuGg4rGHXfqHIjLFMbs7TnnEy9E,44645
18
+ pyerualjetwork/planeat_cuda.py,sha256=Yrf9DDLN1gHXQE8-ZKnWOWShu0Yxt4WX1ued0m6d10w,45239
19
+ pyerualjetwork/ui.py,sha256=JBTFYz5R24XwNKhA3GSW-oYAoiIBxAE3kFGXkvm5gqw,656
20
+ pyerualjetwork/visualizations.py,sha256=utnX9zQhzmtvBJLOLNGm2jecVVk4zHXABQdjb0XzJac,28352
21
+ pyerualjetwork/visualizations_cuda.py,sha256=gnoaaazZ-nc9E1ImqXrZBRgQ4Rnpi2qh2yGJ2eLKMlE,28807
22
+ pyerualjetwork-4.6.8.dist-info/METADATA,sha256=aaVuzlomXfh_qnUUZWhga_sjvjdZVSxSUw3KAI_suUE,7505
23
+ pyerualjetwork-4.6.8.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
24
+ pyerualjetwork-4.6.8.dist-info/top_level.txt,sha256=BRyt62U_r3ZmJpj-wXNOoA345Bzamrj6RbaWsyW4tRg,15
25
+ pyerualjetwork-4.6.8.dist-info/RECORD,,
@@ -1,25 +0,0 @@
1
- pyerualjetwork/__init__.py,sha256=uKOppTDMmBVI819Q_jQUWyvm_UZH3QzdKF3q9SCfXU0,1279
2
- pyerualjetwork/activation_functions.py,sha256=Ms0AGBqkJuCA42ht64MSQnO54Td_1eDGquedpoBDVbc,7642
3
- pyerualjetwork/activation_functions_cuda.py,sha256=5y1Ti3GDfDteQDCUmODwe7tAyDAUlDTKmIikChQ8d6g,7772
4
- pyerualjetwork/data_operations.py,sha256=Y_RdxkjLEszFgeo4VDWIX1keF2syP-88KesLXA5sRyY,15280
5
- pyerualjetwork/data_operations_cuda.py,sha256=9tyD3Bbv5__stuUampgh3_GbMhb_kmTTJmZi7BJsvuA,17381
6
- pyerualjetwork/fitness_functions.py,sha256=urRdeMvUhNgWxD4ZGHCRdQlIf9cTWYMvF3_aVBojRqY,1235
7
- pyerualjetwork/help.py,sha256=nQ_YbYA2RtuafhuvkreNpX0WWL1I_nzlelwCtvei0_Y,775
8
- pyerualjetwork/loss_functions.py,sha256=6PyBI232SQRGuFnG3LDGvnv_PUdWzT2_2mUODJiejGI,618
9
- pyerualjetwork/loss_functions_cuda.py,sha256=C93IZJcrOpT6HMK9x1O4AHJWXYTkN5WZiqdssPbvAPk,617
10
- pyerualjetwork/memory_operations.py,sha256=0yCOHcgiNyF4ccMcRlL1Q9F_byG4nzjhmkbpXE_yU6E,13401
11
- pyerualjetwork/metrics.py,sha256=q7MkhnZDRbCjFBDDfUgrl8lBYnUT_1ro1LxeBq105pI,6077
12
- pyerualjetwork/metrics_cuda.py,sha256=73h9GC7XwmnFCVzFEEiPQfF8CwHIz2wsCbxpZrJtYgw,5061
13
- pyerualjetwork/model_operations.py,sha256=fr64XCwgl1YRh5nP3sEkvQORKHb-2lF_a4KjclNkZfY,15522
14
- pyerualjetwork/model_operations_cuda.py,sha256=-Kv8fYqHSU0L9FalOsQ7EWCwCEwjgUySObyueOqCH_o,16134
15
- pyerualjetwork/plan.py,sha256=UyIvPmvHCHwczlc9KHolE4y6CPEeBfhnRN5yznSbnoM,23028
16
- pyerualjetwork/plan_cuda.py,sha256=iteqgv7x9Z2Pj4vGOZs6HXS3r0bNaF_smr7ZXaOdRnw,23990
17
- pyerualjetwork/planeat.py,sha256=prbkUIrD37Y_b7MmTuGg4rGHXfqHIjLFMbs7TnnEy9E,44645
18
- pyerualjetwork/planeat_cuda.py,sha256=i6WDHkUEAMK7IHNBilM29xyYWq2qvPNpF9idcAkC1EU,44650
19
- pyerualjetwork/ui.py,sha256=JBTFYz5R24XwNKhA3GSW-oYAoiIBxAE3kFGXkvm5gqw,656
20
- pyerualjetwork/visualizations.py,sha256=utnX9zQhzmtvBJLOLNGm2jecVVk4zHXABQdjb0XzJac,28352
21
- pyerualjetwork/visualizations_cuda.py,sha256=gnoaaazZ-nc9E1ImqXrZBRgQ4Rnpi2qh2yGJ2eLKMlE,28807
22
- pyerualjetwork-4.6.6.dist-info/METADATA,sha256=nrasvgqmd7Tb2-NEqbkmaS4FWNIaHmyttYaLLzKm0_Q,7505
23
- pyerualjetwork-4.6.6.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
24
- pyerualjetwork-4.6.6.dist-info/top_level.txt,sha256=BRyt62U_r3ZmJpj-wXNOoA345Bzamrj6RbaWsyW4tRg,15
25
- pyerualjetwork-4.6.6.dist-info/RECORD,,