class exampleClass:
eyes='blue'
age=22
def thisMethod(self):
return 'hey this method worked'
exampleObject=exampleClass()
exampleObject.eyes
exampleObject.age
exampleObject.thisMethod()
**********************************************************************
class className:
def createName(self,name):
self.name=name
def displayName(self):
return self.name
def saying(self):
print "hello %s" % self.name
first=className()
second=className()
first.createName('bucky')
second.createName('tony')
first.displayName()
first.saying()
*************************************************************************
Saturday, March 16, 2013
Wednesday, March 13, 2013
The Algorithm That Helps You Friend People You Don’t Know
Computer scientists have developed an algorithm that uses the structure of a social network to find the best strategy for friending people you don’t know.
Imagine you want to friend an influential person on Facebook who you don’t know and with whom you have no friends in common. How would you go about the task?
One option is simply to send an invitation directly to that person. But without anybody to recommend you, the chances of him or her accepting the invitation are slim.
But there is another strategy: to start friending people who are close to you on the network but more likely to know your target. The idea here is to build a set of friends that your target shares so that when you finally send the important invitation, your target can see that you have similar social circles and so is more likely to accept.
There’s a problem, of course, which is that the structure of the social network is hidden to ordinary users. There is no way of knowing how close you are to your target or who to friend to maximise your chances of getting there.
Today, Wei Chen at Microsoft Research Asia in Beijing and a few pals put forward a solution. These guys suggest that social network companies should offer this kind of “active friending” as a service.
The idea is that you name your target and the company then suggests the friending strategy that is most likely to produce the desired outcome. They’ve even developed and tested an algorithm that does the job.
Social networks already suggest potential friends based on information such as who your existing friends know, who you email and so on.
But this “passive friending” is an entirely undirected service. There is no goal other than to increase your number of friends and the amount of time you spend on the network.
So Wei and co have developed an algorithm called SITINA (Selective Invitation with Tree and In-Node Aggregation) which when given a target, suggests potential friends with the goal of maximising your chances of friending them.
The strategy has some important subtleties. For example, one way to reach a target is to find the shortest route across the network. But the problem with this is that it relies on each person in the chain accepting their invitations.
A better strategy, say Wei and co, is to chart many routes across the network so that it is more likely that at least one will result in the desired connection. What’s more, this strategy can produce several friends in common giving the target invitation a higher chance of success.
But this too has a downside–it means that you have to handle a large number of invitations which is time consuming and tedious.
So there is clearly a balance between flooding the network with invitations and charting the shortest route to reach the target. This where SITINA comes in.
This algorithm is designed to optimise the process so that it maximise the chances of friending a target given a limited budget of invitations.
Wei and co say they’ve tested it on a group of 169 Facebook users who they recruited for the task. The test consisted of giving each Facebook user a set of targets and a limited number of invitations and challenging them to friend each target on their own. In parallel, these users were also given recommendations by SITINA which they also used.
Wei and co say their algorithm significantly outperformed the manual approach. “User study and experimental results manifest that active friending can effectively maximize the acceptance probability of the friending target,” they say.
That’s an interesting idea that could clearly generate substantial demand among social network users who want to initiate contact with distant targets.
However, an important question that Wei and co have not addressed is the impact this algorithm could have on the targets. It doesn’t take much imagination to think of ways this kind of approach could be abused–as a tool for stalking, for example.
Then there are questions of privacy. This approach not only reveals one or more paths across the network to a target but also a certain number of the target’s friends. It may even make it possible to reconstruct a given target’s social network.
Given the high profile mis-steps that various social networks have made in creating unwanted links between people on their networks, it’s clear that the legal and privacy issues that active friending raises need to be carefully studied before releasing it into the wild.
Imagine you want to friend an influential person on Facebook who you don’t know and with whom you have no friends in common. How would you go about the task?
One option is simply to send an invitation directly to that person. But without anybody to recommend you, the chances of him or her accepting the invitation are slim.
But there is another strategy: to start friending people who are close to you on the network but more likely to know your target. The idea here is to build a set of friends that your target shares so that when you finally send the important invitation, your target can see that you have similar social circles and so is more likely to accept.
There’s a problem, of course, which is that the structure of the social network is hidden to ordinary users. There is no way of knowing how close you are to your target or who to friend to maximise your chances of getting there.
Today, Wei Chen at Microsoft Research Asia in Beijing and a few pals put forward a solution. These guys suggest that social network companies should offer this kind of “active friending” as a service.
The idea is that you name your target and the company then suggests the friending strategy that is most likely to produce the desired outcome. They’ve even developed and tested an algorithm that does the job.
Social networks already suggest potential friends based on information such as who your existing friends know, who you email and so on.
But this “passive friending” is an entirely undirected service. There is no goal other than to increase your number of friends and the amount of time you spend on the network.
So Wei and co have developed an algorithm called SITINA (Selective Invitation with Tree and In-Node Aggregation) which when given a target, suggests potential friends with the goal of maximising your chances of friending them.
The strategy has some important subtleties. For example, one way to reach a target is to find the shortest route across the network. But the problem with this is that it relies on each person in the chain accepting their invitations.
A better strategy, say Wei and co, is to chart many routes across the network so that it is more likely that at least one will result in the desired connection. What’s more, this strategy can produce several friends in common giving the target invitation a higher chance of success.
But this too has a downside–it means that you have to handle a large number of invitations which is time consuming and tedious.
So there is clearly a balance between flooding the network with invitations and charting the shortest route to reach the target. This where SITINA comes in.
This algorithm is designed to optimise the process so that it maximise the chances of friending a target given a limited budget of invitations.
Wei and co say they’ve tested it on a group of 169 Facebook users who they recruited for the task. The test consisted of giving each Facebook user a set of targets and a limited number of invitations and challenging them to friend each target on their own. In parallel, these users were also given recommendations by SITINA which they also used.
Wei and co say their algorithm significantly outperformed the manual approach. “User study and experimental results manifest that active friending can effectively maximize the acceptance probability of the friending target,” they say.
That’s an interesting idea that could clearly generate substantial demand among social network users who want to initiate contact with distant targets.
However, an important question that Wei and co have not addressed is the impact this algorithm could have on the targets. It doesn’t take much imagination to think of ways this kind of approach could be abused–as a tool for stalking, for example.
Then there are questions of privacy. This approach not only reveals one or more paths across the network to a target but also a certain number of the target’s friends. It may even make it possible to reconstruct a given target’s social network.
Given the high profile mis-steps that various social networks have made in creating unwanted links between people on their networks, it’s clear that the legal and privacy issues that active friending raises need to be carefully studied before releasing it into the wild.
Monday, March 11, 2013
Algorithms Get a Human Hand in Steering Web
Trading stocks, targeting ads, steering political campaigns, arranging dates, besting people on “Jeopardy” and even choosing bra sizes: computer algorithms are doing all this work and more.
But increasingly, behind the curtain there is a decidedly retro helper — a human being.
But increasingly, behind the curtain there is a decidedly retro helper — a human being.
Although algorithms are growing ever more powerful, fast and precise, the computers themselves are literal-minded, and context and nuance often elude them. Capable as these machines are, they are not always up to deciphering the ambiguity of human language and the mystery of reasoning. Yet these days they are being asked to be more humanlike in what they figure out.
“For all their brilliance, computers can be thick as a brick,” said Tom M. Mitchell, a computer scientist at Carnegie Mellon University.
And so, while programming experts still write the step-by-step instructions of computer code, additional people are needed to make more subtle contributions as the work the computers do has become more involved. People evaluate, edit or correct an algorithm’s work. Or they assemble online databases of knowledge and check and verify them — creating, essentially, a crib sheet the computer can call on for a quick answer. Humans can interpret and tweak information in ways that are understandable to both computers and other humans.
Question-answering technologies like Apple’s Siri and I.B.M.’s Watson rely particularly on the emerging machine-man collaboration. Algorithms alone are not enough.
Twitter uses a far-flung army of contract workers, whom it calls judges, to interpret the meaning and context of search terms that suddenly spike in frequency on the service.
For example, when Mitt Romney talked of cutting government money for public broadcasting in a presidential debate last fall and mentioned Big Bird, messages with that phrase surged. Human judges recognized instantly that “Big Bird,” in that context and at that moment, was mainly a political comment, not a reference to “Sesame Street,” and that politics-related messages should pop up when someone searched for “Big Bird.” People can understand such references more accurately and quickly than software can, and their judgments are fed immediately into Twitter’s search algorithm.
“Humans are core to this system,” two Twitter engineers wrote in a blog post in January.
Even at Google, where algorithms and engineers reign supreme in the company’s business and culture, the human contribution to search results is increasing. Google uses human helpers in two ways. Several months ago, it began presenting summaries of information on the right side of a search page when a user typed in the name of a well-known person or place, like “Barack Obama” or “New York City.” These summaries draw from databases of knowledge like Wikipedia, the C.I.A. World Factbook and Freebase, whose parent company, Metaweb, Google acquired in 2010. These databases are edited by humans.
When Google’s algorithm detects a search term for which this distilled information is available, the search engine is trained to go fetch it rather than merely present links to Web pages.
“There has been a shift in our thinking,” said Scott Huffman, an engineering director in charge of search quality at Google. “A part of our resources are now more human curated.”
Other human helpers, known as evaluators or raters, help Google develop tweaks to its search algorithm, a powerhouse of automation, fielding 100 billion queries a month. “Our engineers evolve the algorithm, and humans help us see if a suggested change is really an improvement,” Mr. Huffman said.
Katherine Young, 23, is a Google rater — a contract worker and a college student in Macon, Ga. She is shown an ambiguous search query like “what does king hold,” presented with two sets of Google search results and asked to rate their relevance, accuracy and quality. The current search result for that imprecise phrase starts with links to Web pages saying that kings typically hold ceremonial scepters, a reasonable inference.
Her judgments, Ms. Young said, are “not completely black and white; some of it is subjective.” She added, “You try to put yourself in the shoes of the person who typed in the query.”
I.B.M.’s Watson, the powerful question-answering computer that defeated “Jeopardy” champions two years ago, is in training these days to help doctors make diagnoses. But it, too, is turning to humans for help.
To prepare for its role in assisting doctors, Watson is being fed medical texts, scientific papers and digital patient records stripped of personal identifying information. Instead of answering questions, however, Watson is asking them of clinicians at the Cleveland Clinic and medical school students. They are giving answers and correcting the computer’s mistakes, using a “Teach Watson” feature.
Watson, for example, might come across this question in a medical text: “What neurological condition contraindicates the use of bupropion?” The software may have bupropion, an antidepressant, in its database, but stumble on “contraindicates.” A human helper will confirm that the word means “do not use,” and Watson returns to its data trove to reason that the neurological condition is seizure disorder.
“We’re using medical experts to help Watson learn, make it smarter going forward,” said Eric Brown, a scientist on I.B.M.’s Watson team.
Ben Taylor, 25, is a product manager at FindTheBest, a fast-growing start-up in Santa Barbara, Calif. The company calls itself a “comparison engine” for finding and comparing more than 100 topics and products, from universities to nursing homes, smartphones to dog breeds. Its Web site went up in 2010, and the company now has 60 full-time employees.
Mr. Taylor helps design and edit the site’s education pages. He is not an engineer, but an English major who has become a self-taught expert in the arcane data found in Education Department studies and elsewhere. His research methods include talking to and e-mailing educators. He is an information sleuth.
On FindTheBest, more than 8,500 colleges can be searched quickly according to geography, programs and tuition costs, among other criteria. Go to the page for a university, and a wealth of information appears in summaries, charts and graphics — down to the gender and race breakdowns of the student body and faculty.
Mr. Taylor and his team write the summaries and design the initial charts and graphs. From hundreds of data points on college costs, for example, they select the ones most relevant to college students and their parents. But much of their information is prepared in templates and tagged with code a computer can read. So the process has become more automated, with Mr. Taylor and others essentially giving “go fetch” commands that the computer algorithm obeys.
The algorithms are getting better. But they cannot do it alone.
“You need judgment, and to be able to intuitively recognize the smaller sets of data that are most important,” Mr. Taylor said. “To do that, you need some level of human involvement.”
Sunday, March 10, 2013
Wednesday, March 6, 2013
Timestamps
<?php
$time=time();
$time_now=date('D M Y @H:i:s', $time);
$time_modified=date('D M Y @H:i:s', strtotime('-1 week 2 hours 30 seconds'));
echo 'The time now is '.$time_now.'<br>The time modified is '.$time_modified;
?>
$time=time();
$time_now=date('D M Y @H:i:s', $time);
$time_modified=date('D M Y @H:i:s', strtotime('-1 week 2 hours 30 seconds'));
echo 'The time now is '.$time_now.'<br>The time modified is '.$time_modified;
?>
Tuesday, March 5, 2013
Find and replace-PHP
<?php
$offset = 0;
if(isset($_POST['text'])&&isset($_POST['searchfor'])&&isset($_POST['replacewith'])){
$text = $_POST['text'];
$search = $_POST['searchfor'];
$replace = $_POST['replacewith'];
$search_length = strlen($search);
if(!empty($text)&&!empty($search)&&!empty($replace)){
while($strpos = strpos($text, $search, $offset)) {
$offset = $strpos + $search_length;
$text = substr_replace($text,$replace, $strpos, $search_length);
}
echo $text;
}else{
echo 'Please fill in all fiels';
}
}
?>
<form action="index.php" method="POST">
<textarea name="text" rows="6" cols="30"></textarea><br><br>
Search for:<br>
<input type="text" name="searchfor"><br><br>
Replace with:<br>
<input type="text" name="replacewith"><br><br>
<input type="submit" value="Find and Replace"><br><br>
</form>
$offset = 0;
if(isset($_POST['text'])&&isset($_POST['searchfor'])&&isset($_POST['replacewith'])){
$text = $_POST['text'];
$search = $_POST['searchfor'];
$replace = $_POST['replacewith'];
$search_length = strlen($search);
if(!empty($text)&&!empty($search)&&!empty($replace)){
while($strpos = strpos($text, $search, $offset)) {
$offset = $strpos + $search_length;
$text = substr_replace($text,$replace, $strpos, $search_length);
}
echo $text;
}else{
echo 'Please fill in all fiels';
}
}
?>
<form action="index.php" method="POST">
<textarea name="text" rows="6" cols="30"></textarea><br><br>
Search for:<br>
<input type="text" name="searchfor"><br><br>
Replace with:<br>
<input type="text" name="replacewith"><br><br>
<input type="submit" value="Find and Replace"><br><br>
</form>
Monday, March 4, 2013
Word Censoring-php
<?php
$find =array('alex','billy','dale');
$replace=array('a**x','b***y','d**e');
if(isset($_POST['user_input'])&& !empty($_POST['user_input'])){
$user_input = $_POST['user_input'];
$user_input_new=str_ireplace($find,$replace,$user_input);
echo $user_input_new;
}
?>
<hr>
<form action="index.php" method="POST">
<textarea name="user_input" rows="7" cols="20"><?php echo $user_input; ?></textarea><br><br>
<input type="submit" value="Submit">
</form>
$find =array('alex','billy','dale');
$replace=array('a**x','b***y','d**e');
if(isset($_POST['user_input'])&& !empty($_POST['user_input'])){
$user_input = $_POST['user_input'];
$user_input_new=str_ireplace($find,$replace,$user_input);
echo $user_input_new;
}
?>
<hr>
<form action="index.php" method="POST">
<textarea name="user_input" rows="7" cols="20"><?php echo $user_input; ?></textarea><br><br>
<input type="submit" value="Submit">
</form>
Subscribe to:
Posts (Atom)