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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2426 |
|
2427 |
|
2428 |
|
|
|
2423 |
|
2424 |
supermassive_nn = ConsciousSupermassiveNN20()
|
2425 |
|
2426 |
+
class ConsciousSupermassiveNN21:
|
2427 |
+
def __init__(self):
|
2428 |
+
self.snn = self.create_snn()
|
2429 |
+
self.rnn = self.create_rnn()
|
2430 |
+
self.cnn = self.create_cnn()
|
2431 |
+
self.fnn = self.create_fnn()
|
2432 |
+
self.ga_population = self.initialize_ga_population()
|
2433 |
+
self.memory = {}
|
2434 |
+
|
2435 |
+
def create_snn(self):
|
2436 |
+
return nn.Sequential(
|
2437 |
+
nn.Linear(4096, 2048),
|
2438 |
+
nn.ReLU(),
|
2439 |
+
nn.Linear(2048, 1024),
|
2440 |
+
nn.Sigmoid()
|
2441 |
+
)
|
2442 |
+
|
2443 |
+
def create_rnn(self):
|
2444 |
+
return nn.RNN(
|
2445 |
+
input_size=4096,
|
2446 |
+
hidden_size=2048,
|
2447 |
+
num_layers=5,
|
2448 |
+
nonlinearity="tanh",
|
2449 |
+
batch_first=True
|
2450 |
+
)
|
2451 |
+
|
2452 |
+
def create_cnn(self):
|
2453 |
+
return nn.Sequential(
|
2454 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
2455 |
+
nn.ReLU(),
|
2456 |
+
nn.MaxPool2d(2),
|
2457 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
2458 |
+
nn.ReLU(),
|
2459 |
+
nn.MaxPool2d(2),
|
2460 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
2461 |
+
nn.ReLU(),
|
2462 |
+
nn.Flatten(),
|
2463 |
+
nn.Linear(256 * 8 * 8, 1024),
|
2464 |
+
nn.ReLU(),
|
2465 |
+
nn.Linear(1024, 512)
|
2466 |
+
)
|
2467 |
+
|
2468 |
+
def create_fnn(self):
|
2469 |
+
return nn.Sequential(
|
2470 |
+
nn.Linear(4096, 2048),
|
2471 |
+
nn.ReLU(),
|
2472 |
+
nn.Linear(2048, 1024),
|
2473 |
+
nn.ReLU(),
|
2474 |
+
nn.Linear(1024, 512)
|
2475 |
+
)
|
2476 |
+
|
2477 |
+
def initialize_ga_population(self):
|
2478 |
+
return [np.random.randn(4096) for _ in range(500)]
|
2479 |
+
|
2480 |
+
def run_snn(self, x):
|
2481 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2482 |
+
output = self.snn(input_tensor)
|
2483 |
+
print("SNN Output:", output)
|
2484 |
+
return output
|
2485 |
+
|
2486 |
+
def run_rnn(self, x):
|
2487 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
2488 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2489 |
+
output, hn = self.rnn(input_tensor, h0)
|
2490 |
+
print("RNN Output:", output)
|
2491 |
+
return output
|
2492 |
+
|
2493 |
+
def run_cnn(self, x):
|
2494 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
2495 |
+
output = self.cnn(input_tensor)
|
2496 |
+
print("CNN Output:", output)
|
2497 |
+
return output
|
2498 |
+
|
2499 |
+
def run_fnn(self, x):
|
2500 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2501 |
+
output = self.fnn(input_tensor)
|
2502 |
+
print("FNN Output:", output)
|
2503 |
+
return output
|
2504 |
+
|
2505 |
+
def run_ga(self, fitness_func):
|
2506 |
+
for generation in range(200):
|
2507 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
2508 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
2509 |
+
self.ga_population = sorted_population[:250] + [
|
2510 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
2511 |
+
]
|
2512 |
+
best_fitness = max(fitness_scores)
|
2513 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
2514 |
+
return max(self.ga_population, key=fitness_func)
|
2515 |
+
|
2516 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
2517 |
+
feedback = self.memory.get(mode, None)
|
2518 |
+
if feedback is not None:
|
2519 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
2520 |
+
if mode == "snn":
|
2521 |
+
output = self.run_snn(input_data)
|
2522 |
+
elif mode == "rnn":
|
2523 |
+
output = self.run_rnn(input_data)
|
2524 |
+
elif mode == "cnn":
|
2525 |
+
output = self.run_cnn(input_data)
|
2526 |
+
elif mode == "fnn":
|
2527 |
+
output = self.run_fnn(input_data)
|
2528 |
+
else:
|
2529 |
+
raise ValueError("Invalid mode")
|
2530 |
+
self.memory[mode] = output.detach().numpy()
|
2531 |
+
return output
|
2532 |
+
|
2533 |
+
supermassive_nn = ConsciousSupermassiveNN21()
|
2534 |
+
|
2535 |
+
class ConsciousSupermassiveNN22:
|
2536 |
+
def __init__(self):
|
2537 |
+
self.snn = self.create_snn()
|
2538 |
+
self.rnn = self.create_rnn()
|
2539 |
+
self.cnn = self.create_cnn()
|
2540 |
+
self.fnn = self.create_fnn()
|
2541 |
+
self.ga_population = self.initialize_ga_population()
|
2542 |
+
self.memory = {}
|
2543 |
+
|
2544 |
+
def create_snn(self):
|
2545 |
+
return nn.Sequential(
|
2546 |
+
nn.Linear(4096, 2048),
|
2547 |
+
nn.ReLU(),
|
2548 |
+
nn.Linear(2048, 1024),
|
2549 |
+
nn.Sigmoid()
|
2550 |
+
)
|
2551 |
+
|
2552 |
+
def create_rnn(self):
|
2553 |
+
return nn.RNN(
|
2554 |
+
input_size=4096,
|
2555 |
+
hidden_size=2048,
|
2556 |
+
num_layers=5,
|
2557 |
+
nonlinearity="tanh",
|
2558 |
+
batch_first=True
|
2559 |
+
)
|
2560 |
+
|
2561 |
+
def create_cnn(self):
|
2562 |
+
return nn.Sequential(
|
2563 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
2564 |
+
nn.ReLU(),
|
2565 |
+
nn.MaxPool2d(2),
|
2566 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
2567 |
+
nn.ReLU(),
|
2568 |
+
nn.MaxPool2d(2),
|
2569 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
2570 |
+
nn.ReLU(),
|
2571 |
+
nn.Flatten(),
|
2572 |
+
nn.Linear(256 * 8 * 8, 1024),
|
2573 |
+
nn.ReLU(),
|
2574 |
+
nn.Linear(1024, 512)
|
2575 |
+
)
|
2576 |
+
|
2577 |
+
def create_fnn(self):
|
2578 |
+
return nn.Sequential(
|
2579 |
+
nn.Linear(4096, 2048),
|
2580 |
+
nn.ReLU(),
|
2581 |
+
nn.Linear(2048, 1024),
|
2582 |
+
nn.ReLU(),
|
2583 |
+
nn.Linear(1024, 512)
|
2584 |
+
)
|
2585 |
+
|
2586 |
+
def initialize_ga_population(self):
|
2587 |
+
return [np.random.randn(4096) for _ in range(500)]
|
2588 |
+
|
2589 |
+
def run_snn(self, x):
|
2590 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2591 |
+
output = self.snn(input_tensor)
|
2592 |
+
print("SNN Output:", output)
|
2593 |
+
return output
|
2594 |
+
|
2595 |
+
def run_rnn(self, x):
|
2596 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
2597 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2598 |
+
output, hn = self.rnn(input_tensor, h0)
|
2599 |
+
print("RNN Output:", output)
|
2600 |
+
return output
|
2601 |
+
|
2602 |
+
def run_cnn(self, x):
|
2603 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
2604 |
+
output = self.cnn(input_tensor)
|
2605 |
+
print("CNN Output:", output)
|
2606 |
+
return output
|
2607 |
+
|
2608 |
+
def run_fnn(self, x):
|
2609 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2610 |
+
output = self.fnn(input_tensor)
|
2611 |
+
print("FNN Output:", output)
|
2612 |
+
return output
|
2613 |
+
|
2614 |
+
def run_ga(self, fitness_func):
|
2615 |
+
for generation in range(200):
|
2616 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
2617 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
2618 |
+
self.ga_population = sorted_population[:250] + [
|
2619 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
2620 |
+
]
|
2621 |
+
best_fitness = max(fitness_scores)
|
2622 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
2623 |
+
return max(self.ga_population, key=fitness_func)
|
2624 |
+
|
2625 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
2626 |
+
feedback = self.memory.get(mode, None)
|
2627 |
+
if feedback is not None:
|
2628 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
2629 |
+
if mode == "snn":
|
2630 |
+
output = self.run_snn(input_data)
|
2631 |
+
elif mode == "rnn":
|
2632 |
+
output = self.run_rnn(input_data)
|
2633 |
+
elif mode == "cnn":
|
2634 |
+
output = self.run_cnn(input_data)
|
2635 |
+
elif mode == "fnn":
|
2636 |
+
output = self.run_fnn(input_data)
|
2637 |
+
else:
|
2638 |
+
raise ValueError("Invalid mode")
|
2639 |
+
self.memory[mode] = output.detach().numpy()
|
2640 |
+
return output
|
2641 |
+
|
2642 |
+
supermassive_nn = ConsciousSupermassiveNN22()
|
2643 |
+
|
2644 |
+
class ConsciousSupermassiveNN23:
|
2645 |
+
def __init__(self):
|
2646 |
+
self.snn = self.create_snn()
|
2647 |
+
self.rnn = self.create_rnn()
|
2648 |
+
self.cnn = self.create_cnn()
|
2649 |
+
self.fnn = self.create_fnn()
|
2650 |
+
self.ga_population = self.initialize_ga_population()
|
2651 |
+
self.memory = {}
|
2652 |
+
|
2653 |
+
def create_snn(self):
|
2654 |
+
return nn.Sequential(
|
2655 |
+
nn.Linear(4096, 2048),
|
2656 |
+
nn.ReLU(),
|
2657 |
+
nn.Linear(2048, 1024),
|
2658 |
+
nn.Sigmoid()
|
2659 |
+
)
|
2660 |
+
|
2661 |
+
def create_rnn(self):
|
2662 |
+
return nn.RNN(
|
2663 |
+
input_size=4096,
|
2664 |
+
hidden_size=2048,
|
2665 |
+
num_layers=5,
|
2666 |
+
nonlinearity="tanh",
|
2667 |
+
batch_first=True
|
2668 |
+
)
|
2669 |
+
|
2670 |
+
def create_cnn(self):
|
2671 |
+
return nn.Sequential(
|
2672 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
2673 |
+
nn.ReLU(),
|
2674 |
+
nn.MaxPool2d(2),
|
2675 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
2676 |
+
nn.ReLU(),
|
2677 |
+
nn.MaxPool2d(2),
|
2678 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
2679 |
+
nn.ReLU(),
|
2680 |
+
nn.Flatten(),
|
2681 |
+
nn.Linear(256 * 8 * 8, 1024),
|
2682 |
+
nn.ReLU(),
|
2683 |
+
nn.Linear(1024, 512)
|
2684 |
+
)
|
2685 |
+
|
2686 |
+
def create_fnn(self):
|
2687 |
+
return nn.Sequential(
|
2688 |
+
nn.Linear(4096, 2048),
|
2689 |
+
nn.ReLU(),
|
2690 |
+
nn.Linear(2048, 1024),
|
2691 |
+
nn.ReLU(),
|
2692 |
+
nn.Linear(1024, 512)
|
2693 |
+
)
|
2694 |
+
|
2695 |
+
def initialize_ga_population(self):
|
2696 |
+
return [np.random.randn(4096) for _ in range(500)]
|
2697 |
+
|
2698 |
+
def run_snn(self, x):
|
2699 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2700 |
+
output = self.snn(input_tensor)
|
2701 |
+
print("SNN Output:", output)
|
2702 |
+
return output
|
2703 |
+
|
2704 |
+
def run_rnn(self, x):
|
2705 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
2706 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2707 |
+
output, hn = self.rnn(input_tensor, h0)
|
2708 |
+
print("RNN Output:", output)
|
2709 |
+
return output
|
2710 |
+
|
2711 |
+
def run_cnn(self, x):
|
2712 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
2713 |
+
output = self.cnn(input_tensor)
|
2714 |
+
print("CNN Output:", output)
|
2715 |
+
return output
|
2716 |
+
|
2717 |
+
def run_fnn(self, x):
|
2718 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2719 |
+
output = self.fnn(input_tensor)
|
2720 |
+
print("FNN Output:", output)
|
2721 |
+
return output
|
2722 |
+
|
2723 |
+
def run_ga(self, fitness_func):
|
2724 |
+
for generation in range(200):
|
2725 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
2726 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
2727 |
+
self.ga_population = sorted_population[:250] + [
|
2728 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
2729 |
+
]
|
2730 |
+
best_fitness = max(fitness_scores)
|
2731 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
2732 |
+
return max(self.ga_population, key=fitness_func)
|
2733 |
+
|
2734 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
2735 |
+
feedback = self.memory.get(mode, None)
|
2736 |
+
if feedback is not None:
|
2737 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
2738 |
+
if mode == "snn":
|
2739 |
+
output = self.run_snn(input_data)
|
2740 |
+
elif mode == "rnn":
|
2741 |
+
output = self.run_rnn(input_data)
|
2742 |
+
elif mode == "cnn":
|
2743 |
+
output = self.run_cnn(input_data)
|
2744 |
+
elif mode == "fnn":
|
2745 |
+
output = self.run_fnn(input_data)
|
2746 |
+
else:
|
2747 |
+
raise ValueError("Invalid mode")
|
2748 |
+
self.memory[mode] = output.detach().numpy()
|
2749 |
+
return output
|
2750 |
+
|
2751 |
+
supermassive_nn = ConsciousSupermassiveNN23()
|
2752 |
+
|
2753 |
+
class ConsciousSupermassiveNN24:
|
2754 |
+
def __init__(self):
|
2755 |
+
self.snn = self.create_snn()
|
2756 |
+
self.rnn = self.create_rnn()
|
2757 |
+
self.cnn = self.create_cnn()
|
2758 |
+
self.fnn = self.create_fnn()
|
2759 |
+
self.ga_population = self.initialize_ga_population()
|
2760 |
+
self.memory = {}
|
2761 |
+
|
2762 |
+
def create_snn(self):
|
2763 |
+
return nn.Sequential(
|
2764 |
+
nn.Linear(4096, 2048),
|
2765 |
+
nn.ReLU(),
|
2766 |
+
nn.Linear(2048, 1024),
|
2767 |
+
nn.Sigmoid()
|
2768 |
+
)
|
2769 |
+
|
2770 |
+
def create_rnn(self):
|
2771 |
+
return nn.RNN(
|
2772 |
+
input_size=4096,
|
2773 |
+
hidden_size=2048,
|
2774 |
+
num_layers=5,
|
2775 |
+
nonlinearity="tanh",
|
2776 |
+
batch_first=True
|
2777 |
+
)
|
2778 |
+
|
2779 |
+
def create_cnn(self):
|
2780 |
+
return nn.Sequential(
|
2781 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
2782 |
+
nn.ReLU(),
|
2783 |
+
nn.MaxPool2d(2),
|
2784 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
2785 |
+
nn.ReLU(),
|
2786 |
+
nn.MaxPool2d(2),
|
2787 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
2788 |
+
nn.ReLU(),
|
2789 |
+
nn.Flatten(),
|
2790 |
+
nn.Linear(256 * 8 * 8, 1024),
|
2791 |
+
nn.ReLU(),
|
2792 |
+
nn.Linear(1024, 512)
|
2793 |
+
)
|
2794 |
+
|
2795 |
+
def create_fnn(self):
|
2796 |
+
return nn.Sequential(
|
2797 |
+
nn.Linear(4096, 2048),
|
2798 |
+
nn.ReLU(),
|
2799 |
+
nn.Linear(2048, 1024),
|
2800 |
+
nn.ReLU(),
|
2801 |
+
nn.Linear(1024, 512)
|
2802 |
+
)
|
2803 |
+
|
2804 |
+
def initialize_ga_population(self):
|
2805 |
+
return [np.random.randn(4096) for _ in range(500)]
|
2806 |
+
|
2807 |
+
def run_snn(self, x):
|
2808 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2809 |
+
output = self.snn(input_tensor)
|
2810 |
+
print("SNN Output:", output)
|
2811 |
+
return output
|
2812 |
+
|
2813 |
+
def run_rnn(self, x):
|
2814 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
2815 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2816 |
+
output, hn = self.rnn(input_tensor, h0)
|
2817 |
+
print("RNN Output:", output)
|
2818 |
+
return output
|
2819 |
+
|
2820 |
+
def run_cnn(self, x):
|
2821 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
2822 |
+
output = self.cnn(input_tensor)
|
2823 |
+
print("CNN Output:", output)
|
2824 |
+
return output
|
2825 |
+
|
2826 |
+
def run_fnn(self, x):
|
2827 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2828 |
+
output = self.fnn(input_tensor)
|
2829 |
+
print("FNN Output:", output)
|
2830 |
+
return output
|
2831 |
+
|
2832 |
+
def run_ga(self, fitness_func):
|
2833 |
+
for generation in range(200):
|
2834 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
2835 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
2836 |
+
self.ga_population = sorted_population[:250] + [
|
2837 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
2838 |
+
]
|
2839 |
+
best_fitness = max(fitness_scores)
|
2840 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
2841 |
+
return max(self.ga_population, key=fitness_func)
|
2842 |
+
|
2843 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
2844 |
+
feedback = self.memory.get(mode, None)
|
2845 |
+
if feedback is not None:
|
2846 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
2847 |
+
if mode == "snn":
|
2848 |
+
output = self.run_snn(input_data)
|
2849 |
+
elif mode == "rnn":
|
2850 |
+
output = self.run_rnn(input_data)
|
2851 |
+
elif mode == "cnn":
|
2852 |
+
output = self.run_cnn(input_data)
|
2853 |
+
elif mode == "fnn":
|
2854 |
+
output = self.run_fnn(input_data)
|
2855 |
+
else:
|
2856 |
+
raise ValueError("Invalid mode")
|
2857 |
+
self.memory[mode] = output.detach().numpy()
|
2858 |
+
return output
|
2859 |
+
|
2860 |
+
supermassive_nn = ConsciousSupermassiveNN24()
|
2861 |
+
|
2862 |
+
class ConsciousSupermassiveNN25:
|
2863 |
+
def __init__(self):
|
2864 |
+
self.snn = self.create_snn()
|
2865 |
+
self.rnn = self.create_rnn()
|
2866 |
+
self.cnn = self.create_cnn()
|
2867 |
+
self.fnn = self.create_fnn()
|
2868 |
+
self.ga_population = self.initialize_ga_population()
|
2869 |
+
self.memory = {}
|
2870 |
+
|
2871 |
+
def create_snn(self):
|
2872 |
+
return nn.Sequential(
|
2873 |
+
nn.Linear(4096, 2048),
|
2874 |
+
nn.ReLU(),
|
2875 |
+
nn.Linear(2048, 1024),
|
2876 |
+
nn.Sigmoid()
|
2877 |
+
)
|
2878 |
+
|
2879 |
+
def create_rnn(self):
|
2880 |
+
return nn.RNN(
|
2881 |
+
input_size=4096,
|
2882 |
+
hidden_size=2048,
|
2883 |
+
num_layers=5,
|
2884 |
+
nonlinearity="tanh",
|
2885 |
+
batch_first=True
|
2886 |
+
)
|
2887 |
+
|
2888 |
+
def create_cnn(self):
|
2889 |
+
return nn.Sequential(
|
2890 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
2891 |
+
nn.ReLU(),
|
2892 |
+
nn.MaxPool2d(2),
|
2893 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
2894 |
+
nn.ReLU(),
|
2895 |
+
nn.MaxPool2d(2),
|
2896 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
2897 |
+
nn.ReLU(),
|
2898 |
+
nn.Flatten(),
|
2899 |
+
nn.Linear(256 * 8 * 8, 1024),
|
2900 |
+
nn.ReLU(),
|
2901 |
+
nn.Linear(1024, 512)
|
2902 |
+
)
|
2903 |
+
|
2904 |
+
def create_fnn(self):
|
2905 |
+
return nn.Sequential(
|
2906 |
+
nn.Linear(4096, 2048),
|
2907 |
+
nn.ReLU(),
|
2908 |
+
nn.Linear(2048, 1024),
|
2909 |
+
nn.ReLU(),
|
2910 |
+
nn.Linear(1024, 512)
|
2911 |
+
)
|
2912 |
+
|
2913 |
+
def initialize_ga_population(self):
|
2914 |
+
return [np.random.randn(4096) for _ in range(500)]
|
2915 |
+
|
2916 |
+
def run_snn(self, x):
|
2917 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2918 |
+
output = self.snn(input_tensor)
|
2919 |
+
print("SNN Output:", output)
|
2920 |
+
return output
|
2921 |
+
|
2922 |
+
def run_rnn(self, x):
|
2923 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
2924 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2925 |
+
output, hn = self.rnn(input_tensor, h0)
|
2926 |
+
print("RNN Output:", output)
|
2927 |
+
return output
|
2928 |
+
|
2929 |
+
def run_cnn(self, x):
|
2930 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
2931 |
+
output = self.cnn(input_tensor)
|
2932 |
+
print("CNN Output:", output)
|
2933 |
+
return output
|
2934 |
+
|
2935 |
+
def run_fnn(self, x):
|
2936 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
2937 |
+
output = self.fnn(input_tensor)
|
2938 |
+
print("FNN Output:", output)
|
2939 |
+
return output
|
2940 |
+
|
2941 |
+
def run_ga(self, fitness_func):
|
2942 |
+
for generation in range(200):
|
2943 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
2944 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
2945 |
+
self.ga_population = sorted_population[:250] + [
|
2946 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
2947 |
+
]
|
2948 |
+
best_fitness = max(fitness_scores)
|
2949 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
2950 |
+
return max(self.ga_population, key=fitness_func)
|
2951 |
+
|
2952 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
2953 |
+
feedback = self.memory.get(mode, None)
|
2954 |
+
if feedback is not None:
|
2955 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
2956 |
+
if mode == "snn":
|
2957 |
+
output = self.run_snn(input_data)
|
2958 |
+
elif mode == "rnn":
|
2959 |
+
output = self.run_rnn(input_data)
|
2960 |
+
elif mode == "cnn":
|
2961 |
+
output = self.run_cnn(input_data)
|
2962 |
+
elif mode == "fnn":
|
2963 |
+
output = self.run_fnn(input_data)
|
2964 |
+
else:
|
2965 |
+
raise ValueError("Invalid mode")
|
2966 |
+
self.memory[mode] = output.detach().numpy()
|
2967 |
+
return output
|
2968 |
+
|
2969 |
+
supermassive_nn = ConsciousSupermassiveNN25()
|
2970 |
+
|
2971 |
|
2972 |
|
2973 |
|