AI and B4X

Star-Dust

Expert
Licensed User
Longtime User
Is there anyone with experience training TensorFlow? I was considering training AI to develop in B4X. I'm following several tutorials, but I need someone already experienced. Who would embark on a crazy project?
 

hatzisn

Expert
Licensed User
Longtime User
I do not have the experience you are looking for, but when I was researching it I noticed that there are ready made python libs that can save you lot of time. If I were you I would buy in Udemy or find in freeCodeCamp a full python tutorial in order to create a back end webapp with tensor flow capabilities in python which would act as the "app-in-the-middle" to save you lot time. Of course you can do this also in Java.
 

Star-Dust

Expert
Licensed User
Longtime User
I'm aware of this, but thank you for writing it. However, I was looking for someone familiar with DL who would like to lend a hand.
 

Magma

Expert
Licensed User
Longtime User
I'm aware of this, but thank you for writing it. However, I was looking for someone familiar with DL who would like to lend a hand.
Hi there,

did you checked that:
 

josejad

Expert
Licensed User
Longtime User
I was considering training AI to develop in B4X
Sorry if it's a bit off-topic about your question, but this is something rounding my head time ago. I'm pretty almost sure, Erel is testing something similar not only to offer us some very exciting and blow-heading kind of using AI in some way on B4X, but because his brain is always hungry of new things, like Web3, the new search engine, etc... It maybe with some kind of IDE copilot, or with a web page which could generate code with less errors than chatGPT, etc...

That said, I don't mean in any way to discourage you from doing more research on it, I've been reading lately about how to train chatGPT.
 

Daestrum

Expert
Licensed User
Longtime User
As an aside I asked qwen-coder-2.5 (running locally on my laptop using the 0.5B parameter set)


D:\qwen tests>python qwen_setup.py
Generating model inputs
Generating ids
Asking : Do you know the B4X computer languages
Yes, I am familiar with the B4X (Basic for Windows) programming language. B4X is an open-source platform for building cross-platform applications on Windows. It allows developers to create applications that run on multiple operating systems, including Windows, macOS, and Linux. B4X is known for its simplicity and ease of use, making it a popular choice for developers looking to build applications for various platforms.

Example of generated code
D:\qwen tests>python qwen_setup.py
Generating model inputs
Generating ids
Asking : write a quick sort algorithm in B4J.
Sure! Below is a simple implementation of the Quick Sort algorithm in B4J. This algorithm sorts an array in ascending order.

```b4j
Sub QuickSort(arr As Array)
If arr.Length <= 1 Then
Return arr
Else
Dim pivotIndex As Integer = Partition(arr, 0, arr.Length - 1)
QuickSort(arr, 0, pivotIndex - 1)
QuickSort(arr, pivotIndex + 1, arr.Length - 1)
End If
End Sub

Sub Partition(arr As Array, low As Integer, high As Integer) As Integer
Dim pivotValue As Integer = arr(high)
Dim i As Integer = low - 1

For j As Integer = low To high - 1
If arr(j) <= pivotValue Then
i = i + 1
arr(i), arr(j) = arr(j), arr(i)
End If
Next

arr(i + 1), arr(high) = arr(high), arr(i + 1)

Return i + 1
End Sub
```

### Explanation:

1. **Partition Function**:
- This function takes an array and two indices (`low` and `high`) as parameters.
- It selects the last element as the pivot.
- It iterates through the array from the start to the pivot index.
- If it finds an element that is less than or equal to the pivot, it increments the index and swaps the elements at the current index and the pivot index.
- After the loop, it swaps the pivot element with the element at the index `i + 1`.

2. **Quick Sort Function**:
- The `QuickSort` function first checks if the array has 0 or 1 element, in which case it returns the array as is.
- Otherwise, it partitions the array into three parts: elements less than or equal to the pivot, elements equal to the pivot, and elements greater than the pivot.
- It recursively calls itself on the partitioned sub-arrays.

This implementation is simple and works well for small to moderately sized arrays. For very large arrays, consider using more advanced sorting algorithms like Merge Sort or Heap Sort.
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
Just from personal experience (playing around with AI code) you probably should look at using Python for training (and creating the parameter files). It has so many available functions to 'Learn' the code from source files.
 

Star-Dust

Expert
Licensed User
Longtime User
I have already started studying the TensorFlow library with Python, but I came across TensorFlow.js
It's less powerful but it's good to start understanding and above all I can combine it with my recent work with BANano and create something that I can add into WebApps.

This is my first experiment for evaluating when an invoice will be collected by creating a model from a DataSet of collections for the last 3 years. It is not precise but very useful for teaching purposes.
Here is the first experiment where we predict when an invoice will be paid considering the past collections of the last 3 years


1735564097776.png



JavaScript:
const newInvoiceDate = parseDate('20241201');
const newCustomerID = 1;
const newAmount = 29.50;
const prediction = model.predict(tf.tensor2d([[newInvoiceDate, newCustomerID, newAmount]])).dataSync();
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I have already started studying the TensorFlow library with Python, but I came across TensorFlow.js
It's less powerful but it's good to start understanding and above all I can combine it with my recent work with BANano and create something that I can add into WebApps.

This is my first experiment for evaluating when an invoice will be collected by creating a model from a DataSet of collections for the last 3 years. It is not precise but very useful for teaching purposes.
Here is the first experiment where we predict when an invoice will be paid considering the past collections of the last 3 years


View attachment 160102


JavaScript:
const newInvoiceDate = parseDate('20241201');
const newCustomerID = 1;
const newAmount = 29.50;
const prediction = model.predict(tf.tensor2d([[newInvoiceDate, newCustomerID, newAmount]])).dataSync();
You can do better with Excel's statistical functions.
 

Magma

Expert
Licensed User
Longtime User

rabbitBUSH

Well-Known Member
Licensed User
Longtime User
I don't think we need the precognitive powers of Artificial I - we just need the Power of @Star-Dust ! 🙏 for your work ..............

this isn't a cross-posting it's just saying the same thing twice ... us ancient mariners tend to do that.....
 
Top