Live data from Hacker News

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

programmers.stackexchange.com

31–40 of 86 posts

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

#31
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".

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

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

#33
A finite state machine is actually not a great solution for this particular problem (in fact, FSMs are often over-used), IMHO. An expert system is a far better solution (as one commenter mentioned). The problem with a FSM is that you still must explicitly specify ALL of the nodes (without some complex algorithm to automate such a task). An expert system, like prolog, only requires you to state all of the rules, and then it will figure out any query for you (via propositional logic, backwards chaining, etc). The number of nodes typically grows exponentially with the number of rules (if the rules are inter-related), so for a problem of any significant size an expert system would probably be the method of choice.

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

#34
post #4

Such a great question. Want to predict cow movement while taking into consideration sudden events, food and sun, using thousands of if then rules? Sounds like the perfect problem for one of the following tree learners that not only manage themselves but build the model for you, in order of suitability to the problem* : Genetic Programming ADTree Random Forest Decision Tree Most of the work would be in figuring out th…

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 like to point out that I although all ML learns models, all those I gave can learn stuff as what amounts to a bunch of IF-THEN statements. Well GP need not be so limited. And Random Forests lose the trees in the forest (harder to interpret) but yeah, that's why I formed that particular list.

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

[2] http://en.wikipedia.org/wiki/Genetic_algorithm

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

#35
Wouldn't this best be handled by something like a decision tree?

http://en.wikipedia.org/wiki/Decision_tree

It's basically thousands of if-this-then-that statements, but dressed up into something you can reason about and most importantly train and build automagically.

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

#36

While I'm not sure thousands of if/then/else rules are actually the best knowledge representation for his domain (it sounds like he really wants to learn some model from data, in which case throwing some off-the-shelf machine learning may be a better fit), the area of "expert systems" may be relevant if they really are rules extracted directly from some source that need to be managed, such as a human domain expert. E…

I don't think thousands should be taken literally. I don't think he has actually built it yet - I sort of saw it as an optimistic estimate =)

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

#37
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".

Last I checked (been a couple years now) Hierarchical Finite State Machines and Behaviour Trees were big for that sort of thing.

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

#38

Mildly unrelated, but I wanted to point out the awesomeness of the K-map[1] for handling simple minimization problems like these. Unfortunately, once your dimensions get large it becomes difficult for humans to visualize the optimizations, which is where Espresso[2][3] comes in handy. [1] http://en.wikipedia.org/wiki/Karnaugh_map [2] http://embedded.eecs.berkeley.edu/pubs/downloads/espresso/in... [3] ftp://ftp.cs.man…

+1 to espresso. Too bad there aren't any "native" bindings in many languages, but in many cases piping it through stdin/stdout works well enough.

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

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

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

#40
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".

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?
Post reply on HN