Softmax + Categorical Crossentropy

I fixed the activation+loss function, you can't select it directly, it automaticly uses it if it can. I also fixed one-hot generator. Still haven't tested the activation + loss nor any other backward function. I'll do that when I get to the optimizers which is next.
This commit is contained in:
2026-08-06 09:53:03 +02:00
parent fecb4c70b1
commit 642bba1198
18 changed files with 627 additions and 378 deletions
@@ -53,10 +53,17 @@ namespace panic{
*
* The struct is used for PANIC neural_network library.
*/
struct loss_categorical_crossentropy: loss{
struct loss_categorical_crossentropy: public loss{
/**
* @brief get_type function for loss
*
* @returns the loss type
*
*/
loss_type get_type() const override {
return loss_type::categorical_crossentropy;
}
/**
* @brief forward function to calculate losses
@@ -65,9 +72,7 @@ struct loss_categorical_crossentropy: loss{
* @param y_true Vector of true label of data.
*
*/
bool forward(
const panic::tensor::real_matrix& y_pred,
const panic::tensor::uint_vector& y_true)override;
bool forward(const panic::tensor::real_matrix& y_pred, const panic::tensor::uint_vector& y_true) override;
/**
* @brief forward function to calculate losses
@@ -78,9 +83,7 @@ struct loss_categorical_crossentropy: loss{
* @Note Overloaded if one-shot endcoded
* is used.
*/
bool forward(
const panic::tensor::real_matrix& y_pred,
const panic::tensor::real_matrix& y_true)override;
bool forward(const panic::tensor::real_matrix& y_pred, const panic::tensor::real_matrix& y_true) override;
/**
@@ -90,9 +93,7 @@ struct loss_categorical_crossentropy: loss{
* @param y_true Vector of true label of data.
*
*/
bool backward(
const panic::tensor::real_matrix& dvalues,
const panic::tensor::uint_vector& y_true) override;
bool backward(const panic::tensor::real_matrix& dvalues, const panic::tensor::uint_vector& y_true) override;
/**
* @brief backward function to calculate from losses
@@ -103,9 +104,7 @@ struct loss_categorical_crossentropy: loss{
* @Note Overloaded if one-shot endcoded
* is used.
*/
bool backward(
const panic::tensor::real_matrix& dvalues,
const panic::tensor::real_matrix& y_true) override;
bool backward(const panic::tensor::real_matrix& dvalues, const panic::tensor::real_matrix& y_true) override;
};