this doesn't look like java/python/c/..etc
its from a book about algorithm/data structures
after a few searches i felt like this is called functional programming, but still
this ADD/ZERO/ISZERO/for_loop_syntax is different in it,
so, what is this thing?, what do i call this type of writings?
& where do i run it? [if its a programming language]
is it wrong, if i write ADD(x,y) as SUM(x,y)?
The code is a formal definition of a Polynomial as computer data structure.
Source is the Book Fundamentals of Data Structures by Ellis Horowitz and Sartaj Sahni. The language being used is called SPARKS.
Introduction to the defintion from the book (page 47; Chapter 2: Arrays):
The first step is to consider how to define polynomials as a
computer structure. For a mathematician a polynomial is a sum of terms where each term has the form ax^e; x is the variable, a is the coefficient and e is the exponent. However this is not an appropriate definition for our purposes. When defining a data object one must decide what functions will be
available, what their input is, what their output is and exactly what it is that they do. A complete specification of the data structure polynomial is now given.
Related question.
Related
I never took a formal GA course, so this question might be vague: I'm trying to see whether I'm approaching this problem well.
Usually a genome is represented as a sequence of homogeneous elements, such as binary numbers, logic gates, elementary functions, etc., which can then be assembled into a homogeneous structure like a syntax-tree for a computer program or a 3D object or whatever.
My problem involves evolving a graph of components, lets say X, Y and Z: the graph can have N nodes and each node is an instance of either X, Y or Z. Encoding such a graph structure in a genome is rather straightforward, however, I also need to attach additional information for what X, Y and Z do themselves--which is actually the main object of the GA.
So it seems like my genome should code for a heterogeneous entity: an entity which is composed both of a structure graph and a functionality specification. It is not impossible to subsume the elements (genes) which code for the structure and those that code for functionality under a single parent "gene", and then simply separate them when the entity is being assembled, but this doesn't feel like the right approach.
Is this a common problem in GA? Am I supposed to find a "lower-level" representation / genome encoding in this situation? What are the relevant considerations?
Yes you can do that with GA, but strictly speaking you will be using Genetic Programming (GP) as opposed of Genetic Algorithms. GP is considered a special case of GA where the genome representation is heterogenous. This means your individual is a "computer program" instead of just "raw data" look here and here. This means you can really get creative on what this "computer program" means, how to represent it and handle it.
Regarding the additional information, it should be fine as long as all your genetic operators consider this representation. For instance, your crossover. It could be prepared to exchange half of the tree and half of the additional information of the parents. If for some reason the additional information cannot be divided, your crossover may decide to clone it from one of the parents.
The main disadvantage of this highly tuned approach is that you probably can't use high level GA/GP frameworks out there (I'm just assuming, I don't know much about them).
I was reading through a paper published by the University of Washington with tips about Machine Learning algorithms.
The way they break down an ML algorithm is into 3 parts. A representation, evaluation and optimization. I would like to understand how these three parts work together, so what is the process like throughout a typical machine learning algorithm.
I understand that my question is very abstract and each algorithm will be different, but if you know of a way to explain it abstractly please do. If not feel free to use a specific algorithm to explain.
Paper: http://homes.cs.washington.edu/~pedrod/papers/cacm12.pdf ~
See Table 1.
Sebastian Raschka has provided a very nice flowchart of the (supervised) machine learning process.
(I am familiar with text classification, so I will use this as an example)
In short :
Representation: Your data needs to be brought into a suitable algorithmic form. For Text classification you would for example extract features from your full text documents (input data) and bring them into a bag-of-words representation.
Application of the respective algorithm: Here your algorithm is executed. After training you have to do some kind of evaluation to measure your success (the criteria for evaluation is depending on the task). (The Evaluation is the final part of this step)
Optimization: The learning algorithms usually have one or more parameters to tune. Having reference pairs of parameter configuration / evaluation (from the previous step) you can now tweak the paramaters and evaluate the effect on your results.
(In the flowchart this is the edge, where we go back to the step "Learning algorithm training")
I'll be more than thankful if anyone would be able to explain me how Kolmogorov complexity is related to randomness, and random inputs.
Another thing that I can't understand - we know that calculating Kolmogorov complexity of a given input X isn't decidable. Given that, how can it be a measure of randomness?
thanks
Kolmogorov random is a particular definition of the vague intuitive concept of 'random' - which other definition are you referring to when asking for relationship (for reference http://en.wikipedia.org/wiki/Random_number)?
I don't follow your thought pattern in asking why one would have to be able to determine in the general case which strings are Kolmogorov random in order for the concept to be well-defined. Could you elaborate on what is giving you trouble? If nothing else, allow me to point you to the halting problem - certainly the concept of a program halting is well-defined even though there can be no algorithm for determining, in the general case, whether a particular program exhibits the property.
You should think the other way round. If something is not random, it means it follows some law, and this law can give a simpler description of the information. Think of zip: instead of the file you give a procedure to generate the file that is usually more compact than the source file. This is possible because the source file contained some order: if the source file was a random sequence of characters no compression would have been possible.
If you are interested in this topic, I strongly recommend "Computability and Randomness" by Andre' Nies, Oxford Logic Guides n.51.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Are they the same thing?
No.
A function is a block of code in a computer program.
An algorithm is an abstract concept that describes how to solve a problem.
In mathematics, a function is "a mathematical relation such that each element of a given set (the domain of the function) is associated with an element of another set (the range of the function)" (source - google.com, define:function).
In computer science, a function is a piece of code that optionally takes parameters, optionally gives a result, and optionally has a side effect (depending on the language - some languages forbid side-effects). It must have a specific machine implementation in order to execute.
The computer science term came out of the mathematical term, being the machine implementation of the mathematical concept.
An algorithm is "a precise rule (or set of rules) specifying how to solve some problem" (source - google.com, define:algorithm). An algorithm can be defined outside of computer science, and does not have a definitive machine implementation. You can "implement" it by writing it out by hand :)
The key difference here is, in computer science, an algorithm is abstract, and doesn't have a definitive machine implementation. A function is concrete, and does have a machine implementation.
An algorithm is a set of instructions.
In computer programming, a function is an implementation of an algorithm.
An algorithm is a series of steps (a process) for performing a calculation, whereas a function is the mathematical relationship between parameters and results.
A function in programming is different than the typical, mathematical meaning of function because it's a set of instructions implementing an algorithm for calculating a function.
An algorithm describes the general idea, whereas a function is an actual working implementation of that idea.
It might be almost a philosophical question, but I'de say an algorithm is the answer(or how-to) to a problem at hand where as a function does not necerally answer one problem in itself.
What you want to do normally is split your algorithm into severals function that each has their own goal, which, in the end, will achieve the problem at hand, when used together.
Ex : You want to Sort a list of numbers. The algorightm used would be for example the Merge-sort algorithm. That specific algorithm is actually composed of more than one functions, one that will split your array, another to check for equality, another to merge everything back together, and so on.
A mathematical function is the interface, or specification of the inputs and outputs of an algorithm.
An algorithm is the precise recipe that defines the steps that may implement a function.
Confusingly, computer language designers diffuse this distinction by using the concept function, func, method, etc, to talk about both concepts.
So the distinction is one of specification vs. definition.
There is also a semantic distinction: an algorithm seeks to provide a solution to a problem. It is goal-oriented. A function simply is - there is no essential teleological component.
An algorithm is the implementation of a function.
In some cases, the algorithm is trivial:
Function: Sum of two numbers.
Algorithm:
int sum(int x, int y){
return x+y;
}
In other cases, it is not:
Function: Best chess move.
Algorithm:
Move bestChessMove(State gameState){
//I don't know the algorithm.
}
Algorithm is a (possibly informal but necessarily precise) sequence of instructions. Function is a formal rule that associates some input w/ a specific output. Functions implement and formalize algorithms. E.g. we can formalize "go from a to b" as go(a)=b or go(x,a)=b (w/ x the one who goes), etc. According to Wikipedia,
An algorithm is an effective method that can be expressed within a
finite amount of space and time and in a well-defined formal
language for calculating a function.
So you can say that "go(ing) from a to b" is an effective method for calculating go(a)=b (if you want)
An Algorithm usually refers to the method or process used to end up with the result after mathematical processing. A Function is a subroutine used to avoid writing the same code over and over again. They are different in their uses. For instance, there may be an Algorithm that is used for encrypting data, and a function for posting code to a webpage.
Here is some further reference:
http://en.wikipedia.org/wiki/Algorithm
http://en.wikipedia.org/wiki/Function_(computer_science)
A function is a symbolic representation whereare a method is the mechanical steps needed to get the answer.
Suppose this function:
f(x) = x^ 2
Now if I tell you to count f(5000) you have to do things that this function doesn't say. Like for example how to multiply. So really these are just symbols.
But if I have a python method for example:
x = math.pow(500, 2) # or whatever it is
Then in this case the steps themselves for each operation are totally defined (in the libraries ;) ).
I'm working on Markov Chains and I would like to know of efficient algorithms for constructing probabilistic transition matrices (of order n), given a text file as input.
I am not after one algorithm, but I'd rather like to build a list of such algorithms. Papers on such algorithms are also more than welcome, as any tips on terminology, etc. Notice that this topic bears a strong resemblance with n-gram identification algorithms.
Any help would be much appreciated.
It sounds like there are two possible questions, you should clarify which one:
The 'text file' contains probability values and "n" and you build the matrix directly, but how to code it? This question is trivial, so let's disregard it
The 'text file' contains something like signal data and you want to model it as a Markov Chain.
'Markov Chain' generally refers to a first order stochastic process, so I'm not sure then what you mean by "order", probably the size of the matrix, but that is not typical terminology. Anyway, for 1st-order, n x n matrix, discrete time random process, you should look at Viterbi Algorithm: http://en.wikipedia.org/wiki/Viterbi_algorithm
Whenever dealing with Markov Models, I tend to end up looking at crm114 Discriminator. One, he goes into great detail about what different models there actually are (Markov isn't always the best, depending on what the application is) and provides general links and lots of background information on how probabilistic models work. While crm114 is generally used as some sort of SPAM identification tool, it is actually a more generic probability engine that I have used in other applications.