FIREFOX EASTER EGGS
In mozilla firefox type in about:robots and then see the magic unfurl !
ABRACADABRA ! .......
..... if you can handle surprises then try about:mozilla
Wednesday, July 28, 2010
Sunday, June 20, 2010
Wednesday, April 28, 2010
HEART TO HEART
HEART TO HEART
Though effective, these means are involved and computationally demanding. However, sometimes by providence we do have sensible shapes made out from simple functions.
PLOTTING THE HEART IN MATLAB
I discuss plotting a heart using simple cardioid, polar plots and algebraic equations
(a) The simplest one
The simplest 'heart curve' is the cardioid. It is not truly a heart, however it looks somewhat similar to one.
(b) Polar plot
A polar curve given by;
gives a near perfect heart !
The Matlab command line is;
(c) Algebraic Equation
A heart can be made from the implicit algebraic function,
However tinkering by adding a factor of (0.35) and (1.3) to the terms makes the heart more aesthetic.
The Matlab command is,
It is worth noting that for using ezplot t, x and y doesn't have to be defined.
A very interesting mathematical recreation is to conceive coherent drawings using algebraic functions. Bezier curves are the authentic way to generate such computer graphics. Bezier came up with his genius in early 60s while designing automobile parts. Other popular means are Hermite curves and Splines.
Though effective, these means are involved and computationally demanding. However, sometimes by providence we do have sensible shapes made out from simple functions.
PLOTTING THE HEART IN MATLAB
I discuss plotting a heart using simple cardioid, polar plots and algebraic equations
(a) The simplest one
The simplest 'heart curve' is the cardioid. It is not truly a heart, however it looks somewhat similar to one.
(b) Polar plot
A polar curve given by;
gives a near perfect heart !
The Matlab command line is;
>> ezpolar('((sin(t)*sqrt(abs(cos(t))))*(sin(t) + (7/5))^(-1)) - 2*sin(t) + 2')
(c) Algebraic Equation
A heart can be made from the implicit algebraic function,
However tinkering by adding a factor of (0.35) and (1.3) to the terms makes the heart more aesthetic.
The Matlab command is,
>> ezplot('(0.35)*((x^2 + y^2 - 1)^3) - (1.3)*(x^2)*(y^3)');
It is worth noting that for using ezplot t, x and y doesn't have to be defined.
(d) Another Algebraic Equation
.
.
.
...then again forget MATLAB, we do have <3 to our rescue !
REFERENCES
(1) ezplot
(2) stackoverflow question 2720180
(3) stackoverflow question 323584
(4) Heart Curve page
(5) Wolfram page
(6) Bezier Heart in Gimp
.
.
...then again forget MATLAB, we do have <3 to our rescue !
REFERENCES
(1) ezplot
(2) stackoverflow question 2720180
(3) stackoverflow question 323584
(4) Heart Curve page
(5) Wolfram page
(6) Bezier Heart in Gimp
Monday, April 19, 2010
A VERY SIMPLE CHATBOX IN PYTHON
A VERY SIMPLE CHATBOX IN PYTHON
A naive chatbot program. No parsing, no cleverness, just a training file and output.
It first trains itself on a text and then later uses the data from that training to generate responses to the interlocutor's input. The training process creates a dictionary where each key is a word and the value is a list of all the words that follow that word sequentially anywhere in the training text. If a word features more than once in this list then that reflects and it is more likely to be chosen by the bot, no need for probabilistic stuff just do it with a list.
The bot chooses a random word from your input and generates a response by choosing another random word that has been seen to be a successor to its held word. It then repeats the process by finding a successor to that word in turn and carrying on iteratively until it thinks it's said enough. It reaches that conclusion by stopping at a word that was prior to a punctuation mark in the training text. It then returns to input mode again to let you respond, and so on.
It isn't very realistic but I hereby challenge anyone to do better in 71 lines of code !! This is a great challenge for any budding Pythonists, and I just wish I could open the challenge to a wider audience than the small number of visitors I get to this blog. To code a bot that is always guaranteed to be grammatical must surely be closer to several hundred lines, I simplified hugely by just trying to think of the simplest rule to give the computer a mere stab at having something to say.
Its responses are rather impressionistic to say the least ! Also you have to put what you say in single quotes.
I used War and Peace for my "corpus" which took a couple of hours for the training run, use a shorter file if you are impatient...
here is the trainer
here is the bot
REFERENCES
(1) Pythomism - Luke's website
A naive chatbot program. No parsing, no cleverness, just a training file and output.
It first trains itself on a text and then later uses the data from that training to generate responses to the interlocutor's input. The training process creates a dictionary where each key is a word and the value is a list of all the words that follow that word sequentially anywhere in the training text. If a word features more than once in this list then that reflects and it is more likely to be chosen by the bot, no need for probabilistic stuff just do it with a list.
The bot chooses a random word from your input and generates a response by choosing another random word that has been seen to be a successor to its held word. It then repeats the process by finding a successor to that word in turn and carrying on iteratively until it thinks it's said enough. It reaches that conclusion by stopping at a word that was prior to a punctuation mark in the training text. It then returns to input mode again to let you respond, and so on.
It isn't very realistic but I hereby challenge anyone to do better in 71 lines of code !! This is a great challenge for any budding Pythonists, and I just wish I could open the challenge to a wider audience than the small number of visitors I get to this blog. To code a bot that is always guaranteed to be grammatical must surely be closer to several hundred lines, I simplified hugely by just trying to think of the simplest rule to give the computer a mere stab at having something to say.
Its responses are rather impressionistic to say the least ! Also you have to put what you say in single quotes.
I used War and Peace for my "corpus" which took a couple of hours for the training run, use a shorter file if you are impatient...
here is the trainer
#lukebot-trainer.py
import pickle
b=open('war&peace.txt')
text=[]
for line in b:
for word in line.split():
text.append (word)
b.close()
textset=list(set(text))
follow={}
for l in range(len(textset)):
working=[]
check=textset[l]
for w in range(len(text)-1):
if check==text[w] and text[w][-1] not in '(),.?!':
working.append(str(text[w+1]))
follow[check]=working
a=open('lexicon-luke','wb')
pickle.dump(follow,a,2)
a.close()
here is the bot
#lukebot.py
import pickle,random
a=open('lexicon-dict','rb')
successorlist=pickle.load(a)
a.close()
def nextword(a):
if a in successorlist:
return random.choice(successorlist[a])
else:
return 'the'
speech=''
while speech!='quit':
speech=input('>')
s=random.choice(speech.split())
response=''
while True:
neword=nextword(s)
response+=' '+neword
s=neword
if neword[-1] in ',?!.':
break
print response
You tend to get an uncanny feeling when it says something that seems partially to make sense. I think this is a universal syndrome with chatbots and shows us a lot about our expectations and hopes for machine intelligence. The tendency to attribute some kind of surreal cosmic wisdom or irony to the responses is common.
TALKING TO TOLSTOY ! ...... ;)
Sample output:( is this like talking to Tolstoy? Not really but still...)
TALKING TO TOLSTOY ! ...... ;)
Sample output:( is this like talking to Tolstoy? Not really but still...)
>>>
>'hello'
the human affairs he thought.
>'oh those affairs were great'
God,
>'what -surprised?'
do you value but she is what had the new country,
>'i do value but i do not blame the war on her'
so alarming them with those around with particular chair by all those who caressed me.
>'i never get anyone caressing me!'
allowed to talk about in a really so.
>'oh do not be prudish I am allowed to mention it'
should she suddenly heard of a duty for reason was handed him very hot.
>'you like these women a lot to talk about them so much'
advantage if your father?
>'my father approves of my romantic side'
love my son's having obeyed in the causes historic events that circle they didn't you know a force producing two Emperors with a certain prince.
>'oh now it is princes is it'
God,
>'do you believe in Him?'
the insistence of incongruities giving you married at his squadron--that is,
>' i don't understand you sir'
>'i do not understand you sir'
the bridge which,
>'i crossed'
himself,
>'ok ok... well 71 lines still is not bad'
the work at Smolensk?
>'yes'
or that of War.
>'no, war'
was gradually that millions of married in which is Dolokhov?
REFERENCES
(1) Pythomism - Luke's website
Sunday, April 11, 2010
RANDOM NUMBER GENERATOR !
RANDOM @DILBERT
RANDOM @NEUMANN
RANDOM @NEUMANN
"Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin. For, as has been pointed out several times, there is no such thing as a random number — there are only methods to produce random numbers, and a strict arithmetic procedure of course is not such a method."
-- John von Neumann
Saturday, April 10, 2010
SINC LOOKS LIKE DIRAC DELTA
DABBLING IN MATLAB
REFERENCES
(1) Delta Function
(2) Sinc - Delta Relationship
After installing Matlab R2009b (7.9.0) on Ubuntu Karmic, I was trying out many thing ! ...... just for fun ! While trying out sinc function .... at a certain point it resembled dirac delta !
.
.
.
One very long spike unto infinity !
.
.
.
One very long spike unto infinity !
REFERENCES
(1) Delta Function
(2) Sinc - Delta Relationship
Thursday, March 25, 2010
THE ASCII TRAIN !
Saturday, March 13, 2010
MOO .....
Thursday, March 4, 2010
Saturday, February 27, 2010
SEMAPHORES IN ADA
THE PROBLEM OF SYNCHRONISATION
Often there are occasions when events must happen in a certain order ! specifically ....
(1) Serialisation: Event A must happen before Event B.
(2) Mutual exclusion: Events A and B must not happen at the same time.
In concurrent programming every process is fighting for time and resource thus in perspective of the above, order must be restored to this apparent chaos. One rather interesting way is to use semaphores.
Semaphores were invented by the Dutch computer scientist Edsger Dijkstra (EWD 74).
A definition will be, a non-negative integer-valued variable that can only be acted upon by two procedures: sem_wait and sem_post
These operations are defined (for a semaphore s) as:
sem_wait(P)
if s>0 then set s:=s-1 and allow task to proceed else suspend task
sem_post(V)
set s:=s+1
For a synchronisation where each process waits for the other, synchronous synchronisation will be done using 2 semaphores, as;
TRYING IN ADA 2005
Trying the scenario in Ada 2005, where Task A and Task B are defined as
Task A : printing 'A' 5 times
Task B : printing 'B' 5 times
however the slicing is of 2 rounds of each task at a time.( i.e. 'AA' , 'BB' ....). This slicing can be tailored with scheduling policies.
REFERENCES
(1) Concurrent and Real Time Programming in Ada
(2) Semaphore construction
(3) http://code.google.com/p/ada-simple/
(1) Serialisation: Event A must happen before Event B.
(2) Mutual exclusion: Events A and B must not happen at the same time.
In concurrent programming every process is fighting for time and resource thus in perspective of the above, order must be restored to this apparent chaos. One rather interesting way is to use semaphores.
Semaphores were invented by the Dutch computer scientist Edsger Dijkstra (EWD 74).
A definition will be, a non-negative integer-valued variable that can only be acted upon by two procedures: sem_wait and sem_post
These operations are defined (for a semaphore s) as:
sem_wait(P)
if s>0 then set s:=s-1 and allow task to proceed else suspend task
sem_post(V)
set s:=s+1
For a synchronisation where each process waits for the other, synchronous synchronisation will be done using 2 semaphores, as;
TRYING IN ADA 2005
Trying the scenario in Ada 2005, where Task A and Task B are defined as
Task A : printing 'A' 5 times
Task B : printing 'B' 5 times
yields the following results, the output strictly interleafs on all ocassions,
however the slicing is of 2 rounds of each task at a time.( i.e. 'AA' , 'BB' ....). This slicing can be tailored with scheduling policies.
REFERENCES
(1) Concurrent and Real Time Programming in Ada
(2) Semaphore construction
(3) http://code.google.com/p/ada-simple/
HELLO WORLD IN ADA 2005
HELLO ADA !
Compilation creates 3 more files.
Running the program,
I should not be writing this article ! ...... however, trying out very simple programs in Ada 2005 made me realise how I have lost touch of the syntax etc !
Ada is a high level language which is a favourite for safety critical and real time systems. Trying out the 'Hello, World' in Ada,
Ada is a high level language which is a favourite for safety critical and real time systems. Trying out the 'Hello, World' in Ada,
The syntax has a 'pascal like' sing to it, Ada program files have extensions adb or ads. The compiler used for Ada is GNAT (which is a part of gcc).
Compilation creates 3 more files.
Running the program,
Monday, February 22, 2010
A SIMPLE EXAMPLE WITH PYCHECKER
BEGINNING TESTING !
Trying out this tool for python testing .... pychecker on program e.py,
.... rectifies the Warnings !
REFERNCES
(1) Pychecker
(2) Beginning Python : From Novice to Professional
Trying out this tool for python testing .... pychecker on program e.py,
The testing software identifies that sum 'shadows builtin' , thus changing name of the function from sum to summation.
.... rectifies the Warnings !
REFERNCES
(1) Pychecker
(2) Beginning Python : From Novice to Professional
Friday, February 19, 2010
DABBLING WITH BASH -1
DABBLING WITH BASH - 1
1a) from command line
1b) from script
BASH (Bourne Again SHell), the name seemed to echo between 'Bashing' to 'Bourne Trilogy'. The command line for nearly all *nix Operating Systems is actually a programming language !
I am working on version 4.0.33
1)The Hello World Program I am working on version 4.0.33
1a) from command line
1b) from script
Sunday, February 14, 2010
CHECKING FOR OPENGL RENDERING IN UBUNTU
CHECKING FOR OPENGL RENDERING !
Details about rendering and also the graphics-card can also be obtained by the command, glxinfo | grep render
Details about rendering and also the graphics-card can also be obtained by the command, glxinfo | grep render
Friday, January 8, 2010
4 GOOGLE SEARCHES IN A SINGLE PAGE !
Try "www.googlegooglegooglegoogle.com" and get the 4 google search on a single page.
Try playing with funny variations ! a mix and match with wiki and google !
Try playing with funny variations ! a mix and match with wiki and google !
Monday, January 4, 2010
ZETA IN SCIPY
PROBLEMS WITH ZETA FUNCTION IN SCIPY
Dabbling with zeta in scipy gave various unsatisfactory results. Few very obvious results of zeta function are ;
(1) For negative even integers the function is zero
(2) zeta(0) = -1/2
(3) zeta(-1) = -1/12
(4) zeta(1/2) = -1.46035450880.....
(5) zeta(1) = infinity
(6) zeta(2) = 1.6449340.....
Trying it on scipy,
The probable reason for this inconsistent behaviour and issues for zeta values below 2 and improbable results for negative numbers is; the module is probably structured abinitio from zeta function
whilst it may be a better idea to structure the zeta function using the functional equation.
It may also help to have a special provision for zeta(1/2)
Subscribe to:
Posts (Atom)