import unittest

from ir_datasets.formats import GenericDoc, GenericQuery, TrecQrel

from .base import DatasetIntegrationTest


class TestBeir(DatasetIntegrationTest):
    def test_docs(self):

        self._test_docs("nano-beir/arguana", count=3635, items={
            0: GenericDoc('test-environment-aeghhgwpe-pro01a', "It is immoral to kill animals  As evolved human beings it is our moral duty to inflict as little pain as possible for our survival. So if we do not need to inflict pain to animals in order to survive, we should not do it. Farm animals such as chickens, pigs, sheep, and cows are sentient living beings like us - they are our evolutionary cousins and like us they can feel pleasure and pain. The 18th century utilitarian philosopher Jeremy Bentham even believed that animal suffering was just as serious as human suffering and likened the idea of human superiority to racism. It is wrong to farm and kill these animals for food when we do not need to do so. The methods of farming and slaughter of these animals are often barbaric and cruel - even on supposedly 'free range' farms. [1] Ten billion animals were slaughtered for human consumption each year, stated PETA. And unlike the farms long time ago, where animals roamed freely, today, most animals are factory farmed: \x97crammed into cages where they can barely move and fed a diet adulterated with pesticides and antibiotics. These animals spend their entire lives in their “prisoner cells” so small that they can't even turn around. Many suffer serious health problems and even death because they are selectively bred to grow or produce milk or eggs at a far greater rate than their bodies are capable of coping with. At the slaughterhouse, there were millions of others who are killed every year for food.  Further on Tom Regan explains that all duties regarding animals are indirect duties to one another from a philosophical point of view. He illustrates it with an analogy regarding children: “Children, for example, are unable to sign contracts and lack rights. But they are protected by the moral contract nonetheless because of the sentimental interests of others. So we have, then, duties involving these children, duties regarding them, but no duties to them. Our duties in their case are indirect duties to other human beings, usually their parents.” [2] With this he supports the theory that animals must be protected from suffering, as it is moral to protect any living being from suffering, not because we have a moral contract with them, but mainly due to respect of life and recognition of suffering itself.  [1] Claire Suddath, A brief history of Veganism, Time, 30 October 2008  [2] Tom Regan, The case for animal rights, 1989"),
            9: GenericDoc('test-environment-assgbatj-con03b', 'When a drug is first tested on human volunteers, they are only given a tiny fraction of the amount shown safe to give to primates showing there is another way, to start with very low doses. Animal research isn’t a reliable indicator of how a drug will work in people – even with animal testing, some drugs trials go very wrong [15].'),
            3634: GenericDoc('validation-society-fyhwscdcj-con03a', 'Sponsorship is often more about the intentions of the donors rather than the needs of poor children.  Some schemes have a clear cultural and religious motive – a desire to give aid in such a way that it will affect and even impose (force) foreign ideas onto a vulnerable (weaker) society. Any organisation that has such a clear overlap between their own ideas of faith [19] and the practical side of helping people is ultimately imposing its ideas onto people without giving them any choice in the matter. Families may even come to think that they have to show belief in order to keep receiving sponsorship. For example, sponsored children may be encouraged to send cards at Christmas, even if they are not Christians. At the end of the day this comes down to a very serious question of choice – many would argue that by offering aid with the intention of turning children into adult Christians [20], organisations like “Compassion” are effectively manipulating charity into part of a conversion campaign.'),
        })
        self._test_docs("nano-beir/climate-fever", count=3408, items={
            0: GenericDoc('1993_Storm_of_the_Century', "The 1993 Storm of the Century ( also known as the 93 Super Storm or the Great Blizzard of 1993 ) was a large cyclonic storm that formed over the Gulf of Mexico on March 12 , 1993 . The storm eventually dissipated in the North Atlantic Ocean on March 15 , 1993 . It was unique for its intensity , massive size , and wide-reaching effects . At its height , the storm stretched from Canada to the Gulf of Mexico . The cyclone moved through the Gulf of Mexico and then through the eastern United States before moving onto Canada .   Heavy snow was first reported in highland areas as far south as Alabama and northern Georgia , with Union County , Georgia reporting up to 35 inches of snow in the north Georgia mountains . Birmingham , Alabama , reported a rare 13 in of snow .  The Florida Panhandle reported up to 4 in , with hurricane-force wind gusts and record low barometric pressures . Between Louisiana and Cuba , the hurricane-force winds produced high storm surges across Northwestern Florida which , in combination with scattered tornadoes , killed dozens of people .   Record cold temperatures were seen across portions of the south and east of the US in the wake of this storm . In the United States , the storm was responsible for the loss of electric power to more than 10 million households . An estimated 40 percent of the country 's population experienced the effects of the storm with a total of 208 fatalities ."),
            9: GenericDoc('1990', "For the album by Enigma see MCMXC a.D.   Important events of 1990 include the Reunification of Germany and the unification of Yemen , the formal beginning of the Human Genome Project ( finished in 2003 ) , the launch of the Hubble Space Telescope , the separation of Namibia from South Africa , and the Baltic states declaring independence from the Soviet Union amidst Perestroika . Yugoslavia 's communist regime collapses amidst increasing internal tensions and multiparty elections held within its constituent republics result in separatist governments being elected in most of the republics marking the beginning of the breakup of Yugoslavia . Also in this year began the crisis that would lead to the Gulf War in 1991 following the Iraq invasion and the largely internationally unrecognized annexation of Kuwait resulting in a crisis in the Persian Gulf involving the issue of the sovereignty of Kuwait and fears by Saudi Arabia over Iraqi aggression against their oil fields near Kuwait , this resulted in Operation Desert Shield being enacted with an international coalition of military forces being built up on the Kuwaiti-Saudi border with demands for Iraq to peacefully withdraw from Kuwait . Also in this year , Nelson Mandela was released from prison , and Margaret Thatcher resigned as Prime Minister of the United Kingdom after over 11 years .   1990 was an important year in the Internet 's early history . In the fall of 1990 , Tim Berners-Lee created the first web server and the foundation for the World Wide Web . Test operations began around December 20 and it was released outside of CERN the following year . 1990 also saw the official decommissioning of the ARPANET , a forerunner of the Internet system and the introduction of the first content search engine , Archie on September 10 .   September 14 , 1990 saw the first case of successful somatic gene therapy on a patient .   Due to the early 1990s recession that began that year and uncertainty due to the collapse of the socialist governments in Eastern Europe , birth rates in many countries stopped rising or fell steeply in 1990 . In most western countries the Echo Boom peaked in 1990 ; fertility rates declined thereafter .   Encyclopædia Britannica , which ceased printing in 2012 , saw its highest all time sales in 1990 ; 120,000 volumes were sold that year . The number of librarians in the United States also peaked around 1990 ."),
            3407: GenericDoc('Climate_change_(general_concept)', 'Climate variability includes all the variations in the climate that last longer than individual weather events, whereas the term climate change only refers to those variations that persist for a longer period of time, typically decades or more. In the time since the industrial revolution the climate has increasingly been affected by human activities that are causing global warming and climate change.The climate system receives nearly all of its energy from the sun. The climate system also radiates energy to outer space. The balance of incoming and outgoing energy, and the passage of the energy through the climate system, determines Earth\\\'s energy budget. When the incoming energy is greater than the outgoing energy, earth\\\'s energy budget is positive and the climate system is warming. If more energy goes out, the energy budget is negative and earth experiences cooling.\\nThe energy moving through Earth\\\'s climate system finds expression in weather, varying on geographic scales and time. Long-term averages and variability of weather in a region constitute the region\\\'s climate. Such changes can be the result of "internal variability", when natural processes inherent to the various parts of the climate system alter the distribution of energy. Examples include variability in ocean basins such as the Pacific decadal oscillation and Atlantic multidecadal oscillation. Climate variability can also result from external forcing, when events outside of the climate system\\\'s components nonetheless produce changes within the system. Examples include changes in solar output and volcanism.\\nClimate variability has consequences for sea level changes, plant life, and mass extinctions; it also affects human societies.'),
        })
        self._test_docs("nano-beir/dbpedia-entity", count=6045, items={
            0: GenericDoc('<dbpedia:Academy_Award_for_Best_Production_Design>', "The Academy Awards are the oldest awards ceremony for achievements in motion pictures. The Academy Award for Best Production Design recognizes achievement in art direction on a film. The category's original name was Best Art Direction, but was changed to its current name in 2012 for the 85th Academy Awards.  This change resulted from the Art Director's branch of the Academy being renamed the Designer's branch."),
            9: GenericDoc('<dbpedia:Apollo_program>', "The Apollo program, also known as Project Apollo, was the third United States human spaceflight program carried out by the National Aeronautics and Space Administration (NASA), which accomplished landing the first humans on the Moon from 1969 to 1972. First conceived during Dwight D. Eisenhower's administration as a three-man spacecraft to follow the one-man Project Mercury which put the first Americans in space, Apollo was later dedicated to President John F."),
            6044: GenericDoc('<dbpedia:Frankfurt>', "Frankfurt am Main (German pronunciation: [ˈfʁaŋkfʊɐ̯t am ˈmaɪ̯n] ) is the largest city in the German state of Hesse (Hessia) and the fifth-largest city in Germany, with a 2015 population of 731,095 within its administrative boundaries. The urban area called Frankfurt Rhein-Main has a population of 2,221,910. The city is at the centre of the larger Frankfurt Rhine-Main Metropolitan Region which has a population of 5,500,000 and is Germany's second-largest metropolitan region. Since the enlargement of the European Union in 2013, the geographic centre of the EU is about 40 km (25 mi) to the east."),
        })
        self._test_docs("nano-beir/fever", count=4996, items={
            0: GenericDoc('1999_Pulitzer_Prize', 'The Pulitzer Prizes for 1999 were announced on April 12 , 1999 .'),
            9: GenericDoc('1951_NBA_Playoffs', "The 1951 NBA Playoffs was the postseason tournament of the National Basketball Association 1950 -- 51 season . The tournament concluded with the Western Division champion Rochester Royals defeating the Eastern Division champion New York Knicks 4 games to 3 in the NBA Finals .   The eight qualified teams began tournament play on Tuesday and Wednesday , March 20 and 21 , and the Finals concluded on Saturday , April 21 . Rochester and New York played 14 games in a span of 33 days ; their seven final games in fifteen days .   The Rochester Royals ( now the Sacramento Kings ) were `` royalty '' in their first nine seasons , from 1945 -- 46 to 1954 -- 54 always one of the strong teams in their league . Rochester had played three seasons in the National Basketball League , winning the 1946 NBL championship and losing the Finals in 1947 and 1948 . In one BAA and one NBA season , the team had won 75 % of its games before losing in the second round , then first round , of the 1949 and 1950 playoffs . The 1950 -- 51 team won more than 60 % of its games , as the Royals would do for three more seasons , and participated in the club 's only NBA Finals . That remains true more than 60 years later , covering stints in Rochester , Cincinnati , Kansas City , and Sacramento .   The New York Knicks were an original Basketball Association of America franchise , now in its sixth season and participating in the BAA or NBA Finals for the first time . It would be the first three consecutive years as losing finalist .   Another six-year-old , original BAA team , the Boston Celtics had qualified only for the 1948 BAA Playoffs . Now the second-place Eastern Division team , Boston had earned home-court advantage for a first-round series with third-place New York . It was the first playoff meeting in the Celtics -- Knicks rivalry and it would be the first of 19 consecutive years in the playoffs ."),
            4995: GenericDoc('XSM-74', 'The Convair XSM-74 was a sub-sonic , jet-powered , ground-launched decoy cruise missile .'),
        })
        self._test_docs("nano-beir/fiqa", count=4598, items={
            0: GenericDoc('277', "My super fund and I would say many other funds give you one free switch of strategies per year.  Some suggest you should change from high growth option to a more balance option once you are say about 10 to 15 years from retirement, and then change to a more capital guaranteed option a few years from retirement. This is a more passive approach and has benefits as well as disadvantages. The benefit is that there is not much work involved, you just change your investment option based on your life stage, 2 to 3 times during your lifetime. This allows you to take more risk when you are young to aim for higher returns, take a balanced approach with moderate risk and returns during the middle part of your working life, and take less risk with lower returns (above inflation) during the latter part of your working life. A possible disadvantage of this strategy is you may be in the higher risk/ higher growth option during a market correction and then change to a more balanced option just when the market starts to pick up again. So your funds will be hit with large losses whilst the market is in retreat and just when things look to be getting better you change to a more balanced portfolio and miss out on the big gains. A second more active approach would be to track the market and change investment option as the market changes. One approach which shouldn't take much time is to track the index such as the ASX200 (if you investment option is mainly invested in the Australian stock market) with a 200 day Simple Moving Average (SMA). The concept is that if the index crosses above the 200 day SMA the market is bullish and if it crosses below it is bearish. See the chart below:  This strategy will work well when the market is trending up or down but not very well when the market is going sideways, as you will be changing from aggressive to balanced and back too often. Possibly a more appropriate option would be a combination of the two. Use the first passive approach to change investment option from aggressive to balanced to capital guaranteed with your life stages, however use the second active approach to time the change. For example, if you were say in your late 40s now and were looking to change from aggressive to balanced in the near future, you could wait until the ASX200 crosses below the 200 day SMA before making the change. This way you could capture the majority of the uptrend (which could go on for years) before changing from the high growth/aggressive option to the balanced option. If you where after more control over your superannuation assets another option open to you is to start a SMSF, however I would recommend having at least $300K to $400K in assets before starting a SMSF, or else the annual costs would be too high as a percentage of your total super assets."),
            9: GenericDoc('1699', '"The TWRR calculation will work even with negative values: TWRR = (1 + 0.10) x (1 + (-0.191) ) x (1 + 0.29) ^ (1/3) = 1.047 which is a 4.7% return. Your second question concerns the -19% return calculated for the second quarter.  You seem to think this return is ""way-off"".  Not really.  The TWRR calculates a return by accounting for cash that was added or deducted to/from the account.  So if I started with $100,000, added $10,000 to the account, and ended up with $110,000, what should be the return on my investment?  My answer would be 0% since the only reason my account balance went up was due to me adding cash to it.  Therefore, if I started with $100,000, added $10,000 in cash to the account, and ended up with $100,000 in my account, then my return would be a negative value since I lost the $10,000 that I deposited in the account. In the second quarter you started with $15,000, deposited $4,000, and ended with $15,750.  You essentially lost almost all of the $4,000 you deposited.  That is a significant loss."'),
            4597: GenericDoc('599925', "Investopedia has a good explanation of the term shorting which is what this is. In the simplest of terms, someone is borrowing the bond and selling it with the intent to replace the security and any dividends or coupons in the end. The idea is that if a bond is overvalued, one may be able to buy it back later for a cheaper price and pocket the difference. There are various rules about this including margin requirements to maintain since there is the risk of the security going up in price enough that someone may be forced into a buy to cover in the form of a margin call. If one can sell the bond at $960 now and then buy it back later for $952.38 then one could pocket the difference. Part of what you aren't seeing is what are other bonds doing in terms of their prices over time here. The key point here is that brokers may lend out securities and accrue interest on loaned securities for another point here."),
        })
        self._test_docs("nano-beir/hotpotqa", count=5090, items={
            0: GenericDoc('974', 'Augusta Ada King-Noel, Countess of Lovelace ("née" Byron; 10 December 1815\xa0– 27 November 1852) was an English mathematician and writer, chiefly known for her work on Charles Babbage\'s proposed mechanical general-purpose computer, the Analytical Engine. She was the first to recognise that the machine had applications beyond pure calculation, and created the first algorithm intended to be carried out by such a machine. As a result, she is often regarded as the first to recognise the full potential of a "computing machine" and the first computer programmer.'),
            9: GenericDoc('11242', 'Final Fantasy: The Spirits Within is a 2001 American computer-animated science fiction film directed by Hironobu Sakaguchi, creator of the "Final Fantasy" series of role-playing video games. It was the first photorealistic computer-animated feature film and remains the most expensive video game-inspired film of all time. It features the voices of Ming-Na Wen, Alec Baldwin, Donald Sutherland, James Woods, Ving Rhames, Peri Gilpin and Steve Buscemi.'),
            5089: GenericDoc('55344979', 'The augerino is a legendary creature present in the folk tales of lumberjack and ranching communities in the western United States. Tales of the augerino described it as a subterranean creature which inhabited the drier regions of Colorado. The augerino required a dry environment to survive and would bore holes in dams and irrigation ditches to let the water drain out. Some accounts described the augerino as a type of worm, though tales differ on the exact physical description of the creature. The name appears to derive from the diminutive of the common hand tool, the auger.'),
        })
        self._test_docs("nano-beir/msmarco", count=5043, items={
            0: GenericDoc('2004', 'n (Brit. history) a local government committee composed of magistrates and representatives of the county borough council responsible for the efficiency of the local police force. English Collins Dictionary-English Definition & Thesaurus &nbsp.'),
            9: GenericDoc('25901', 'understood within the framework of intersubjectivity (Trevarthen, C., 2001, Diamond, N., & Marrone, M., (2003), which has a central role in the healthy development of brain systems (Shore, 1994), social functioning, and interpersonal relationships.'),
            5042: GenericDoc('8841335', 'On September 9, 1890, Colonel Harland Sanders was born on a farm outside Henryville, Indiana. More than 30 years after his death, the man in the trademark white suit and black string tie who pioneered Kentucky Fried Chicken’s “finger-lickin’ good” secret recipe remains the public face of the fast-food chain.'),
        })
        self._test_docs("nano-beir/nfcorpus", count=2953, items={
            0: GenericDoc('MED-10', 'Recent studies have suggested that statins, an established drug group in the prevention of cardiovascular mortality, could delay or prevent breast cancer recurrence but the effect on disease-specific mortality remains unclear. We evaluated risk of breast cancer death among statin users in a population-based cohort of breast cancer patients. The study cohort included all newly diagnosed breast cancer patients in Finland during 1995–2003 (31,236 cases), identified from the Finnish Cancer Registry. Information on statin use before and after the diagnosis was obtained from a national prescription database. We used the Cox proportional hazards regression method to estimate mortality among statin users with statin use as time-dependent variable. A total of 4,151 participants had used statins. During the median follow-up of 3.25 years after the diagnosis (range 0.08–9.0 years) 6,011 participants died, of which 3,619 (60.2%) was due to breast cancer. After adjustment for age, tumor characteristics, and treatment selection, both post-diagnostic and pre-diagnostic statin use were associated with lowered risk of breast cancer death (HR 0.46, 95% CI 0.38–0.55 and HR 0.54, 95% CI 0.44–0.67, respectively). The risk decrease by post-diagnostic statin use was likely affected by healthy adherer bias; that is, the greater likelihood of dying cancer patients to discontinue statin use as the association was not clearly dose-dependent and observed already at low-dose/short-term use. The dose- and time-dependence of the survival benefit among pre-diagnostic statin users suggests a possible causal effect that should be evaluated further in a clinical trial testing statins’ effect on survival in breast cancer patients.'),
            9: GenericDoc('MED-666', 'Breast pain is a common condition affecting most women at some stage in their reproductive life. Mastalgia is resistant to treatment in 6% of cyclical and 26% non-cyclical patients. Surgery is not widely used to treat this condition and only considered in patients with severe mastalgia resistant to medication. The aims of this study were to audit the efficacy of surgery in severe treatment resistant mastalgia and to assess patient satisfaction following surgery. This is a retrospective review of the medical records of all patients seen in mastalgia clinic in the University Hospital of Wales, Cardiff since 1973. A postal questionnaire was distributed to all patients who had undergone surgery. Results showed that of the 1054 patients seen in mastalgia clinic, 12 (1.2%) had undergone surgery. Surgery included 8 subcutaneous mastectomies with implants (3 bilateral, 5 unilateral), 1 bilateral simple mastectomy and 3 quadrantectomies (1 having a further simple mastectomy). The median duration of symptoms was 6.5 years (range 2-16 years). Five patients (50%) were pain free following surgery, 3 developed capsular contractures and 2 wound infections with dehiscence. Pain persisted in both patients undergoing quadrantectomy. We conclude that surgery for mastalgia should only be considered in a minority of patients. Patients should be informed of possible complications inherent of reconstructive surgery and warned that in 50% cases their pain will not be improved.'),
            2952: GenericDoc('MED-942', 'Apple cider vinegar products are advertised in the popular press and over the Internet for treatment of a variety of conditions. After an adverse event was reported to the authors, eight apple cider vinegar tablet products were tested for pH, component acid content, and microbial growth. Considerable variability was found between the brands in tablet size, pH, component acid content, and label claims. Doubt remains as to whether apple cider vinegar was in fact an ingredient in the evaluated products. The inconsistency and inaccuracy in labeling, recommended dosages, and unsubstantiated health claims make it easy to question the quality of the products.'),
        })
        self._test_docs("nano-beir/nq", count=5035, items={
            0: GenericDoc('doc806', "The team arrives at an underground antipurge hideout run by Dante Bishop. Barnes discovers that Bishop's group intends to assassinate Owens, in an effort to end the purge. A large group of paramilitary forces arrives at the hideout looking for Bishop. Barnes and Roan escape back to the streets and meet Joe, Marcos, and Laney, who had left the hideout earlier to return to Joe's store."),
            9: GenericDoc('doc2836', "Belle befriends the castle's servants, who invite her to a spectacular dinner. When she wanders into the forbidden west wing and finds the rose, the Beast, enraged, scares her into the woods. She is ambushed by a pack of wolves, but the Beast rescues her, and is injured in the process. As Belle nurses his wounds, a friendship develops between them. The Beast shows Belle a gift from the enchantress, a book that transports readers wherever they want. Belle uses it to visit her childhood home in Paris, where she discovers a plague doctor mask and realizes that she and her father were forced to leave her mother's deathbed when her mother succumbed to the plague."),
            5034: GenericDoc('doc2680676', "The film was primarily shot in County Donegal, Ireland.  Some of the orphanage scenes were shot in an abandoned hospital 'touched-up' by the design crew. Over 500 locals/extras were seen for casting, over three days, including many children. 'Smudge' was an animatronic, and its scenes were shot first, due to concerns about bad weather on the beach, which never occurred. In fact, for the 'rain scene' (jumping in puddles), they had to produce it, as it failed to rain during production.[2]"),
        })
        self._test_docs("nano-beir/quora", count=5046, items={
            0: GenericDoc('58', 'What is best way to ask for money online?'),
            9: GenericDoc('575', 'Who will win if a war starts between India and Pakistan?'),
            5045: GenericDoc('537834', 'How good is the Sony MDR ZX 100 as a headphone?'),
        })
        self._test_docs("nano-beir/scidocs", count=2210, items={
            0: GenericDoc('1b2a0e8af5c1f18e47e71244973ce4ace4ac6034', 'Hierarchical Pitman-Yor Process priors are compelling methods for learning language models, outperforming point-estimate based methods. However, these models remain unpopular due to computational and statistical inference issues, such as memory and time usage, as well as poor mixing of sampler. In this work we propose a novel framework which represents the HPYP model compactly using compressed suffix trees. Then, we develop an efficient approximate inference scheme in this framework that has a much lower memory footprint compared to full HPYP and is fast in the inference time. The experimental results illustrate that our model can be built on significantly larger datasets compared to previous HPYP models, while being several orders of magnitudes smaller, fast for training and inference, and outperforming the perplexity of the state-of-the-art Modified Kneser-Ney countbased LM smoothing by up to 15%.'),
            9: GenericDoc('922b5eaa5ca03b12d9842b7b84e0e420ccd2feee', 'AN IMPORTANT class of theoretical and practical problems in communication and control is of a statistical nature. Such problems are: (i) Prediction of random signals; (ii) separation of random signals from random noise; (iii) detection of signals of known form (pulses, sinusoids) in the presence of random noise. In his pioneering work, Wiener [1]3 showed that problems (i) and (ii) lead to the so-called Wiener-Hopf integral equation; he also gave a method (spectral factorization) for the solution of this integral equation in the practically important special case of stationary statistics and rational spectra. Many extensions and generalizations followed Wiener’s basic work. Zadeh and Ragazzini solved the finite-memory case [2]. Concurrently and independently of Bode and Shannon [3], they also gave a simplified method [2) of solution. Booton discussed the nonstationary Wiener-Hopf equation [4]. These results are now in standard texts [5-6]. A somewhat different approach along these main lines has been given recently by Darlington [7]. For extensions to sampled signals, see, e.g., Franklin [8], Lees [9]. Another approach based on the eigenfunctions of the WienerHopf equation (which applies also to nonstationary problems whereas the preceding methods in general don’t), has been pioneered by Davis [10] and applied by many others, e.g., Shinbrot [11], Blum [12], Pugachev [13], Solodovnikov [14]. In all these works, the objective is to obtain the specification of a linear dynamic system (Wiener filter) which accomplishes the prediction, separation, or detection of a random signal.4 ——— 1 This research was supported in part by the U. S. Air Force Office of Scientific Research under Contract AF 49 (638)-382. 2 7212 Bellona Ave. 3 Numbers in brackets designate References at end of paper. 4 Of course, in general these tasks may be done better by nonlinear filters. At present, however, little or nothing is known about how to obtain (both theoretically and practically) these nonlinear filters. Contributed by the Instruments and Regulators Division and presented at the Instruments and Regulators Conference, March 29– Apri1 2, 1959, of THE AMERICAN SOCIETY OF MECHANICAL ENGINEERS. NOTE: Statements and opinions advanced in papers are to be understood as individual expressions of their authors and not those of the Society. Manuscript received at ASME Headquarters, February 24, 1959. Paper No. 59-IRD—11. A New Approach to Linear Filtering and Prediction Problems'),
            2209: GenericDoc('dec997b20ebe2b867f68cc5c123d9cb9eafad6bb', 'Training deep neural networks generally requires massive amounts of data and is very computation intensive. We show here that it may be possible to circumvent the expensive gradient descent procedure and derive the parameters of a neural network directly from properties of the training data. We show that, near convergence, the gradient descent equations for layers close to the input can be linearized and become stochastic equations with noise related to the covariance of data for each class. We derive the distribution of solutions to these equations and discover that it is related to a “supervised principal component analysis.” We implement these results on image datasets MNIST, CIFAR10 and CIFAR100 and find that, indeed, pretrained layers using our findings performs comparable or superior to neural networks of the same size and architecture trained with gradient descent. Moreover, our pretrained layers can often be calculated using a fraction of the training data, owing to the quick convergence of the covariance matrix. Thus, our findings indicate that we can cut the training time both by requiring only a fraction of the data used for gradient descent, and by eliminating layers in the costly backpropagation step of the training. Additionally, these findings partially elucidate the inner workings of deep neural networks and allow us to mathematically calculate optimal solutions for some stages of classification problems, thus significantly boosting our ability to solve such problems efficiently.'),
        })
        self._test_docs("nano-beir/scifact", count=2919, items={
            0: GenericDoc('5836', 'Myelodysplastic syndromes (MDS) are age-dependent stem cell malignancies that share biological features of activated adaptive immune response and ineffective hematopoiesis. Here we report that myeloid-derived suppressor cells (MDSC), which are classically linked to immunosuppression, inflammation, and cancer, were markedly expanded in the bone marrow of MDS patients and played a pathogenetic role in the development of ineffective hematopoiesis. These clonally distinct MDSC overproduce hematopoietic suppressive cytokines and function as potent apoptotic effectors targeting autologous hematopoietic progenitors. Using multiple transfected cell models, we found that MDSC expansion is driven by the interaction of the proinflammatory molecule S100A9 with CD33. These 2 proteins formed a functional ligand/receptor pair that recruited components to CD33’s immunoreceptor tyrosine-based inhibition motif (ITIM), inducing secretion of the suppressive cytokines IL-10 and TGF-β by immature myeloid cells. S100A9 transgenic mice displayed bone marrow accumulation of MDSC accompanied by development of progressive multilineage cytopenias and cytological dysplasia. Importantly, early forced maturation of MDSC by either all-trans-retinoic acid treatment or active immunoreceptor tyrosine-based activation motif–bearing (ITAM-bearing) adapter protein (DAP12) interruption of CD33 signaling rescued the hematologic phenotype. These findings indicate that primary bone marrow expansion of MDSC driven by the S100A9/CD33 pathway perturbs hematopoiesis and contributes to the development of MDS.'),
            9: GenericDoc('104130', 'Bone tissue undergoes constant turnover supported by stem cells. Recent studies showed that perivascular mesenchymal stem cells (MSCs) contribute to the turnover of long bones. Craniofacial bones are flat bones derived from a different embryonic origin than the long bones. The identity and regulating niche for craniofacial-bone MSCs remain unknown. Here, we identify Gli1+ cells within the suture mesenchyme as the main MSC population for craniofacial bones. They are not associated with vasculature, give rise to all craniofacial bones in the adult and are activated during injury repair. Gli1+ cells are typical MSCs in vitro. Ablation of Gli1+ cells leads to craniosynostosis and arrest of skull growth, indicating that these cells are an indispensable stem cell population. Twist1(+/-) mice with craniosynostosis show reduced Gli1+ MSCs in sutures, suggesting that craniosynostosis may result from diminished suture stem cells. Our study indicates that craniofacial sutures provide a unique niche for MSCs for craniofacial bone homeostasis and repair.'),
            2918: GenericDoc('196664003', 'A signaling pathway transmits information from an upstream system to downstream systems, ideally in a unidirectional fashion. A key obstacle to unidirectional transmission is retroactivity, the additional reaction flux that affects a system once its species interact with those of downstream systems. This raises the fundamental question of whether signaling pathways have developed specialized architectures that overcome retroactivity and transmit unidirectional signals. Here, we propose a general procedure based on mathematical analysis that provides an answer to this question. Using this procedure, we analyze the ability of a variety of signaling architectures to transmit one-way (from upstream to downstream) signals, as key biological parameters are tuned. We find that single stage phosphorylation and phosphotransfer systems that transmit signals from a kinase show a stringent design trade-off that hampers their ability to overcome retroactivity. Interestingly, cascades of these architectures, which are highly represented in nature, can overcome this trade-off and thus enable unidirectional transmission. By contrast, phosphotransfer systems, and single and double phosphorylation cycles that transmit signals from a substrate are unable to mitigate retroactivity effects, even when cascaded, and hence are not well suited for unidirectional information transmission. Our results identify signaling architectures that, allowing unidirectional transmission of signals, embody modular processes that conserve their input/output behavior across multiple contexts. These findings can be used to decompose natural signal transduction networks into modules, and, at the same time, they establish a library of devices that can be used in synthetic biology to facilitate modular circuit design.'),
        })
        self._test_docs("nano-beir/webis-touche2020", count=5745, items={
            0: GenericDoc('ffd45b01-2019-04-18T18:54:19Z-00004-000', "Well, we meet again. If we were to prevent MLB players from entering the Hall of Fame because they used steroids; nearly every All-Star from 1980 to early 2000's would be ineligible. Take a look at the Mitchell Report, and you will find a list of incredible players which is far too long to list on here, who would all be banned from baseball's greatest honor. Steroids were just as part of the game during the 80's and 90's as Peanuts and Cracker Jacks. It was an era of steroids. If you weren't using them, then you were considered abnormal. You cannot fault an entire generation of players for just being a product of the times. I agree that records, such as the HR record broken by Bonds, should have an asterisk with them, but this should not be the case with the Hall of Fame. If we were to do what you propose, then from 1980 to 2000 there would be about 5 people in the Hall."),
            9: GenericDoc('934989d9-2019-04-18T11:38:17Z-00000-000', 'Enacting more gun laws in the United States would not stop crimes or dangerous situations from occurring. In fact, according to the National Academy of Sciences, Justice Department, there is no apparent link between restrictions on gun ownership and lower rates of crime, firearms violence, or even accidents with guns. Creating such laws would not stop criminals from committing crimes. As John R Lott, the author of "More Guns, Less Crime: Understanding Crime and Gun Control Laws", stated in 1998, "States with the largest increases in gun ownership also have the largest drops in violent crimes". In other words, increasing the number of guns did not increase the rate of violent crimes but instead decreased. With this, it is clear that people should be able to own guns because doing so prevents more crimes from occurring than actual gun laws. University of Chicago Press. (1998). Interview with John R. Lott, Jr. Retrieved March 28, 2018, from http://press.uchicago.edu... WND. (2004, December 30). Gun control doesn\'t reduce crime, violence, say studies. Retrieved March 28, 2018, from http://mobile.wnd.com...'),
            5744: GenericDoc('671509c8-2019-04-17T11:47:34Z-00051-000', 'Charter school administrators can hand-pick the best teachers'),
        })

    def test_queries(self):
        self._test_queries("nano-beir/arguana", count=50, items={
            0: GenericQuery('test-science-wsihwclscaaw-con01a', 'Cyber attacks are often carried out by non-state actors  Cyber attacks are often carried out by non-state actors, such as cyberterrorists or hacktivists (social activists who hack), without any involvement of the actual state. For instance, in 2007 a massive cyber attack launched on Estonia was blamed on Russia due to the then on-going tensions between these two states [17]. However, the attacks on Estonia were generated from all over the world; and even those from Russia could not have been linked to the Russian authorities, who denied involvement. Similarly, a huge wave of cyber attacks dubbed GhostNet that compromised computers in 103 countries in 2009 was blamed on China, not the least for hacking computers of Tibetan authorities. However, it could not be conclusively proven that this was an attack perpetrated by the Chinese authorities [18]. Any retaliation against a state for a cyber attack can never be certain to be against the right target – the state should not be blamed for the actions of its individual citizens.'),
            9: GenericQuery('test-politics-gvhbhlsbr-con04a', "The public is apathetic to reform.  Whether or not reform of the House of Lords should be a top priority in the current economic climate is debateable, let alone whether or not a coalition government would be able to initiate and drive through such measures. Attempts to reform the House of Lords have been delayed time and time again, demonstrating the House of Commons’ reservations on change. [1] A feeling that is no doubt echoed in popular British opinion – as demonstrated by the recent outcome of the Alternative Vote – the public are either adverse to the idea of change or apathetic to it. [2]  [1] Summers, Deborah, ‘Labour's attempts to reform the House of Lords’, The Guardian (27 January, 2009), viewed on 1 June 2011   [2] BBC News, ‘Vote 2011: UK rejects alternative vote, 7 May 2011,"),
            49: GenericQuery('test-politics-lghwdecm-con02a', 'Directly elected mayors provide opportunities for populists.  The position of elected mayor is likely to attract populist and maverick candidates, who will seek to capitalise on the unpopularity of party politics with “single issue sloganising, glib promises and headline grabbing” (Ken Walker, Labour leader of Middlesbrough council). [1] A good example is Paul Massey, who has had 25 convictions in the past and yet is running to be Mayor of Salford and could even have a chance of winning. [2] In office such candidates are likely to alienate elected councillors and other crucial local partners, to disappoint voters as their promises run up against the actual limitations of their power, and to neglect many aspects of local government in favour of their own pet issue. This danger is even greater if a far-right candidate were to exploit local concerns about immigration and asylum-seekers to inflame racial tensions. Again Lutfur Rahman of Tower Hamlets is a good example of how this could happen, he has links to a Muslim extremist group, and only needed a mere 23,000 votes, 13% of the electorate because there was such low turnout. [3]  [1] Hetherington, Peter, ‘Vote for US-style mayors exposes deep Labour rifts’, The Guardian, 20 October 2001.  [2] Gilligan, Andrew, ;The town hall dictator taking over near you’, The Telegraph, 22 April 2012.  [3] ibid'),
        })
        self._test_queries("nano-beir/climate-fever", count=50, items={
            0: GenericQuery('555', 'In Alaska, brown bears are changing their feeding habits to eat elderberries that ripen earlier.'),
            9: GenericQuery('1390', '“Lyme Disease is much more common in northern, cooler regions of the United States than in southern, warmer regions.'),
            49: GenericQuery('1157', '“In 2013 the level of U.S. farm output was about 2.7 times its 1948 level, and productivity was growing at an average annual rate of 1.52%.'),
        })
        self._test_queries("nano-beir/dbpedia-entity", count=50, items={
            0: GenericQuery('INEX_LD-2012319', '1994 short story collection Alice Munro is Open'),
            9: GenericQuery('INEX_XER-143', 'Hanseatic league in Germany in the Netherlands Circle'),
            49: GenericQuery('INEX_LD-20120332', 'tango dance history'),
        })
        self._test_queries("nano-beir/fever", count=50, items={
            0: GenericQuery('74951', 'Caesar is an original play by Orson Welles.'),
            9: GenericQuery('179112', 'The Good German starred Tobey Maguire.'),
            49: GenericQuery('85454', 'Nero is a person.'),
        })
        self._test_queries("nano-beir/fiqa", count=50, items={
            0: GenericQuery('3357', 'Why big clients want the contractor to be incorporated before giving them work'),
            9: GenericQuery('1736', 'How can people have such high credit card debts?'),
            49: GenericQuery('8378', 'Should I wait a few days to sell ESPP Stock?'),
        })
        self._test_queries("nano-beir/hotpotqa", count=50, items={
            0: GenericQuery('5ae5669755429960a22e02ec', 'Which of the campaign that brought out the term Vichy Republican on social media was formally launched on June 16, 2015, at Trump Tower in New York City?'),
            9: GenericQuery('5ac4e593554299076e296e37', 'OU812 was the second album to feature a vocalist that also played what instrument in "Finish What Ya Started"?'),
            49: GenericQuery('5a81ed345542995ce29dcc85', 'The Florida Atlantic Owls team represents a school classified by the Carnegie Foundation as what?'),
        })
        self._test_queries("nano-beir/msmarco", count=50, items={
            0: GenericQuery('994479', 'which health care system provides all citizens or residents with equal access to health care services'),
            9: GenericQuery('1048359', 'what is php in mental health care'),
            49: GenericQuery('1049867', 'who sang here i go again'),
        })
        self._test_queries("nano-beir/nfcorpus", count=50, items={
            0: GenericQuery('PLAIN-2800', 'Prolonged Liver Function Enhancement From Broccoli'),
            9: GenericQuery('PLAIN-2301', 'uterine health'),
            49: GenericQuery('PLAIN-3271', 'Saturated Fat & Cancer Progression'),
        })
        self._test_queries("nano-beir/nq", count=50, items={
            0: GenericQuery('test1618', 'was nightmare before christmas originally a disney movie'),
            9: GenericQuery('test2845', 'how many paintings of sunflowers did van gogh paint'),
            49: GenericQuery('test2247', 'here we go round the mulberry bush origin'),
        })
        self._test_queries("nano-beir/quora", count=50, items={
            0: GenericQuery('127728', 'Why does Quora frequently suggest answers to my feed that put down Donald Trump?'),
            9: GenericQuery('14755', 'How often is it good to masturbate?'),
            49: GenericQuery('215681', 'What can I do to get more energy?'),
        })
        self._test_queries("nano-beir/scidocs", count=50, items={
            0: GenericQuery('a352061134daa2c47861b8c4216ee5482a93be1d', 'BPM Governance: An Exploratory Study in Public Organizations'),
            9: GenericQuery('88ee8b13451deac38384c9f31196227f2535aa65', 'Stochastic Geometric Analysis of User Mobility in Heterogeneous Wireless Networks'),
            49: GenericQuery('458f1428273254fc5dd399f3c104f507680ddd54', 'Measuring discrimination in algorithmic decision making'),
        })
        self._test_queries("nano-beir/scifact", count=50, items={
            0: GenericQuery('514', 'High dietary calcium intakes are unnecessary for prevention of secondary hyperparathyroidism in subjects with 25(OH)D levels above 75 nmol/liter.'),
            9: GenericQuery('1202', 'The center of the granuloma in an immune cell induces a pro-inflammatory immune response.'),
            49: GenericQuery('1278', 'The treatment of cancer patients with co-IR blockade does not cause any adverse autoimmune events.'),
        })
        self._test_queries("nano-beir/webis-touche2020", count=49, items={
            0: GenericQuery('47', 'Is homework beneficial?'),
            9: GenericQuery('14', 'Is sexual orientation determined at birth?'),
            48: GenericQuery('33', 'Should people become vegetarian?'),
        })

    def test_qrels(self):
        self._test_qrels("nano-beir/arguana", count=50, items={
            0: TrecQrel('test-science-wsihwclscaaw-con01a', 'test-science-wsihwclscaaw-con01b', 1, '0'),
            9: TrecQrel('test-politics-gvhbhlsbr-con04a', 'test-politics-gvhbhlsbr-con04b', 1, '0'),
            49: TrecQrel('test-politics-lghwdecm-con02a', 'test-politics-lghwdecm-con02b', 1, '0'),
        })
        self._test_qrels("nano-beir/climate-fever", count=148, items={
            0: TrecQrel('555', 'Brown_bear', 1, '0'),
            9: TrecQrel('971', 'Effects_of_global_warming', 1, '0'),
            147: TrecQrel('1157', 'Reaganomics', 1, '0'),
        })
        self._test_qrels("nano-beir/dbpedia-entity", count=1158, items={
            0: TrecQrel('INEX_LD-2012319', '<dbpedia:Alice_Munro>', 1, '0'),
            9: TrecQrel('INEX_XER-87', '<dbpedia:Axis_occupation_of_Serbia>', 1, '0'),
            1157: TrecQrel('INEX_LD-20120332', '<dbpedia:Uruguayan_tango>', 1, '0'),
        })
        self._test_qrels("nano-beir/fever", count=57, items={
            0: TrecQrel('74951', 'Caesar_(Mercury_Theatre)', 1, '0'),
            9: TrecQrel('109817', 'Louis_Malle', 1, '0'),
            56: TrecQrel('85454', 'Nero', 1, '0'),
        })
        self._test_qrels("nano-beir/fiqa", count=123, items={
            0: TrecQrel('3357', '209974', 1, '0'),
            9: TrecQrel('6199', '414693', 1, '0'),
            122: TrecQrel('8378', '125298', 1, '0'),
        })
        self._test_qrels("nano-beir/hotpotqa", count=100, items={
            0: TrecQrel('5ae5669755429960a22e02ec', '49892372', 1, '0'),
            9: TrecQrel('5ae0ae4555429945ae959419', '76592', 1, '0'),
            99: TrecQrel('5a81ed345542995ce29dcc85', '880200', 1, '0'),
        })
        self._test_qrels("nano-beir/msmarco", count=50, items={
            0: TrecQrel('994479', '7275120', 1, '0'),
            9: TrecQrel('1048359', '7187663', 1, '0'),
            49: TrecQrel('1049867', '7946528', 1, '0'),
        })
        self._test_qrels("nano-beir/nfcorpus", count=2518, items={
            0: TrecQrel('PLAIN-2800', 'MED-4040', 1, '0'),
            9: TrecQrel('PLAIN-2800', 'MED-4050', 1, '0'),
            2517: TrecQrel('PLAIN-3271', 'MED-3790', 1, '0'),
        })
        self._test_qrels("nano-beir/nq", count=57, items={
            0: TrecQrel('test1618', 'doc57226', 1, '0'),
            9: TrecQrel('test2845', 'doc97421', 1, '0'),
            56: TrecQrel('test2247', 'doc77971', 1, '0'),
        })
        self._test_qrels("nano-beir/quora", count=70, items={
            0: TrecQrel('127728', '127729', 1, '0'),
            9: TrecQrel('287245', '322650', 1, '0'),
            69: TrecQrel('215681', '215680', 1, '0'),
        })
        self._test_qrels("nano-beir/scidocs", count=244, items={
            0: TrecQrel('a352061134daa2c47861b8c4216ee5482a93be1d', '38d555bfe13b61e838364016219c7e42fb5dc919', 1, '0'),
            9: TrecQrel('f4195462f27158c4afd86ca364347dacfd228bdd', '59fa9d40d129f18f1f3193f65935fcb9e2042afb', 1, '0'),
            243: TrecQrel('458f1428273254fc5dd399f3c104f507680ddd54', '4556f3f9463166aa3e27b2bec798c0ca7316bd65', 1, '0'),
        })
        self._test_qrels("nano-beir/scifact", count=56, items={
            0: TrecQrel('514', '16256507', 1, '0'),
            9: TrecQrel('971', '28617573', 1, '0'),
            55: TrecQrel('1278', '11335781', 1, '0'),
        })
        self._test_qrels("nano-beir/webis-touche2020", count=932, items={
            0: TrecQrel('47', '48cd3dfc-2019-04-18T13:56:49Z-00004-000', 1, '0'),
            9: TrecQrel('47', '1733befb-2019-04-18T15:36:46Z-00003-000', 1, '0'),
            931: TrecQrel('33', '916864f7-2019-04-18T11:10:13Z-00002-000', 1, '0'),
        })

       
if __name__ == '__main__':
    unittest.main()
