Tuesday, October 13, 2009

find cosine and euclidean distance of given documents.

PROBLEM STATEMENT:
Write a progrm to report the Euclidean distance and Cosine distance for every pair of documents in the dataset. In other words, for all pairs of document vectors {A,B}, find the Euclidean distance and the Cosine distance between A and B.

SOLUTION:

#!/usr/bin/perl -w
# file: sub.pl
use strict;
my @sen1 = qw(a delighted nobel laureate venkatraman ramakrishnan said he was deeply indebted to his associates students and researchers in his cambridge based laboratory for the path breaking work he has conducted in the area of ribosomes ramakrishnan venki to his friends and family is a senior researcher at the medical research council laboratory of molecular biology which has conducted pioneering research over the years he was born in the temple town of chidambaram in tamil nadu i have to say that i am deeply indebted to all of the brilliant associates students and post docs who worked in my lab as science is a highly collaborative enterprise the year old said soon after being told of the nobel accolade the mrc laboratory of molecular biology and the university of utah supported this work and the collegiate atmosphere there made it all possible the idea of supporting long term basic research like that at the lmb does lead to break throughs the ribosome is already starting to show its medical importance he said mrc chief executive sir leszek borysiewicz said we are absolutely delighted that ramakrishnan work has been recognised with the nobel prize for chemistry venki award is the mrc nobel prize and is a reflection of the excellent work that our scientists do a delighted nobel laureate venkatraman ramakrishnan said he was deeply indebted to his associates students and researchers in his cambridge based laboratory for the path breaking work he has conducted in the area of ribosomes ramakrishnan venki to his friends and family is a senior researcher at the medical research council laboratory of molecular biology which has conducted pioneering research over the years he was born in the temple town of chidambaram in tamil nadu i have to say that i am deeply indebted to all of the brilliant associates students and post docs who worked in my lab as science is a highly collaborative enterprise the year old said soon after being told of the nobel accolade the mrc laboratory of molecular biology and the university of utah supported this work and the collegiate atmosphere there made it all possible the idea of supporting long term basic research like that at the lmb does lead to breakthroughs the ribosome is already starting to show its medical importance he said mrc chief executive sir leszek borysiewicz said we are absolutely delighted that ramakrishnan work has been recognised with the nobel prize for chemistry venki award is the mrc nobel prize and is a reflection of the excellent work that our scientists do venkatraman ramakrishnan the tamil nadu born winner of the nobel prize in chemistry kept his connections with india and the state alive in recent years not only to deliver scientific lectures but also to listen to classical music in the sabhas of chennai most of his scientific career has been in the us and the uk in the last decade ramakrishnan revived his academic links with the land of his birth and started collaborating with indian institutions and interacting with indian students and faculty after a long gap he came for the biophysics society meeting at the university of madras and delivered the gn ramachandran memorial lecture in said biotechnologist m vijayan president of the indian national science academy and an honorary professor at the indian institute of science who had chaired that meeting pk ponnuswamy an expert in biophysics and former vice chancellor of the madras and madurai kamaraj universities remembers that visit when ramakrishnan impressed the scientific community with his presentation the slide presentation was a result of very hard work working on ribosomes is a very complex task he was an authority on the subject even then said ponnuswamy the symposium organisers offered him an honorarium for the lecture but he politely declined and instead wanted the university to use it for other purposes in december he visited the university of madras again at the invitation of the department of biophysics to deliver lectures on ribosome structure during his interaction with us he was appreciative of the work being done by our university such as techniques being used in x-ray crystallography said n gautham a professor in the department he showed keen interest in the work being done by our faculty and students there were long hours of discussions in the lab exchanging ideas and expertise on current areas of research he showed keen interest in classical music and found time to listen to concerts at various sabhas during visits to chennai he told us that he is interested in music and wanted to spend time in the music academy says gautham although he was born in the temple town of chidambaram he spent much of his youth in gujarat where his father was head of the department of biochemistry at the maharaja sayajirao university in baroda now vadodara ramakrishnan known to friends and colleagues as venki earned a bsc in physics from that university in the university head of the department of physics ac sharma fondly recalls his visit to the university three years ago he delivered a talk on his subject and freely interacted with our students and faculty said sharma last year the indian national science academy elected him as a foreign fellow while the iisc convinced him to accept its gn ramachandran chair a few years ago a delighted nobel laureate venkatraman ramakrishnan said he was deeply indebted to his associates students and researchers in his cambridge based laboratory for the path breaking work he has conducted in the area of ribosomes ramakrishnan venki to his friends and family is a senior researcher at the medical research council laboratory of molecular biology which has conducted pioneering research over the years he was born in the temple town of chidambaram in tamil nadu i have to say that i am deeply indebted to all of the brilliant associates students and post docs who worked in my lab as science is a highly collaborative enterprise the year old said soon after being told of the nobel accolade the mrc laboratory of molecular biology and the university of utah supported this work and the collegiate atmosphere there made it all possible the idea of supporting long term basic research like that at the lmb does lead to breakthroughs the ribosome is already starting to show its medical importance he said mrc chief executive sir leszek borysiewicz said we are absolutely delighted that ramakrishnan work has been recognised with the nobel prize for chemistry venki award is the mrc nobel prize and is a reflection of the excellent work that our scientists do venkatraman ramakrishnan the tamil nadu born winner of the nobel prize in chemistry kept his connections with india and the state alive in recent years not only to deliver scientific lectures but also to listen to classical music in the sabhas of chennai most of his scientific career has been in the us and the uk in the last decade ramakrishnan revived his academic links with the land of his birth and started collaborating with indian institutions and interacting with indian students and faculty after a long gap he came for the biophysics society meeting at the university of madras and delivered the gn ramachandran memorial lecture in said biotechnologist m vijayan president of the indian national science academy and an honorary professor at the indian institute of science who had chaired that meeting pk ponnuswamy an expert in biophysics and former vice chancellor of the madras and madurai kamaraj universities remembers that visit when ramakrishnan impressed the scientific community with his presentation he slide presentation was a result of very hard work working on ribosomes is a very complex task he was an authority on the subject even then said ponnuswamy the symposium organisers offered him an honorarium for the lecture but he politely declined and instead wanted the university to use it for other purposes in december he visited the university of madras again at the invitation of the department of biophysics to deliver lectures on ribosome structure during his interaction with us he was appreciative of the work being done by our university such as techniques being used in x-ray crystallography said n gautham a professor in the department he showed keen interest in the work being done by our faculty and students there were long hours of discussions in the lab exchanging ideas and expertise on current areas of research he showed keen interest in classical music and found time to listen to concerts at various sabhas during visits to chennai he told us that he is interested in music and wanted to spend time in the music academy says gautham although he was born in the temple town of chidambaram he spent much of his youth in gujarat where his father was head of the department of biochemistry at the maharaja sayajirao university in baroda now vadodara ramakrishnan known to friends and colleagues as venki earned a bsc in physics from that university in the university head of the department of physics ac sharma fondly recalls his visit to the university three years ago he delivered a talk on his subject and freely interacted with our students and faculty said sharma last year the indian national science academy elected him as a foreign fellow while the iisc convinced him to accept its gn ramachandran chair a few years ago two americans and an israeli scientist won the nobel prize in chemistry on wednesday for atom by atom mapping of the protein making factories within cells the royal swedish academy of sciences said americans venkatraman ramakrishnan thomas steitz and israeli ada yonath work on ribosomes has been fundamental to the scientific understanding of life and has helped researchers develop antibiotics yonath is the fourth woman to win the nobel chemistry prize and the first since when dorothy crowfoot hodgkin of britain received the award i am really really happy yonath said i thought it was wonderful when the discovery came it was a series of discoveries we still do not know every everything but we progressed a lot this year three laureates who will share the million kronor million award generated three dimensional models that show how different antibiotics bind to ribosomes these models are now used by scientists in order to develop new antibiotics directly assisting the saving of lives and decreasing humanity suffering the academy said in its announcement they used a method called x-ray crystallography to pinpoint the positions of the hundreds of thousands of atoms that make up the ribosome this knowledge can be put to a practical and immediate use many of today antibiotics cure various diseases by blocking the function of bacterial ribosomes the citation said without functional ribosomes bacteria cannot survive this is why ribosomes are such an important target for new antibiotics building on darwin theory their work builds on charles darwin theory of evolution and more directly on the work done by james watson francis crick and maurice wilkins who won the nobel prize in medicine for mapping dna double helix the citation said in roger d kornberg won the nobel prize in chemistry for x-ray structures that showed how information is copied to messenger rna molecules which carry information from dna to the ribosomes now one of the last pieces of the puzzles has been added understanding how proteins are made said professor gunnar von heijne of the swedish academy of sciences the chairman of the nobel committee for chemistry this discovery is important not only for science as such but also gives us tools to develop new antibiotics ramakrishnan who was born in chidambaram tamil nadu india is the senior scientist and group leader at the structural studies division of the mrc laboratory of molecular biology in cambridge england ramakrishnan said that he was not convinced when he got the morning phone call from the academy well you know i thought it was an elaborate joke i have friends who play practical jokes ramakrishnan told the associated press by telephone from his lab in cambridge i complimented him on his swedish accent steitz a year old born in milwaukee is a professor of molecular biophysics and biochemistry at yale university and attached to the howard hughes medical institute yonath is a professor of structural biology at the weizmann institute of science in rehovot israel and the ninth israeli to win a nobel prize she told israel radio she did not think her gender played a role in the decision it true that a woman has not won since but i do not know what that means does it mean that i am the best woman since then i do not think that gender played a role here she said she had to end the interview abruptly because israeli president shimon peres a nobel peace prize laureate was on the other line alfred nobel a swedish industrialist who invented dynamite established the nobel prizes in his will in the first awards were handed out six years later each prize comes with a million kronor million purse a diploma a gold medal and an invitation to the prize ceremony in stockholm on dec the peace prize is handed out in oslo on monday three american scientists shared the nobel prize in medicine for discovering a key mechanism in the genetic operations of cells an insight that has inspired new lines of research into cancer the physics prize on tuesday was split between a hong kong based scientist who helped develop fibre optic cable and two canadian and american researchers who invented the eye in digital cameras technology that has revolutionised communications and science the literature and peace prize winners will be announced later this week and the economics announcement is set for monday talking tough a day after the beheading of a jharkhand police officer home minister p chidambaram on wednesday said the security forces would engage the maoists till they abjured violence and the indian air force would take steps to protect itself against any naxal attack as long as the cpi maoist believes in an armed liberation struggle we have no option but to ask our security forces to engage them we will arrest them we will apprehend them he told a press conference here not a war he said the government did not consider the naxalite confrontation as a war we do not wage a war against our own people what we said was that the naxalite or cpi maoist must abjure violence and take the path of democracy and dialogue he said counter measures asked about the iaf seeking permission to fight back if the naxals fire upon its helicopters and crew operating in maoist hit areas the home minister said the iaf would take adequate counter measures however the home minister refused to reveal any details mr chidambaram said an indian air force helicopter was fired at by the maoists a few weeks back in chhattisgarh permission sought air chief marshal pv naik had said the iaf had sought permission from the defence ministry to open fire in self defence if its helicopters or air crew operating in the maoist infested areas came under attack union home minister p chidambaram said on wednesday that the government was ready to hold a dialogue with naxals or supporters of the communist party of india maoist provided they abjure violence they maoists use words like war and war of liberation we do not regard our confrontation with them as war we do not wage war against our own people he said maoists should take the path of democracy we will help the state governments discuss with the maoists all the issues of neglect corruption development etc but no development is possible with violence no democracy can accept the theory of an armed rebellion they should first abjure violence award for rukhsana he commended the jammu and kashmir police for doing a good job in the ongoing encounters with militants the j k police are set to become the frontline security force in the country mr chidambaram said he also hailed the heroism of rukhsana kaur who gunned down militants in her house the government had recommended her for a bravery award and she would receive it in due time he dismissed reports of taliban militants being inducted in j k as speculative and baseless on the banned organisation students islamic movement of india simi the minister said it was trying to metamorphose into new organisations under different names we are aware that one or two organisations are being floated by ex-simi cadres);

