RE: JESS: Reversing logic
Learning multiplication and division before asking questions about partial differential equations, Fourier Transforms, Dempsy-Schaeffer, Field Theory, Magnetic Resonance and Flux Theory, etc., etc. is extremely good advice ! Ola James Rich! My newbee advice, from painful experience, is simple: Learn to crawl before you attempt to run with scissors. -Jason Morris Technical Solutions, LLC. [EMAIL PROTECTED] www.morristechnicalsolutions.com fax/phone: 503.692.1088 To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
Re: JESS: Reversing logic
(text ?tName2:(regex-match (upcase ?tName2) ^[A-Z][A-Z\\-]+,?$)) (x ?xName2:( ?xName2 ?xName1)) (y ?rowName2)) (adjacent (left ?name1)(right ?name2)) ?partic - (word (text ?tPartic:(regex-match ?tPartic [0-9]{4,9})) (x ?xPartic:(and ( ?xPartic ?xName2)( ?xPartic ?xAmt))) (y ?rowPartic:(same-row ?rowPartic ?rowAmt))) (adjacent (left ?name2)(right ?partic)) (process-page (page ?p)) (and (not (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt))) (not (word (x ?xOther:( ?xOther ?xName1)) (y ?yOther:(same-row ?yOther ?rowAmt) = (printout t Allocation entity found: ocr ?tName1 ?tName2 ?tPartic ?tAmt at ?xAmt ,?rowAmt crlf) (assert (allocation-entity (source ocr)(page ?p)(row ?rowAmt) (firstName ?name2) (lastName ?name1) (particid ?partic)) ) (assert (allocation-amount (page ?p)(row ?rowAmt)(x ?xAmt)(value ?tAmt)(word ?amt P.P.S I still need to take advantage of the new regular expression pattern matching instead of using my regex-match user function. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dusan Sormaz Sent: Wednesday, March 09, 2005 12:01 AM To: jess-users@sandia.gov Subject: Re: JESS: Reversing logic First morning shot on it: De Morgan's laws: (not ( and a b)) == (or (not a) (not b)) Dusan Sormaz At 08:17 PM 3/8/2005, you wrote: Ok, I know that I should know this, but I'm having trouble reasoning through it. Why do the following two CEs versions produce significantly different results? The only difference is that I'm reversing the and/not order, but this results significantly different activation results. (not (and (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt)) (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) (and (not (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt))) (not (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) Thanks. -Mitch * * Du9an )ormaz, PhD, Associate Professor * Ohio University * Industrial and Manufacturing Systems Engineering Department * 277 Stocker Center, Athens, OH 45701-2979 * phone: (740) 593-1545 * fax: (740) 593-0778 * e-mail: [EMAIL PROTECTED] * url: http://www.ent.ohiou.edu/~sormaz * To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
RE: JESS: Reversing logic
Oh boy... ;) The statement that James made that caught my attention was this: rules are declarative and each rule must be incrementally independent; it must contain the logic that it needs and not depend on another rule to fire first before it fires. This *seems* (i.e. in my mind) to run counter to the notion of forward-chaining rules as described in chapter 7.4 of JIA (the Sherlock Holmes analogy). My current system is chock full of such dependancies, and I just want to know if by doing so I'm asking for trouble down the road. -Mitch P.S. I apologize for this not being specifically related to Jess. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Owen jco Sent: Friday, March 11, 2005 9:57 AM To: jess-users@sandia.gov Subject: Re: JESS: Reversing logic Normally I don't get into long-winded discussions on the Jess group because it is, and should be, devoted to answering questions about Jess. After all, it is the Jess User's Group, not the Long-Winded-Rambling-What-About-That Group. However, Mitch wanted to open up the following to discussion by the Jess group so I'm posting my private answer in the public forum. Then I'm going back to work. :-) I've been doing rulebased systems (RBS) since 1989. I even worked for Neuron Data way back when the only real tool that they had was Nexpert, a full opportunistic backward chaining system. Anyway, I've picked up a few tricks along the way. Jess (along with OPSJ, drools, Mandarex, JEOPS and others) are tools for programmers, not for business analysts; much like C++ and Java. There are other, must more expensive systems, that have extensive debugging tools, GUI screens for business analysts and special language processors for the business analysts. Some are scalable; some are not. Also, the thought process jump from OO to declarative languages is akin to the thought process jump from procedural to OO. It's still bits and bytes on the computer, the change is the approach and the view of the logic. The Jess In Action book is good and does an excellent job of teaching Jess, but it only goes so far. There are many other books that might help, but not many programmers have the time to read and understand these books. See http://www.kbsc.com/aibooks.html for a suggested list. Many of these go more into the technical, statistical, theory, etc. than most programmers or users have a need. I suppose that the main thing to consider is that the rules are declarative and each rule must be incrementally independent; it must contain the logic that it needs and not depend on another rule to fire first before it fires. We get around that by using either goal-driven rules or priorities, but priorities are something that should be used with great discretion - no more than three levels if possible. Setup priority rules, logic priority rules and clean-up priority rules. Take care and remember, it's a long, long road with lots of study on your own. The time problem is something that management rarely understands so you have to sell that concept to the management. Working with rules is 70% thought and design and only 30% implementation. I just go off the phone with the Maricopa County Attorney's office who have implemented a rulebased system over a three year period, but they spend a lot of time up front considering all of the requirements, constraints, etc. BEFORE writing the first line of code. And they follow that same process for any new project that comes along that needs rules. Something well worth thinking about. SDG jco Mitch Christensen wrote: Thanks All. DeMorgan's laws is what I was trying to remember last night (and couldn't). I knew there was a way to transpose/normalize logic, but couldn't recall the specifics. However, ;) I did do a truth table, and I did change the logic to fix my rule before posting my question. My problem is that now I am having a hard time explaining *why* it works. In other words, it works now, but looking at the rule, I would insist that it shouldn't. Here is my truth table. StmtA : (not (and A B)) which is equivalent to (or (not A)(not B)) StmtB : (and (not A)(not B)) +---+---+---+---+ | A | B | StmtA | StmtB | +---+---+---+---+ | 0 | 0 | 1 | 1 | +---+---+---+---+ | 1 | 0 | 1 | 0 | +---+---+---+---+ | 0 | 1 | 1 | 0 | +---+---+---+---+ | 1 | 1 | 0 | 0 | +---+---+---+---+ Now, whenever my CE is true (i.e. StmtX is 1), my rule should fire. Since I was incorrectly using StmtA instead of StmtB, I would expect my rule to fire occasionally when it shouldn't (i.e. false positives). The symptom I was getting was that my rule wasn't firing when it otherwise should as all the previous patterns were matched. I simply converted to the StmtB form and the rule fired. How can that be? To address Ernest's warning, this CE is the last statement
Re: JESS: Reversing logic
I think Mitch Christensen wrote: rules are declarative and each rule must be incrementally independent; it must contain the logic that it needs and not depend on another rule to fire first before it fires. This *seems* (i.e. in my mind) to run counter to the notion of forward-chaining rules as described in chapter 7.4 of JIA (the Sherlock Holmes analogy). Sherlock Holmes (modus ponens) chaining is not only fine, it's great. In the Sherlock Holmes scenario, each rule operates on working memory, and it can be written with no awareness of any other specific rule and modifications that other rule may make to working memory; the rules only care about what's in working memory, not how it got there. So they are indeed independent, even though they work together. I think what jco is talking about is the common newbie mistake in thinking that leads to the question I wrote three rules. How do I fire them in order, 1, 2, 3? - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
RE: JESS: Reversing logic
Ah...that would make sense, and clear up my concern completely. Given that, I'll assert that jco's reference to backward chaining to resolve 'incremental dependancies' simply means rule 3 would backward chain to rule 2 which may in turn backward chain to rule 1 to get the nessary facts into WM. As for his reference to 'priorities', these would be implemented in Jess using salience. If my last two assertions are true, then I'll go back to work too. :) Thanks. -Mitch -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Friday, March 11, 2005 5:58 PM To: jess-users@sandia.gov Subject: Re: JESS: Reversing logic I think Mitch Christensen wrote: rules are declarative and each rule must be incrementally independent; it must contain the logic that it needs and not depend on another rule to fire first before it fires. This *seems* (i.e. in my mind) to run counter to the notion of forward-chaining rules as described in chapter 7.4 of JIA (the Sherlock Holmes analogy). Sherlock Holmes (modus ponens) chaining is not only fine, it's great. In the Sherlock Holmes scenario, each rule operates on working memory, and it can be written with no awareness of any other specific rule and modifications that other rule may make to working memory; the rules only care about what's in working memory, not how it got there. So they are indeed independent, even though they work together. I think what jco is talking about is the common newbie mistake in thinking that leads to the question I wrote three rules. How do I fire them in order, 1, 2, 3? - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
Re: JESS: Reversing logic
I think Mitch Christensen wrote: Ok, I know that I should know this, but I'm having trouble reasoning through it. Why do the following two CEs versions produce significantly different results? The only difference is that I'm reversing the and/not order, but this results significantly different activation results. The first one is not (A and B), while the second is not A and not B. The first one is satisfied as long as both A and B are not true; A could be true, but not B, and the first would match, but not the second. There are possibly some another difference depending on where ?rowAmt is defined. If ?rowAmt is defined in a previous pattern, then both of these will unify the ?rowAmt variable across both patterns; but if ?rowAmt is first used in the allocation-amount pattern here, then the first version unifies the variable, but the second one does not -- i.e., in that version there are two independent ?rowAmt variables, because no variable defined in a (not) CE is visible outside of that CE. (not (and (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt)) (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) (and (not (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt))) (not (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) Thanks. -Mitch - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
Re: JESS: Reversing logic
Hi Mitch, You should have had a terrible day, as this is basic logic equivalence : !(a AND b) equals to !a OR !b. When I get in trouble following the logic I usually return to the basis and builds a truth table. Regards. Rodolfo. Mitch Christensen wrote: Ok, I know that I should know this, but Im having trouble reasoning through it. Why do the following two CEs versions produce significantly different results? The only difference is that Im reversing the and/not order, but this results significantly different activation results. (not (and (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt)) (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) (and (not (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt))) (not (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) Thanks. -Mitch To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
Re: JESS: Reversing logic
First morning shot on it: De Morgan's laws: (not ( and a b)) == (or (not a) (not b)) Dusan Sormaz At 08:17 PM 3/8/2005, you wrote: Ok, I know that I should know this, but Im having trouble reasoning through it. Why do the following two CEs versions produce significantly different results? The only difference is that Im reversing the and/not order, but this results significantly different activation results. (not (and (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt)) (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) (and (not (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt))) (not (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) Thanks. -Mitch * * Duan ormaz, PhD, Associate Professor * Ohio University * Industrial and Manufacturing Systems Engineering Department * 277 Stocker Center, Athens, OH 45701-2979 * phone: (740) 593-1545 * fax: (740) 593-0778 * e-mail: [EMAIL PROTECTED] * url: http://www.ent.ohiou.edu/~sormaz *
RE: JESS: Reversing logic
Thanks All. DeMorgan's laws is what I was trying to remember last night (and couldn't). I knew there was a way to transpose/normalize logic, but couldn't recall the specifics. However, ;) I did do a truth table, and I did change the logic to fix my rule before posting my question. My problem is that now I am having a hard time explaining *why* it works. In other words, it works now, but looking at the rule, I would insist that it shouldn't. Here is my truth table. StmtA : (not (and A B)) which is equivalent to (or (not A)(not B)) StmtB : (and (not A)(not B)) +---+---+---+---+ | A | B | StmtA | StmtB | +---+---+---+---+ | 0 | 0 | 1 | 1 | +---+---+---+---+ | 1 | 0 | 1 | 0 | +---+---+---+---+ | 0 | 1 | 1 | 0 | +---+---+---+---+ | 1 | 1 | 0 | 0 | +---+---+---+---+ Now, whenever my CE is true (i.e. StmtX is 1), my rule should fire. Since I was incorrectly using StmtA instead of StmtB, I would expect my rule to fire occasionally when it shouldn't (i.e. false positives). The symptom I was getting was that my rule wasn't firing when it otherwise should as all the previous patterns were matched. I simply converted to the StmtB form and the rule fired. How can that be? To address Ernest's warning, this CE is the last statement prior to the =, so ?rowAmt is declared outside of the CE. I apologize if I'm just noising up the list. It's great that it works, but it worries me that I can't explain why. -Mitch P.S. Here is the complete rule in case that helps: (defrule find-ncp-row-partic-name Find all NCP records (column (type amount)(x ?xc)(y ?yc)(width ?wc)(height ?hc)) ?amt - (word (text ?tAmt:(not (regex-match ?tAmt ^\\p{Punct}+$))) (x ?xAmt:(and (= ?xAmt ?xc)( ?xAmt (+ ?xc ?wc (y ?rowAmt:(and (= ?rowAmt ?yc)( ?rowAmt (+ ?yc ?hc (width ?wAmt:(and ( ?wAmt 5)(= ?wAmt ?wc ?name1 - (word (text ?tName1:(regex-match (upcase ?tName1) ^[A-Z][A-Z\\-]+,?$)) (x ?xName1) (y ?rowName1:(same-row ?rowName1 ?rowAmt))) ?name2 - (word (text ?tName2:(regex-match (upcase ?tName2) ^[A-Z][A-Z\\-]+,?$)) (x ?xName2:( ?xName2 ?xName1)) (y ?rowName2)) (adjacent (left ?name1)(right ?name2)) ?partic - (word (text ?tPartic:(regex-match ?tPartic [0-9]{4,9})) (x ?xPartic:(and ( ?xPartic ?xName2)( ?xPartic ?xAmt))) (y ?rowPartic:(same-row ?rowPartic ?rowAmt))) (adjacent (left ?name2)(right ?partic)) (process-page (page ?p)) (and (not (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt))) (not (word (x ?xOther:( ?xOther ?xName1)) (y ?yOther:(same-row ?yOther ?rowAmt) = (printout t Allocation entity found: ocr ?tName1 ?tName2 ?tPartic ?tAmt at ?xAmt ,?rowAmt crlf) (assert (allocation-entity (source ocr)(page ?p)(row ?rowAmt) (firstName ?name2) (lastName ?name1) (particid ?partic)) ) (assert (allocation-amount (page ?p)(row ?rowAmt)(x ?xAmt)(value ?tAmt)(word ?amt P.P.S I still need to take advantage of the new regular expression pattern matching instead of using my regex-match user function. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dusan Sormaz Sent: Wednesday, March 09, 2005 12:01 AM To: jess-users@sandia.gov Subject: Re: JESS: Reversing logic First morning shot on it: De Morgan's laws: (not ( and a b)) == (or (not a) (not b)) Dusan Sormaz At 08:17 PM 3/8/2005, you wrote: Ok, I know that I should know this, but I'm having trouble reasoning through it. Why do the following two CEs versions produce significantly different results? The only difference is that I'm reversing the and/not order, but this results significantly different activation results. (not (and (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt)) (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) (and (not (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt))) (not (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) Thanks. -Mitch * * Du9an )ormaz, PhD, Associate Professor * Ohio University * Industrial and Manufacturing Systems Engineering Department * 277 Stocker Center, Athens, OH 45701-2979 * phone: (740) 593-1545 * fax: (740) 593-0778 * e-mail: [EMAIL PROTECTED] * url: http://www.ent.ohiou.edu/~sormaz * To unsubscribe
Re: JESS: Reversing logic
Best answer is always the easiest. But one other heuristic that I like to follow is to always express things in a positive manner rather than a negated manner. If it works in the positive manner, reversing can lead to incredibly long and complicated errors in logic. The other answer about a truth table is always good as well. Also, building a spread sheet wherever possible also helps to expose poor logical conclusions and hypotheses. Dusan Sormaz wrote: First morning shot on it: De Morgan's laws: (not ( and a b)) == (or (not a) (not b)) Dusan Sormaz At 08:17 PM 3/8/2005, you wrote: Ok, I know that I should know this, but Im having trouble reasoning through it. Why do the following two CEs versions produce significantly different results? The only difference is that Im reversing the and/not order, but this results significantly different activation results. (not (and (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt)) (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) (and (not (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt))) (not (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) Thanks. -Mitch * * Duan ormaz, PhD, Associate Professor * Ohio University * Industrial and Manufacturing Systems Engineering Department * 277 Stocker Center, Athens, OH 45701-2979 * phone: (740) 593-1545 * fax: (740) 593-0778 * e-mail: [EMAIL PROTECTED] * url: http://www.ent.ohiou.edu/~sormaz http://www.ent.ohiou.edu/%7Esormaz * -- SDG jco Do No Evil. Do Only Good Things. See the good in every one. Always keep learning. Teach those who want to be taught. Avoid fools at all costs. Harm No One, Except to Defend Yourself, Or to Defend Another. Kill No One, Except to Keep From Being Killed, Or to Keep Another From Being Killed. CafeBabe 1210151411101114 To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
JESS: Reversing logic
Ok, I know that I should know this, but Im having trouble reasoning through it. Why do the following two CEs versions produce significantly different results? The only difference is that Im reversing the and/not order, but this results significantly different activation results. (not (and (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt)) (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) (and (not (allocation-amount (page ?p)(row ?rowAa:(same-row ?rowAa ?rowAmt))(x ?xAmt))) (not (word (x ?xOther:( ?xOther ?xName1))(y ?yOther:(same-row ?yOther ?rowAmt) Thanks. -Mitch