Live data from Hacker News

How can one manage thousands of IF…THEN…ELSE rules?

programmers.stackexchange.com

41–50 of 86 posts

Re: How can one manage thousands of IF…THEN…ELSE rules?

#41
post #26

Is it just me? It's not a good question, it shows lack of core coding experience. For example a video game consists of millions of possibilities/results in movement based on environment - it's not approached as a collection of thousands of if/then/else statements. In fact the movement of cows seems very much like video game coding, it needs a "cow engine".

I think it was a really good question. It showed that he had the intuitive instinct that there had to be a better way. He just didn't know how to ask for a "cow engine" by name.

I am not so certain. Note their question is not if there is another way - they are asking how to manage all the statements they are planning to write.

Imagine being given a problem such as "add any two given integers but do not use math operators".

A person without anything but if/then/else knowledge would proceed to try to write

   if (a==1 && b==2) c==3  
and repeat it for every variation until they gave up.

Someone with more core experience and coding instinct would immediately recognize there must be away to set patterns for 0-9 and then analyze each decimal place, apply a matrix, or a number of other approaches.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#42
post #23

Earlier quoted context omitted.

Can you explain you think Genetic Programming is unsuitable? I honestly can't see why you think it wouldn't work.

As SeanLuke said, genetic programming is an optimization method. I don't see a function being optimized here, so what would you run it on?

If you had samples of cow behavior such as videos, you could then simulate behavior at each step and optimize for a genetic algorithm that produces similar behaviors. In this case it's probably not the right solution, but it's not that hard to swap out different learning algorithms when things don't seem to jell.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#44
post #6

You really don't want to think of this in terms of IF ... THEN ... ELSE but as individual binary or multi-path choices. These are most efficiently handled with hash tables that choose a route through a logic diagram in a way that is more intuitive than If ... THEN ... ELSE as well as more efficient. You start by writing a logic flowchart that you understand, then you reduce the logic flowchart to code, usually automa…

Maybe I'm off the mark, but whenever I see a long runon procedure full of if-then-else, I think "This is a job for a state machine!" With that approach, you can exhaustively provide actions for every combination of states and events. You can also immediately identify the code responsible for handling any state+event. You can also track which state+event transitions have been tested automatically.

> Maybe I'm off the mark, but whenever I see a long runon procedure full of if-then-else, I think "This is a job for a state machine!"

I'm a big fan of state machines, but systems like this are often multitasking and (for all practical purposes) stateless. OTOH it might be more accurate to say their state is formally unpredictable.

A system like the one being described would be more like a multi-threaded critical-path flowchart, where multiple processes are active at a given time. And at any time a high-level linear programming result might mandate a change of strategy based on available resources, even though individual processes continued to follow the tactical flowchart.

So even though a state machine approach looks attractive (as it always does), it's a matter of deciding how many states and how many levels. Because of the nature of the original problem and the number of connections with everyday reality, the fact that it was a state machine might escape the attention of even a careful observer.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#45
post #23

Earlier quoted context omitted.

All machine learning techniques build models for you. ADTrees, Random Forests, and Decision trees are all classifiers, so they serve this guy's needs. Genetic Programming is not a machine learning technique: it is an optimization method for a very specific task and is quite unsuited for his purposes.

Can you explain you think Genetic Programming is unsuitable? I honestly can't see why you think it wouldn't work.

Obviously various optimization techniques can be used essentially as poor-man's machine learners. That doesn't mean they're particularly good at it.

In this case, Genetic Programming uses trees as its representation, and so it could be used as a tree-based classifier, but the OP has already indicated that he expects enormous numbers of rules, necessitating huge trees. For Genetic Programming, this translates into a gigantic search space.

As it was my thesis work, I'm always ready to promote Genetic Programming where appropriate. This is not the place. There are better tools for this task.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#46
post #34

Earlier quoted context omitted.

All machine learning techniques build models for you. ADTrees, Random Forests, and Decision trees are all classifiers, so they serve this guy's needs. Genetic Programming is not a machine learning technique: it is an optimization method for a very specific task and is quite unsuited for his purposes.

No, I am certain you are confusing Genetic Programming [1] for Genetic Algorithms [2]. I am a fan (do a lot with them) of the prior but have never really been impressed by the latter. Wikipedia says Genetic Programming is a specialization of genetic algorithms where the objects are programs. I think this is the only thing I have ever seen where the specialization turns out to be more general than the parent. I'd also…

> No, I am certain you are confusing Genetic Programming [1] for Genetic Algorithms [2].

Trust me. I am not.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#47
I am late to this discussion, but I would like to ad my experiences with compiling rules to a Rete network. I have done a lot of hacking on the old Lisp OPS5 code and found it easy to work with, once you read and understood Charles Forgy's papers. I hacked OPS5 to support multiple data worlds and a few other enhancements for specific projects.

The more modern Rete based software projects are probably also easy to work with.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#49
post #34

Earlier quoted context omitted.

No, I am certain you are confusing Genetic Programming [1] for Genetic Algorithms [2]. I am a fan (do a lot with them) of the prior but have never really been impressed by the latter. Wikipedia says Genetic Programming is a specialization of genetic algorithms where the objects are programs. I think this is the only thing I have ever seen where the specialization turns out to be more general than the parent. I'd also…

> No, I am certain you are confusing Genetic Programming [1] for Genetic Algorithms [2]. Trust me. I am not.

Then you will know that Genetic Programming can be used for classification, structured learning, symbolic regression and even meta learning [1]. For classification you can build a program that searches for a program that best uses the input to predicts classes. I have done this (there are better heuristics than the old kind that lead to really big dumb programs). Or you can combine boosting with Genetic Programming or you can use them in Learning Classifier Systems. All these lead to classification based on genetic programming.

[1] http://en.wikipedia.org/wiki/Eurisko

As an aside, My definition of Machine learning is more inclusive than yours. I mean if you are going to separate out optimization then I guess you don't count stochastic gradient descent or Matrix factorization as part of machine learning? Machine learning is basically the combination of statistics and optimization where you can work with a lot of data and the output of your computation is more important than the model.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#50
post #40

Earlier quoted context omitted.

Totally agreed -- that's the first thing I thought while reading the question. OOP made this kind of problem easy to tackle long ago.

I really don't see how OOP is going to make it much easier to tackle this kind of problem, care to elaborate how?

http://pragprog.com/articles/tell-dont-ask
Post reply on HN