Replies: 5 comments 12 replies
-
For instance, a custom loss function would greatly improve training times when using reinforcement learning. |
Beta Was this translation helpful? Give feedback.
-
OMG 🤣 Soooo... A lot more digging, and I found out that this was already solved 🥰 |
Beta Was this translation helpful? Give feedback.
-
btw the work is being done in this branch. Already have a working implementation for function loss(
this: IKernelFunctionThis,
actual: KernelOutput, // The actual output data of the neural network during this run.
expected: KernelOutput, // The output data expected to be produced by the neural network given the provided input data.
inputs: InputType, // The input data provided to entire neural network (the data passed into the `NeuralNetwork.run(input)` method).
state: KernelOutput[][], // The current training state of the neural network; see below for more information.
) {
return expected[this.thread.x] - actual[this.thread.x];
} Where:
The aspect of the An example designed to optimize training for XOR might look like: function loss(
this: IKernelFunctionThis,
actual: KernelOutput, // The actual output data of the neural network during this run.
expected: KernelOutput, // The output data expected to be produced by the neural network given the provided input data.
inputs: InputType, // The input data provided to entire neural network (the data passed into the `NeuralNetwork.run(input)` method).
state: KernelOutput[][], // The current training state of the neural network; see above for more information.
) {
// Perform a standard loss function as our foundation to build upon.
let neuronLoss = expected[this.thread.x] - actual[this.thread.x];
// if ( o == i0 ^ i1 ) then return 10% of the loss value.
// Otherwise, return the full loss value.
if (Math.round(actual[0]) === Math.round(inputs[0]) ^ Math.round(inputs[1])) neuronLoss *= 0.1;
return neuronLoss;
} which allows for you to train a neural network to predict XOR calculations without ever even having been fed a data set. Just stream random data as training input, allow it to produce random output at first, and train on the error from the calculation. Instead of telling the network, "Hey! There's a bounty reward for whoever can solve for Y given X," you can instead define a rule to determine what is or is not good behavior, or even create a hybrid loss function. The above kernel function is a simple example of a hybrid loss function that I kind of just tossed together to train a standard feed-forward network to solve for XOR by using the standard XOR training set. In my experience, this greatly improves training times when done correctly. Sending tons of positivity and good vibes your way friend 💕 |
Beta Was this translation helpful? Give feedback.
-
I just realized that a |
Beta Was this translation helpful? Give feedback.
-
Okay, this is honestly the coolest feature I've ever added to anything. This has me so excited!!! Like, to give you an idea of why I'm so excited: A custom loss function made training an autoencoder much faster, and within a single |
Beta Was this translation helpful? Give feedback.
-
Is it possible to define a custom loss function for a neural network in Brain.js like in Tensorflow?
If not, where might I begin to implement it? I took a look in the codebase and searched for terms like "loss", "cost", etc. without much luck. I found the error calculation functions, but I'm still lost tbh. Any help would be greatly appreciated 🥰
Beta Was this translation helpful? Give feedback.
All reactions