Jump to content

For-loop in Rulex


Jack Adams

Recommended Posts

Hi @Jack Adams

actually there is no task For in Rulex but there is a way to recreate its operation and even if a bit trickey once you understand the mechanism is not too complicated.
Here below I will explain its functionality with a simple example: let's pretend to have to create different classification models depending on the day of the week in which we recorded the data.

First we need a dataset with the data of our interest, like this one below

image.thumb.png.6a4c11d7394ead31eab0a0f30551e155.png

output is the values on which we want to make the classification, date_att is the day on which the data was recorded, "all other attributes"  contain the values that will be used to create the rules to classify the outputs.
After defining all the starting variables, let's create one on which the iteration will be carried out and to do this we then add a process variable i_weekday and initialize it to 1

iweekday.png.2598fbdcd0a2deb9948a8ba04e997460.png
We then return to the initial dataset and create a week_day variable using the weekDay() function, based on the date the function will define which day it refers to (1 is Monday, 2 Tuesday and so on)
weekday.png.caf341f885b6b227bd888e28df6cd2d4.png

The iteration part will be done dynamically and therefore rather than creating a filter using a precise value we will use the process variable created previously. By doing this we will obtain a dataset containing only the days corresponding to the value set previously, 1, and therefore for the moment all the data related to Monday.

filtro.png.1ed30f9fa2ca9aaed4416e646098844d.png

Last steps before getting to the actual iteration is to add the tasks for generating the model: use an LLM(Logic Learning Machine) to find the rules for our classification, a Rule Manager to view the rules and a Convert Ruleset to Dataset to have a dataset containing all the rules. You can also add an additional Data Manager to insert in a column the day to which the rules generated by the model correspond. You can observe alle these steps in the next three images.

LLM.thumb.png.ca5842968626ed80cead12e340e1f0e0.png

1696038585_Regoleluned.thumb.png.c77b3099a039610bff2a3c89492a0d74.png
723689937_finalDM.thumb.png.a9c04218ac7a642c219cf621b0e7cc6f.png

It's time to do the magic! Select the Data Manager where you insert the filter, the LLM task, the Rule Manager, the Convert Ruleset to Dataset and the eventual last Data Manager containing the day of the rule; right click and select Create Module.
 

image.png.34c40ad3aa747e23813abc6dfcf7e53d.png

Inside the module select the last task of your iteration (Endpoint task) and in the Advanced settings you will enter more specific details:

  • Number of executions: how many times to iterate, in our case for each day of the week and then 7
  • For each exectuon: for each iteration you can decide whether to increment or decrease, we have put as starting value 1 and therefore we want to increase up to 7
  • Process variable: on which variable do you effect the increment or decrease, in this case i_weekday

Selecting the option Accumulate iterations data you will also obtain as output of the module a single dataset containing the concatenation of all the iterations made (just what is right for us). In the next two images you can see in detail the settings of this task

modulo.thumb.png.5f9c6d7cfc1ad58b30d404cbca028668.png
Adnced.thumb.png.bb5b5ee5294a49ebfe3cc5dd9b00890d.png

What you will get in the end will then be a dataset containing a list of rules divided by days of the week.

image.thumb.png.d8f4fa721be1b4244ad81c6bf621bea6.png

I hope this example will be useful for your work 🙂 

Regards

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...