import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.decomposition import PCA
import itertools
# Step 1: Define parameters and generate 100 positions
np.random.seed(42)
n_positions = 100
n_dimensions = 6 # Expanded to 6D with magnetic field as x6
# Generate 50 merit-biased and 50 demerit-biased positions
merit_positions = np.random.uniform(0.5, 1.0, (50, n_dimensions))
demerit_positions = np.random.uniform(0.0, 0.5, (50, n_dimensions))
positions = np.vstack((merit_positions, demerit_positions))
# Define ideal planet coordinates (high values for life-supporting factors)
ideal_planet = np.array([1.0, 0.0, 1.0, 0.5, 1.0, 1.0]) # [dark oxygen, CO2, water, energy, life potential, magnetic field]
# Step 2: Optimize coordinates with permutations for each position
def optimize_position(pos):
weights = np.array([0.25, 0.15, 0.15, 0.15, 0.25, 0.1])
perms = list(itertools.permutations(pos))
best_perm = max(perms, key=lambda p: np.dot(p, weights))
return np.array(best_perm)
optimized_positions = np.array([optimize_position(pos) for pos in positions])
# Step 3: Compute merit scores with SHP weights
shp_weights = 1 / np.arange(1, n_dimensions + 1) # Simple Harmonic Progression: 1/1, 1/2, 1/3, ...
shp_weights /= shp_weights.sum() # Normalize weights
merit_scores = np.dot(optimized_positions, shp_weights)
# Step 4: Test different kappa values and compute distances
kappa_values = [0.07, 0.08, 0.09]
results = {}
for kappa in kappa_values:
# Adjusted merit strength with covalent factor
merit_strength = merit_scores * (1 - kappa)
# Factorial distance to ideal planet
distances = np.sum(np.abs(optimized_positions - ideal_planet) * shp_weights, axis=1)
results[kappa] = {'merit_strength': merit_strength, 'distances': distances}
# Choose kappa with balanced entropy and merit strength
entropies = [-(r['merit_strength'] * np.log(r['merit_strength'] + 1e-10)).sum() for r in results.values()]
best_kappa = kappa_values[np.argmin(entropies)]
distances = results[best_kappa]['distances']
merit_strength = results[best_kappa]['merit_strength']
# Step 5: Select top 20 conditions using combinations
top_indices = np.argsort(merit_strength)[-20:][::-1]
top_positions = optimized_positions[top_indices]
# Step 6: Map to real planets/moons based on geophysical traits
planet_mappings = []
for pos in top_positions:
x1, x2, x3, x4, x5, x6 = pos
if x1 > 0.7 and x3 > 0.7 and x5 > 0.7:
planet_mappings.append("Europa")
elif x3 > 0.7 and x4 > 0.6:
planet_mappings.append("Enceladus")
elif x1 > 0.5 and x5 > 0.5:
planet_mappings.append("Mars")
elif x3 > 0.7 and x2 < 0.3:
planet_mappings.append("Titan")
elif x2 > 0.7 and x5 < 0.3:
planet_mappings.append("Venus")
else:
planet_mappings.append("Unknown")
# Step 7: Visualization
# Reduce to 2D and 3D using PCA
pca_2d = PCA(n_components=2)
pca_3d = PCA(n_components=3)
positions_2d = pca_2d.fit_transform(optimized_positions)
positions_3d = pca_3d.fit_transform(optimized_positions)
top_positions_2d = positions_2d[top_indices]
top_positions_3d = positions_3d[top_indices]
# 2D Plot with Heatmap
plt.figure(figsize=(10, 8))
scatter = plt.scatter(positions_2d[:, 0], positions_2d[:, 1], c=distances, cmap='viridis', alpha=0.6)
plt.scatter(top_positions_2d[:, 0], top_positions_2d[:, 1], c='red', label='Top 20')
for i, name in enumerate(planet_mappings):
plt.annotate(name, (top_positions_2d[i, 0], top_positions_2d[i, 1]))
plt.colorbar(scatter, label='Distance to Ideal Planet')
plt.title(f'2D Solar System Map (κ = {best_kappa})')
plt.xlabel('PCA Component 1')
plt.ylabel('PCA Component 2')
plt.legend()
plt.savefig('solar_system_2d.png')
# 3D Plot with Heatmap
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
scatter = ax.scatter(positions_3d[:, 0], positions_3d[:, 1], positions_3d[:, 2], c=distances, cmap='viridis', alpha=0.6)
ax.scatter(top_positions_3d[:, 0], top_positions_3d[:, 1], top_positions_3d[:, 2], c='red', label='Top 20')
for i, name in enumerate(planet_mappings):
ax.text(top_positions_3d[i, 0], top_positions_3d[i, 1], top_positions_3d[i, 2], name)
plt.colorbar(scatter, label='Distance to Ideal Planet')
ax.set_title(f'3D Solar System Map (κ = {best_kappa})')
ax.set_xlabel('PCA Component 1')
ax.set_ylabel('PCA Component 2')
ax.set_zlabel('PCA Component 3')
ax.legend()
plt.savefig('solar_system_3d.png')
# Step 8: Adjust kappa dynamically based on variance (optional refinement)
variance = np.var(distances)
dynamic_kappa = 0.01 + 0.08 * (variance / np.max([variance, 1e-10]))
print(f"Best κ: {best_kappa}, Dynamic κ: {dynamic_kappa}")
print("Top 20 conditions mapped to planets/moons:")
for i, (pos, name) in enumerate(zip(top_positions, planet_mappings)):
print(f"Condition {i+1}: {pos} → {name}")

