If you want to parallelize CPU threads, you can build a console app (like the one this thread is making) and use Folderitem.launch to instantiate multiple items across multiple cores as needed, assuming they communicate data efficiently.
I would try to persuade XOJO to focus on GPU integration before multicore. For the same reason. If you have to discretize information for multicore, than you can discretize it for GPU. Then you get thousands of cores working independently on the same problem. Check out a cuda-neural-network on my GitHub if you are on windows with Nvidia.
I have found better results with a network topology of: 11 20 5 1
So change that at the top of the winedata file. Here is the code to input manual data:
Function Run(args() as String) As Integer #Pragma Unused args
Var inputfilename As String = "winedata.txt" '"trainingdata.txt"
Var trainData As New trainingData(inputfilename)
//check trainingData constructor to change path to file
//default is desktop
trainData.getTopology
var myNet as new ai.Net(trainData.topology)
var resultVals() as double
var trainingPass as integer = 0
var consoleprintremainder as integer = 99 //print to console every x operations
var d1 as DateTime = DateTime.now
while not trainData.isEof
trainingPass = trainingPass + 1
if trainingPass Mod consoleprintremainder = 0 then
Print( "Pass " + trainingPass.ToString)
end if
if trainData.getNextInputs <> trainData.topology(0) then
break
end if
If trainingPass Mod consoleprintremainder = 0 Then
showVectorVals("Inputs :",trainData.inputVals)
end if
myNet.feedForward(trainData.inputVals)
resultVals = myNet.getResults
If trainingPass Mod consoleprintremainder = 0 Then
showVectorVals("Outputs:", myNet.getResults)
end if
trainData.getTargetOutputs(trainData.targetOutputVals)
If trainingPass Mod consoleprintremainder = 0 Then
showVectorVals("Targets:", trainData.targetOutputVals)
end if
myNet.backProp(trainData.targetOutputVals)
if trainingPass Mod consoleprintremainder = 0 then
print("Net recent average error: " + myNet.getRecentAverageError.ToString + EndOfLine)
end if
Wend
var d2 as datetime = datetime.now
print(EndOfLine + "DONE")
var elapsed as double = d2.SecondsFrom1970 - d1.SecondsFrom1970
print("ELAPSED " + elapsed.ToString)
Print "processed file: " + inputfilename
//pause terminal
//new code
//Print("Input New Wine Data (11 parameters")
print("input new wine parameters:")
Var s As String = stdin.ReadLine
var newstringentry() as string
var newentry() as double
newstringentry = s.Split(" ")
for i as integer = 0 to newstringentry.Count - 1
newentry.add( Val(newstringentry(i)) )
next
trainData.inputVals = newentry
myNet.feedForward(trainData.inputVals)
resultVals = myNet.getResults
showVectorVals("Outputs:", myNet.getResults)
s = stdin.ReadLine
#Pragma Unused s
End Function
Thanks for the example, a question about the model.
When I enter the following input I should get 0.7 but I get 0.606:
ā0.28 0.16 0.4 0.015 0.044 0.48 0.3575 0.9912 0.82 0.52 0.44ā
When I enter the following input I should get 0.3 but I also get 0.606:
ā0.47 0.26 0.21 0.162 0.074 0.41 0.4925 0.998 0.3 0.5 0.18ā
Are the outputs incorrect because there is not enough data for 0.7 and 0.3 in the windata.txt? Or can the model also be adapted so that one can also find values of which only a few samples are previous?
There may not be enough data, and there are possibly better hyperparameters for the dataset. This includes the eta and alpha values in the neuron class, and the network topology specified at the top of the trainingdata file. The winedata instance was used mostly to test the speed. I am not sure if the wine qualities themselves are totally accurate. They reflect the opinion of a wine tester. Maybe there is a combination of parameters that can predict it accurately.
If you want to see the neural network work successfully on raw logic, try the other dataset (trainingData.txt). For the wines, maybe someone is willing to develop computational hyperparameter optimization to see if they can be accurately predictedā¦
Hello Alexander,
I have now used the file: traningData.txt. Here, however, I already have an error of around 0.5 when learning. Am I doing something wrong here?
No, I have the same issue. I have moved the newer code to a beta folder on the GitHub and uploaded the original projects. Try it again once with trainingData.txt
XOJO Forum Users,
The YouTube Link at the top of this thread has been updated, the new video demonstrates that XOJO is competitive with C++ for machine learning applications when utilizing aggressive built optimization, pragma statements, and loop boundary caching. https://youtu.be/na4lY2B7uco
Iāve used xojo since realbasic days and itās great for many tasks. Iāve also been doing a lot of ML in the last few years. My advice: do not re-invent the wheel in xojo (I too wanted to do it all in xojo at first). The python codebase for ML is absolutely massive and it quickly became apparent that learning python and doing ML in python is the way to go.
And this is not as hard as it seems: I knew 0 python at first, and now write multi-threaded and GPU based scripts that will run circles around xojo e.g. a recent benchmark on my new 5090OC gpu card and a cuda script clocked in at >200 Tflops using half-precision floats. The secret is to use AIs for help: I use Perplexity and Claude 4 as the back-end. It would take me a week to get a massively parallel GPU-based script working. With Claude 4 I had the above benchmark running in <5 min. The AIs are particularly good at python (not so much with xojo as they often hallucinate, Claude is the best behaved in my experience, Gemini is the worst).
And donāt be fooled by the fact that python is interpreted (I too had a bias: interpreted = 100x slower). Yes and no: if you hand code a loop in python it will be much slower. But keep in mind that pythonās numerical libraries like numpy are vectorized and written in highly optimized C/C++ under the hood. So a large matrix multiplication requires a single line of python:
result = X @ Y
and while this single line pre se is interpreted, the actual operation uses highly optimized linear algebra libraries (BLAS/LAPACK) that have been refined over decades, and can be shifted to the GPU if u wish (Claude writes nvidia/cuda and apple silicon versions that select whatās available automatically, oh, and default to cpu if no gpu. quite amazing actually)
In the end, I have my cake and can eat it at the same time: I wrote a front-end app in xojo that encapsulates 8GB of x86 and arm64 python libraries, allowing user interaction, graphics display, etc to be done by xojo and its nice GUI, while the heavy lifting is done by myriad python libraries that are added as needed. I do my prototyping in JupyterLab, then incorporate the working scripts into my xojo-based app. Best of both worlds, allowing less sophisticated users to run complex ML algorithms with a friendly GUI.
I just tried the Neural Network solution in Xojo, after figuring out how it worksā¦
Confidence level was way too low and predictions were mostly wrong.
@Peter Stys: Interesting. How do you make the Python app since Python isnāt installed anymore on macOS? I remember that being a PITA some 10ish years ago when I dabbled with Python.
ChatGPT gave me all the steps to setup a python script that reads JSON data and outputs JSON data using the Machine Learning model it helped me create.
Now I need to figure out how to run all this on a Debian 12 VPS as I want it to run automatically every 6 hours.
How do you make the Python app since Python isnāt installed anymore on macOS?
Even if it were, it wouldnāt solve the problem because you (or users) would manually have to pip install the required libs. What i ended up doing is use miniconda to create 2 parallel python installations, one for x86 the other for arm64, then a shell script copies this installation (hence the 8GB size) into the app bundle after compilation. This way I maintain control over the python version and all required libs to ensure it all works on any machine the user happens to be running on.
possibly, but from the docs, where is python supposed to be installed? if in the system, then full circle back to the same problem of different versions on different machines and missing libraries. I wanted the entire thing self-contained in the app bundle, otherwise no end of compatibility complaints: copy the app bundle to wherever you want and it will always work, with no ancillary files written/required anywhere else. I think this is the single biggest hurdle in getting python & libs deployed for ānormalā users.