This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Auxiliary function creating graph of classification boundaries | |
| def save_model_prediction_graph(epoch, logs): | |
| prediction_probs = model.predict_proba(grid_2d, batch_size=32, verbose=0) | |
| plt.figure(figsize=(10,10)) | |
| sns.set_style("whitegrid") | |
| plt.title('Binary classification with KERAS - epoch: ' + makeIndexOfLength(epoch, 3), fontsize=20) | |
| plt.xlabel('X', fontsize=15) | |
| plt.ylabel('Y', fontsize=15) | |
| plt.contourf(X, Y, prediction_probs.reshape(100, 100), alpha = 0.7, cmap=cm.Spectral) | |
| plt.scatter(X_train[:, 0], X_train[:, 1], c=y_train.ravel(), s=50, cmap=plt.cm.Spectral, edgecolors='black') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| convert -delay 10 -loop 0 *.png keras_class_boundaries.gif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Animation creation | |
| anim = FuncAnimation(fig, update, | |
| frames=np.arange(0, int(STEPS/STEPS_PER_FRAME)), interval=40) | |
| # Saving animation | |
| anim.save('lorenz_attractor.gif', dpi=80, writer='imagemagick') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Updating chart | |
| def update(i): | |
| frame_end = (i + 1) * STEPS_PER_FRAME | |
| for plot, dot, data in zip(plots, dots, plots_data): | |
| xs, ys, zs = data | |
| # Updating the trajectory | |
| plot.set_data(xs[:frame_end], ys[:frame_end]) | |
| plot.set_3d_properties(zs[:frame_end]) | |
| # Updating the position of dots | |
| dot._offsets3d = ([xs[frame_end]], [ys[frame_end]], [zs[frame_end]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Calculation of the points belonging to the three trajectories, | |
| # based on the given starting conditions | |
| plots_data = [build_lorenz_trajectory(DELTA_T, STEPS, | |
| initial_values=initial_conditions[i]) for i in range(3)] | |
| # Creation of an empty chart | |
| fig, ax = create_blank_chart_with_styling(plots_data, PADDING, (8, 8)) | |
| # Setting up (for the time being empty) data sequences for each trajectory | |
| plots = [ax.plot([],[],[], color=colors[i], label=str(initial_conditions[i]), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from mpl_toolkits.mplot3d import Axes3D | |
| import numpy as np | |
| from matplotlib.animation import FuncAnimation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create_frames(dt, steps, padding, output_dir): | |
| fig, ax = create_blank_chart_with_styling((6, 6)) | |
| # creation of data describing the trajectory | |
| xs, ys, zs = build_lorenz_trajectory(dt, steps) | |
| # setting the fixed range of axes | |
| ax.set_xlim3d(xs.min() - padding, xs.max() + padding) | |
| ax.set_ylim3d(ys.min() - padding, ys.max() + padding) | |
| ax.set_zlim3d(zs.min() - padding, zs.max() + padding) | |
| for i in range(steps-1): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.models import Sequential | |
| from keras.layers import Dense | |
| model = Sequential() | |
| model.add(Dense(4, input_dim=2,activation='relu')) | |
| model.add(Dense(6, activation='relu')) | |
| model.add(Dense(6, activation='relu')) | |
| model.add(Dense(4, activation='relu')) | |
| model.add(Dense(1, activation='sigmoid')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model.add(Conv2D( | |
| filters = 32, | |
| kernel_size = (5,5), | |
| padding = 'Same', | |
| activation ='relu', | |
| input_shape = (28,28,1) | |
| )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script> |