Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Add errors to dashboard for the chart
Browse files Browse the repository at this point in the history
  • Loading branch information
hugolgst committed Mar 21, 2020
1 parent f6d0061 commit daf053c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
16 changes: 10 additions & 6 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"math"
"os"
"strconv"
"time"

"github.com/gookit/color"
Expand All @@ -20,7 +19,7 @@ type Network struct {
Biases []Matrix
Output Matrix
Rate float64
Error float64
Errors []float64
Time float64
}

Expand Down Expand Up @@ -173,6 +172,15 @@ func (network *Network) Train(iterations int) {
network.FeedForward()
network.FeedBackward()

// Append errors for dashboard data
if i%(iterations/20) == 0 {
network.Errors = append(
network.Errors,
// Round the error to two decimals
network.ComputeError(),
)
}

// Increment the progress bar
bar.Increment()
}
Expand All @@ -181,10 +189,6 @@ func (network *Network) Train(iterations int) {
// Print the error
arrangedError := fmt.Sprintf("%.5f", network.ComputeError())

// Set the error inside the network struct
errorLoss, _ := strconv.ParseFloat(arrangedError, 5)
network.Error = errorLoss

// Calculate elapsed time
elapsed := time.Since(start)
// Round the elapsed time at two decimals
Expand Down
2 changes: 1 addition & 1 deletion res/training.json

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ import (
"github.com/olivia-ai/olivia/network"
)

// Dashboard contains the data sent for the dashboard
type Dashboard struct {
Layers Layers `json:"layers"`
Training Training `json:"training"`
}

// Layers contains the data of the network's layers
type Layers struct {
InputNodes int `json:"input"`
HiddenLayers int `json:"hidden"`
OutputNodes int `json:"output"`
}

// Training contains the data related to the training of the network
type Training struct {
Rate float64 `json:"rate"`
Error float64 `json:"error"`
Time float64 `json:"time"`
Rate float64 `json:"rate"`
Errors []float64 `json:"errors"`
Time float64 `json:"time"`
}

// GetDashboardData encodes the json for the dashboard data
Expand Down Expand Up @@ -56,8 +59,8 @@ func GetLayers() Layers {
func GetTraining() Training {
// Retrieve the information from the neural network
return Training{
Rate: neuralNetwork.Rate,
Error: neuralNetwork.Error,
Time: neuralNetwork.Time,
Rate: neuralNetwork.Rate,
Errors: neuralNetwork.Errors,
Time: neuralNetwork.Time,
}
}

0 comments on commit daf053c

Please sign in to comment.