Best κ: 0.07, Dynamic κ: 0.09
Top 20 conditions mapped to planets/moons:
Condition 1: [0.97022929 0.9574322 0.68507935 0.96415928 0.97696429 0.50772831] → Mars
Condition 2: [0.96974947 0.77335514 0.88756641 0.94741368 0.98479231 0.59242723] → Europa
Condition 3: [0.94500267 0.82498197 0.85098344 0.89789633 0.89914759 0.66899758] → Europa
Condition 4: [0.93353616 0.7556712 0.9050567 0.90468058 0.95662028 0.75075815] → Europa
Condition 5: [0.9462795 0.81670188 0.90183604 0.76967112 0.9357303 0.59328503] → Europa
Condition 6: [0.98332741 0.71409207 0.92650473 0.69254886 0.98180999 0.64722445] → Europa
Condition 7: [0.94602328 0.81556931 0.75131855 0.78845194 0.89740565 0.74625885] → Europa
Condition 8: [0.95020903 0.81655073 0.67460479 0.86297784 0.94855513 0.6695149 ] → Mars
Condition 9: [0.93868654 0.84850787 0.85124204 0.67974558 0.87038431 0.64679592] → Europa
Condition 10: [0.92461171 0.82481645 0.82880645 0.7841543 0.8732457 0.66269985] → Europa
Condition 11: [0.94354321 0.88993777 0.82101582 0.58081436 0.94927709 0.54206998] → Europa
Condition 12: [0.97444277 0.80377243 0.58526206 0.90419867 0.98281602 0.5325258 ] → Mars
Condition 13: [0.92556834 0.77840063 0.8480149 0.658461 0.96807739 0.58474637] → Europa
Condition 14: [0.98589104 0.6818148 0.74862425 0.65043915 0.98122365 0.62589115] → Europa
Condition 15: [0.99502693 0.78503059 0.75916483 0.57004201 0.80750361 0.54858825] → Europa
Condition 16: [0.88039252 0.85662239 0.7806386 0.7468978 0.88548359 0.55979712] → Europa
Condition 17: [0.88080981 0.83606777 0.68389157 0.81615292 0.86410817 0.61881877] → Mars
Condition 18: [0.93308807 0.80055751 0.52904181 0.85403629 0.98495493 0.51029225] → Mars
Condition 19: [0.88563517 0.85342867 0.86450358 0.53702233 0.90773071 0.50276106] → Europa
Condition 20: [0.97535715 0.68727006 0.79932924 0.57800932 0.86599697 0.57799726] → Europa
No comments:
Post a Comment