How to interpert this decision tree? - weka

I am using Weka (for the first time). After loading my data into Explorer I calculated a classifier model with a RandomTree. In the output I got the following:
RandomTree
==========
center_letter < 0
| center_letter < 0 : A (462/0)
| center_letter >= 0
| | next_letter < 0.06
| | | first_letter < 0.05
| | | | center_letter < 0
| | | | | next_letter < 0.05
| | | | | | first_letter < 0.03 : A (3/0)
| | | | | | first_letter >= 0.03 : B (1/0)
| | | | | next_letter >= 0.05 : B (2/0)
| | | | center_letter >= 0 : A (21/0)
| | | first_letter >= 0.05 : B (5/0)
| | next_letter >= 0.06 : B (20/0)
center_letter >= 0
... so on
What I understand from this doesn't make any sense:
In the first statement it will enter that node if value of "center_letter" is negative (I have no negative values in my data!). Then it checks the same thing again and reports class A (this happened for 462 values?). But then it goes into a branch where "center_letter" is non-negative which is impossible and still finds values in the inner conditions.
What is the proper way to read this tree as what I read doesn't make any sense? A link to an explanation would be great as I can't find one.

tie your eyes on the dashes like this:
center_letter < 0
|
center_letter >= 0
They are like traditional branching < ie right and left then:
center_letter < 0 : A (462/0)
is a leaf ie stops then dashes continue with:
center_letter >= 0
which has two childs:
next_letter < 0.06
|
next_letter >= 0.06 : B (20/0) this is leaf and stops the navigation
then continue with next_letter < 0.06
and so on..

Related

How to increase the verbosity level of SCIP solver log

I have the following SCIP solver log
time | node | left |LP iter|LP it/n| mem |mdpt |frac |vars |cons |cols |rows |
0.0s| 1 | 0 | 4 | - | 6k| 0 | 0 | 6 | 200 | 6 | 200 |
0.0s| 1 | 0 | 7 | - | 6k| 0 | 0 | 8 | 200 | 8 | 200 |
0.0s| 1 | 0 | 10 | - | 6k| 0 | 0 | 9 | 200 | 9 | 200 |
0.0s| 1 | 0 | 10 | - | 6k| 0 | 0 | 9 | 200 | 9 | 200 |
0.0s| 1 | 0 | 10 | - | 6k| 0 | 0 | 9 | 200 | 9 | 200 |
0.0s| 1 | 0 | 10 | - | 6k| 0 | 0 | 9 | 200 | 9 | 200 |
I want the log to be more verbose, as in display a new line at each LP iteration. So far I only came across
SCIP_CALL( SCIPsetIntParam(scip, "display/verblevel", 5));
This is increasing but not as much as I want and not where I want. Essentially I would like to have lines at LP iter 4, 5, 6, 7, 8, 9 and 10 too.
You cannot print a line of SCIP output at every LP iteration. You can set display/freq to 1, then SCIP will display a line at every node.
Additionally you can set display/lpinfo to true, then the LP solver will print additional information. I don't think any LP solver will print you a line for every LP iteration though . Do you use SCIP with SoPlex?
Edit: Looked and you can set the SoPlex frequency to 1 with the parameter "--int:displayfreq". I don't think you can set this through the SCIP api though. If you only want to solve the LP you could just do it in SoPlex or you would have to edit the lpi_spx2 source code.

bit wise addtion in C++

I am looking to following code at following link
https://www.geeksforgeeks.org/divide-and-conquer-set-2-karatsuba-algorithm-for-fast-multiplication/
// The main function that adds two bit sequences and returns the addition
string addBitStrings( string first, string second )
{
string result; // To store the sum bits
// make the lengths same before adding
int length = makeEqualLength(first, second);
int carry = 0; // Initialize carry
// Add all bits one by one
for (int i = length-1 ; i >= 0 ; i--)
{
int firstBit = first.at(i) - '0';
int secondBit = second.at(i) - '0';
// boolean expression for sum of 3 bits
int sum = (firstBit ^ secondBit ^ carry)+'0';
result = (char)sum + result;
// boolean expression for 3-bit addition
carry = (firstBit&secondBit) | (secondBit&carry) | (firstBit&carry);
}
// if overflow, then add a leading 1
if (carry) result = '1' + result;
return result;
}
I am having difficulty in understanding following expressions
// boolean expression for sum of 3 bits
int sum = (firstBit ^ secondBit ^ carry)+'0';
and other expression
// boolean expression for 3-bit addition
carry = (firstBit&secondBit) | (secondBit&carry) | (firstBit&carry);
What is difference between two? What are they trying to achieve?
Thanks
To understand this, a table with all possible combinations may help. (For our luck, the number of combinations is very limited for bits.)
Starting with AND (&), OR (|), XOR (^):
a | b | a & b | a | b | a ^ b
---+---+-------+-------+-------
0 | 0 | 0 | 0 | 0
0 | 1 | 0 | 1 | 1
1 | 0 | 0 | 1 | 1
1 | 1 | 1 | 1 | 0
Putting it together:
a | b | carry | a + b + carry | a ^ b ^ carry | a & b | b & carry | a & carry | a & b | a & carry | b & carry
---+---+-------+---------------+---------------+-------+-----------+-----------+-------------------------------
0 | 0 | 0 | 00 | 0 | 0 | 0 | 0 | 0
0 | 0 | 1 | 01 | 1 | 0 | 0 | 0 | 0
0 | 1 | 0 | 01 | 1 | 0 | 0 | 0 | 0
0 | 1 | 1 | 10 | 0 | 0 | 1 | 0 | 1
1 | 0 | 0 | 01 | 1 | 0 | 0 | 0 | 0
1 | 0 | 1 | 10 | 0 | 0 | 0 | 1 | 1
1 | 1 | 0 | 10 | 0 | 1 | 0 | 0 | 1
1 | 1 | 1 | 11 | 1 | 1 | 1 | 1 | 1
Please, note, how the last digit of a + b resembles exactly the result of a ^ b ^ carry as well as a & b | a & carry | b & carry resembles the first digit of a + b.
The last detail is, adding '0' (ASCII code of digit 0) to the resp. result (0 or 1) translates this to the corresponding ASCII character ('0' or '1') again.

