diff --git a/knn/49960 b/knn/49960 new file mode 100644 index 0000000..94a900c --- /dev/null +++ b/knn/49960 @@ -0,0 +1,293 @@ +From: mathew +Subject: Alt.Atheism FAQ: Atheist Resources + +Archive-name: atheism/resources +Alt-atheism-archive-name: resources +Last-modified: 11 December 1992 +Version: 1.0 + + Atheist Resources + + Addresses of Atheist Organizations + + USA + +FREEDOM FROM RELIGION FOUNDATION + +Darwin fish bumper stickers and assorted other atheist paraphernalia are +available from the Freedom From Religion Foundation in the US. + +Write to: FFRF, P.O. Box 750, Madison, WI 53701. +Telephone: (608) 256-8900 + +EVOLUTION DESIGNS + +Evolution Designs sell the "Darwin fish". It's a fish symbol, like the ones +Christians stick on their cars, but with feet and the word "Darwin" written +inside. The deluxe moulded 3D plastic fish is $4.95 postpaid in the US. + +Write to: Evolution Designs, 7119 Laurel Canyon #4, North Hollywood, + CA 91605. + +People in the San Francisco Bay area can get Darwin Fish from Lynn Gold -- +try mailing . For net people who go to Lynn directly, the +price is $4.95 per fish. + +AMERICAN ATHEIST PRESS + +AAP publish various atheist books -- critiques of the Bible, lists of +Biblical contradictions, and so on. One such book is: + +"The Bible Handbook" by W.P. Ball and G.W. Foote. American Atheist Press. +372 pp. ISBN 0-910309-26-4, 2nd edition, 1986. Bible contradictions, +absurdities, atrocities, immoralities... contains Ball, Foote: "The Bible +Contradicts Itself", AAP. Based on the King James version of the Bible. + +Write to: American Atheist Press, P.O. Box 140195, Austin, TX 78714-0195. + or: 7215 Cameron Road, Austin, TX 78752-2973. +Telephone: (512) 458-1244 +Fax: (512) 467-9525 + +PROMETHEUS BOOKS + +Sell books including Haught's "Holy Horrors" (see below). + +Write to: 700 East Amherst Street, Buffalo, New York 14215. +Telephone: (716) 837-2475. + +An alternate address (which may be newer or older) is: +Prometheus Books, 59 Glenn Drive, Buffalo, NY 14228-2197. + +AFRICAN-AMERICANS FOR HUMANISM + +An organization promoting black secular humanism and uncovering the history of +black freethought. They publish a quarterly newsletter, AAH EXAMINER. + +Write to: Norm R. Allen, Jr., African Americans for Humanism, P.O. Box 664, + Buffalo, NY 14226. + + United Kingdom + +Rationalist Press Association National Secular Society +88 Islington High Street 702 Holloway Road +London N1 8EW London N19 3NL +071 226 7251 071 272 1266 + +British Humanist Association South Place Ethical Society +14 Lamb's Conduit Passage Conway Hall +London WC1R 4RH Red Lion Square +071 430 0908 London WC1R 4RL +fax 071 430 1271 071 831 7723 + +The National Secular Society publish "The Freethinker", a monthly magazine +founded in 1881. + + Germany + +IBKA e.V. +Internationaler Bund der Konfessionslosen und Atheisten +Postfach 880, D-1000 Berlin 41. Germany. + +IBKA publish a journal: +MIZ. (Materialien und Informationen zur Zeit. Politisches +Journal der Konfessionslosesn und Atheisten. Hrsg. IBKA e.V.) +MIZ-Vertrieb, Postfach 880, D-1000 Berlin 41. Germany. + +For atheist books, write to: + +IBDK, Internationaler B"ucherdienst der Konfessionslosen +Postfach 3005, D-3000 Hannover 1. Germany. +Telephone: 0511/211216 + + + Books -- Fiction + +THOMAS M. DISCH + +"The Santa Claus Compromise" +Short story. The ultimate proof that Santa exists. All characters and +events are fictitious. Any similarity to living or dead gods -- uh, well... + +WALTER M. MILLER, JR + +"A Canticle for Leibowitz" +One gem in this post atomic doomsday novel is the monks who spent their lives +copying blueprints from "Saint Leibowitz", filling the sheets of paper with +ink and leaving white lines and letters. + +EDGAR PANGBORN + +"Davy" +Post atomic doomsday novel set in clerical states. The church, for example, +forbids that anyone "produce, describe or use any substance containing... +atoms". + +PHILIP K. DICK + +Philip K. Dick Dick wrote many philosophical and thought-provoking short +stories and novels. His stories are bizarre at times, but very approachable. +He wrote mainly SF, but he wrote about people, truth and religion rather than +technology. Although he often believed that he had met some sort of God, he +remained sceptical. Amongst his novels, the following are of some relevance: + +"Galactic Pot-Healer" +A fallible alien deity summons a group of Earth craftsmen and women to a +remote planet to raise a giant cathedral from beneath the oceans. When the +deity begins to demand faith from the earthers, pot-healer Joe Fernwright is +unable to comply. A polished, ironic and amusing novel. + +"A Maze of Death" +Noteworthy for its description of a technology-based religion. + +"VALIS" +The schizophrenic hero searches for the hidden mysteries of Gnostic +Christianity after reality is fired into his brain by a pink laser beam of +unknown but possibly divine origin. He is accompanied by his dogmatic and +dismissively atheist friend and assorted other odd characters. + +"The Divine Invasion" +God invades Earth by making a young woman pregnant as she returns from +another star system. Unfortunately she is terminally ill, and must be +assisted by a dead man whose brain is wired to 24-hour easy listening music. + +MARGARET ATWOOD + +"The Handmaid's Tale" +A story based on the premise that the US Congress is mysteriously +assassinated, and fundamentalists quickly take charge of the nation to set it +"right" again. The book is the diary of a woman's life as she tries to live +under the new Christian theocracy. Women's right to own property is revoked, +and their bank accounts are closed; sinful luxuries are outlawed, and the +radio is only used for readings from the Bible. Crimes are punished +retroactively: doctors who performed legal abortions in the "old world" are +hunted down and hanged. Atwood's writing style is difficult to get used to +at first, but the tale grows more and more chilling as it goes on. + +VARIOUS AUTHORS + +"The Bible" +This somewhat dull and rambling work has often been criticized. However, it +is probably worth reading, if only so that you'll know what all the fuss is +about. It exists in many different versions, so make sure you get the one +true version. + + Books -- Non-fiction + +PETER DE ROSA + +"Vicars of Christ", Bantam Press, 1988 +Although de Rosa seems to be Christian or even Catholic this is a very +enlighting history of papal immoralities, adulteries, fallacies etc. +(German translation: "Gottes erste Diener. Die dunkle Seite des Papsttums", +Droemer-Knaur, 1989) + +MICHAEL MARTIN + +"Atheism: A Philosophical Justification", Temple University Press, + Philadelphia, USA. +A detailed and scholarly justification of atheism. Contains an outstanding +appendix defining terminology and usage in this (necessarily) tendentious +area. Argues both for "negative atheism" (i.e. the "non-belief in the +existence of god(s)") and also for "positive atheism" ("the belief in the +non-existence of god(s)"). Includes great refutations of the most +challenging arguments for god; particular attention is paid to refuting +contempory theists such as Platinga and Swinburne. +541 pages. ISBN 0-87722-642-3 (hardcover; paperback also available) + +"The Case Against Christianity", Temple University Press +A comprehensive critique of Christianity, in which he considers +the best contemporary defences of Christianity and (ultimately) +demonstrates that they are unsupportable and/or incoherent. +273 pages. ISBN 0-87722-767-5 + +JAMES TURNER + +"Without God, Without Creed", The Johns Hopkins University Press, Baltimore, + MD, USA +Subtitled "The Origins of Unbelief in America". Examines the way in which +unbelief (whether agnostic or atheistic) became a mainstream alternative +world-view. Focusses on the period 1770-1900, and while considering France +and Britain the emphasis is on American, and particularly New England +developments. "Neither a religious history of secularization or atheism, +Without God, Without Creed is, rather, the intellectual history of the fate +of a single idea, the belief that God exists." +316 pages. ISBN (hardcover) 0-8018-2494-X (paper) 0-8018-3407-4 + +GEORGE SELDES (Editor) + +"The great thoughts", Ballantine Books, New York, USA +A "dictionary of quotations" of a different kind, concentrating on statements +and writings which, explicitly or implicitly, present the person's philosophy +and world-view. Includes obscure (and often suppressed) opinions from many +people. For some popular observations, traces the way in which various +people expressed and twisted the idea over the centuries. Quite a number of +the quotations are derived from Cardiff's "What Great Men Think of Religion" +and Noyes' "Views of Religion". +490 pages. ISBN (paper) 0-345-29887-X. + +RICHARD SWINBURNE + +"The Existence of God (Revised Edition)", Clarendon Paperbacks, Oxford +This book is the second volume in a trilogy that began with "The Coherence of +Theism" (1977) and was concluded with "Faith and Reason" (1981). In this +work, Swinburne attempts to construct a series of inductive arguments for the +existence of God. His arguments, which are somewhat tendentious and rely +upon the imputation of late 20th century western Christian values and +aesthetics to a God which is supposedly as simple as can be conceived, were +decisively rejected in Mackie's "The Miracle of Theism". In the revised +edition of "The Existence of God", Swinburne includes an Appendix in which he +makes a somewhat incoherent attempt to rebut Mackie. + +J. L. MACKIE + +"The Miracle of Theism", Oxford +This (posthumous) volume contains a comprehensive review of the principal +arguments for and against the existence of God. It ranges from the classical +philosophical positions of Descartes, Anselm, Berkeley, Hume et al, through +the moral arguments of Newman, Kant and Sidgwick, to the recent restatements +of the classical theses by Plantinga and Swinburne. It also addresses those +positions which push the concept of God beyond the realm of the rational, +such as those of Kierkegaard, Kung and Philips, as well as "replacements for +God" such as Lelie's axiarchism. The book is a delight to read - less +formalistic and better written than Martin's works, and refreshingly direct +when compared with the hand-waving of Swinburne. + +JAMES A. HAUGHT + +"Holy Horrors: An Illustrated History of Religious Murder and Madness", + Prometheus Books +Looks at religious persecution from ancient times to the present day -- and +not only by Christians. +Library of Congress Catalog Card Number 89-64079. 1990. + +NORM R. ALLEN, JR. + +"African American Humanism: an Anthology" +See the listing for African Americans for Humanism above. + +GORDON STEIN + +"An Anthology of Atheism and Rationalism", Prometheus Books +An anthology covering a wide range of subjects, including 'The Devil, Evil +and Morality' and 'The History of Freethought'. Comprehensive bibliography. + +EDMUND D. COHEN + +"The Mind of The Bible-Believer", Prometheus Books +A study of why people become Christian fundamentalists, and what effect it +has on them. + + Net Resources + +There's a small mail-based archive server at mantis.co.uk which carries +archives of old alt.atheism.moderated articles and assorted other files. For +more information, send mail to archive-server@mantis.co.uk saying + + help + send atheism/index + +and it will mail back a reply. + + +mathew +ÿ diff --git a/knn/51060 b/knn/51060 new file mode 100644 index 0000000..a13e88f --- /dev/null +++ b/knn/51060 @@ -0,0 +1,649 @@ +From: mathew +Subject: Alt.Atheism FAQ: Introduction to Atheism + +Archive-name: atheism/introduction +Alt-atheism-archive-name: introduction +Last-modified: 5 April 1993 +Version: 1.2 + +-----BEGIN PGP SIGNED MESSAGE----- + + An Introduction to Atheism + by mathew + +This article attempts to provide a general introduction to atheism. Whilst I +have tried to be as neutral as possible regarding contentious issues, you +should always remember that this document represents only one viewpoint. I +would encourage you to read widely and draw your own conclusions; some +relevant books are listed in a companion article. + +To provide a sense of cohesion and progression, I have presented this article +as an imaginary conversation between an atheist and a theist. All the +questions asked by the imaginary theist are questions which have been cropped +up repeatedly on alt.atheism since the newsgroup was created. Some other +frequently asked questions are answered in a companion article. + +Please note that this article is arguably slanted towards answering questions +posed from a Christian viewpoint. This is because the FAQ files reflect +questions which have actually been asked, and it is predominantly Christians +who proselytize on alt.atheism. + +So when I talk of religion, I am talking primarily about religions such as +Christianity, Judaism and Islam, which involve some sort of superhuman divine +being. Much of the discussion will apply to other religions, but some of it +may not. + +"What is atheism?" + +Atheism is characterized by an absence of belief in the existence of God. +Some atheists go further, and believe that God does not exist. The former is +often referred to as the "weak atheist" position, and the latter as "strong +atheism". + +It is important to note the difference between these two positions. "Weak +atheism" is simple scepticism; disbelief in the existence of God. "Strong +atheism" is a positive belief that God does not exist. Please do not +fall into the trap of assuming that all atheists are "strong atheists". + +Some atheists believe in the non-existence of all Gods; others limit their +atheism to specific Gods, such as the Christian God, rather than making +flat-out denials. + +"But isn't disbelieving in God the same thing as believing he doesn't exist?" + +Definitely not. Disbelief in a proposition means that one does not believe +it to be true. Not believing that something is true is not equivalent to +believing that it is false; one may simply have no idea whether it is true or +not. Which brings us to agnosticism. + +"What is agnosticism then?" + +The term 'agnosticism' was coined by Professor Huxley at a meeting of the +Metaphysical Society in 1876. He defined an agnostic as someone who +disclaimed ("strong") atheism and believed that the ultimate origin of things +must be some cause unknown and unknowable. + +Thus an agnostic is someone who believes that we do not and cannot know for +sure whether God exists. + +Words are slippery things, and language is inexact. Beware of assuming that +you can work out someone's philosophical point of view simply from the fact +that she calls herself an atheist or an agnostic. For example, many people +use agnosticism to mean "weak atheism", and use the word "atheism" only when +referring to "strong atheism". + +Beware also that because the word "atheist" has so many shades of meaning, it +is very difficult to generalize about atheists. About all you can say for +sure is that atheists don't believe in God. For example, it certainly isn't +the case that all atheists believe that science is the best way to find out +about the universe. + +"So what is the philosophical justification or basis for atheism?" + +There are many philosophical justifications for atheism. To find out why a +particular person chooses to be an atheist, it's best to ask her. + +Many atheists feel that the idea of God as presented by the major religions +is essentially self-contradictory, and that it is logically impossible that +such a God could exist. Others are atheists through scepticism, because they +see no evidence that God exists. + +"But isn't it impossible to prove the non-existence of something?" + +There are many counter-examples to such a statement. For example, it is +quite simple to prove that there does not exist a prime number larger than +all other prime numbers. Of course, this deals with well-defined objects +obeying well-defined rules. Whether Gods or universes are similarly +well-defined is a matter for debate. + +However, assuming for the moment that the existence of a God is not provably +impossible, there are still subtle reasons for assuming the non-existence of +God. If we assume that something does not exist, it is always possible to +show that this assumption is invalid by finding a single counter-example. + +If on the other hand we assume that something does exist, and if the thing in +question is not provably impossible, showing that the assumption is invalid +may require an exhaustive search of all possible places where such a thing +might be found, to show that it isn't there. Such an exhaustive search is +often impractical or impossible. There is no such problem with largest +primes, because we can prove that they don't exist. + +Therefore it is generally accepted that we must assume things do not exist +unless we have evidence that they do. Even theists follow this rule most of +the time; they don't believe in unicorns, even though they can't conclusively +prove that no unicorns exist anywhere. + +To assume that God exists is to make an assumption which probably cannot be +tested. We cannot make an exhaustive search of everywhere God might be to +prove that he doesn't exist anywhere. So the sceptical atheist assumes by +default that God does not exist, since that is an assumption we can test. + +Those who profess strong atheism usually do not claim that no sort of God +exists; instead, they generally restrict their claims so as to cover +varieties of God described by followers of various religions. So whilst it +may be impossible to prove conclusively that no God exists, it may be +possible to prove that (say) a God as described by a particular religious +book does not exist. It may even be possible to prove that no God described +by any present-day religion exists. + +In practice, believing that no God described by any religion exists is very +close to believing that no God exists. However, it is sufficiently different +that counter-arguments based on the impossibility of disproving every kind of +God are not really applicable. + +"But what if God is essentially non-detectable?" + +If God interacts with our universe in any way, the effects of his interaction +must be measurable. Hence his interaction with our universe must be +detectable. + +If God is essentially non-detectable, it must therefore be the case that he +does not interact with our universe in any way. Many atheists would argue +that if God does not interact with our universe at all, it is of no +importance whether he exists or not. + +If the Bible is to be believed, God was easily detectable by the Israelites. +Surely he should still be detectable today? + +Note that I am not demanding that God interact in a scientifically +verifiable, physical way. It must surely be possible to perceive some +effect caused by his presence, though; otherwise, how can I distinguish him +from all the other things that don't exist? + +"OK, you may think there's a philosophical justification for atheism, but + isn't it still a religious belief?" + +One of the most common pastimes in philosophical discussion is "the +redefinition game". The cynical view of this game is as follows: + +Person A begins by making a contentious statement. When person B points out +that it can't be true, person A gradually re-defines the words he used in the +statement until he arrives at something person B is prepared to accept. He +then records the statement, along with the fact that person B has agreed to +it, and continues. Eventually A uses the statement as an "agreed fact", but +uses his original definitions of all the words in it rather than the obscure +redefinitions originally needed to get B to agree to it. Rather than be seen +to be apparently inconsistent, B will tend to play along. + +The point of this digression is that the answer to the question "Isn't +atheism a religious belief?" depends crucially upon what is meant by +"religious". "Religion" is generally characterized by belief in a superhuman +controlling power -- especially in some sort of God -- and by faith and +worship. + +[ It's worth pointing out in passing that some varieties of Buddhism are not + "religion" according to such a definition. ] + +Atheism is certainly not a belief in any sort of superhuman power, nor is it +categorized by worship in any meaningful sense. Widening the definition of +"religious" to encompass atheism tends to result in many other aspects of +human behaviour suddenly becoming classed as "religious" as well -- such as +science, politics, and watching TV. + +"OK, so it's not a religion. But surely belief in atheism (or science) is + still just an act of faith, like religion is?" + +Firstly, it's not entirely clear that sceptical atheism is something one +actually believes in. + +Secondly, it is necessary to adopt a number of core beliefs or assumptions to +make some sort of sense out of the sensory data we experience. Most atheists +try to adopt as few core beliefs as possible; and even those are subject to +questioning if experience throws them into doubt. + +Science has a number of core assumptions. For example, it is generally +assumed that the laws of physics are the same for all observers. These are +the sort of core assumptions atheists make. If such basic ideas are called +"acts of faith", then almost everything we know must be said to be based on +acts of faith, and the term loses its meaning. + +Faith is more often used to refer to complete, certain belief in something. +According to such a definition, atheism and science are certainly not acts of +faith. Of course, individual atheists or scientists can be as dogmatic as +religious followers when claiming that something is "certain". This is not a +general tendency, however; there are many atheists who would be reluctant to +state with certainty that the universe exists. + +Faith is also used to refer to belief without supporting evidence or proof. +Sceptical atheism certainly doesn't fit that definition, as sceptical atheism +has no beliefs. Strong atheism is closer, but still doesn't really match, as +even the most dogmatic atheist will tend to refer to experimental data (or +the lack of it) when asserting that God does not exist. + +"If atheism is not religious, surely it's anti-religious?" + +It is an unfortunate human tendency to label everyone as either "for" or +"against", "friend" or "enemy". The truth is not so clear-cut. + +Atheism is the position that runs logically counter to theism; in that sense, +it can be said to be "anti-religion". However, when religious believers +speak of atheists being "anti-religious" they usually mean that the atheists +have some sort of antipathy or hatred towards theists. + +This categorization of atheists as hostile towards religion is quite unfair. +Atheist attitudes towards theists in fact cover a broad spectrum. + +Most atheists take a "live and let live" attitude. Unless questioned, they +will not usually mention their atheism, except perhaps to close friends. Of +course, this may be in part because atheism is not "socially acceptable" in +many countries. + +A few atheists are quite anti-religious, and may even try to "convert" others +when possible. Historically, such anti-religious atheists have made little +impact on society outside the Eastern Bloc countries. + +(To digress slightly: the Soviet Union was originally dedicated to separation +of church and state, just like the USA. Soviet citizens were legally free to +worship as they wished. The institution of "state atheism" came about when +Stalin took control of the Soviet Union and tried to destroy the churches in +order to gain complete power over the population.) + +Some atheists are quite vocal about their beliefs, but only where they see +religion encroaching on matters which are not its business -- for example, +the government of the USA. Such individuals are usually concerned that +church and state should remain separate. + +"But if you don't allow religion to have a say in the running of the state, + surely that's the same as state atheism?" + +The principle of the separation of church and state is that the state shall +not legislate concerning matters of religious belief. In particular, it +means not only that the state cannot promote one religion at the expense of +another, but also that it cannot promote any belief which is religious in +nature. + +Religions can still have a say in discussion of purely secular matters. For +example, religious believers have historically been responsible for +encouraging many political reforms. Even today, many organizations +campaigning for an increase in spending on foreign aid are founded as +religious campaigns. So long as they campaign concerning secular matters, +and so long as they do not discriminate on religious grounds, most atheists +are quite happy to see them have their say. + +"What about prayer in schools? If there's no God, why do you care if people + pray?" + +Because people who do pray are voters and lawmakers, and tend to do things +that those who don't pray can't just ignore. Also, Christian prayer in +schools is intimidating to non-Christians, even if they are told that they +need not join in. The diversity of religious and non-religious belief means +that it is impossible to formulate a meaningful prayer that will be +acceptable to all those present at any public event. + +Also, non-prayers tend to have friends and family who pray. It is reasonable +to care about friends and family wasting their time, even without other +motives. + +"You mentioned Christians who campaign for increased foreign aid. What about + atheists? Why aren't there any atheist charities or hospitals? Don't + atheists object to the religious charities?" + +There are many charities without religious purpose that atheists can +contribute to. Some atheists contribute to religious charities as well, for +the sake of the practical good they do. Some atheists even do voluntary work +for charities founded on a theistic basis. + +Most atheists seem to feel that atheism isn't worth shouting about in +connection with charity. To them, atheism is just a simple, obvious everyday +matter, and so is charity. Many feel that it's somewhat cheap, not to say +self-righteous, to use simple charity as an excuse to plug a particular set +of religious beliefs. + +To "weak" atheists, building a hospital to say "I do not believe in God" is a +rather strange idea; it's rather like holding a party to say "Today is not my +birthday". Why the fuss? Atheism is rarely evangelical. + +"You said atheism isn't anti-religious. But is it perhaps a backlash against + one's upbringing, a way of rebelling?" + +Perhaps it is, for some. But many people have parents who do not attempt to +force any religious (or atheist) ideas upon them, and many of those people +choose to call themselves atheists. + +It's also doubtless the case that some religious people chose religion as a +backlash against an atheist upbringing, as a way of being different. On the +other hand, many people choose religion as a way of conforming to the +expectations of others. + +On the whole, we can't conclude much about whether atheism or religion are +backlash or conformism; although in general, people have a tendency to go +along with a group rather than act or think independently. + +"How do atheists differ from religious people?" + +They don't believe in God. That's all there is to it. + +Atheists may listen to heavy metal -- backwards, even -- or they may prefer a +Verdi Requiem, even if they know the words. They may wear Hawaiian shirts, +they may dress all in black, they may even wear orange robes. (Many +Buddhists lack a belief in any sort of God.) Some atheists even carry a copy +of the Bible around -- for arguing against, of course! + +Whoever you are, the chances are you have met several atheists without +realising it. Atheists are usually unexceptional in behaviour and +appearance. + +"Unexceptional? But aren't atheists less moral than religious people?" + +That depends. If you define morality as obedience to God, then of course +atheists are less moral as they don't obey any God. But usually when one +talks of morality, one talks of what is acceptable ("right") and unacceptable +("wrong") behaviour within society. + +Humans are social animals, and to be maximally successful they must +co-operate with each other. This is a good enough reason to discourage most +atheists from "anti-social" or "immoral" behaviour, purely for the purposes +of self-preservation. + +Many atheists behave in a "moral" or "compassionate" way simply because they +feel a natural tendency to empathize with other humans. So why do they care +what happens to others? They don't know, they simply are that way. + +Naturally, there are some people who behave "immorally" and try to use +atheism to justify their actions. However, there are equally many people who +behave "immorally" and then try to use religious beliefs to justify their +actions. For example: + + "Here is a trustworthy saying that deserves full acceptance: Jesus Christ + came into the world to save sinners... But for that very reason, I was + shown mercy so that in me... Jesus Christ might display His unlimited + patience as an example for those who would believe in him and receive + eternal life. Now to the king eternal, immortal, invisible, the only God, + be honor and glory forever and ever." + +The above quote is from a statement made to the court on February 17th 1992 +by Jeffrey Dahmer, the notorious cannibal serial killer of Milwaukee, +Wisconsin. It seems that for every atheist mass-murderer, there is a +religious mass-murderer. But what of more trivial morality? + + A survey conducted by the Roper Organization found that behavior + deteriorated after "born again" experiences. While only 4% of respondents + said they had driven intoxicated before being "born again," 12% had done + so after conversion. Similarly, 5% had used illegal drugs before + conversion, 9% after. Two percent admitted to engaging in illicit sex + before salvation; 5% after. + ["Freethought Today", September 1991, p. 12.] + +So it seems that at best, religion does not have a monopoly on moral +behaviour. + +"Is there such a thing as atheist morality?" + +If you mean "Is there such a thing as morality for atheists?", then the +answer is yes, as explained above. Many atheists have ideas about morality +which are at least as strong as those held by religious people. + +If you mean "Does atheism have a characteristic moral code?", then the answer +is no. Atheism by itself does not imply anything much about how a person +will behave. Most atheists follow many of the same "moral rules" as theists, +but for different reasons. Atheists view morality as something created by +humans, according to the way humans feel the world 'ought' to work, rather +than seeing it as a set of rules decreed by a supernatural being. + +"Then aren't atheists just theists who are denying God?" + +A study by the Freedom From Religion Foundation found that over 90% of the +atheists who responded became atheists because religion did not work for +them. They had found that religious beliefs were fundamentally incompatible +with what they observed around them. + +Atheists are not unbelievers through ignorance or denial; they are +unbelievers through choice. The vast majority of them have spent time +studying one or more religions, sometimes in very great depth. They have +made a careful and considered decision to reject religious beliefs. + +This decision may, of course, be an inevitable consequence of that +individual's personality. For a naturally sceptical person, the choice +of atheism is often the only one that makes sense, and hence the only +choice that person can honestly make. + +"But don't atheists want to believe in God?" + +Atheists live their lives as though there is nobody watching over them. Many +of them have no desire to be watched over, no matter how good-natured the +"Big Brother" figure might be. + +Some atheists would like to be able to believe in God -- but so what? Should +one believe things merely because one wants them to be true? The risks of +such an approach should be obvious. Atheists often decide that wanting to +believe something is not enough; there must be evidence for the belief. + +"But of course atheists see no evidence for the existence of God -- they are + unwilling in their souls to see!" + +Many, if not most atheists were previously religious. As has been explained +above, the vast majority have seriously considered the possibility that God +exists. Many atheists have spent time in prayer trying to reach God. + +Of course, it is true that some atheists lack an open mind; but assuming that +all atheists are biased and insincere is offensive and closed-minded. +Comments such as "Of course God is there, you just aren't looking properly" +are likely to be viewed as patronizing. + +Certainly, if you wish to engage in philosophical debate with atheists it is +vital that you give them the benefit of the doubt and assume that they are +being sincere if they say that they have searched for God. If you are not +willing to believe that they are basically telling the truth, debate is +futile. + +"Isn't the whole of life completely pointless to an atheist?" + +Many atheists live a purposeful life. They decide what they think gives +meaning to life, and they pursue those goals. They try to make their lives +count, not by wishing for eternal life, but by having an influence on other +people who will live on. For example, an atheist may dedicate his life to +political reform, in the hope of leaving his mark on history. + +It is a natural human tendency to look for "meaning" or "purpose" in random +events. However, it is by no means obvious that "life" is the sort of thing +that has a "meaning". + +To put it another way, not everything which looks like a question is actually +a sensible thing to ask. Some atheists believe that asking "What is the +meaning of life?" is as silly as asking "What is the meaning of a cup of +coffee?". They believe that life has no purpose or meaning, it just is. + +"So how do atheists find comfort in time of danger?" + +There are many ways of obtaining comfort; from family, friends, or even pets. +Or on a less spiritual level, from food or drink or TV. + +That may sound rather an empty and vulnerable way to face danger, but so +what? Should individuals believe in things because they are comforting, or +should they face reality no matter how harsh it might be? + +In the end, it's a decision for the individual concerned. Most atheists are +unable to believe something they would not otherwise believe merely because +it makes them feel comfortable. They put truth before comfort, and consider +that if searching for truth sometimes makes them feel unhappy, that's just +hard luck. + +"Don't atheists worry that they might suddenly be shown to be wrong?" + +The short answer is "No, do you?" + +Many atheists have been atheists for years. They have encountered many +arguments and much supposed evidence for the existence of God, but they have +found all of it to be invalid or inconclusive. + +Thousands of years of religious belief haven't resulted in any good proof of +the existence of God. Atheists therefore tend to feel that they are unlikely +to be proved wrong in the immediate future, and they stop worrying about it. + +"So why should theists question their beliefs? Don't the same arguments + apply?" + +No, because the beliefs being questioned are not similar. Weak atheism is +the sceptical "default position" to take; it asserts nothing. Strong atheism +is a negative belief. Theism is a very strong positive belief. + +Atheists sometimes also argue that theists should question their beliefs +because of the very real harm they can cause -- not just to the believers, +but to everyone else. + +"What sort of harm?" + +Religion represents a huge financial and work burden on mankind. It's not +just a matter of religious believers wasting their money on church buildings; +think of all the time and effort spent building churches, praying, and so on. +Imagine how that effort could be better spent. + +Many theists believe in miracle healing. There have been plenty of instances +of ill people being "healed" by a priest, ceasing to take the medicines +prescribed to them by doctors, and dying as a result. Some theists have died +because they have refused blood transfusions on religious grounds. + +It is arguable that the Catholic Church's opposition to birth control -- and +condoms in particular -- is increasing the problem of overpopulation in many +third-world countries and contributing to the spread of AIDS world-wide. + +Religious believers have been known to murder their children rather than +allow their children to become atheists or marry someone of a different +religion. + +"Those weren't REAL believers. They just claimed to be believers as some + sort of excuse." + +What makes a real believer? There are so many One True Religions it's hard +to tell. Look at Christianity: there are many competing groups, all +convinced that they are the only true Christians. Sometimes they even fight +and kill each other. How is an atheist supposed to decide who's a REAL +Christian and who isn't, when even the major Christian churches like the +Catholic Church and the Church of England can't decide amongst themselves? + +In the end, most atheists take a pragmatic view, and decide that anyone who +calls himself a Christian, and uses Christian belief or dogma to justify his +actions, should be considered a Christian. Maybe some of those Christians +are just perverting Christian teaching for their own ends -- but surely if +the Bible can be so readily used to support un-Christian acts it can't be +much of a moral code? If the Bible is the word of God, why couldn't he have +made it less easy to misinterpret? And how do you know that your beliefs +aren't a perversion of what your God intended? + +If there is no single unambiguous interpretation of the Bible, then why +should an atheist take one interpretation over another just on your say-so? +Sorry, but if someone claims that he believes in Jesus and that he murdered +others because Jesus and the Bible told him to do so, we must call him a +Christian. + +"Obviously those extreme sorts of beliefs should be questioned. But since + nobody has ever proved that God does not exist, it must be very unlikely + that more basic religious beliefs, shared by all faiths, are nonsense." + +That does not hold, because as was pointed out at the start of this dialogue, +positive assertions concerning the existence of entities are inherently much +harder to disprove than negative ones. Nobody has ever proved that unicorns +don't exist, but that doesn't make it unlikely that they are myths. + +It is therefore much more valid to hold a negative assertion by default than +it is to hold a positive assertion by default. Of course, "weak" atheists +would argue that asserting nothing is better still. + +"Well, if atheism's so great, why are there so many theists?" + +Unfortunately, the popularity of a belief has little to do with how "correct" +it is, or whether it "works"; consider how many people believe in astrology, +graphology, and other pseudo-sciences. + +Many atheists feel that it is simply a human weakness to want to believe in +gods. Certainly in many primitive human societies, religion allows the +people to deal with phenomena that they do not adequately understand. + +Of course, there's more to religion than that. In the industrialized world, +we find people believing in religious explanations of phenomena even when +there are perfectly adequate natural explanations. Religion may have started +as a means of attempting to explain the world, but nowadays it serves other +purposes as well. + +"But so many cultures have developed religions. Surely that must say + something?" + +Not really. Most religions are only superficially similar; for example, it's +worth remembering that religions such as Buddhism and Taoism lack any sort of +concept of God in the Christian sense. + +Of course, most religions are quick to denounce competing religions, so it's +rather odd to use one religion to try and justify another. + +"What about all the famous scientists and philosophers who have concluded + that God exists?" + +For every scientist or philosopher who believes in a god, there is one who +does not. Besides, as has already been pointed out, the truth of a belief is +not determined by how many people believe it. Also, it is important to +realize that atheists do not view famous scientists or philosophers in the +same way that theists view their religious leaders. + +A famous scientist is only human; she may be an expert in some fields, but +when she talks about other matters her words carry no special weight. Many +respected scientists have made themselves look foolish by speaking on +subjects which lie outside their fields of expertise. + +"So are you really saying that widespread belief in religion indicates + nothing?" + +Not entirely. It certainly indicates that the religion in question has +properties which have helped it so spread so far. + +The theory of memetics talks of "memes" -- sets of ideas which can propagate +themselves between human minds, by analogy with genes. Some atheists view +religions as sets of particularly successful parasitic memes, which spread by +encouraging their hosts to convert others. Some memes avoid destruction by +discouraging believers from questioning doctrine, or by using peer pressure +to keep one-time believers from admitting that they were mistaken. Some +religious memes even encourage their hosts to destroy hosts controlled by +other memes. + +Of course, in the memetic view there is no particular virtue associated with +successful propagation of a meme. Religion is not a good thing because of +the number of people who believe it, any more than a disease is a good thing +because of the number of people who have caught it. + +"Even if religion is not entirely true, at least it puts across important + messages. What are the fundamental messages of atheism?" + +There are many important ideas atheists promote. The following are just a +few of them; don't be surprised to see ideas which are also present in some +religions. + + There is more to moral behaviour than mindlessly following rules. + + Be especially sceptical of positive claims. + + If you want your life to have some sort of meaning, it's up to you to + find it. + + Search for what is true, even if it makes you uncomfortable. + + Make the most of your life, as it's probably the only one you'll have. + + It's no good relying on some external power to change you; you must change + yourself. + + Just because something's popular doesn't mean it's good. + + If you must assume something, assume something it's easy to test. + + Don't believe things just because you want them to be true. + +and finally (and most importantly): + + All beliefs should be open to question. + +Thanks for taking the time to read this article. + + +mathew + +-----BEGIN PGP SIGNATURE----- +Version: 2.2 + +iQCVAgUBK8AjRXzXN+VrOblFAQFSbwP+MHePY4g7ge8Mo5wpsivX+kHYYxMErFAO +7ltVtMVTu66Nz6sBbPw9QkbjArbY/S2sZ9NF5htdii0R6SsEyPl0R6/9bV9okE/q +nihqnzXE8pGvLt7tlez4EoeHZjXLEFrdEyPVayT54yQqGb4HARbOEHDcrTe2atmP +q0Z4hSSPpAU= +=q2V5 +-----END PGP SIGNATURE----- + +For information about PGP 2.2, send mail to pgpinfo@mantis.co.uk. +ÿ diff --git a/knn/data/batches.meta b/knn/data/batches.meta new file mode 100644 index 0000000..4467a6e Binary files /dev/null and b/knn/data/batches.meta differ diff --git a/knn/data/data_batch_1 b/knn/data/data_batch_1 new file mode 100644 index 0000000..ab404a5 Binary files /dev/null and b/knn/data/data_batch_1 differ diff --git a/knn/data/data_batch_2 b/knn/data/data_batch_2 new file mode 100644 index 0000000..6bf1369 Binary files /dev/null and b/knn/data/data_batch_2 differ diff --git a/knn/data/data_batch_3 b/knn/data/data_batch_3 new file mode 100644 index 0000000..66a0d63 Binary files /dev/null and b/knn/data/data_batch_3 differ diff --git a/knn/data/data_batch_4 b/knn/data/data_batch_4 new file mode 100644 index 0000000..cf8d03d Binary files /dev/null and b/knn/data/data_batch_4 differ diff --git a/knn/data/data_batch_5 b/knn/data/data_batch_5 new file mode 100644 index 0000000..468b2aa Binary files /dev/null and b/knn/data/data_batch_5 differ diff --git a/knn/data/iris.data.webarchive b/knn/data/iris.data.webarchive new file mode 100644 index 0000000..fa8d0b1 Binary files /dev/null and b/knn/data/iris.data.webarchive differ diff --git a/knn/data/readme.html b/knn/data/readme.html new file mode 100644 index 0000000..e377ade --- /dev/null +++ b/knn/data/readme.html @@ -0,0 +1 @@ + diff --git a/knn/data/test_batch b/knn/data/test_batch new file mode 100644 index 0000000..3e03f1f Binary files /dev/null and b/knn/data/test_batch differ diff --git a/knn/file_knn.ipynb b/knn/file_knn.ipynb new file mode 100644 index 0000000..3c89617 --- /dev/null +++ b/knn/file_knn.ipynb @@ -0,0 +1,203 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 99, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# file similarity using knn\n", + "import sklearn\n", + "import numpy as np\n" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "UnicodeDecodeError", + "evalue": "'utf-8' codec can't decode byte 0xff in position 11597: invalid start byte", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mUnicodeDecodeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;31m# data2=f2.read()\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 13\u001b[0;31m \u001b[0mread_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'./49960'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'./51060'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36mread_data\u001b[0;34m(file1, file2)\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mread_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfile1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfile2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfile1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'rb'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mf1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mdata1\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mf1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'utf-8'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mwords\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mWORD\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfindall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mUnicodeDecodeError\u001b[0m: 'utf-8' codec can't decode byte 0xff in position 11597: invalid start byte" + ] + } + ], + "source": [ + "# actual data loader not working\n", + "WORD = re.compile(r'\\w+')\n", + "def read_data(file1, file2):\n", + " with open(file1, 'rb') as f1:\n", + " data1=f1.read().decode('utf-8')\n", + " print(data1)\n", + " words = WORD.findall(data1)\n", + " print(words)\n", + " \n", + "# with open(file2, 'rb') as f2:\n", + "# data2=f2.read()\n", + "\n", + "read_data('./49960', './51060')" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# load the docs and queries for sample data\n", + "import re, math\n", + "from collections import Counter\n", + "\n", + "WORD = re.compile(r'\\w+')\n", + "\n", + "\n", + "def text_to_vector(docs):\n", + " w_to_vect = []\n", + " for doc in docs:\n", + " words = WORD.findall(doc)\n", + " w_to_vect.append(Counter(words))\n", + " return w_to_vect\n", + "\n", + "query = ['This is a foo bar sentence .', 'lets meet at the drinks bar']\n", + "docs = ['Hello lets go the bar tonight', 'This sentence is similar to a foo bar sentence .']\n", + "\n", + "#convert the queries to word frequency counts \n", + "v_queries = text_to_vector(query)\n", + "v_docs = text_to_vector(docs)\n", + "# define the class for documents\n", + "y_docs = [1,2]" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# calculate cosine similarity\n", + "def calculate_similarity(vec1, vec2):\n", + " intersection = set(vec1.keys()) & set(vec2.keys()) \n", + " numerator = sum([vec1[x] * vec2[x] for x in intersection])\n", + " sum1 = sum([vec1[x]**2 for x in vec1.keys()])\n", + " sum2 = sum([vec2[x]**2 for x in vec2.keys()])\n", + " denominator = math.sqrt(sum1) * math.sqrt(sum2)\n", + "\n", + " if not denominator:\n", + " return 0.0\n", + " else:\n", + " return float(numerator) / denominator" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Given a set of docs, find the nearest neighbors \n", + "# and return the similarity array for a query\n", + "def find_neighbors(v_query, v_docs):\n", + " similarity = []\n", + " for v_doc in v_docs:\n", + " similarity.append(1-calculate_similarity(v_query, v_doc))\n", + " return np.array(similarity)" + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 1]" + ] + }, + "execution_count": 121, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# find the predicted class for set of n queries \n", + "def find_class(k, v_queries, v_docs, y_docs):\n", + " y_pred = []\n", + " for v_query in v_queries:\n", + " vote_dict = dict()\n", + " sim_docs = find_neighbors(v_query, v_docs)\n", + " k_sim_docs = np.argpartition(sim_docs, k-1)[:k]\n", + " for sim in k_sim_docs:\n", + " if y_docs[sim] not in vote_dict:\n", + " vote_dict[y_docs[sim]] = 0\n", + " vote_dict[y_docs[sim]] += 1/sim_docs[sim]\n", + " y_pred.append(max(vote_dict.items(), key=lambda x: x[1])[0])\n", + " return y_pred \n", + "\n", + "# k =1 (1-NN)\n", + "# v_queries - array of word freq counter for each quries\n", + "# v_docs - array of word freq counter for each docs\n", + "# y_docs - class labels for the docs\n", + "find_class(1, v_queries, v_docs, y_docs)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/knn/knn.ipynb b/knn/knn.ipynb new file mode 100644 index 0000000..1b419de --- /dev/null +++ b/knn/knn.ipynb @@ -0,0 +1,233 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 280, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, 2, 6, 4, 3, 6, 6, 2, 6, 3, 5, 4, 0, 0, 9, 1, 3, 4, 0, 3, 7, 3, 3, 5, 2, 2, 7, 1, 1, 1, 2, 2, 0, 9, 5, 7, 9, 2, 2, 5, 2, 4, 3, 1, 1, 8, 2, 1, 1, 4, 9, 7, 8, 5, 9, 6, 7, 3, 1, 9, 0, 3, 1, 3, 5, 4, 5, 7, 7, 4, 7, 9, 4, 2, 3, 8, 0, 1, 6, 1, 1, 4, 1]\n" + ] + } + ], + "source": [ + "import pickle\n", + "with open('data/data_batch_1', 'rb') as fo:\n", + " image_data = pickle.load(fo, encoding='bytes')\n", + "n_samples = 100\n", + "sampled_data = image_data[b'data'][:1000]\n", + "sampled_labels = image_data[b'labels'][:1000]\n", + "#data\n", + "train_data = sampled_data[n_samples:]\n", + "test_data = sampled_data[:n_samples]\n", + "test_labels = sampled_labels[:n_samples]\n", + "train_labels = sampled_labels[n_samples:]\n", + "\n", + "#single test instance\n", + "test_one = test_data[0]\n", + "test_one = test_one.reshape((1, 3072))\n", + "test_label_one = test_labels[0]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 194, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def calculate_distance(a, b):\n", + " # one row [3072] length is one image pixels of 1024 red, \n", + " # 1024 green and 1024 blue pixels \n", + " # distance between two images ?\n", + " #a= np.array([1,2,3,4]) \n", + " #b = np.array([5,6,7,8])\n", + " distance = np.sqrt(np.sum((a-b)**2))\n", + " dist = np.linalg.norm(a-b)\n", + " return distance \n", + "#calculate_distance()" + ] + }, + { + "cell_type": "code", + "execution_count": 195, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def find_neighbors(k, train_pca, test_pca):\n", + "# samp_train = np.array([[2, 2], [4, 4], [3, 3], [4.5,4.5], [4.9,4.9]])\n", + "# samp_labels = ['cats', 'fishes', 'birds', 'fishes', 'dogs']\n", + "# samp_test = np.array([5, 5])\n", + "# samp_test_labels = ['dogs']\n", + " distance = []\n", + " neighbors = []\n", + "# k = 3\n", + " for i in range(len(train_pca)):\n", + " distance.append((train_pca[i],calculate_distance(train_pca[i], test_pca), train_labels[i]))\n", + " distance.sort(key=lambda x: x[1])\n", + " for x in range(k):\n", + " neighbors.append(distance[x])\n", + " return neighbors\n", + "#find_neighbors()" + ] + }, + { + "cell_type": "code", + "execution_count": 233, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def find_class(neighbors):\n", + " vote_dict = {}\n", + " #neighbors = find_neighbors()\n", + " for neighbor in neighbors:\n", + " label = neighbor[-1]\n", + " distance = neighbor[1]\n", + " if label in vote_dict:\n", + " #count\n", + " vote_dict[label] += 1/distance\n", + " else:\n", + " vote_dict[label] = 1/distance\n", + " #print(vote_dict)\n", + " return max(vote_dict.items(), key=lambda x: x[1])[0]\n", + "#find_class() " + ] + }, + { + "cell_type": "code", + "execution_count": 279, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[(6, 6), (8, 9), (9, 9), (0, 4), (2, 1), (1, 1), (8, 2), (0, 7), (0, 8), (0, 3), (4, 4), (8, 7), (8, 7), (4, 2), (4, 9), (8, 9), (0, 9), (3, 3), (7, 2), (6, 6), (0, 4), (6, 3), (6, 6), (4, 6), (0, 2), (7, 6), (6, 3), (6, 5), (4, 4), (8, 0), (4, 0), (8, 9), (4, 1), (6, 3), (8, 4), (2, 0), (6, 3), (4, 7), (0, 3), (3, 3), (2, 5), (2, 2), (2, 2), (8, 7), (0, 1), (2, 1), (8, 1), (4, 2), (2, 2), (0, 0), (6, 9), (2, 5), (2, 7), (0, 9), (0, 2), (2, 2), (4, 5), (0, 2), (4, 4), (3, 3), (0, 1), (4, 1), (2, 8), (2, 2), (0, 1), (5, 1), (4, 4), (8, 9), (0, 7), (8, 8), (4, 5), (3, 9), (9, 6), (1, 7), (2, 3), (4, 1), (8, 9), (5, 0), (4, 3), (0, 1), (3, 3), (6, 5), (4, 4), (4, 5), (5, 7), (6, 7), (6, 4), (7, 7), (0, 9), (8, 4), (2, 2), (6, 3), (0, 8), (0, 0), (8, 1), (0, 6), (3, 1), (2, 1), (0, 4), (6, 1)]\n", + "24\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "from sklearn.decomposition import PCA\n", + "import matplotlib.pyplot as plt\n", + "def knn(k, d, n):\n", + " # PCA\n", + " train_grayed = convert_gray(train_data, 1000-n, 1024)\n", + " test_grayed = convert_gray(test_data, n, 1024)\n", + " pca_obj, train_pca = do_pca(train_grayed, d)\n", + " test_pca = reduce_dimension(test_grayed, pca_obj)\n", + " # knn\n", + " labels = []\n", + " accuracy=0\n", + " for i in range(len(test_pca)):\n", + " neighbors = find_neighbors(k, train_pca, test_pca[i])\n", + " prediction = find_class(neighbors)\n", + " actual = test_labels[i]\n", + " if prediction == actual:\n", + " accuracy+=1\n", + " labels.append((prediction,actual))\n", + " print(labels)\n", + " print(accuracy)\n", + "knn(3, 400, 100)" + ] + }, + { + "cell_type": "code", + "execution_count": 225, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [], + "source": [ + "def convert_gray(data, row, column):\n", + " img = data[:]\n", + " grayed = np.zeros((row, column))\n", + "\n", + "# print(img.dtype, img.max())\n", + "# img = np.reshape(img,(3,32,32))\n", + "# img = np.transpose(img, (1,2,0))\n", + "# print(img.dtype, img.max())\n", + " for i in range(len(img)):\n", + " grayed[i] = img[i][:1024]*0.299 + img[i][1024:2048]*0.587 + img[i][2048:]*0.114\n", + "# reshape = np.reshape(grayed[0],(32,32))\n", + "# plt.imshow(reshape, 'gray')\n", + "# plt.show()\n", + " return grayed" + ] + }, + { + "cell_type": "code", + "execution_count": 235, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def do_pca(gray_data, d):\n", + " \n", + " pca = PCA(n_components=d, svd_solver='full')\n", + " pca_obj = pca.fit(gray_data)\n", + " train_pca = pca_obj.transform(gray_data)\n", + " #print(train_pca.shape)\n", + " return (pca_obj, train_pca)" + ] + }, + { + "cell_type": "code", + "execution_count": 227, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def reduce_dimension(gray_data, pca):\n", + " return pca.transform(gray_data)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/knn/knn.py b/knn/knn.py new file mode 100644 index 0000000..a843c57 --- /dev/null +++ b/knn/knn.py @@ -0,0 +1,110 @@ +import sys +import pickle +import numpy as np +from sklearn.decomposition import PCA + + +def calculate_distance(a, b): + distance = np.sqrt(np.sum((a - b) ** 2)) + return distance + + +def find_class(neighbors): + vote_dict = {} + for neighbor in neighbors: + label = neighbor[-1] + distance = neighbor[1] + if label in vote_dict: + # voting weight using inverse euclidean distance + vote_dict[label] += 1 / distance + else: + vote_dict[label] = 1 / distance + return max(vote_dict.items(), key=lambda x: x[1])[0] + + +def find_neighbors(k, train_pca, test_pca, train_labels): + distance = [] + neighbors = [] + for i in range(len(train_pca)): + distance.append((train_pca[i], calculate_distance(train_pca[i], test_pca), train_labels[i])) + distance.sort(key=lambda x: x[1]) + for x in range(k): + neighbors.append(distance[x]) + return neighbors + + +def convert_gray(data, row, column): + img = data[:] + grayed = np.zeros((row, column)) + for i in range(len(img)): + grayed[i] = img[i][:1024] * 0.299 + img[i][1024:2048] * 0.587 + img[i][2048:] * 0.114 + return grayed + + +def do_pca(gray_data, d): + pca = PCA(n_components=d, svd_solver='full') + pca_obj = pca.fit(gray_data) + train_pca = pca_obj.transform(gray_data) + # print(train_pca.shape) + return pca_obj, train_pca + + +def reduce_dimension(gray_data, pca): + return pca.transform(gray_data) + + +def write_output(file, result): + with open(file, 'w') as f: + for res in result: + f.write('{0} {1}\n'.format(res[0], res[1])) + f.close() + + +def knn(train_data, test_data, test_labels, train_labels, k, d): + # do pca and reduce dimension for train data + pca_obj, train_pca = do_pca(train_data, d) + # reduce dimension for test data + test_pca = reduce_dimension(test_data, pca_obj) + # perform kNN for each test sample + labels = [] + for i in range(len(test_pca)): + neighbors = find_neighbors(k, train_pca, test_pca[i], train_labels) + prediction = find_class(neighbors) + actual = test_labels[i] + labels.append((prediction, actual)) + return labels + + +def main(): + if len(sys.argv) == 5: + k = int(sys.argv[1]) # number of nearest neighbor + d = int(sys.argv[2]) # number of pca dimension + n = int(sys.argv[3]) # number of test samples to consider + input_data = sys.argv[4] + total_samples = 1000 # total number of train+test samples + + # load image data + with open(input_data, 'rb') as fo: + image_data = pickle.load(fo, encoding='bytes') + sampled_data = image_data[b'data'][:total_samples] + sampled_labels = image_data[b'labels'][:total_samples] + + # create train and test splits + train_data = sampled_data[n:] + test_data = sampled_data[:n] + test_labels = sampled_labels[:n] + train_labels = sampled_labels[n:] + + # convert the image to gray scale + train_grayed = convert_gray(train_data, 1000 - n, 1024) + test_grayed = convert_gray(test_data, n, 1024) + + # perform kNN using PCA + labels = knn(train_grayed, test_grayed, test_labels, train_labels, k, d) + + # output the predicted and actual labels for every image + write_output('output.txt', labels) + + +if __name__ == '__main__': + main() diff --git a/knn/output.txt b/knn/output.txt new file mode 100644 index 0000000..bc31c37 --- /dev/null +++ b/knn/output.txt @@ -0,0 +1,200 @@ +4 6 +8 9 +9 9 +6 4 +2 1 +1 1 +2 2 +5 7 +2 8 +4 3 +6 4 +1 7 +0 7 +4 2 +0 9 +3 9 +0 9 +6 3 +9 2 +5 6 +3 4 +7 3 +6 6 +3 6 +2 2 +0 6 +8 3 +6 5 +6 4 +1 0 +2 0 +9 9 +1 1 +5 3 +7 4 +7 0 +6 3 +0 7 +1 3 +6 3 +6 5 +0 2 +2 2 +7 7 +2 1 +2 1 +1 1 +0 2 +0 2 +3 0 +4 9 +4 5 +6 7 +1 9 +3 2 +9 2 +4 5 +9 2 +0 4 +9 3 +8 1 +2 1 +1 8 +1 2 +7 1 +4 1 +4 4 +9 9 +0 7 +6 8 +7 5 +1 9 +2 6 +4 7 +2 3 +0 1 +8 9 +6 0 +5 3 +0 1 +3 3 +2 5 +4 4 +9 5 +1 7 +6 7 +6 4 +7 7 +2 9 +6 4 +3 2 +2 3 +2 8 +9 0 +8 1 +0 6 +1 1 +2 1 +5 4 +5 1 +0 8 +9 3 +7 9 +6 6 +6 6 +1 1 +2 8 +4 5 +2 2 +3 9 +5 9 +2 8 +2 1 +8 7 +3 7 +8 0 +7 0 +7 6 +8 9 +0 1 +5 2 +0 2 +0 9 +2 2 +9 6 +9 6 +9 1 +8 9 +5 5 +0 0 +4 4 +8 7 +6 6 +4 7 +6 1 +0 8 +0 1 +8 1 +2 2 +9 8 +6 1 +7 3 +4 3 +2 6 +0 2 +5 4 +1 9 +2 9 +3 5 +4 4 +1 3 +6 6 +8 7 +2 4 +9 6 +2 8 +7 5 +4 5 +3 4 +9 3 +8 1 +8 8 +3 4 +7 7 +4 6 +8 0 +2 9 +2 5 +1 1 +7 3 +1 8 +4 2 +0 7 +6 5 +7 3 +7 4 +2 1 +6 5 +1 7 +6 0 +3 4 +5 7 +7 5 +1 5 +1 1 +8 0 +4 9 +6 6 +9 9 +8 0 +0 8 +0 7 +9 8 +8 8 +4 2 +6 5 +0 2 +2 3 +3 5 +8 0