Calculate the result according to a matrix table

Hello all,

I am new to Knime and may i know which node should i use for calculating the result according to a matrix table.

Here is the sample material i have:
Matrix:
Range…Class A…Class B…Class C
1 - 10…OK…Good…OK
11 - 20…Good …OK…OK
20 - 30…OK…OK…Good

Date:
Range…Class
… 8…B
…11… B
…21…C

I believe i can use the node “rule engine” to define the calculation logic one by one, but i have a very huge matrix table.

Thank you so much for the help

Hello @Petertang94
If I interpreted correctly the challenge, when you say …11 …B; you mean …11 …A based in above matrix criteria table.

Please find attached a possible solution based in unpivoting the matrix reference table and a merge with join:

20230418_matrix_table_v0.knwf (47.6 KB)

BR

1 Like

Hello @gonhaddock , thank you so much for helping me out on the KNIME. Sorry i didn’t explain my problem clearly. I would like to develop a workflow to calculate the result as “Good” according to the matrix table (When Range = 8, Class = B)

Hi @Petertang94
This is what current provided workflow does:

11; A

BR

Hello @Petertang94,

in order to achieve what you want you need to modify both tables. Matrix table needs Unpivoting node to get class names in rows. Date table needs first Rule Engine to transition Range 8 to 1 - 10, 11 to 11-20 and so on. Also in date table modify Class column to have same value as class column names in matrix table (B → Class B; use String Manipulation node for it). Then you can match it with Joiner node based both conditions and bring for range appropriate class value.

Give it a try and if any issues/problems I can give it a try and provide workflow example. Welcome to KNIME Community!

Br,
Ivan

1 Like

Hello @ipazin & @gonhaddock

I take reference to your 20230418 workflow and follow the instruction to develop a workflow which works well. However, my database has more than 100 range group (e.g. 1-10, 11-20, … 991-1000). Is there a way to create formula i write in the “rule engin” in a more efficient way?

20230419.knwf (14.5 KB)

Thank you so much

1 Like

Hello @Petertang94
The 20230418’s workflow, currently doesn’t use a ‘Rule Engine’ node:

I would recommend you to follow this approach. It’s already working with your reference tables, just copy and paste the nodes. No further implementation is needed for unlimited number of samples and ranges.

The only suggested change will be to add the $Range$ column to Retained columns in Unpivoting node, then you can aggregate it in Join node together with $ColumnValues$…


20230418_matrix_table_v1.knwf (68.7 KB)

BR

2 Likes

Hi again @Petertang94
The joiner was taking class from lower table… please find the following update:

image
20230418_matrix_table_v2.knwf (68.2 KB)

The class column in samples table is not needed in fact (as in v0).

BR

1 Like

Hello @gonhaddock,

Sorry i feel like i dont understand the logic of the workflow.

Since the result (Good or OK) is calculated according to the matrix table, so i suppose both class column and range are needed. (For example. when range is 30 and class is A, the result should be “OK”). However, currently in the workflow, it didnt put class column in consideration and range cannot be greater than 27

Hello @Petertang94
What you are saying is completely logic:

You can only query to values from 1-30 because your ranges reference table only is fulfilled with continuous range up to 30. You would need to extend this table for your use case.

Since there isn’t a rule engine, we are automatizing the conditions from your matrix conditions table, that i guess is needed already in your process. So you don´t need to transfer your conditions to any scripting node -saving a boring task-, as they are embedded in the matrix table.

BR

P.S. Could happen that i am misunderstanding the logic of the challenge, and your initial data is already classified; then you just want to populate informative columns. If the case the mechanic should be similar.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.