Sets of equalities and inequalities constraint satisfiability problem - constraints

I am relatively new to CSPs and I am trying to find the value of all the variables from their respective domains, based on ==, >, < and != constraints imposed between the variables.
I looked at Choco and Jacop but, I couldn't find out more about solving these type of problems.
Could you please point me to somewhere I can find an implementation of this example?
I have solved this using Prolog, but I want to use OOP to get this done.
Thank You.

The type of problem you are describing is a direct description of a constraint programming problem, given that the variables have finite domains that can be mapped to integers.
All CP systems have the operators you need for operating over finite domain integers, so it should be straightforward.
If you are trying to solve for variables with unbounded domains or real domains, then there are some tools that can help you but they are not as common.

Related

h2o categorical_encoding understanding when to use and why

I'm trying to understand the pros/cons and when to use the various encoding options that are available to me in h2o with the parameter 'categorical_encoding'.
It would be helpful if people could point out general rules of thumb on how to use this.
Typically I use the 'Enum' value because I like how all categorical values are grouped together when looking at feature importance. On the other hand, xgboost's default value is 'label-encoder' I believe, which breaks things up by categorical level/value.
Unfortunately, I don't really know where to begin or questions to ask around these other values available:
one hot internal
one hot explicit
sort_by_response
enum_limited
enum
-label-encoder
Again, I primarily stick with enum, sometimes label-encoder, but honestly I don't know practical implications of these various options. Would love a generalized understanding of when one might be better than other from someone knowledgeable !
As requested (thanks!) this question was reposted to cross-validated. So the answer on what the pros and cons are can be found at: https://stats.stackexchange.com/questions/376203/categorical-encoding-in-h2o-what-is-the-difference-between-the-options

is it possible to write a program that can find zeros of a certain function?

In Gauss-legendre integration we need to find zeros of the legendre function but i can't find a way to write code that enable me to do that?
I understand there are list of "xi"s out there by which this function equals to zero but can we write program that find these "xi"s on it own?
In general, finding zeroes of an arbitrary function is not a problem that can be solved by an algorithm. Whether your particular function or class of functions can be solved by an algorithm or not must depend intimately upon the specific mathematical properties of your functions, since your algorithm must rely on those properties specifically. Questions on your functions and what properties it might possess is out of scope for programming and probably computer science as well; I suggest math stack exchange. If you can get a mathematician to explain how to solve the problem by hand, at least in theory, then you are at the point where programmers and computer scientists can start to help you.

Fuzzy systems with same output from different rules

I'm new in fuzzy logic modeling. I'm using the package "sets" in R. Starting form a database of crisps variables of 8 input varialbes and 1 output variable, I performed the fuzzyfication and I assigned a membership function to each variables (inputs and output).
I'm now stucking with the definition of the fuzzy rules.
I would like to ask if we have the same consequent from different rules, how are these rules processed?
I read that it's possible for this problem to assign a weight to each rule? Is it the correct way to proceed?
There's some one how has already experiences with this issue?
Thanks a lot in advance.
Michele
it is possible to assign rules with two different antecedents to the same output. I have previous Matlab experience, not R, but it is the same principle everywhere and the system is evaluated like a charm. However, be careful if you want to use neurofuzzy network (ANFIS), because it doesn't allow the particular characteristic.

OCL : express the unique constraint in a more optimal way

I am learning OCL (using "USE"), I've a question about the isUnique() constraint here's the following example:
We want to establish the unique constraint of customer numbers through the class full as follows
context Client
inv NoClientUnique : Client.allInstances -> isUnique(noClient)
but this expression is far from optimal , because it is possible that the constraint is validated repeatedly. Please anyone can explain me when this is the case and why, and please if you could give me another way to express the unique constraint of Client.noClient using an optimal. i'll appreciate any help.
OCL is a declarative language. Therefore you express what you want to happen, not how to do it. It doesn't make sense to discuss about how optimal is an OCL expression when optimal referes to the execution time. The translation engine should then be able to translate this declarative expression into the most efficient imperative traversal of the object graph in order to verify it.
Today, you can avoid the inefficiency by placing the constraint in a neutral scoping class such as perhaps the ClientManager that just needs to assert once that all-my-clients are unique.
Realistically there should always be such a scoping class, since if you take your subsystem and instantiate it multiple times, the Constraint that all Clients are unique is a fallacy. There is no reason why two different companies shouldn't have the same client if uniqueness is defined by a set of attributes rather than object identity.
(It has been suggested that it should be possible to have Package constraints so that in this case you could have used the Package as the neutral location.)