Sprites; changing frames is not fluid in C++ Allegro 5

Watch the video: https://youtu.be/i2EXKY3EQPo
The dragon movement is not fluid. It's like if all the frames were changing at the same time. What am I doing wrong?
shipImage = al_load_bitmap("dragon_stationary.png");
ship.maxFrame = 5;
ship.curFrame = 0;
ship.frameCount = 0;
ship.frameDelay = 50;
ship.frameWidth = 180;
ship.frameHeight = 126;
ship.animationColumns = 5;
ship.animationDirection = 1;
//this occurs every 1/60 of a second
void drawShip(SpaceShip &ship, ALLEGRO_BITMAP *flyingShip) {
if (++ship.frameCount >= ship.frameDelay) {
if (++ship.curFrame >= ship.maxFrame) {
ship.curFrame = 0;
ship.frameCount = 0;
}
}
al_draw_bitmap_region(ship.image, ship.curFrame * ship.frameWidth, 0, ship.frameWidth, ship.frameHeight, ship.x, ship.y, 0);
This is the sprite:
Try plotting out what happens for various values:
| frameCount | curFrame |
| ---------- | -------- |
| 0 | 0 |
| 1 | 0 |
| 2 | 0 |
| ... | ... |
| 49 | 0 |
| 50 | 1 |
| 51 | 2 |
| 52 | 3 |
| 54 | 4 |
| 55 | 5 |
| 56 | 0 |
| 0 | 0 |
Note that when frameCount hits 50, it blasts through all your frames in sequence, then only resets once the animation is complete. You need to reset frameCount every timme it reaches frameDelay

Django Queryset two problems

my queryset :
Status.objects.filter(date__gte='2017-07-05', date__lt='2017-07-09', type='X').update(value=F('value') + 1)
my database :
date | value | value1 | value2 | type
2017-07-05 | 0 | 0 | 0 | X
2017-07-06 | 0 | 0 | 0 | X
2017-07-07 | 0 | 0 | 0 | X
2017-07-08 | 0 | 0 | 0 | X
2017-07-09 | 0 | 0 | 0 | X
2017-07-10 | 0 | 0 | 0 | X
I have two question, but my above queryset don't work.
1 - How update field "value" in date range ?
2 - How to replace "value" with a variable ?
update(value=F('value') + 1)
I need to dynamically select field (value1, value2, valuse3) from the database to change value.
you can path a field name with a variable using this.
somename='some_field' #value.value1,... in your case
Status.objects.filter(Q(date__gte='2017-07-05'), Q(date__lt='2017-07-09'), Q(type='X')).update(**{somename: F(somename)+1})

REPtree algorithm output

Can anyone tell me how to interpret the output of REPtree algorithm under some kind of dataset.
Here is part if the output:
won < 36.5
| team = BOS
| | year < 1961.5 : 36.6 (4/41.19) [1/3.06]
| | year >= 1961.5
| | | pace < 96.31 : 43.4 (2/1) [3/86]
| | | pace >= 96.31 : 51.86 (3/2) [4/73]
| team = CH1 : 20 (0/0) [1/913.28]
| team = CL1 : 30 (1/0) [0/0]
| team = DE1 : 40 (1/0) [0/0]
| team = NYK
| | year < 1958
| | | year < 1952.5 : 26.75 (3/1.56) [1/40.11]
| | | year >= 1952.5 : 36.67 (2/0) [1/1]
| | year >= 1958 : 51.06 (12/91.24) [4/18.92]
| team = PH1 : 36.89 (7/126.49) [2/15.44]
I just found a good answer for you question.
the number before : is the conditional rule.
the first number after : is the class value.
the first figures in both brackets, that's the number of instances matching the rule.
the second figures in both brackets, that's the percentage of instances misclassified by the rule.
more reference, please see this link