Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/just-cameron/mongo-hack.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import numpy as npimport matplotlib.pyplot as pltfrom sklearn.preprocessing import MinMaxScaler
# Define the dimensions of the matrixn = 1000k = 2 # Use 2D data for easier visualization
# Create the matrixdata = np.random.randn(n, k)
# Re-center the matrix around the first rowrecentered_data = data - data[0]
# Define the rotation angle in degreesrotation_angle_deg = 45# Convert rotation angle to radiansrotation_angle_rad = np.deg2rad(rotation_angle_deg)
# Define scaling factors for each axisscaling_x = 1.5scaling_y = 0.75
# Define shear factors for each axisshear_x = 0.5shear_y = 0.2
# Create a 2D rotation matrixrotation_matrix = np.array([ [np.cos(rotation_angle_rad), -np.sin(rotation_angle_rad)], [np.sin(rotation_angle_rad), np.cos(rotation_angle_rad)]])
# Create a 2D scaling matrixscaling_matrix = np.array([ [scaling_x, 0], [0, scaling_y]])
# Create a 2D shear matrixshear_matrix = np.array([ [1, shear_x], [shear_y, 1]])
# Combine rotation, scaling, and shear matricestransformation_matrix = np.dot(rotation_matrix, np.dot(scaling_matrix, shear_matrix))
# Apply the transformation matrix to the recentered datatransformed_data = np.dot(recentered_data, transformation_matrix)
# Normalize the transformed data to be between -1 and 1scaler = MinMaxScaler(feature_range=(-1, 1))normalized_transformed_data = scaler.fit_transform(transformed_data)
# Plotting the original and normalized transformed dataplt.figure(figsize=(10, 5))
# Plot original data (re-centered)plt.subplot(1, 2, 1)plt.scatter(recentered_data[:, 0], recentered_data[:, 1], color='b', label='Original Data')plt.scatter(recentered_data[0, 0], recentered_data[0, 1], color='r', marker='*', s=100, label='First Row')plt.title('Recentered Data')plt.xlabel('X')plt.ylabel('Y')plt.legend()
# Plot normalized transformed dataplt.subplot(1, 2, 2)plt.scatter(normalized_transformed_data[:, 0], normalized_transformed_data[:, 1], color='r', label='Normalized Transformed Data')plt.scatter(normalized_transformed_data[0, 0], normalized_transformed_data[0, 1], color='b', marker='*', s=100, label='First Row')plt.title('Normalized Transformed Data')plt.xlabel('X')plt.ylabel('Y')plt.legend()
# Show the plotsplt.tight_layout()plt.show()