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


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

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)

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.


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.



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.


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


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


I hope this example will be useful for your work 🙂 





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.

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...