Surjective functions

As an extension question my lecturer for my maths in computer science module asked us to find examples of when a surjective function is vital to the operation of a system, he said he can't think of any!
I've been doing some googling and have only found a single outdated paper about non surjective rounding functions creating some flaws in some cryptographic systems.
Master edit:
[btw, thank you for the accepted response.]
In reviewing my response, and these of others in this post, I realized two things.
The first one is the fact that in looking things at a higher level of abstraction, most (all?) of the [counter-]examples provided are a form of "discretization" function. In other words, they correspond to the ubiquitous requirement in computer systems of mapping [possibly infinitely] numerous entities/values to a set (possibly "infinite" too, though most often a finite one) of discrete entities/values. While not all such mappings imply or require a non bijective surjection, many do, hence the several examples found.
The other observation is that the most compelling examples seem to be tied to stochastic (random) processes, or to the underlying primitives which support them.
Both of these things are quite telling, I think, for it mirrors, if only loosely, the way the real world's complexity (read "randomness", at many levels) is exploited in various systems in human (and animals) to produce simplified/stable/discrete maps that represent elements of this complex reality: Another case where mathematics and its practical-oriented friend, Computer Science, team up to describe or to mimic fundamental realities (or... are these realities? hum... we're getting too philosophical...)
It could be a matter of understanding exactly the frame of the question:
do bijective functions count (they are indeed a special case of a surjection)
Edit: No, bijective functions are not considered.
has it got to be a "function" in the sense of a procedural calculation as opposed to say a "relation" as in databases
Edit: yes, a procedural function of sorts... "take in a value and return another value" (IMHO this distinction is very tenuous as any "map" is a function, regardless of the inner working, but let's entertain this "numeric calculation like" restriction in the spirit of this question)
define "vital"...
With all these caveats in mind, the following may apply:
Elementary mathematical functions such as ABS() or even ROUND(), FLOOR() (absolute value, rouding of a decimal/float value to the nearest int respectively) etc.
In the case of ABS(), for example, used in the context of a program which draws shapes on the screen, using various properties of say symmetry, would be able to count on getting two, and exactly two values to map to a a given value, and to have all values in a given integral range (say from 0 to 10), to be an ABS() value, lest the drawings will start to look funny ;-)
the Soundex function (and its many derivations)
Modulo operations, even in such trivial uses as to show the status of a process, every x items processed.
Classification processes: it is both important that there'd be a important reduction factors (thousands instances mapped to a handful of categories), and it is vital [in some cases] that all instances yield one and only one category (ex: in real-time decision systems).
Various "simple" mathematical functions used in pseudo-random number generators.
It is vital that they'd be surjective, so that a) all values within the namespace would be reacheable, indeed, expectations of a specific, often uniform, distribution is implied. (Note, could be bit of a repeat of the "modulo" example above, although it doesn't have to use modulo arithmetic proper, other math function can do)
Following is a bad example, now that Martin clarified that [math operations like functions that] "take in a value and return another value" is what defines "function" hence disqualifying database/table-driven "maps" and such. And also that bijections were not considered either.
One-to-One relations (or one-to-many relations for that matter) : it can be so important to maintain these that we require triggers etc. to keep up with referential integrity
A very simple scheduler implemented by the function random(0, number of processes - 1) expects this function to be surjective, otherwise some processes will never run.
In practice the scheduler has some sort of internal state that it modifies. If you want to see it as a function in the mathematical sense, it takes a state and returns a new state and a process number to run, and in this context it's no longer important that it is surjective because not all possible states have to be reachable. Not a very good example, I'm afraid, but the only one I can think of.
A hashing function should ideally be surjective.
But in general I think the question is too vague to be answered. What is a system? What is a function used inside a system?
Edit:
I think the question is not very meaningful. After all there are many cases where you need to be able to produce every desired result. Just think about the identity function and imagine where you could argue that it is used:
using a reference to a variable in programming
using a text (or even hex-editor) to produce a file
It would be very bad, if you could not create any bit combination by xor or not when doing bit manipulations.

Resources