Navigation

Quick search

Enter search terms or a module, class or function name.

Source code for datasets.majmin

# Copyright 2011 Hugo Larochelle. All rights reserved.# # Redistribution and use in source and binary forms, with or without modification, are# permitted provided that the following conditions are met:# # 1. Redistributions of source code must retain the above copyright notice, this list of# conditions and the following disclaimer.# # 2. Redistributions in binary form must reproduce the above copyright notice, this list# of conditions and the following disclaimer in the documentation and/or other materials# provided with the distribution.# # THIS SOFTWARE IS PROVIDED BY Hugo Larochelle ``AS IS'' AND ANY EXPRESS OR IMPLIED# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Hugo Larochelle OR# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.# # The views and conclusions contained in the software and documentation are those of the# authors and should not be interpreted as representing official policies, either expressed# or implied, of Hugo Larochelle."""Module ``datasets.majmin`` gives access to the MajMin dataset.| **Reference:** | A Web-Based Game for Collecting Music Metadata| Mandel and Ellis| http://mr-pc.org/work/jnmr08.pdf"""importmlpython.misc.ioasmlioimportnumpyasnpimportos

[docs]defload(dir_path,load_to_memory=False):""" Loads the MajMin dataset. The data is given by a dictionary mapping from strings ``'train'``, ``'valid'`` and ``'test'`` to the associated pair of data and metadata. **Defined metadata:** * ``'input_size'`` * ``'target_size'`` * ``'length'`` """input_size=389target_size=96dir_path=os.path.expanduser(dir_path)defconvert_target(target_str):targets=np.zeros((target_size))iftarget_str!='':forlintarget_str.split(','):id=int(l)targets[id]=1returntargetsdefload_line(line):returnmlio.libsvm_load_line(line,convert_target=convert_target,sparse=False,input_size=input_size)train_file,valid_file,test_file=[os.path.join(dir_path,'majmin_'+ds+'.libsvm')fordsin['train','valid','test']]# Get datatrain,valid,test=[mlio.load_from_file(f,load_line)forfin[train_file,valid_file,test_file]]lengths=[1587,471,480]ifload_to_memory:train,valid,test=[mlio.MemoryDataset(d,[(input_size,),(target_size,)],[np.float64,bool],l)ford,linzip([train,valid,test],lengths)]# Get metadatatrain_meta,valid_meta,test_meta=[{'input_size':input_size,'target_size':target_size,'length':l}forlinlengths]return{'train':(train,train_meta),'valid':(valid,valid_meta),'test':(test,test_meta)}

[docs]defobtain(dir_path):""" Downloads the dataset to ``dir_path``. """dir_path=os.path.expanduser(dir_path)print'Downloading the dataset'importurlliburllib.urlretrieve('http://www.cs.toronto.edu/~larocheh/public/datasets/majmin/majmin_train.libsvm',os.path.join(dir_path,'majmin_train.libsvm'))urllib.urlretrieve('http://www.cs.toronto.edu/~larocheh/public/datasets/majmin/majmin_valid.libsvm',os.path.join(dir_path,'majmin_valid.libsvm'))urllib.urlretrieve('http://www.cs.toronto.edu/~larocheh/public/datasets/majmin/majmin_test.libsvm',os.path.join(dir_path,'majmin_test.libsvm'))print'Done '