AbstractIntegratedModule 1.3.6__tar.gz → 1.3.8__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 (23) hide show
  1. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/AbstractIntegratedModule.egg-info/PKG-INFO +1 -1
  2. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/AbstractIntegratedModule.py +148 -112
  3. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/AbstractOptimizedModules.c +6 -6
  4. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/PKG-INFO +1 -1
  5. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/pyproject.toml +1 -1
  6. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/setup.py +1 -1
  7. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
  8. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
  9. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
  10. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
  11. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/AbstractOptimizedModules.pyx +0 -0
  12. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/MANIFEST.in +0 -0
  13. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/README.md +0 -0
  14. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/abstract_model_storage/Cargo.toml +0 -0
  15. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/abstract_model_storage/pyproject.toml +0 -0
  16. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/abstract_model_storage/src/lib.rs +0 -0
  17. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
  18. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
  19. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
  20. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
  21. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
  22. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
  23. {abstractintegratedmodule-1.3.6 → abstractintegratedmodule-1.3.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AbstractIntegratedModule
3
- Version: 1.3.6
3
+ Version: 1.3.8
4
4
  Summary: IntegratedPipeline Specifically provide a Framework to build Stateful continual learning Machine Learning Models optimized for Edge devices (ARM64).
5
5
  Author: Micro-Novelty
6
6
  Author-email: Micro-Novelty <hernikpuspita5@gmail.com>
@@ -7585,16 +7585,11 @@ class ExplainabilityModule:
7585
7585
  # Train on this single example for a few epochs
7586
7586
  self.pipeline.model3.train(X_features, y_onehot, epochs=1000, lr=self.pipeline.mlp.lr, verbose=True, max_samples_for_focused_fit=200)
7587
7587
  self.pipeline.model3.lr = old_lr # Restore old LR
7588
- # 5. Store in memory gate for fast retrieval
7589
- self.pipeline.modular_prediction_saving(
7590
- self.pipeline.encode(text, self.pipeline.vocab),
7591
- X_features,
7592
- correct_label
7593
- )
7594
- # 6. Add to buffer for batch consolidation later.
7588
+
7589
+ # 5. Add to buffer for batch consolidation later.
7595
7590
  self.feedback_buffer.append((X_features, y_onehot, text, correct_label))
7596
7591
 
7597
- # 7. Batch train when buffer is full
7592
+ # 6. Batch train when buffer is full
7598
7593
  if len(self.feedback_buffer) >= self.buffer_size:
7599
7594
  print(f"\n[🔄] Buffer full with {len(self.feedback_buffer)} feedback examples. Starting batch training...")
7600
7595
  self._batch_train_from_feedback()
@@ -8844,6 +8839,16 @@ class ModelStorage:
8844
8839
  finally:
8845
8840
  if conn:
8846
8841
  conn.close()
8842
+
8843
+ def get_depth(self, lst):
8844
+ if not isinstance(lst, list):
8845
+ return 0
8846
+ if not lst:
8847
+ return 1
8848
+ return 1 + max(self.get_depth(item) for item in lst)
8849
+
8850
+ def is_more_than_2d(self, lst):
8851
+ return self.get_depth(lst) > 2
8847
8852
 
8848
8853
 
8849
8854
  def _validate_and_repair(self, data, memory_name=None):
@@ -8888,19 +8893,34 @@ class ModelStorage:
8888
8893
  # dynamic corruption check
8889
8894
  if isinstance(value, list):
8890
8895
  try:
8891
- arr = np.asarray(value)
8892
- if arr.ndim > 2:
8893
- print(f'[!] Corrupted value for key {key} '
8894
- f'(ndim={arr.ndim}), removing')
8895
- continue
8896
+
8897
+ if self.is_more_than_2d(value):
8898
+ print(f'[!] value for key: {key} with more than 2 dimensions, getting the actual probabilities...')
8899
+ try:
8900
+ try:
8901
+ if isinstance(value[0][0][0], (float, int)):
8902
+ value = value[0][1]
8903
+ else:
8904
+ continue
8905
+ except:
8906
+ if isinstance(value[0][0], (float, int)):
8907
+ value = value[1]
8908
+ else:
8909
+ continue
8910
+ except Exception as e:
8911
+ print(f'[>] Cannot process probabilities due to possible corruption: {e}')
8912
+ continue
8913
+
8896
8914
 
8897
- if num_classes > 0 and arr.ndim == 1 and \
8898
- len(arr) not in (num_classes, num_classes * 2):
8915
+ if num_classes > 0 and \
8916
+ len(value) not in (num_classes, num_classes * 2):
8899
8917
  print(f'[!] Suspicious shape for key {key}: '
8900
8918
  f'{arr.shape}, expected {num_classes} — removing')
8901
8919
  continue
8920
+
8902
8921
  except Exception as e:
8903
8922
  print(f'[>] Cannot determine value: {e}')
8923
+ traceback.print_exc()
8904
8924
  continue
8905
8925
 
8906
8926
  # None values — skipped silently
@@ -9204,7 +9224,7 @@ class ModelStorage:
9204
9224
  c = conn.cursor()
9205
9225
 
9206
9226
  c.execute("""
9207
- SELECT weights FROM accurate_cache_storage
9227
+ SELECT weights FROM weight_storage
9208
9228
  WHERE memory_name = ? AND is_active = 1
9209
9229
  """, (memory_name,))
9210
9230
 
@@ -13430,7 +13450,6 @@ class IntegratedPipeline:
13430
13450
  self.autonomous = False
13431
13451
  self.show_explainability_details = True
13432
13452
  self.freeze_learning = False
13433
- self._cache_save_count = None
13434
13453
  self._prob_save_count = None
13435
13454
  self.hashing_vectorizer = None
13436
13455
 
@@ -13459,7 +13478,9 @@ class IntegratedPipeline:
13459
13478
  print(f'|| Found Matched Memory: {memory_name}!')
13460
13479
  self.memory = self.storage.memory_retrieval(memory_name, type_func='Pipeline', verbose=True)
13461
13480
 
13462
- is_corrupted, reason, suggested_fix = self.is_memory_corrupted(self.memory)
13481
+ result = self.is_memory_corrupted(self.memory)
13482
+ if result is not None and isinstance(result, tuple):
13483
+ is_corrupted, reason, suggested_fix = result[0], result[1], result[2]
13463
13484
  if is_corrupted:
13464
13485
  print(f'[⚠️] MEMORY CORRUPTION DETECTED!')
13465
13486
  print(f' Reason: {reason}')
@@ -13511,7 +13532,7 @@ class IntegratedPipeline:
13511
13532
  if len(memory) == self._get_num_classes():
13512
13533
  return memory
13513
13534
  else:
13514
- print('[!] Memory length is not tied with current number of classes! skipping Memory.')
13535
+
13515
13536
  return None
13516
13537
 
13517
13538
  return memory
@@ -13976,7 +13997,7 @@ class IntegratedPipeline:
13976
13997
  if not memory:
13977
13998
  return (False, "Empty dict (no memory)", None)
13978
13999
 
13979
- valid_keys = {'TW', 'MW', 'TP', 'MP', 'TA', 'local',
14000
+ valid_keys = {'TP', 'MP', 'TA', 'local',
13980
14001
  '_cached_probs', '_data'}
13981
14002
 
13982
14003
  for key, value in memory.items():
@@ -14727,32 +14748,6 @@ class IntegratedPipeline:
14727
14748
 
14728
14749
  return anisotropy
14729
14750
 
14730
- def modular_prediction_saving(self, X, X2, output):
14731
- memory_name = self.memory_name
14732
-
14733
- X = self._sanitize_for_storage(X)
14734
- X2 = self._sanitize_for_storage(X2)
14735
- output = self._sanitize_for_storage(output)
14736
-
14737
- if self.memory is None:
14738
- self.memory = {}
14739
-
14740
- elif not isinstance(self.memory, dict):
14741
- print(f'[!] Warning: memory was {type(self.memory)}, converting to dict')
14742
- # Try to convert or reset
14743
- if isinstance(self.memory, np.ndarray):
14744
- # If memory was an array, changing type - log it
14745
- print(f'[!] Converting memory from array to dict, old shape: {self.memory.shape}')
14746
- self.memory = {}
14747
-
14748
- self.memory['TW'] = X, output # transformers Weight
14749
- self.memory['MW'] = X2, output # MLP Weight
14750
- try:
14751
- print('🚀 Memory Prediction Added!')
14752
- self.storage.save_model_dict(memory_name, self.memory, type='Pipeline', model_type='prediction')
14753
- except Exception as e:
14754
- print(f'[!] Cant save model memory: {e}')
14755
-
14756
14751
 
14757
14752
  def modular_probability_saving(self, X, X2, prob):
14758
14753
  memory_name = self.memory_name
@@ -14838,7 +14833,14 @@ class IntegratedPipeline:
14838
14833
 
14839
14834
  def model_memory_gate(self, x, x2, i=1):
14840
14835
  memory = self.memory
14841
- is_corrupted, reason, _ = self.is_memory_corrupted(memory)
14836
+ result = self.is_memory_corrupted(memory)
14837
+
14838
+ is_corrupted = False
14839
+ is_val_corrupted = False
14840
+ reason = None
14841
+
14842
+ if result is not None and isinstance(result, tuple):
14843
+ is_corrupted, _, _ = result[0], result[1], result[2]
14842
14844
 
14843
14845
  if isinstance(memory, np.ndarray):
14844
14846
  if self._get_num_classes() and memory.shape[-1] == self._get_num_classes():
@@ -14907,7 +14909,9 @@ class IntegratedPipeline:
14907
14909
 
14908
14910
  if isinstance(memory, dict):
14909
14911
  for key, value in list(memory.items()):
14910
- is_val_corrupted, reason, _ = self.is_memory_corrupted(value)
14912
+ result = self.is_memory_corrupted(value)
14913
+ if result is not None and isinstance(result, tuple):
14914
+ is_val_corrupted, reason, _ = result[0], result[1], result[2]
14911
14915
  if is_val_corrupted and not key.startswith('supervised'):
14912
14916
  print(f'[!] Removing corrupted entry {key}: {reason}')
14913
14917
  del memory[key]
@@ -15051,8 +15055,14 @@ class IntegratedPipeline:
15051
15055
  output_mlp = None
15052
15056
  out = None
15053
15057
 
15058
+ is_corrupted = False
15059
+ reason = None
15060
+
15061
+
15054
15062
  memory = self.memory
15055
- is_corrupted, reason, _ = self.is_memory_corrupted(memory)
15063
+ result = self.is_memory_corrupted(memory)
15064
+ if result is not None and isinstance(result, tuple):
15065
+ is_corrupted, reason, _ = result[0], result[1], result[2]
15056
15066
 
15057
15067
  if isinstance(memory, np.ndarray):
15058
15068
  if self._get_num_classes() and not memory.shape[-1] == self._get_num_classes():
@@ -15113,10 +15123,15 @@ class IntegratedPipeline:
15113
15123
 
15114
15124
  if isinstance(memory, dict):
15115
15125
  for key, value in list(memory.items()):
15116
- is_val_corrupted, reason, _ = self.is_memory_corrupted(value)
15117
- if is_val_corrupted:
15118
- print(f'[!] Removing corrupted entry {key}: {reason}')
15119
- del memory[key]
15126
+ result = self.is_memory_corrupted(value)
15127
+
15128
+ if result is not None and isinstance(result, tuple):
15129
+ is_val_corrupted, reason, _ = result[0], result[1], result[2]
15130
+ if is_val_corrupted:
15131
+ print(f'[!] Removing corrupted entry {key}: {reason}')
15132
+ del memory[key]
15133
+ else:
15134
+ return None
15120
15135
 
15121
15136
  cache_trans_memory = [key for key, (inp) in memory.items() if key.startswith('TP') and (isinstance(inp, np.ndarray) or isinstance(inp, list)) and self.cosine_robust_similarity(x, inp) >= 0.85]
15122
15137
  cache_mlp_memory = [key for key, (inp2) in memory.items() if key.startswith('MP') and (isinstance(inp2, np.ndarray) or isinstance(inp2, list)) and self.cosine_similarity(x2, inp2) >= 0.85]
@@ -15394,8 +15409,6 @@ class IntegratedPipeline:
15394
15409
  if fresh_probs.ndim == 1:
15395
15410
  fresh_probs = fresh_probs[np.newaxis, :]
15396
15411
 
15397
- cached_count = 0 # track global cache count
15398
-
15399
15412
  for i, fresh_idx in enumerate(needs_fresh):
15400
15413
  row = fresh_probs[i]
15401
15414
 
@@ -15408,15 +15421,6 @@ class IntegratedPipeline:
15408
15421
 
15409
15422
  chunk_probs[fresh_idx] = row
15410
15423
 
15411
- # cap caching meaningfully
15412
- if cached_count < 2:
15413
- self.modular_prediction_saving(
15414
- fresh_ids[i:i+1],
15415
- fresh_X[i:i+1],
15416
- row[np.newaxis, :]
15417
- )
15418
- cached_count += 1
15419
-
15420
15424
 
15421
15425
  return np.array([
15422
15426
  p if p is not None else np.zeros(num_classes)
@@ -15602,14 +15606,7 @@ class IntegratedPipeline:
15602
15606
 
15603
15607
  batch_probs[idx] = row
15604
15608
 
15605
- # instance-level counter
15606
- if getattr(self, '_cache_save_count', 0) < 2:
15607
- self.modular_prediction_saving(
15608
- fresh_input_ids[i:i+1],
15609
- fresh_X_raw[i:i+1],
15610
- row[np.newaxis, :]
15611
- )
15612
- self._cache_save_count = getattr(self, '_cache_save_count', 0) + 1
15609
+
15613
15610
 
15614
15611
  # build valid_probs with guaranteed consistent shape
15615
15612
  valid_probs = []
@@ -15825,9 +15822,6 @@ class IntegratedPipeline:
15825
15822
  print('[+] Autonomous dynamic prediction: ')
15826
15823
  probs, details = self.ensemble.predict_ensemble(input_ids, X, y, method='dynamic', embedded=use_embedded)
15827
15824
 
15828
- self.modular_prediction_saving(input_ids, X, probs)
15829
- print('🚀 Memory Added!')
15830
-
15831
15825
  return probs
15832
15826
 
15833
15827
  def _handle_distributed_connections(self, probs, self_attn_weights, input_ids, agreement):
@@ -18608,40 +18602,43 @@ class AccurateAnswerCache:
18608
18602
  best_combined_sim = 0.0
18609
18603
 
18610
18604
  for entry in self.cache.values():
18611
- mlp_sim = self.pipeline.cosine_robust_similarity(x_mlp, entry['x_mlp'])
18605
+ if 'x_mlp' in entry and 'input_ids' in entry:
18606
+ mlp_sim = self.pipeline.cosine_robust_similarity(x_mlp, entry['x_mlp'])
18612
18607
 
18613
- seq_sim = 1.0
18614
- if input_ids is not None and entry['input_ids'] is not None:
18615
- ids_a = self._flatten_indices(input_ids)
18616
- ids_b = entry['input_ids'].ravel()
18608
+ seq_sim = 1.0
18609
+ if input_ids is not None and entry['input_ids'] is not None:
18610
+ ids_a = self._flatten_indices(input_ids)
18611
+ ids_b = entry['input_ids'].ravel()
18617
18612
 
18618
- if ids_a.shape != ids_b.shape:
18619
- ids_a, ids_b = self._adapt_ids_shape(ids_a, ids_b)
18613
+ if ids_a.shape != ids_b.shape:
18614
+ ids_a, ids_b = self._adapt_ids_shape(ids_a, ids_b)
18620
18615
 
18621
- min_len = min(len(ids_a), len(ids_b))
18622
- if min_len > 0:
18623
- seq_sim = float(np.mean(ids_a[:min_len] == ids_b[:min_len]))
18616
+ min_len = min(len(ids_a), len(ids_b))
18617
+ if min_len > 0:
18618
+ seq_sim = float(np.mean(ids_a[:min_len] == ids_b[:min_len]))
18624
18619
 
18625
- combined_env_sim = ((mlp_sim + seq_sim) / 2 * anisotropy)
18626
- deterministic_modelling_sim = ((mlp_sim + seq_sim) / 2 * AME)
18620
+ combined_env_sim = ((mlp_sim + seq_sim) / 2 * anisotropy)
18621
+ deterministic_modelling_sim = ((mlp_sim + seq_sim) / 2 * AME)
18627
18622
 
18628
- combinatorial_absolute_factor = (
18629
- deterministic_modelling_sim > best_combined_sim and
18630
- AME < 0.5 and
18631
- entry['confidence'] > 0.5
18632
- )
18633
- dynamic_environmental_factor = (
18634
- combined_env_sim > best_combined_sim and
18635
- AME > 0.5 and
18636
- entry['confidence'] > confidence_threshold
18637
- )
18623
+ combinatorial_absolute_factor = (
18624
+ deterministic_modelling_sim > best_combined_sim and
18625
+ AME < 0.5 and
18626
+ entry['confidence'] > 0.5
18627
+ )
18628
+ dynamic_environmental_factor = (
18629
+ combined_env_sim > best_combined_sim and
18630
+ AME > 0.5 and
18631
+ entry['confidence'] > confidence_threshold
18632
+ )
18638
18633
 
18639
- if combinatorial_absolute_factor:
18640
- best_combined_sim = deterministic_modelling_sim
18641
- else:
18642
- best_combined_sim = combined_env_sim
18634
+ if combinatorial_absolute_factor:
18635
+ best_combined_sim = deterministic_modelling_sim
18636
+ else:
18637
+ best_combined_sim = combined_env_sim
18643
18638
 
18644
- best_match = entry
18639
+ best_match = entry
18640
+ else:
18641
+ return None
18645
18642
 
18646
18643
  if best_match and best_combined_sim >= self.similarity_threshold:
18647
18644
  best_match['hit_count'] += 1
@@ -18660,6 +18657,7 @@ class AccurateAnswerCache:
18660
18657
 
18661
18658
  except Exception as e:
18662
18659
  print(f'[!] Cant search for Correct answer in cache due to: {e}')
18660
+ traceback.print_exc()
18663
18661
  return None
18664
18662
 
18665
18663
  def _hash_ids(self, input_ids):
@@ -18669,6 +18667,7 @@ class AccurateAnswerCache:
18669
18667
  return hashlib.md5(ids.tobytes(), usedforsecurity=False).hexdigest()
18670
18668
  except Exception as e:
18671
18669
  print(f'[!] cannot create a Hash ID for samples due to: {e}')
18670
+
18672
18671
  return None
18673
18672
 
18674
18673
  def _make_key(self, x_mlp):
@@ -21781,16 +21780,28 @@ def print_confidence_report(results, top_k=3, max_print_threshold=50):
21781
21780
  f"|| Top-{top_k}: [{top_str}]")
21782
21781
  return pred_cache
21783
21782
 
21784
- def initialize_snn_network(X=None, y=None, label_map=None, n_hidden=64, n_in=None, n_classes=None, seed=0, random_state=42):
21783
+ def initialize_snn_network(X=None, y=None, label_map=None, task=None, n_hidden=64, n_in=None, n_classes=None, seed=0, random_state=42):
21785
21784
  try:
21786
21785
  utility = SNNUtility()
21787
21786
  rng = utility.seed_everything(seed)
21787
+ if isinstance(X, list):
21788
+ X = np.asarray(X)
21788
21789
  if n_in is not None and n_classes is not None:
21789
21790
  net, hidden_layer = build_snn_network(n_in, n_hidden, n_classes, rng)
21790
21791
  else:
21792
+ if task is None:
21793
+ task = infer_target_type(y=y)
21794
+ if task == 'regression':
21795
+ if X.ndim > 2:
21796
+ X = X.reshape(len(X), -1)
21797
+
21791
21798
  X_train, X_test, y_train, y_test, X_val, y_val = _prepare_train_val_split(X=X, y=y, random_state=random_state)
21792
21799
  n_in = X_train.shape[1]
21793
- n_classes = max(len(label_map), int(y_train.max() + 1))
21800
+ if label_map is not None:
21801
+ n_classes = max(len(label_map), int(y_train.max() + 1))
21802
+ else:
21803
+ n_classes = y.shape[1]
21804
+
21794
21805
  net, hidden_layer = build_snn_network(n_in, n_hidden, n_classes, rng)
21795
21806
 
21796
21807
  print(f'[>] Initialized SNN Network with hidden dim: {n_hidden}')
@@ -21825,7 +21836,7 @@ def infer_target_type(y=None, max_classes_ratio=0.05, max_unique_absolute=50):
21825
21836
 
21826
21837
 
21827
21838
 
21828
- def train_snn_network(X=None, y=None, net=None, hidden_layer=None, utility=None, task='classification', label_map=None,
21839
+ def train_snn_network(X=None, y=None, net=None, hidden_layer=None, utility=None, task=None, label_map=None,
21829
21840
  epochs=50, batch_size=32, n_steps=20,
21830
21841
  n_hidden=64, lr=2e-3, seed=0, pretrain_steps=200, unsupervised_stdp=False,
21831
21842
  random_state=42, jepa_pretrain_enabled=False, X_unlabeled=None, jepa_kwargs=None):
@@ -21944,22 +21955,45 @@ def train_snn_network(X=None, y=None, net=None, hidden_layer=None, utility=None,
21944
21955
 
21945
21956
  return encoder, net, report, warnings
21946
21957
 
21947
- def _snn_predict_regression(X, net, encoder, n_mc=20):
21958
+
21959
+ def _snn_predict_regression(X, net, encoder, n_mc=20, z_score=1.96):
21948
21960
  sc = getattr(net, 'regression_scalers', None)
21949
21961
  if sc is None:
21950
21962
  raise ValueError('[>] net has no regression_scalers: train it with train_snn_network(task="regression") first')
21963
+
21951
21964
  X = np.asarray(X, dtype=np.float64)
21952
21965
  X = X.reshape(len(X), -1) # (N, W*F)
21953
21966
  Xs = np.clip((X - sc['lo']) / sc['span'], 0.0, 1.0)
21954
-
21955
- # the Poisson encoder is stochastic, its repeated to get a prediction and a spread
21967
+
21956
21968
  outs = np.stack([net.predict(encoder.encode(Xs), task='regression')[1] for _ in range(n_mc)]) # (n_mc, N, n_out)
21969
+
21970
+ # Unscaled std in normalized space (useful for scale-free confidence score)
21971
+ norm_std = outs.std(0)
21972
+
21957
21973
  mean = outs.mean(0) * sc['y_sd'] + sc['y_mu']
21958
- std = outs.std(0) * sc['y_sd']
21959
-
21974
+ std = norm_std * sc['y_sd']
21975
+
21976
+ # 1. Confidence Intervals (e.g., 95% CI when z_score=1.96)
21977
+ ci_lower = mean - z_score * std
21978
+ ci_upper = mean + z_score * std
21979
+
21980
+ # 2. Heuristic Confidence Score (0 to 1)
21981
+ confidence_score = 1.0 / (1.0 + norm_std)
21982
+
21960
21983
  if mean.shape[1] == 1:
21961
- mean, std = mean[:, 0], std[:, 0]
21962
- return {'prediction': mean, 'std': std}
21984
+ mean = mean[:, 0]
21985
+ std = std[:, 0]
21986
+ ci_lower = ci_lower[:, 0]
21987
+ ci_upper = ci_upper[:, 0]
21988
+ confidence_score = confidence_score[:, 0]
21989
+
21990
+ return {
21991
+ 'prediction': mean,
21992
+ 'std': std,
21993
+ 'ci_lower': ci_lower,
21994
+ 'ci_upper': ci_upper,
21995
+ 'confidence': confidence_score
21996
+ }
21963
21997
 
21964
21998
 
21965
21999
  def snn_predict(X=None, y=None, task='classification', label_map=None, encoder=None, net=None, random_state=42, max_print_threshold=50):
@@ -22000,6 +22034,7 @@ def snn_predict(X=None, y=None, task='classification', label_map=None, encoder=N
22000
22034
 
22001
22035
  if task == 'regression':
22002
22036
  result = _snn_predict_regression(X, net, encoder)
22037
+ print(f"[>] SNN Prediction: {result['prediction']} || Confidence: {result['confidence']}")
22003
22038
  return result
22004
22039
 
22005
22040
  try:
@@ -26975,3 +27010,4 @@ if __name__ == "__main__":
26975
27010
  traceback.print_exc()
26976
27011
  pass
26977
27012
 
27013
+
@@ -4,14 +4,14 @@
4
4
  {
5
5
  "distutils": {
6
6
  "depends": [
7
- "/tmp/build-env-o0tc6imy/lib/python3.12/site-packages/numpy/_core/include/numpy/arrayobject.h",
8
- "/tmp/build-env-o0tc6imy/lib/python3.12/site-packages/numpy/_core/include/numpy/arrayscalars.h",
9
- "/tmp/build-env-o0tc6imy/lib/python3.12/site-packages/numpy/_core/include/numpy/ndarrayobject.h",
10
- "/tmp/build-env-o0tc6imy/lib/python3.12/site-packages/numpy/_core/include/numpy/ndarraytypes.h",
11
- "/tmp/build-env-o0tc6imy/lib/python3.12/site-packages/numpy/_core/include/numpy/ufuncobject.h"
7
+ "/tmp/build-env-h3rxfgt6/lib/python3.12/site-packages/numpy/_core/include/numpy/arrayobject.h",
8
+ "/tmp/build-env-h3rxfgt6/lib/python3.12/site-packages/numpy/_core/include/numpy/arrayscalars.h",
9
+ "/tmp/build-env-h3rxfgt6/lib/python3.12/site-packages/numpy/_core/include/numpy/ndarrayobject.h",
10
+ "/tmp/build-env-h3rxfgt6/lib/python3.12/site-packages/numpy/_core/include/numpy/ndarraytypes.h",
11
+ "/tmp/build-env-h3rxfgt6/lib/python3.12/site-packages/numpy/_core/include/numpy/ufuncobject.h"
12
12
  ],
13
13
  "include_dirs": [
14
- "/tmp/build-env-o0tc6imy/lib/python3.12/site-packages/numpy/_core/include"
14
+ "/tmp/build-env-h3rxfgt6/lib/python3.12/site-packages/numpy/_core/include"
15
15
  ],
16
16
  "name": "AbstractOptimizedModules",
17
17
  "sources": [
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AbstractIntegratedModule
3
- Version: 1.3.6
3
+ Version: 1.3.8
4
4
  Summary: IntegratedPipeline Specifically provide a Framework to build Stateful continual learning Machine Learning Models optimized for Edge devices (ARM64).
5
5
  Author: Micro-Novelty
6
6
  Author-email: Micro-Novelty <hernikpuspita5@gmail.com>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "AbstractIntegratedModule"
7
- version = "1.3.6"
7
+ version = "1.3.8"
8
8
  authors = [
9
9
  {name = "Micro-Novelty", email = "hernikpuspita5@gmail.com"},
10
10
  ]
@@ -24,7 +24,7 @@ extensions = [
24
24
 
25
25
  setup(
26
26
  name="AbstractIntegratedModule",
27
- version="1.3.6",
27
+ version="1.3.8",
28
28
  description="IntegratedPipeline Specifically provide a Framework to build Stateful continual learning Machine Learning Models optimized for Edge devices (ARM64).",
29
29
  readme="README.md",
30
30
  long_description=long_description,