A previous post introduced ojAlgo's Artificial Neural Network feature. It did so by presenting a fully functional program that trained and evaluated a network model to categorise handwritten digits using the MNIST data set. That example then included all necessary pre and post processing as well as code that would generate the actual image (*.png) files. All of that may have obscured just how simple it is to work with ojAlgo's neural networks.
The code below is not complete – it simply outlines the basic steps involved to build, train and use a neural network with ojAlgo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.ojalgo.ann.ArtificialNeuralNetwork.Activator.*; | |
import static org.ojalgo.ann.ArtificialNeuralNetwork.Error.CROSS_ENTROPY; | |
import java.util.Collections; | |
import org.ojalgo.ann.ArtificialNeuralNetwork; | |
import org.ojalgo.ann.NetworkTrainer; | |
import org.ojalgo.structure.Access1D; | |
/** | |
* This is not a functioning program. It's just something that outlines the basic steps involved in using | |
* ojAlgo's artificial neural network functionality. | |
* | |
* @see https://www.ojalgo.org/2018/09/neural-network-basics/ | |
*/ | |
public class OutlineNeuralNetworkUsage { | |
public static void main(final String[] args) { | |
/** | |
* Start by instantiating a neural network builder/trainer. This particular network has 200 input and | |
* 10 output nodes. The numbers 100 and 50 define the hidden layers. Some would say this is a 4-layer | |
* network, but there are only 3 calculation layers. The first layer has 200 input and 100 output | |
* nodes. The second layer has 100 input and 50 output nodes, and ly the third 50 inputs and 10 | |
* outputs. | |
*/ | |
NetworkTrainer builder = ArtificialNeuralNetwork.builder(200, 100, 50, 10); | |
/** | |
* That network builder/trainer is ready to be used, but it can be reconfigured. You can (re)define | |
* which kind of activator function should be used for each of the calculation layers. You can | |
* (re)define how to meassure error/loss, and you can modify the learning rate. | |
*/ | |
builder.activators(SIGMOID, RELU, SOFTMAX).error(CROSS_ENTROPY).rate(0.1); | |
/** | |
* The input and output can be typed as ojAlgo's most basic data type – Access1D. Just about anything | |
* in ojAlgo "is" an Access1D. If you have arrays or lists of numbers then you can wrap them in | |
* Access1D instances to avoid copying. Most natuarally you work with ojAlgo data structures from the | |
* beginning. | |
*/ | |
Access1D<Double> input = Access1D.wrap(new double[] { 1, 2, 3 }); // To match the builder this should have 200 elements, | |
Access1D<Double> output = Access1D.wrap(Collections.singletonList(4.0)); // and this should have 10. | |
/** | |
* Repeatedly call this to train the neural network. | |
*/ | |
builder.train(input, output); | |
/** | |
* When you're done training you get the finished product. | |
*/ | |
ArtificialNeuralNetwork network = builder.get(); | |
/** | |
* You evaluate/use the trained neural network by invoking it (it's a function). | |
*/ | |
output = network.newInvoker().invoke(input); | |
} | |
} |
Now have a look at that fully functional example...
Hej!
ReplyDeleteHäftigt bibliotek du har! Jag tänker faktiskt använda detta för reglersystem och maskinlärning. Det blir SVD som jag använder. Jag hittade inte din epostaddress, men jag ville bara ge ett tips på att du borde snygga till din hemsida för OjAlgo. Jag tycker att du har lagt ned så mycket fin tid på att få OjAlgo riktigt effektivt och kraftfullt, så den förtjänar statusen. Just nu tycker jag at ojAlgo ser mer ut som en sida från 2003.
För mig är det viktigt att en hemsida har modern design. Annars tappar den anhängare för första intrycket är viktigt.
Du kan kontakta mig om du vill ha några förslag på hur jag tycker hemsidan för ojAlgo borde set ut. Jag kan säga detta nu att denna hemsida har snygg design. https://atom.io/
oJAlgo borde få en logotyp också. Ett förslag från mig är en modern grön fontdesign av "oJ!"
Tack! (Upptäckte inte din kommentar förrän nu.)
DeleteJo, ojAlgo's hemsida är "enkel". Det håller jag med om. Det handlar inte bara om design. Det behövs innehåll också. Och så ska allt underhållas...
Om du kan och vill bidra med något får du gärna det.
Angående logotyp så när jag började ladda upp till maven repository skapade de i princip en logotyp åt mig. Vet inte riktigt hur det där gick till.
https://mvnrepository.com/artifact/org.ojalgo
De tog bara "oj!" och gjorde en bild av det. Ganska snyggt typsnitt också. Den gröna färgen här på bloggen trivs jag ganska bra med.
/Anders
anders at optimatika punkt se