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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2971 |
|
2972 |
|
2973 |
|
|
|
2968 |
|
2969 |
supermassive_nn = ConsciousSupermassiveNN25()
|
2970 |
|
2971 |
+
class ConsciousSupermassiveNN26:
|
2972 |
+
def __init__(self):
|
2973 |
+
self.snn = self.create_snn()
|
2974 |
+
self.rnn = self.create_rnn()
|
2975 |
+
self.cnn = self.create_cnn()
|
2976 |
+
self.fnn = self.create_fnn()
|
2977 |
+
self.ga_population = self.initialize_ga_population()
|
2978 |
+
self.memory = {}
|
2979 |
+
|
2980 |
+
def create_snn(self):
|
2981 |
+
return nn.Sequential(
|
2982 |
+
nn.Linear(4096, 2048),
|
2983 |
+
nn.ReLU(),
|
2984 |
+
nn.Linear(2048, 1024),
|
2985 |
+
nn.Sigmoid()
|
2986 |
+
)
|
2987 |
+
|
2988 |
+
def create_rnn(self):
|
2989 |
+
return nn.RNN(
|
2990 |
+
input_size=4096,
|
2991 |
+
hidden_size=2048,
|
2992 |
+
num_layers=5,
|
2993 |
+
nonlinearity="tanh",
|
2994 |
+
batch_first=True
|
2995 |
+
)
|
2996 |
+
|
2997 |
+
def create_cnn(self):
|
2998 |
+
return nn.Sequential(
|
2999 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
3000 |
+
nn.ReLU(),
|
3001 |
+
nn.MaxPool2d(2),
|
3002 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
3003 |
+
nn.ReLU(),
|
3004 |
+
nn.MaxPool2d(2),
|
3005 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
3006 |
+
nn.ReLU(),
|
3007 |
+
nn.Flatten(),
|
3008 |
+
nn.Linear(256 * 8 * 8, 1024),
|
3009 |
+
nn.ReLU(),
|
3010 |
+
nn.Linear(1024, 512)
|
3011 |
+
)
|
3012 |
+
|
3013 |
+
def create_fnn(self):
|
3014 |
+
return nn.Sequential(
|
3015 |
+
nn.Linear(4096, 2048),
|
3016 |
+
nn.ReLU(),
|
3017 |
+
nn.Linear(2048, 1024),
|
3018 |
+
nn.ReLU(),
|
3019 |
+
nn.Linear(1024, 512)
|
3020 |
+
)
|
3021 |
+
|
3022 |
+
def initialize_ga_population(self):
|
3023 |
+
return [np.random.randn(4096) for _ in range(500)]
|
3024 |
+
|
3025 |
+
def run_snn(self, x):
|
3026 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3027 |
+
output = self.snn(input_tensor)
|
3028 |
+
print("SNN Output:", output)
|
3029 |
+
return output
|
3030 |
+
|
3031 |
+
def run_rnn(self, x):
|
3032 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
3033 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3034 |
+
output, hn = self.rnn(input_tensor, h0)
|
3035 |
+
print("RNN Output:", output)
|
3036 |
+
return output
|
3037 |
+
|
3038 |
+
def run_cnn(self, x):
|
3039 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
3040 |
+
output = self.cnn(input_tensor)
|
3041 |
+
print("CNN Output:", output)
|
3042 |
+
return output
|
3043 |
+
|
3044 |
+
def run_fnn(self, x):
|
3045 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3046 |
+
output = self.fnn(input_tensor)
|
3047 |
+
print("FNN Output:", output)
|
3048 |
+
return output
|
3049 |
+
|
3050 |
+
def run_ga(self, fitness_func):
|
3051 |
+
for generation in range(200):
|
3052 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
3053 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
3054 |
+
self.ga_population = sorted_population[:250] + [
|
3055 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
3056 |
+
]
|
3057 |
+
best_fitness = max(fitness_scores)
|
3058 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
3059 |
+
return max(self.ga_population, key=fitness_func)
|
3060 |
+
|
3061 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
3062 |
+
feedback = self.memory.get(mode, None)
|
3063 |
+
if feedback is not None:
|
3064 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
3065 |
+
if mode == "snn":
|
3066 |
+
output = self.run_snn(input_data)
|
3067 |
+
elif mode == "rnn":
|
3068 |
+
output = self.run_rnn(input_data)
|
3069 |
+
elif mode == "cnn":
|
3070 |
+
output = self.run_cnn(input_data)
|
3071 |
+
elif mode == "fnn":
|
3072 |
+
output = self.run_fnn(input_data)
|
3073 |
+
else:
|
3074 |
+
raise ValueError("Invalid mode")
|
3075 |
+
self.memory[mode] = output.detach().numpy()
|
3076 |
+
return output
|
3077 |
+
|
3078 |
+
supermassive_nn = ConsciousSupermassiveNN26()
|
3079 |
+
|
3080 |
+
class ConsciousSupermassiveNN27:
|
3081 |
+
def __init__(self):
|
3082 |
+
self.snn = self.create_snn()
|
3083 |
+
self.rnn = self.create_rnn()
|
3084 |
+
self.cnn = self.create_cnn()
|
3085 |
+
self.fnn = self.create_fnn()
|
3086 |
+
self.ga_population = self.initialize_ga_population()
|
3087 |
+
self.memory = {}
|
3088 |
+
|
3089 |
+
def create_snn(self):
|
3090 |
+
return nn.Sequential(
|
3091 |
+
nn.Linear(4096, 2048),
|
3092 |
+
nn.ReLU(),
|
3093 |
+
nn.Linear(2048, 1024),
|
3094 |
+
nn.Sigmoid()
|
3095 |
+
)
|
3096 |
+
|
3097 |
+
def create_rnn(self):
|
3098 |
+
return nn.RNN(
|
3099 |
+
input_size=4096,
|
3100 |
+
hidden_size=2048,
|
3101 |
+
num_layers=5,
|
3102 |
+
nonlinearity="tanh",
|
3103 |
+
batch_first=True
|
3104 |
+
)
|
3105 |
+
|
3106 |
+
def create_cnn(self):
|
3107 |
+
return nn.Sequential(
|
3108 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
3109 |
+
nn.ReLU(),
|
3110 |
+
nn.MaxPool2d(2),
|
3111 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
3112 |
+
nn.ReLU(),
|
3113 |
+
nn.MaxPool2d(2),
|
3114 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
3115 |
+
nn.ReLU(),
|
3116 |
+
nn.Flatten(),
|
3117 |
+
nn.Linear(256 * 8 * 8, 1024),
|
3118 |
+
nn.ReLU(),
|
3119 |
+
nn.Linear(1024, 512)
|
3120 |
+
)
|
3121 |
+
|
3122 |
+
def create_fnn(self):
|
3123 |
+
return nn.Sequential(
|
3124 |
+
nn.Linear(4096, 2048),
|
3125 |
+
nn.ReLU(),
|
3126 |
+
nn.Linear(2048, 1024),
|
3127 |
+
nn.ReLU(),
|
3128 |
+
nn.Linear(1024, 512)
|
3129 |
+
)
|
3130 |
+
|
3131 |
+
def initialize_ga_population(self):
|
3132 |
+
return [np.random.randn(4096) for _ in range(500)]
|
3133 |
+
|
3134 |
+
def run_snn(self, x):
|
3135 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3136 |
+
output = self.snn(input_tensor)
|
3137 |
+
print("SNN Output:", output)
|
3138 |
+
return output
|
3139 |
+
|
3140 |
+
def run_rnn(self, x):
|
3141 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
3142 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3143 |
+
output, hn = self.rnn(input_tensor, h0)
|
3144 |
+
print("RNN Output:", output)
|
3145 |
+
return output
|
3146 |
+
|
3147 |
+
def run_cnn(self, x):
|
3148 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
3149 |
+
output = self.cnn(input_tensor)
|
3150 |
+
print("CNN Output:", output)
|
3151 |
+
return output
|
3152 |
+
|
3153 |
+
def run_fnn(self, x):
|
3154 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3155 |
+
output = self.fnn(input_tensor)
|
3156 |
+
print("FNN Output:", output)
|
3157 |
+
return output
|
3158 |
+
|
3159 |
+
def run_ga(self, fitness_func):
|
3160 |
+
for generation in range(200):
|
3161 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
3162 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
3163 |
+
self.ga_population = sorted_population[:250] + [
|
3164 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
3165 |
+
]
|
3166 |
+
best_fitness = max(fitness_scores)
|
3167 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
3168 |
+
return max(self.ga_population, key=fitness_func)
|
3169 |
+
|
3170 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
3171 |
+
feedback = self.memory.get(mode, None)
|
3172 |
+
if feedback is not None:
|
3173 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
3174 |
+
if mode == "snn":
|
3175 |
+
output = self.run_snn(input_data)
|
3176 |
+
elif mode == "rnn":
|
3177 |
+
output = self.run_rnn(input_data)
|
3178 |
+
elif mode == "cnn":
|
3179 |
+
output = self.run_cnn(input_data)
|
3180 |
+
elif mode == "fnn":
|
3181 |
+
output = self.run_fnn(input_data)
|
3182 |
+
else:
|
3183 |
+
raise ValueError("Invalid mode")
|
3184 |
+
self.memory[mode] = output.detach().numpy()
|
3185 |
+
return output
|
3186 |
+
|
3187 |
+
supermassive_nn = ConsciousSupermassiveNN27()
|
3188 |
+
|
3189 |
+
class ConsciousSupermassiveNN28:
|
3190 |
+
def __init__(self):
|
3191 |
+
self.snn = self.create_snn()
|
3192 |
+
self.rnn = self.create_rnn()
|
3193 |
+
self.cnn = self.create_cnn()
|
3194 |
+
self.fnn = self.create_fnn()
|
3195 |
+
self.ga_population = self.initialize_ga_population()
|
3196 |
+
self.memory = {}
|
3197 |
+
|
3198 |
+
def create_snn(self):
|
3199 |
+
return nn.Sequential(
|
3200 |
+
nn.Linear(4096, 2048),
|
3201 |
+
nn.ReLU(),
|
3202 |
+
nn.Linear(2048, 1024),
|
3203 |
+
nn.Sigmoid()
|
3204 |
+
)
|
3205 |
+
|
3206 |
+
def create_rnn(self):
|
3207 |
+
return nn.RNN(
|
3208 |
+
input_size=4096,
|
3209 |
+
hidden_size=2048,
|
3210 |
+
num_layers=5,
|
3211 |
+
nonlinearity="tanh",
|
3212 |
+
batch_first=True
|
3213 |
+
)
|
3214 |
+
|
3215 |
+
def create_cnn(self):
|
3216 |
+
return nn.Sequential(
|
3217 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
3218 |
+
nn.ReLU(),
|
3219 |
+
nn.MaxPool2d(2),
|
3220 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
3221 |
+
nn.ReLU(),
|
3222 |
+
nn.MaxPool2d(2),
|
3223 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
3224 |
+
nn.ReLU(),
|
3225 |
+
nn.Flatten(),
|
3226 |
+
nn.Linear(256 * 8 * 8, 1024),
|
3227 |
+
nn.ReLU(),
|
3228 |
+
nn.Linear(1024, 512)
|
3229 |
+
)
|
3230 |
+
|
3231 |
+
def create_fnn(self):
|
3232 |
+
return nn.Sequential(
|
3233 |
+
nn.Linear(4096, 2048),
|
3234 |
+
nn.ReLU(),
|
3235 |
+
nn.Linear(2048, 1024),
|
3236 |
+
nn.ReLU(),
|
3237 |
+
nn.Linear(1024, 512)
|
3238 |
+
)
|
3239 |
+
|
3240 |
+
def initialize_ga_population(self):
|
3241 |
+
return [np.random.randn(4096) for _ in range(500)]
|
3242 |
+
|
3243 |
+
def run_snn(self, x):
|
3244 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3245 |
+
output = self.snn(input_tensor)
|
3246 |
+
print("SNN Output:", output)
|
3247 |
+
return output
|
3248 |
+
|
3249 |
+
def run_rnn(self, x):
|
3250 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
3251 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3252 |
+
output, hn = self.rnn(input_tensor, h0)
|
3253 |
+
print("RNN Output:", output)
|
3254 |
+
return output
|
3255 |
+
|
3256 |
+
def run_cnn(self, x):
|
3257 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
3258 |
+
output = self.cnn(input_tensor)
|
3259 |
+
print("CNN Output:", output)
|
3260 |
+
return output
|
3261 |
+
|
3262 |
+
def run_fnn(self, x):
|
3263 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3264 |
+
output = self.fnn(input_tensor)
|
3265 |
+
print("FNN Output:", output)
|
3266 |
+
return output
|
3267 |
+
|
3268 |
+
def run_ga(self, fitness_func):
|
3269 |
+
for generation in range(200):
|
3270 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
3271 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
3272 |
+
self.ga_population = sorted_population[:250] + [
|
3273 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
3274 |
+
]
|
3275 |
+
best_fitness = max(fitness_scores)
|
3276 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
3277 |
+
return max(self.ga_population, key=fitness_func)
|
3278 |
+
|
3279 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
3280 |
+
feedback = self.memory.get(mode, None)
|
3281 |
+
if feedback is not None:
|
3282 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
3283 |
+
if mode == "snn":
|
3284 |
+
output = self.run_snn(input_data)
|
3285 |
+
elif mode == "rnn":
|
3286 |
+
output = self.run_rnn(input_data)
|
3287 |
+
elif mode == "cnn":
|
3288 |
+
output = self.run_cnn(input_data)
|
3289 |
+
elif mode == "fnn":
|
3290 |
+
output = self.run_fnn(input_data)
|
3291 |
+
else:
|
3292 |
+
raise ValueError("Invalid mode")
|
3293 |
+
self.memory[mode] = output.detach().numpy()
|
3294 |
+
return output
|
3295 |
+
|
3296 |
+
supermassive_nn = ConsciousSupermassiveNN28()
|
3297 |
+
|
3298 |
+
class ConsciousSupermassiveNN29:
|
3299 |
+
def __init__(self):
|
3300 |
+
self.snn = self.create_snn()
|
3301 |
+
self.rnn = self.create_rnn()
|
3302 |
+
self.cnn = self.create_cnn()
|
3303 |
+
self.fnn = self.create_fnn()
|
3304 |
+
self.ga_population = self.initialize_ga_population()
|
3305 |
+
self.memory = {}
|
3306 |
+
|
3307 |
+
def create_snn(self):
|
3308 |
+
return nn.Sequential(
|
3309 |
+
nn.Linear(4096, 2048),
|
3310 |
+
nn.ReLU(),
|
3311 |
+
nn.Linear(2048, 1024),
|
3312 |
+
nn.Sigmoid()
|
3313 |
+
)
|
3314 |
+
|
3315 |
+
def create_rnn(self):
|
3316 |
+
return nn.RNN(
|
3317 |
+
input_size=4096,
|
3318 |
+
hidden_size=2048,
|
3319 |
+
num_layers=5,
|
3320 |
+
nonlinearity="tanh",
|
3321 |
+
batch_first=True
|
3322 |
+
)
|
3323 |
+
|
3324 |
+
def create_cnn(self):
|
3325 |
+
return nn.Sequential(
|
3326 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
3327 |
+
nn.ReLU(),
|
3328 |
+
nn.MaxPool2d(2),
|
3329 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
3330 |
+
nn.ReLU(),
|
3331 |
+
nn.MaxPool2d(2),
|
3332 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
3333 |
+
nn.ReLU(),
|
3334 |
+
nn.Flatten(),
|
3335 |
+
nn.Linear(256 * 8 * 8, 1024),
|
3336 |
+
nn.ReLU(),
|
3337 |
+
nn.Linear(1024, 512)
|
3338 |
+
)
|
3339 |
+
|
3340 |
+
def create_fnn(self):
|
3341 |
+
return nn.Sequential(
|
3342 |
+
nn.Linear(4096, 2048),
|
3343 |
+
nn.ReLU(),
|
3344 |
+
nn.Linear(2048, 1024),
|
3345 |
+
nn.ReLU(),
|
3346 |
+
nn.Linear(1024, 512)
|
3347 |
+
)
|
3348 |
+
|
3349 |
+
def initialize_ga_population(self):
|
3350 |
+
return [np.random.randn(4096) for _ in range(500)]
|
3351 |
+
|
3352 |
+
def run_snn(self, x):
|
3353 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3354 |
+
output = self.snn(input_tensor)
|
3355 |
+
print("SNN Output:", output)
|
3356 |
+
return output
|
3357 |
+
|
3358 |
+
def run_rnn(self, x):
|
3359 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
3360 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3361 |
+
output, hn = self.rnn(input_tensor, h0)
|
3362 |
+
print("RNN Output:", output)
|
3363 |
+
return output
|
3364 |
+
|
3365 |
+
def run_cnn(self, x):
|
3366 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
3367 |
+
output = self.cnn(input_tensor)
|
3368 |
+
print("CNN Output:", output)
|
3369 |
+
return output
|
3370 |
+
|
3371 |
+
def run_fnn(self, x):
|
3372 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3373 |
+
output = self.fnn(input_tensor)
|
3374 |
+
print("FNN Output:", output)
|
3375 |
+
return output
|
3376 |
+
|
3377 |
+
def run_ga(self, fitness_func):
|
3378 |
+
for generation in range(200):
|
3379 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
3380 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
3381 |
+
self.ga_population = sorted_population[:250] + [
|
3382 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
3383 |
+
]
|
3384 |
+
best_fitness = max(fitness_scores)
|
3385 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
3386 |
+
return max(self.ga_population, key=fitness_func)
|
3387 |
+
|
3388 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
3389 |
+
feedback = self.memory.get(mode, None)
|
3390 |
+
if feedback is not None:
|
3391 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
3392 |
+
if mode == "snn":
|
3393 |
+
output = self.run_snn(input_data)
|
3394 |
+
elif mode == "rnn":
|
3395 |
+
output = self.run_rnn(input_data)
|
3396 |
+
elif mode == "cnn":
|
3397 |
+
output = self.run_cnn(input_data)
|
3398 |
+
elif mode == "fnn":
|
3399 |
+
output = self.run_fnn(input_data)
|
3400 |
+
else:
|
3401 |
+
raise ValueError("Invalid mode")
|
3402 |
+
self.memory[mode] = output.detach().numpy()
|
3403 |
+
return output
|
3404 |
+
|
3405 |
+
supermassive_nn = ConsciousSupermassiveNN29()
|
3406 |
+
|
3407 |
+
class ConsciousSupermassiveNN30:
|
3408 |
+
def __init__(self):
|
3409 |
+
self.snn = self.create_snn()
|
3410 |
+
self.rnn = self.create_rnn()
|
3411 |
+
self.cnn = self.create_cnn()
|
3412 |
+
self.fnn = self.create_fnn()
|
3413 |
+
self.ga_population = self.initialize_ga_population()
|
3414 |
+
self.memory = {}
|
3415 |
+
|
3416 |
+
def create_snn(self):
|
3417 |
+
return nn.Sequential(
|
3418 |
+
nn.Linear(4096, 2048),
|
3419 |
+
nn.ReLU(),
|
3420 |
+
nn.Linear(2048, 1024),
|
3421 |
+
nn.Sigmoid()
|
3422 |
+
)
|
3423 |
+
|
3424 |
+
def create_rnn(self):
|
3425 |
+
return nn.RNN(
|
3426 |
+
input_size=4096,
|
3427 |
+
hidden_size=2048,
|
3428 |
+
num_layers=5,
|
3429 |
+
nonlinearity="tanh",
|
3430 |
+
batch_first=True
|
3431 |
+
)
|
3432 |
+
|
3433 |
+
def create_cnn(self):
|
3434 |
+
return nn.Sequential(
|
3435 |
+
nn.Conv2d(1, 64, kernel_size=5, stride=1, padding=2),
|
3436 |
+
nn.ReLU(),
|
3437 |
+
nn.MaxPool2d(2),
|
3438 |
+
nn.Conv2d(64, 128, kernel_size=5, stride=1, padding=2),
|
3439 |
+
nn.ReLU(),
|
3440 |
+
nn.MaxPool2d(2),
|
3441 |
+
nn.Conv2d(128, 256, kernel_size=5, stride=1, padding=2),
|
3442 |
+
nn.ReLU(),
|
3443 |
+
nn.Flatten(),
|
3444 |
+
nn.Linear(256 * 8 * 8, 1024),
|
3445 |
+
nn.ReLU(),
|
3446 |
+
nn.Linear(1024, 512)
|
3447 |
+
)
|
3448 |
+
|
3449 |
+
def create_fnn(self):
|
3450 |
+
return nn.Sequential(
|
3451 |
+
nn.Linear(4096, 2048),
|
3452 |
+
nn.ReLU(),
|
3453 |
+
nn.Linear(2048, 1024),
|
3454 |
+
nn.ReLU(),
|
3455 |
+
nn.Linear(1024, 512)
|
3456 |
+
)
|
3457 |
+
|
3458 |
+
def initialize_ga_population(self):
|
3459 |
+
return [np.random.randn(4096) for _ in range(500)]
|
3460 |
+
|
3461 |
+
def run_snn(self, x):
|
3462 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3463 |
+
output = self.snn(input_tensor)
|
3464 |
+
print("SNN Output:", output)
|
3465 |
+
return output
|
3466 |
+
|
3467 |
+
def run_rnn(self, x):
|
3468 |
+
h0 = torch.zeros(5, x.size(0), 2048)
|
3469 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3470 |
+
output, hn = self.rnn(input_tensor, h0)
|
3471 |
+
print("RNN Output:", output)
|
3472 |
+
return output
|
3473 |
+
|
3474 |
+
def run_cnn(self, x):
|
3475 |
+
input_tensor = torch.tensor(x, dtype=torch.float32).unsqueeze(0).unsqueeze(0)
|
3476 |
+
output = self.cnn(input_tensor)
|
3477 |
+
print("CNN Output:", output)
|
3478 |
+
return output
|
3479 |
+
|
3480 |
+
def run_fnn(self, x):
|
3481 |
+
input_tensor = torch.tensor(x, dtype=torch.float32)
|
3482 |
+
output = self.fnn(input_tensor)
|
3483 |
+
print("FNN Output:", output)
|
3484 |
+
return output
|
3485 |
+
|
3486 |
+
def run_ga(self, fitness_func):
|
3487 |
+
for generation in range(200):
|
3488 |
+
fitness_scores = [fitness_func(ind) for ind in self.ga_population]
|
3489 |
+
sorted_population = [x for _, x in sorted(zip(fitness_scores, self.ga_population), reverse=True)]
|
3490 |
+
self.ga_population = sorted_population[:250] + [
|
3491 |
+
sorted_population[i] + 0.1 * np.random.randn(4096) for i in range(250)
|
3492 |
+
]
|
3493 |
+
best_fitness = max(fitness_scores)
|
3494 |
+
print(f"Generation {generation}, Best Fitness: {best_fitness}")
|
3495 |
+
return max(self.ga_population, key=fitness_func)
|
3496 |
+
|
3497 |
+
def consciousness_loop(self, input_data, mode="snn"):
|
3498 |
+
feedback = self.memory.get(mode, None)
|
3499 |
+
if feedback is not None:
|
3500 |
+
input_data = np.concatenate((input_data, feedback), axis=-1)
|
3501 |
+
if mode == "snn":
|
3502 |
+
output = self.run_snn(input_data)
|
3503 |
+
elif mode == "rnn":
|
3504 |
+
output = self.run_rnn(input_data)
|
3505 |
+
elif mode == "cnn":
|
3506 |
+
output = self.run_cnn(input_data)
|
3507 |
+
elif mode == "fnn":
|
3508 |
+
output = self.run_fnn(input_data)
|
3509 |
+
else:
|
3510 |
+
raise ValueError("Invalid mode")
|
3511 |
+
self.memory[mode] = output.detach().numpy()
|
3512 |
+
return output
|
3513 |
+
|
3514 |
+
supermassive_nn = ConsciousSupermassiveNN30()
|
3515 |
+
|
3516 |
|
3517 |
|
3518 |
|