Done with activation softmax backwards

This commit is contained in:
2026-07-31 19:08:57 +02:00
parent d7b74ab40f
commit 11da534fd6
30 changed files with 3029 additions and 184 deletions
@@ -77,7 +77,7 @@ struct activation_relu : public layer{
*
* @Note Calculates -> outputs = inputs * weights + biases
*/
bool forward(const panic::tensor::real_matrix& inputs);
bool forward(const panic::tensor::real_matrix& input_data);
/**
* @brief Backward function for layer
@@ -86,7 +86,7 @@ struct activation_relu : public layer{
*
* @Note Calculates derivative of forward function.
*/
bool backward(const panic::tensor::real_matrix& dinpus);
bool backward(const panic::tensor::real_matrix& dvalues);
};
} // namespace tensor
@@ -77,7 +77,7 @@ struct activation_softmax : public layer{
*
* @Note Calculates -> outputs = inputs * weights + biases
*/
bool forward(const panic::tensor::real_matrix& inputs);
bool forward(const panic::tensor::real_matrix& input_data);
/**
* @brief Backward function for layer
@@ -86,7 +86,7 @@ struct activation_softmax : public layer{
*
* @Note Calculates derivative of forward function.
*/
bool backward(const panic::tensor::real_matrix& dinpus);
bool backward(const panic::tensor::real_matrix& dvalues);
};
} // namespace tensor
+14
View File
@@ -56,6 +56,14 @@ namespace panic{
*/
struct layer{
/**
* @brief Emphty output matrix to store layer input
*
* Output shape:
* samples x neuron_count
*/
panic::tensor::real_matrix inputs;
/**
* @brief Emphty output matrix to store layer output
*
@@ -64,6 +72,12 @@ struct layer{
*/
panic::tensor::real_matrix outputs;
/**
* @brief Emphty matrix to store output for backward pass
*
*/
panic::tensor::real_matrix dinputs;
/**
* @brief Default de-constructor
*
+10 -2
View File
@@ -58,6 +58,12 @@ namespace panic{
*/
struct layer_dense : public layer{
/**
* @brief Emphty matrix to store input data
*
*/
panic::tensor::real_matrix ipnuts;
/**
* @brief Emphty weight matrix to store layer weights
*
@@ -65,6 +71,7 @@ struct layer_dense : public layer{
* input_size x neuron_count
*/
panic::tensor::real_matrix weights;
panic::tensor::real_matrix dweights;
/**
* @brief Emphty bias vector to store layer bias
@@ -73,6 +80,7 @@ struct layer_dense : public layer{
* 1 x neuron_count
*/
panic::tensor::real_vector biases;
panic::tensor::real_vector dbiases;
/**
* @brief Empthy constructor
@@ -102,7 +110,7 @@ struct layer_dense : public layer{
*
* @Note Calculates -> outputs = inputs * weights + biases
*/
bool forward(const panic::tensor::real_matrix& inputs);
bool forward(const panic::tensor::real_matrix& input_data);
/**
* @brief Backward function for layer
@@ -111,7 +119,7 @@ struct layer_dense : public layer{
*
* @Note Calculates derivative of forward function.
*/
bool backward(const panic::tensor::real_matrix& dinpus);
bool backward(const panic::tensor::real_matrix& dvalues);
};
} // namespace tensor
+6
View File
@@ -68,6 +68,12 @@ struct loss{
*/
panic::types::real_t data_loss;
/**
* @brief Matrix for backwards pass
*/
panic::tensor::real_matrix dinputs;
/**
* @brief Default de-constructor
*
@@ -82,9 +82,35 @@ struct loss_categorical_crossentropy: loss{
const panic::tensor::real_matrix& y_pred,
const panic::tensor::real_matrix& y_true);
};
/**
* @brief backward function to calculate from losses
*
* @param y_pred Matrix of model predection.
* @param y_true Vector of true label of data.
*
*/
bool backward(
const panic::tensor::real_matrix& dvalues,
const panic::tensor::uint_vector& y_true);
/**
* @brief backward function to calculate from losses
*
* @param y_pred Matrix of model predection.
* @param y_true Vector of true label of data.
*
* @Note Overloaded if one-shot endcoded
* is used.
*/
bool backward(
const panic::tensor::real_matrix& dvalues,
const panic::tensor::real_matrix& y_true);
};
} // namespace neural_network
} // namespace panic