y_true = np.repeat(range(confmat.shape[0]), confmat.sum(axis=1)) y_pred = np.repeat(range(confmat.shape[1]), confmat.sum(axis=0))
report_text = ( f"Seed Results {seed_id}:\n" f"Accuracy: {metrics.get('test_accuracy', 'N/A'):.4f}\n" f"F1 Score: {metrics.get('f1_score', 'N/A'):.4f}\n" f"Classification Report:\n{classification_report(y_true, y_pred)}" )
Training Curves
fig, ax = plt.subplots(figsize=(8, 5)) ax.plot(history['epoch'], history['accuracy'], label='Training Accuracy') ax.plot(history['epoch'], history['val_accuracy'], label='Validation Accuracy') ax.set_title(f'Training Curves – Seed {seed_id}') ax.set_xlabel('Epoch') ax.set_ylabel('Accuracy') ax.legend() pdf.savefig(fig) plt.close()
Confusion Matrix
fig, ax = plt.subplots(figsize=(6, 5)) im = ax.imshow(confmat, cmap='viridis', aspect='auto') plt.colorbar(im, ax=ax) ax.set_title(f'Confusion Matrix – Seed {seed_id}') pdf.savefig(fig) plt.close()
Text Page
fig, ax = plt.subplots(figsize=(8.5, 11)) ax.axis('off') ax.text(0, 1, report_text, va='top', family='monospace', fontsize=8) pdf.savefig(fig) plt.close()
---------- Part 2: Piezoelectric Sensor Simulation ----------
Parameters (constant values)
PARAMS = { 'd33': 2.5e-10, # C/N 'thickness_m': 0.001, # m 'spring_k': 1000, # N/m 'damping_c': 10, # Ns/m 'capacitance_C': 1e-6, # Farad 'radius': 0.01 # m }
Time and Displacement
time = np.linspace(0, 1, 500) x = 0.01 * np.sin(2 * np.pi * 5 * time) dx_dt = np.gradient(x, time)
Calculations
cross_section = np.pi * PARAMS['radius'] ** 2 F_mech = PARAMS['spring_k'] * x + PARAMS['damping_c'] * dx_dt sigma = F_mech / cross_section Q = PARAMS['d33'] * F_mech V = Q / PARAMS['capacitance_C']
Plotting
fig, axs = plt.subplots(3, 1, figsize=(10, 12), sharex=True)
axs[0].plot(time, V * 1e3) axs[0].set_ylabel('Voltage (mV)') axs[0].set_title('Piezoelectric voltage vs time') axs[0].grid(True, alpha=0.3)
axs[1].plot(time, F_mech) axs[1].set_ylabel('Force (N)') axs[1].set_title('Mechanical Force vs Time') axs[1].grid(True, alpha=0.3)
axs[2].plot(time, sigma / 1e6) axs[2].set_ylabel('Pressure (MPa)') axs[2].set_xlabel('Time (s)') axs[2].set_title('Pressure vs Time') axs[2].grid(True, alpha=0.3)
plt.tight_layout() pdf.savefig(fig) plt.close()
---------- Section 3: Innovations ----------
innovation_text = """ Model Innovations:
- Combining a dual-hemisphere neural network with an array of intelligent piezoelectric sensors for simultaneous processing of mechanical and Electrical.
- Physical model including spring, damping and capacitance to simulate more accurately the sensor behavior.
- Automatic multi-run reporting mechanism combining machine learning results and sensor circuits into a comprehensive PDF file. """
fig, ax = plt.subplots(figsize=(8.5, 11)) ax.axis('off') ax.text(0.05, 0.95, innovation_text, va='top', family='sans-serif', fontsize=12, linespacing=1.5) pdf.savefig(fig) plt.close()
print(f"Final report created:
Log in or sign up for Devpost to join the conversation.