@sen1 = sort(@sen1);

my @uni = qw();

my $words = $#sen1 + 1;

print "\n total words are $words \n";

my $i = 0;

push (@uni, $sen1[$i]);

for ($i; $i<=$#sen1; $i++)
{
if ($i == $#sen1)
{
if ($uni[$#uni] ne $sen1[$#sen1])
{
push (@uni, $sen1[$#sen1]);
}
}
else
{
if ($uni[$#uni] ne $sen1[$i])
{
push (@uni, $sen1[$i]);
}
}
}

my $total = $#uni + 1;

print "total no. of unique words are = $total \n\n";






my @a = qw(a delighted nobel laureate venkatraman ramakrishnan said he was deeply indebted to his associates students and researchers in his cambridge based laboratory for the path breaking work he has conducted in the area of ribosomes ramakrishnan venki to his friends and family is a senior researcher at the medical research council laboratory of molecular biology which has conducted pioneering research over the years he was born in the temple town of chidambaram in tamil nadu i have to say that i am deeply indebted to all of the brilliant associates students and post docs who worked in my lab as science is a highly collaborative enterprise the year old said soon after being told of the nobel accolade the mrc laboratory of molecular biology and the university of utah supported this work and the collegiate atmosphere there made it all possible the idea of supporting long term basic research like that at the lmb does lead to break throughs the ribosome is already starting to show its medical importance he said mrc chief executive sir leszek borysiewicz said we are absolutely delighted that ramakrishnan work has been recognised with the nobel prize for chemistry venki award is the mrc nobel prize and is a reflection of the excellent work that our scientists do);
@a = sort(@a);

my @va = ();

for (my $j=0; $j<=$#uni; $j++)
{
my $count = 0;
for (my $k=0; $k<=$#a; $k++)
{
if ($uni[$j] eq $a[$k])
{
$count = $count + 1;
}
}
push(@va, $count);
}







my @b = qw(a delighted nobel laureate venkatraman ramakrishnan said he was deeply indebted to his associates students and researchers in his cambridge based laboratory for the path breaking work he has conducted in the area of ribosomes ramakrishnan venki to his friends and family is a senior researcher at the medical research council laboratory of molecular biology which has conducted pioneering research over the years he was born in the temple town of chidambaram in tamil nadu i have to say that i am deeply indebted to all of the brilliant associates students and post docs who worked in my lab as science is a highly collaborative enterprise the year old said soon after being told of the nobel accolade the mrc laboratory of molecular biology and the university of utah supported this work and the collegiate atmosphere there made it all possible the idea of supporting long term basic research like that at the lmb does lead to breakthroughs the ribosome is already starting to show its medical importance he said mrc chief executive sir leszek borysiewicz said we are absolutely delighted that ramakrishnan work has been recognised with the nobel prize for chemistry venki award is the mrc nobel prize and is a reflection of the excellent work that our scientists do venkatraman ramakrishnan the tamil nadu born winner of the nobel prize in chemistry kept his connections with india and the state alive in recent years not only to deliver scientific lectures but also to listen to classical music in the sabhas of chennai most of his scientific career has been in the us and the uk in the last decade ramakrishnan revived his academic links with the land of his birth and started collaborating with indian institutions and interacting with indian students and faculty after a long gap he came for the biophysics society meeting at the university of madras and delivered the gn ramachandran memorial lecture in said biotechnologist m vijayan president of the indian national science academy and an honorary professor at the indian institute of science who had chaired that meeting pk ponnuswamy an expert in biophysics and former vice chancellor of the madras and madurai kamaraj universities remembers that visit when ramakrishnan impressed the scientific community with his presentation the slide presentation was a result of very hard work working on ribosomes is a very complex task he was an authority on the subject even then said ponnuswamy the symposium organisers offered him an honorarium for the lecture but he politely declined and instead wanted the university to use it for other purposes in december he visited the university of madras again at the invitation of the department of biophysics to deliver lectures on ribosome structure during his interaction with us he was appreciative of the work being done by our university such as techniques being used in x-ray crystallography said n gautham a professor in the department he showed keen interest in the work being done by our faculty and students there were long hours of discussions in the lab exchanging ideas and expertise on current areas of research he showed keen interest in classical music and found time to listen to concerts at various sabhas during visits to chennai he told us that he is interested in music and wanted to spend time in the music academy says gautham although he was born in the temple town of chidambaram he spent much of his youth in gujarat where his father was head of the department of biochemistry at the maharaja sayajirao university in baroda now vadodara ramakrishnan known to friends and colleagues as venki earned a bsc in physics from that university in the university head of the department of physics ac sharma fondly recalls his visit to the university three years ago he delivered a talk on his subject and freely interacted with our students and faculty said sharma last year the indian national science academy elected him as a foreign fellow while the iisc convinced him to accept its gn ramachandran chair a few years ago a delighted nobel laureate venkatraman ramakrishnan said he was deeply indebted to his associates students and researchers in his cambridge based laboratory for the path-breaking work he has conducted in the area of ribosomes ramakrishnan venki to his friends and family is a senior researcher at the medical research council laboratory of molecular biology which has conducted pioneering research over the years he was born in the temple town of chidambaram in tamil nadu i have to say that i am deeply indebted to all of the brilliant associates students and post docs who worked in my lab as science is a highly collaborative enterprise the year old said soon after being told of the nobel accolade the mrc laboratory of molecular biology and the university of utah supported this work and the collegiate atmosphere there made it all possible the idea of supporting long term basic research like that at the lmb does lead to breakthroughs the ribosome is already starting to show its medical importance he said mrc chief executive sir leszek borysiewicz said we are absolutely delighted that ramakrishnan work has been recognised with the nobel prize for chemistry venki award is the mrc nobel prize and is a reflection of the excellent work that our scientists do);

@b = sort(@b);
my @vb = ();

for (my $j=0; $j<=$#uni; $j++)
{
my $count = 0;
for (my $k=0; $k<=$#b; $k++)
{
if ($uni[$j] eq $b[$k])
{
$count = $count + 1;
}
}
push(@vb, $count);
}








my @c = qw(venkatraman ramakrishnan the tamil nadu born winner of the nobel prize in chemistry kept his connections with india and the state alive in recent years not only to deliver scientific lectures but also to listen to classical music in the sabhas of chennai most of his scientific career has been in the us and the uk in the last decade ramakrishnan revived his academic links with the land of his birth and started collaborating with indian institutions and interacting with indian students and faculty after a long gap he came for the biophysics society meeting at the university of madras and delivered the gn ramachandran memorial lecture in said biotechnologist m vijayan president of the indian national science academy and an honorary professor at the indian institute of science who had chaired that meeting pk ponnuswamy an expert in biophysics and former vice chancellor of the madras and madurai kamaraj universities remembers that visit when ramakrishnan impressed the scientific community with his presentation he slide presentation was a result of very hard work working on ribosomes is a very complex task he was an authority on the subject even then said ponnuswamy the symposium organisers offered him an honorarium for the lecture but he politely declined and instead wanted the university to use it for other purposes in december he visited the university of madras again at the invitation of the department of biophysics to deliver lectures on ribosome structure during his interaction with us he was appreciative of the work being done by our university such as techniques being used in x-ray crystallography said n gautham a professor in the department he showed keen interest in the work being done by our faculty and students there were long hours of discussions in the lab exchanging ideas and expertise on current areas of research he showed keen interest in classical music and found time to listen to concerts at various sabhas during visits to chennai he told us that he is interested in music and wanted to spend time in the music academy says gautham although he was born in the temple town of chidambaram he spent much of his youth in gujarat where his father was head of the department of biochemistry at the maharaja sayajirao university in baroda now vadodara ramakrishnan known to friends and colleagues as venki earned a bsc in physics from that university in the university head of the department of physics ac sharma fondly recalls his visit to the university three years ago he delivered a talk on his subject and freely interacted with our students and faculty said sharma last year the indian national science academy elected him as a foreign fellow while the iisc convinced him to accept its gn ramachandran chair a few years ago);
@c = sort(@c);
my @vc = ();

for (my $j=0; $j<=$#uni; $j++)
{
my $count = 0;
for (my $k=0; $k<=$#c; $k++)
{
if ($uni[$j] eq $c[$k])
{
$count = $count + 1;
}
}
push(@vc, $count);
}








my @d = qw(two americans and an israeli scientist won the nobel prize in chemistry on wednesday for atom by atom mapping of the protein making factories within cells the royal swedish academy of sciences said americans venkatraman ramakrishnan thomas steitz and israeli ada yonath work on ribosomes has been fundamental to the scientific understanding of life and has helped researchers develop antibiotics yonath is the fourth woman to win the nobel chemistry prize and the first since when dorothy crowfoot hodgkin of britain received the award i am really really happy yonath said i thought it was wonderful when the discovery came it was a series of discoveries we still do not know every everything but we progressed a lot this year three laureates who will share the million kronor million award generated three dimensional models that show how different antibiotics bind to ribosomes these models are now used by scientists in order to develop new antibiotics directly assisting the saving of lives and decreasing humanity suffering the academy said in its announcement they used a method called x-ray crystallography to pinpoint the positions of the hundreds of thousands of atoms that make up the ribosome this knowledge can be put to a practical and immediate use many of today antibiotics cure various diseases by blocking the function of bacterial ribosomes the citation said without functional ribosomes bacteria cannot survive this is why ribosomes are such an important target for new antibiotics building on darwin theory their work builds on charles darwin theory of evolution and more directly on the work done by james watson francis crick and maurice wilkins who won the nobel prize in medicine for mapping dna double helix the citation said in roger d kornberg won the nobel prize in chemistry for x-ray structures that showed how information is copied to messenger rna molecules which carry information from dna to the ribosomes now one of the last pieces of the puzzles has been added understanding how proteins are made said professor gunnar von heijne of the swedish academy of sciences the chairman of the nobel committee for chemistry this discovery is important not only for science as such but also gives us tools to develop new antibiotics ramakrishnan who was born in chidambaram tamil nadu india is the senior scientist and group leader at the structural studies division of the mrc laboratory of molecular biology in cambridge england ramakrishnan said that he was not convinced when he got the morning phone call from the academy well you know i thought it was an elaborate joke i have friends who play practical jokes ramakrishnan told the associated press by telephone from his lab in cambridge i complimented him on his swedish accent steitz a year old born in milwaukee is a professor of molecular biophysics and biochemistry at yale university and attached to the howard hughes medical institute yonath is a professor of structural biology at the weizmann institute of science in rehovot israel and the ninth israeli to win a nobel prize she told israel radio she did not think her gender played a role in the decision it true that a woman has not won since but i do not know what that means does it mean that i am the best woman since then i do not think that gender played a role here she said she had to end the interview abruptly because israeli president shimon peres a nobel peace prize laureate was on the other line alfred nobel a swedish industrialist who invented dynamite established the nobel prizes in his will in the first awards were handed out six years later each prize comes with a million kronor million purse a diploma a gold medal and an invitation to the prize ceremony in stockholm on dec the peace prize is handed out in oslo on monday three american scientists shared the nobel prize in medicine for discovering a key mechanism in the genetic operations of cells an insight that has inspired new lines of research into cancer the physics prize on tuesday was split between a hong kong based scientist who helped develop fibre optic cable and two canadian and american researchers who invented the eye in digital cameras technology that has revolutionised communications and science the literature and peace prize winners will be announced later this week and the economics announcement is set for monday);
@d = sort(@d);
my @vd = ();

for (my $j=0; $j<=$#uni; $j++)
{
my $count = 0;
for (my $k=0; $k<=$#d; $k++)
{
if ($uni[$j] eq $d[$k])
{
$count = $count + 1;
}
}
push(@vd, $count);
}










my @e = qw(talking tough a day after the beheading of a jharkhand police officer home minister p chidambaram on wednesday said the security forces would engage the maoists till they abjured violence and the indian air force would take steps to protect itself against any naxal attack as long as the cpi maoist believes in an armed liberation struggle we have no option but to ask our security forces to engage them we will arrest them we will apprehend them he told a press conference here not a war he said the government did not consider the naxalite confrontation as a war we do not wage a war against our own people what we said was that the naxalite or cpi maoist must abjure violence and take the path of democracy and dialogue he said counter measures asked about the iaf seeking permission to fight back if the naxals fire upon its helicopters and crew operating in maoist hit areas the home minister said the iaf would take adequate counter measures however the home minister refused to reveal any details mr chidambaram said an indian air force helicopter was fired at by the maoists a few weeks back in chhattisgarh permission sought air chief marshal pv naik had said the iaf had sought permission from the defence ministry to open fire in self defence if its helicopters or air crew operating in the maoist infested areas came under attack);
@e = sort(@e);
my @ve = ();

for (my $j=0; $j<=$#uni; $j++)
{
my $count = 0;
for (my $k=0; $k<=$#e; $k++)
{
if ($uni[$j] eq $e[$k])
{
$count = $count + 1;
}
}
push(@ve, $count);
}







my @f = qw(union home minister p chidambaram said on wednesday that the government was ready to hold a dialogue with naxals or supporters of the communist party of india maoist provided they abjure violence they maoists use words like war and war of liberation we do not regard our confrontation with them as war we do not wage war against our own people he said maoists should take the path of democracy we will help the state governments discuss with the maoists all the issues of neglect corruption development etc but no development is possible with violence no democracy can accept the theory of an armed rebellion they should first abjure violence award for rukhsana he commended the jammu and kashmir police for doing a good job in the ongoing encounters with militants the j k police are set to become the frontline security force in the country mr chidambaram said he also hailed the heroism of rukhsana kaur who gunned down militants in her house the government had recommended her for a bravery award and she would receive it in due time he dismissed reports of taliban militants being inducted in j k as speculative and baseless on the banned organisation students islamic movement of india simi the minister said it was trying to metamorphose into new organisations under different names we are aware that one or two organisations are being floated by ex-simi cadres);
@f = sort(@f);
my @vf = ();

for (my $j=0; $j<=$#uni; $j++)
{
my $count = 0;
for (my $k=0; $k<=$#f; $k++)
{
if ($uni[$j] eq $f[$k])
{
$count = $count + 1;
}
}
push(@vf, $count);
}





my $magva = 0;
my $magvb = 0;
my $product = 0;
my $ed = 0;

for (my $i=0; $i<=$#va; $i++)
{
$magva = $magva + $va[$i] ** 2;
$magvb = $magvb + $vb[$i] ** 2;
$product = $product + ( $va[$i] * $vb[$i] );
my $p = ( $vb[$i] - $va[$i] ) ** 2;
$ed = $ed + $p;
}
print "\n Euclidean distance between A and B is $ed \n";
$magva = $magva ** ( 1 / 2 );
$magvb = $magvb ** ( 1 / 2 );
my $cosine = $product / ($magva * $magvb);
print "cosine value of A and B is $cosine \n\n\n";





$magva = 0;
my $magvc = 0;
$product = 0;
$ed = 0;
for (my $i=0; $i<=$#va; $i++)
{
$magva = $magva + $va[$i] ** 2;
$magvc = $magvc + $vc[$i] ** 2;
$product = $product + ( $va[$i] * $vc[$i] );
my $p = ( $vc[$i] - $va[$i] ) ** 2;
$ed = $ed + $p;
}
print "\n Euclidean distance between A and C is $ed\n";
$magva = $magva ** ( 1 / 2 );
$magvc = $magvc ** ( 1 / 2 );
$cosine = $product / ($magva * $magvc);
print "cosine value of A and C is $cosine \n\n\n";




$magva = 0;
my $magvd = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#va; $i++)
{
$magva = $magva + $va[$i] ** 2;
$magvd = $magvd + $vd[$i] ** 2;
$product = $product + ( $va[$i] * $vd[$i] );
my $p = ( $vd[$i] - $va[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between A and D is $ed\n";
$magva = $magva ** ( 1 / 2 );
$magvd = $magvd ** ( 1 / 2 );
$cosine = $product / ($magva * $magvd);
print "cosine value of A and D is $cosine \n\n\n";




$magva = 0;
my $magve = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#va; $i++)
{
$magva = $magva + $va[$i] ** 2;
$magve = $magve + $ve[$i] ** 2;
$product = $product + ( $va[$i] * $ve[$i] );
my $p = ( $ve[$i] - $va[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between A and E is $ed\n";
$magva = $magva ** ( 1 / 2 );
$magve = $magve ** ( 1 / 2 );
$cosine = $product / ($magva * $magve);
print "cosine value of A and E is $cosine \n\n\n";





$magva = 0;
my $magvf = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#va; $i++)
{
$magva = $magva + $va[$i] ** 2;
$magvf = $magvf + $vf[$i] ** 2;
$product = $product + ( $va[$i] * $vf[$i] );
my $p = ( $vf[$i] - $va[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between A and F is $ed\n";
$magva = $magva ** ( 1 / 2 );
$magvf = $magvf ** ( 1 / 2 );
$cosine = $product / ($magva * $magvf);
print "cosine value of A and F is $cosine \n\n\n";






$magvb = 0;
$magvc = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#vb; $i++)
{
$magvb = $magvb + $vb[$i] ** 2;
$magvc = $magvc + $vc[$i] ** 2;
$product = $product + ( $vb[$i] * $vc[$i] );
my $p = ( $vc[$i] - $vb[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between B and C is $ed\n";
$magvb = $magvb ** ( 1 / 2 );
$magvc = $magvc ** ( 1 / 2 );
$cosine = $product / ($magvb * $magvc);
print "cosine value of B and C is $cosine \n\n\n";







$magvb = 0;
$magvd = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#vb; $i++)
{
$magvb = $magvb + $vb[$i] ** 2;
$magvd = $magvd + $vd[$i] ** 2;
$product = $product + ( $vb[$i] * $vd[$i] );
my $p = ( $vd[$i] - $vb[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between B and D is $ed\n";
$magvb = $magvb ** ( 1 / 2 );
$magvd = $magvd ** ( 1 / 2 );
$cosine = $product / ($magvb * $magvd);
print "cosine value of B and D is $cosine \n\n\n";






$magvb = 0;
$magve = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#vb; $i++)
{
$magvb = $magvb + $vb[$i] ** 2;
$magve = $magve + $ve[$i] ** 2;
$product = $product + ( $vb[$i] * $ve[$i] );
my $p = ( $ve[$i] - $vb[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between B and E is $ed\n";
$magvb = $magvb ** ( 1 / 2 );
$magve = $magve ** ( 1 / 2 );
$cosine = $product / ($magvb * $magve);
print "cosine value of B and E is $cosine \n\n\n";





$magvb = 0;
$magvf = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#vb; $i++)
{
$magvb = $magvb + $vb[$i] ** 2;
$magvf = $magvf + $vf[$i] ** 2;
$product = $product + ( $vb[$i] * $vf[$i] );
my $p = ( $vf[$i] - $vb[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between B and F is $ed\n";
$magvb = $magvb ** ( 1 / 2 );
$magvf = $magvf ** ( 1 / 2 );
$cosine = $product / ($magvb * $magvf);
print "cosine value of B and F is $cosine \n\n\n";





$magvc = 0;
$magvd = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#vc; $i++)
{
$magvc = $magvc + $vc[$i] ** 2;
$magvd = $magvd + $vd[$i] ** 2;
$product = $product + ( $vc[$i] * $vd[$i] );
my $p = ( $vd[$i] - $vc[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between C and D is $ed\n";
$magvc = $magvc ** ( 1 / 2 );
$magvd = $magvd ** ( 1 / 2 );
$cosine = $product / ($magvc * $magvd);
print "cosine value of C and D is $cosine \n\n\n";





$magvc = 0;
$magve = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#vc; $i++)
{
$magvc = $magvc + $vc[$i] ** 2;
$magve = $magve + $ve[$i] ** 2;
$product = $product + ( $vc[$i] * $ve[$i] );
my $p = ( $ve[$i] - $vc[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between C and E is $ed\n";
$magvc = $magvc ** ( 1 / 2 );
$magve = $magve ** ( 1 / 2 );
$cosine = $product / ($magvc * $magve);
print "cosine value of C and E is $cosine \n\n\n";






$magvc = 0;
$magvf = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#vc; $i++)
{
$magvc = $magvc + $vc[$i] ** 2;
$magvf = $magvf + $vf[$i] ** 2;
$product = $product + ( $vc[$i] * $vf[$i] );
my $p = ( $vf[$i] - $vc[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between C and F is $ed\n";
$magvc = $magvc ** ( 1 / 2 );
$magvf = $magvf ** ( 1 / 2 );
$cosine = $product / ($magvc * $magvf);
print "cosine value of C and F is $cosine \n\n\n";




$magvd = 0;
$magve = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#vd; $i++)
{
$magvd = $magvd + $vd[$i] ** 2;
$magve = $magve + $ve[$i] ** 2;
$product = $product + ( $vd[$i] * $ve[$i] );
my $p = ( $ve[$i] - $vd[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between D and E is $ed\n";
$magvd = $magvd ** ( 1 / 2 );
$magve = $magve ** ( 1 / 2 );
$cosine = $product / ($magvd * $magve);
print "cosine value of D and E is $cosine \n\n\n";





$magvd = 0;
$magvf = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#vd; $i++)
{
$magvd = $magvd + $vd[$i] ** 2;
$magvf = $magvf + $vf[$i] ** 2;
$product = $product + ( $vd[$i] * $vf[$i] );
my $p = ( $vf[$i] - $vd[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between D and F is $ed\n";
$magvd = $magvd ** ( 1 / 2 );
$magvf = $magvf ** ( 1 / 2 );
$cosine = $product / ($magvd * $magvf);
print "cosine value of D and F is $cosine \n\n\n";





$magve = 0;
$magvf = 0;
$product = 0;
$ed = 0;

for (my $i=0; $i<=$#ve; $i++)
{
$magve = $magve + $ve[$i] ** 2;
$magvf = $magvf + $vf[$i] ** 2;
$product = $product + ( $ve[$i] * $vf[$i] );
my $p = ( $vf[$i] - $ve[$i] ) ** 2;
$ed = $ed + $p;
}
print "Euclidean distance between E and F is $ed\n";
$magve = $magve ** ( 1 / 2 );
$magvf = $magvf ** ( 1 / 2 );
$cosine = $product / ($magve * $magvf);
print "cosine value of E and F is $cosine \n\n\n";

Friday, September 18, 2009

code for monty hall problem in perl

#! /usr/bin/perl -w
# file: experiment3.pl
use strict;

my $i = 0;
my $j = 0;
my $k = 0;
print "number of trials: \n";
my $trials = ;

for ($k; $k<$trials; $k++)
{
my $car = int(rand 3);
my $choice = int(rand 3);
if ($car == $choice)
{
my $option = int(rand 1);
# $option = 1 is considered as not switching
# $option = 0 is considered as switching
if ($option == 1)
{
$i++;
}
else
{
$j++;
}
}
else
{
my $options = int(rand 1);
if ($options == 1)
{
$j++;
}
else
{
$i++;
}
}
}
print "you won the car in $i trials\n";
print "you lost the car in $j trials\n";
exit 0;