phitodeep.model

Classes

Sequential

SequentialBuilder

Fluent API for building Sequential models.

Module Contents

class phitodeep.model.Sequential(*layers, alpha=0.01, optimizer: phitodeep.optimization.optimizers.Optimizer = o.Adam(), batch_size=None, epochs=1000, loss_class=ls.MeanSquaredError())[source]
layers = []
alpha = 0.01
optimizer_type
batch_size = None
epochs = 1000
loss_class
add(layer) None[source]

Add a layer to the network.

setoptimizer(optimizer)[source]
setbatchsize(num)[source]
setloss(loss_class)[source]
train(X, y, X_test, y_test)[source]

Train the model using the specified optimizer and loss function.

Parameters:
  • X (np.ndarray) – Training data.

  • y (np.ndarray) – Training labels.

  • X_test (np.ndarray) – Test data.

  • y_test (np.ndarray) – Test labels.

Returns:

A list of tuples containing the training and test losses for each epoch.

Return type:

list

predict(X)[source]

Forward pass through all layers.

Parameters:

X – input array

Returns:

output after passing through all layers

backward(gradient)[source]

Backward pass through all layers.

Parameters:

gradient – dL/dY from loss function (shape: batch_size x output_size)

Propagates gradient backwards through all layers in reverse order. Each layer computes its parameter gradients, updates parameters, and returns the gradient for the previous layer.

__call__(X)[source]

Allow model(X) syntax.

summary()[source]

Print model architecture.

copy()[source]

Return a copy of the model.

class phitodeep.model.SequentialBuilder[source]

Fluent API for building Sequential models.

layers = []
alpha_value = 1
optimizer_type
batch_size = None
epochs_value = 1000
loss_class
flatten()[source]

Add a Flatten layer.

dense(input_size, output_size, initializer=He())[source]

Add a Dense layer.

relu()[source]

Add a ReLU activation.

sigmoid()[source]

Add a Sigmoid activation.

tanh()[source]

Add a Tanh activation.

softmax()[source]

Add a Softmax activation.

elu(alpha_activation=1.0)[source]

Add an ELU activation.

optimizer(optimizer)[source]

Set the optimizer.

batch(num)[source]

Set the batch size.

alpha(num)[source]

Set the learning rate.

epochs(num)[source]

Set the number of epochs.

loss(loss_class)[source]

Set the loss function.

build()[source]

Build and return the Sequential model.