├── .gitignore ├── LICENSE ├── README.txt ├── analogy ├── code │ ├── evaluateAnalogy.m │ ├── loadWeWords.m │ ├── run_analogy.sh │ └── splitWordVectorFile.sh └── data │ ├── capital-common-countries.txt │ ├── capital-world.txt │ ├── city-in-state.txt │ ├── currency.txt │ ├── family.txt │ ├── gram1-adjective-to-adverb.txt │ ├── gram2-opposite.txt │ ├── gram3-comparative.txt │ ├── gram4-superlative.txt │ ├── gram5-present-participle.txt │ ├── gram6-nationality-adjective.txt │ ├── gram7-past-tense.txt │ ├── gram8-plural.txt │ └── gram9-plural-verbs.txt ├── bivec.c ├── cldc ├── build.xml └── scripts │ ├── de2en │ ├── prepare-data-klement-4cat-1000-my-embeddings.ch │ └── run-perceptron-1000-my-embeddings.ch │ └── en2de │ ├── prepare-data-klement-4cat-1000-my-embeddings.ch │ └── run-perceptron-1000-my-embeddings.ch ├── compute-accuracy.c ├── data ├── data.10k.align ├── data.10k.de └── data.10k.en ├── demo-bi-cbow-neg.sh ├── demo-bi-cbow.sh ├── demo-bi-sg-neg.sh ├── demo-bi-sg.sh ├── demo-mono-cbow-neg.sh ├── demo-mono-cbow.sh ├── demo-mono-classes.sh ├── demo-mono-distance.sh ├── demo-mono-sg-neg.sh ├── demo-mono-sg.sh ├── distance.c ├── git_commit.sh ├── makefile ├── runCLDC.c ├── run_bi.sh ├── run_mono.sh ├── run_word2vec.sh ├── scripts ├── select_words.py └── visual.py ├── word-analogy.c ├── word2phrase.c ├── word2vec.c └── wordsim ├── annotation ├── de.1.seb.txt ├── de.1.txt ├── de.2.seb.txt ├── de.2.txt ├── de.3.seb.txt ├── de.3.txt ├── de.4.julia.txt ├── de.4.txt ├── de.5.julia.txt ├── de.5.txt ├── de.6.julia.txt ├── de.6.txt ├── de.txt ├── dict.en-de.txt ├── wordsim353.words.de.txt ├── wordsim353.words.en.txt └── ws353.en-de.xlsx ├── code ├── cell2map.m ├── evaluateWordSim.m ├── findUnkStr.m ├── getSimScore.m ├── getSimScores.m ├── loadWeWords.m ├── loadWordSimData.m ├── run_wordSim.sh ├── sltoolbox_r101 │ ├── license.txt │ └── sltoolbox_r101 │ │ ├── introduction.txt │ │ ├── readme.txt │ │ └── sltoolbox │ │ ├── ExpDL │ │ ├── @dataset │ │ │ ├── construct_dataset_filenames.m │ │ │ ├── disp.m │ │ │ ├── display.m │ │ │ ├── get.m │ │ │ ├── readfile.m │ │ │ ├── subsref.m │ │ │ └── writefile.m │ │ ├── ds1.xml │ │ ├── ds2.xml │ │ ├── dsdml.xsd │ │ ├── edl.spec.txt │ │ ├── edl_batchexp.m │ │ ├── edl_buildiidxdict.m │ │ ├── edl_check_internalindices.m │ │ ├── edl_go.m │ │ ├── edl_initctrlfile.m │ │ ├── edl_logerror.m │ │ ├── edl_readctrlfile.m │ │ ├── edl_readenvvars.m │ │ ├── edl_readexpdefs.m │ │ ├── edl_readexpdefs_old.m │ │ ├── edl_readprops.m │ │ ├── edl_readreport.m │ │ ├── edl_readscript.m │ │ ├── edl_updatectrlfile.m │ │ ├── edl_writeprops.m │ │ ├── edl_writereport.m │ │ ├── edl_writescript.m │ │ ├── example_samplegrps.xml │ │ └── example_samples.xml │ │ ├── ann │ │ ├── annsearch.m │ │ ├── annsearch_wrapper.cpp │ │ ├── annsearch_wrapper.mexw32 │ │ └── annsearch_wrapper.mexw64 │ │ ├── cluster │ │ ├── slkmeans.m │ │ └── slkmeansex.m │ │ ├── core │ │ ├── pwcalc_core.cpp │ │ ├── pwcalc_core.mexw32 │ │ ├── pwcalc_core.mexw64 │ │ ├── pwdiff_core.cpp │ │ ├── pwdiff_core.mexw32 │ │ ├── pwdiff_core.mexw64 │ │ ├── pwhamming_cimp.cpp │ │ ├── pwhamming_cimp.mexw32 │ │ ├── pwmetrics_cimp.cpp │ │ ├── pwmetrics_cimp.mexw32 │ │ ├── readme.html │ │ ├── rowcolop_core.cpp │ │ ├── rowcolop_core.mexw32 │ │ ├── rowcolop_core.mexw64 │ │ ├── sladd.m │ │ ├── sladdrowcols.m │ │ ├── sladdvec.m │ │ ├── slclassify_eucnn.m │ │ ├── slconfine.m │ │ ├── sldiff_pw.m │ │ ├── sldiscrep.m │ │ ├── sldistmean.m │ │ ├── slenforce.m │ │ ├── slinitarray.m │ │ ├── sllabeledsum.m │ │ ├── sllogdet.m │ │ ├── slmax.m │ │ ├── slmetric_cp.m │ │ ├── slmetric_pw.m │ │ ├── slmetric_pw_blks.m │ │ ├── slmetric_pw_compile.m │ │ ├── slmin.m │ │ ├── slmul.m │ │ ├── slmulrowcols.m │ │ ├── slmulvec.m │ │ ├── slnorm.m │ │ ├── slnormalize.m │ │ ├── slpwcalc.m │ │ ├── slpwcomp_blks.m │ │ ├── slpweval.m │ │ ├── slsum.m │ │ ├── slsumstat_blks.m │ │ ├── slsymeig.m │ │ ├── slsymgeig.m │ │ ├── vecop_core.cpp │ │ ├── vecop_core.mexw32 │ │ └── vecop_core.mexw64 │ │ ├── discrete │ │ ├── histmetricpw_core.cpp │ │ ├── histmetricpw_core.mexw32 │ │ ├── histmetricpw_core.mexw64 │ │ ├── slcountvote.m │ │ ├── slhistmetric_cp.m │ │ ├── slhistmetric_pw.m │ │ ├── slvechist.m │ │ └── slvote.m │ │ ├── fileio │ │ ├── @sllog │ │ │ ├── addfiles.m │ │ │ ├── close.m │ │ │ ├── decindent.m │ │ │ ├── detachfiles.m │ │ │ ├── get.m │ │ │ ├── incindent.m │ │ │ ├── isactive.m │ │ │ ├── isattached.m │ │ │ ├── setactive.m │ │ │ ├── sllog.m │ │ │ ├── subsref.m │ │ │ ├── write.m │ │ │ ├── writeblank.m │ │ │ └── writeinfo.m │ │ ├── array_fileformat.txt │ │ ├── report.txt │ │ ├── slchangefilepart.m │ │ ├── slcountlines.m │ │ ├── slfilepart.m │ │ ├── slimgsetprep.m │ │ ├── slisabspath.m │ │ ├── slmkdir.m │ │ ├── slreadarray.m │ │ ├── slreadtext.m │ │ ├── slrmdir.m │ │ ├── slwritearray.m │ │ └── slwritetext.m │ │ ├── graph │ │ ├── graph_represent.txt │ │ ├── sladjlist.m │ │ ├── sladjlist2edgeset.m │ │ ├── sladjmat.m │ │ ├── slaffinitymat.m │ │ ├── sledges2adjmat.m │ │ ├── sledgeset.m │ │ ├── sledgeset2adjlist.m │ │ ├── slfindnn.m │ │ ├── slgraphinfo.m │ │ ├── slmakeadjmat.m │ │ ├── slnngraph.m │ │ ├── slpruneedgeset.m │ │ ├── slpwgraph.m │ │ ├── slpwmetricgraph.m │ │ └── slsymgraph.m │ │ ├── imgproc │ │ ├── slapplyfilterband.m │ │ ├── slbenchmark_batchfilter.m │ │ ├── slcalcpadsize.m │ │ ├── slfiltersize.m │ │ ├── slgaborbands.m │ │ ├── slimginterp.m │ │ ├── slpadimg.m │ │ ├── slpixlinnorm.m │ │ ├── slpixneighbors.m │ │ ├── slresizeimg.m │ │ └── slvecfilters.m │ │ ├── install_cppcores.m │ │ ├── install_paths.m │ │ ├── interp │ │ └── slgetinterpkernel.m │ │ ├── kernel │ │ ├── slcenkernel.m │ │ ├── sldists2kernels.m │ │ ├── slgda.m │ │ ├── slkernel.m │ │ ├── slkernelfea.m │ │ ├── slkernels2dists.m │ │ ├── slkernelscatter.m │ │ ├── slkfd.m │ │ └── slkpca.m │ │ ├── learn │ │ ├── sliterproc.m │ │ ├── slproglearn.m │ │ └── slreevallearn.m │ │ ├── manifold │ │ ├── slcmds.m │ │ ├── slgembed.m │ │ ├── slisomap.m │ │ ├── slkernelembed.m │ │ ├── sllemap.m │ │ ├── sllle.m │ │ ├── sllle_wg.m │ │ ├── sllocalcoordalign.m │ │ ├── sllocaltancoords.m │ │ ├── sllocaltanspace.m │ │ ├── slltsa.m │ │ ├── slnbreconweights.m │ │ └── swiss_roll_data.mat │ │ ├── perfeval │ │ ├── slcorrectrate.m │ │ ├── slcorrectrate_blks.m │ │ ├── slcumuscore.m │ │ ├── slgetroc.m │ │ ├── slhistroc.m │ │ ├── slroc.m │ │ ├── slverifyroc.m │ │ └── slverifyroc_blks.m │ │ ├── regression │ │ ├── sllinreg.m │ │ ├── sllinrega.m │ │ └── sllogistreg.m │ │ ├── smallmat │ │ ├── sldet2x2.m │ │ ├── slinv2x2.m │ │ ├── slrotmat.m │ │ └── sltrace2x2.m │ │ ├── stat │ │ ├── gauss_struct.txt │ │ ├── gaussexample.mat │ │ ├── slcov.m │ │ ├── slcovlarge.m │ │ ├── slcovs.m │ │ ├── slfmm.m │ │ ├── slgausscomb.m │ │ ├── slgaussest.m │ │ ├── slgaussinv.m │ │ ├── slgaussmdist.m │ │ ├── slgausspdf.m │ │ ├── slgaussrnd.m │ │ ├── slgausstype.m │ │ ├── slgmm.m │ │ ├── slinvcov.m │ │ ├── slinvevals.m │ │ ├── slmean.m │ │ ├── slmeans.m │ │ ├── slpoolcov.m │ │ ├── slposteriori.m │ │ ├── slposterioritrue.m │ │ ├── slpwscatter.m │ │ ├── slregcov.m │ │ ├── slwhiten_from_cov.m │ │ └── slwhiten_from_samples.m │ │ ├── subspace │ │ ├── pca_struct.txt │ │ ├── slapplypca.m │ │ ├── slcopca.m │ │ ├── slcovpca.m │ │ ├── sldim_by_eigval.m │ │ ├── sldlda.m │ │ ├── slfld.m │ │ ├── slgbfe.m │ │ ├── sllda.m │ │ ├── slnlda.m │ │ ├── slnullspace.m │ │ ├── slpca.m │ │ ├── slpcarecon.m │ │ ├── slpcareduce.m │ │ ├── slrangespace.m │ │ └── slscatter.m │ │ ├── subspace_ex │ │ ├── sl2dmatcov.m │ │ ├── sl2dpca_apply.m │ │ ├── sl2dpca_construct.m │ │ ├── sl2dpcaex.m │ │ ├── slarrmean.m │ │ ├── slpartitionpca.m │ │ ├── slpartitionpca_apply.m │ │ └── slpartitionpca_construct.m │ │ ├── tensor │ │ ├── sltensor_dot.m │ │ ├── sltensor_fold.m │ │ ├── sltensor_multiply.m │ │ ├── sltensor_norm.m │ │ ├── sltensor_svd.m │ │ └── sltensor_unfold.m │ │ ├── text │ │ ├── slcompresstext.m │ │ ├── slfiltertext.m │ │ ├── slparse_assignment.m │ │ ├── slshowtext.m │ │ └── slstrsplit.m │ │ ├── utils │ │ ├── raise_lackinput.m │ │ ├── sladdpath.m │ │ ├── slallcombs.m │ │ ├── slallsubinds.m │ │ ├── slcartprod.m │ │ ├── slclassify.m │ │ ├── slclassify_blks.m │ │ ├── slcount.m │ │ ├── slequalpar2D.m │ │ ├── slevalfunctor.m │ │ ├── slexpand.m │ │ ├── slgridsamples.m │ │ ├── slignorevars.m │ │ ├── slimg2mat.m │ │ ├── slinvoke.m │ │ ├── slisfields.m │ │ ├── sllabelinds.m │ │ ├── slnums2bounds.m │ │ ├── slparblocks.m │ │ ├── slparseprops.m │ │ ├── slpartition.m │ │ ├── slrange2indcells.m │ │ ├── slsharedisp.m │ │ ├── slsharedisp_attach.m │ │ ├── slsharedisp_decindent.m │ │ ├── slsharedisp_detach.m │ │ ├── slsharedisp_incindent.m │ │ ├── slsharedisp_reset.m │ │ ├── slsharedisp_word.m │ │ ├── slstructsize.m │ │ ├── sltakeval.m │ │ ├── sltypesize.m │ │ └── slverifyroc_par.m │ │ ├── utils_ex │ │ ├── slguid.m │ │ ├── slguidstr.m │ │ ├── slisguid.m │ │ ├── win32guid_core.cpp │ │ ├── win32guid_core.mexw32 │ │ └── win32guid_core.mexw64 │ │ ├── visualize │ │ ├── sldrawellipse.m │ │ ├── sldrawgraph.m │ │ ├── sldrawlabeledpts.m │ │ ├── sldrawmanipts.m │ │ ├── sldrawmultiellipse.m │ │ └── sldrawpts.m │ │ └── xmlkits │ │ ├── xml_addattribs.m │ │ └── xml_getattribs.m └── splitWordVectorFile.sh └── data ├── MC.txt ├── RG.txt ├── de.txt ├── rare.txt ├── scws.txt ├── ws353.txt └── zh.txt /.gitignore: -------------------------------------------------------------------------------- 1 | cldc/* 2 | test 3 | trunk 4 | vectors.bin* 5 | text2vec 6 | bivec 7 | runCLDC 8 | output/* 9 | cldc/data/* 10 | *compute-accuracy 11 | *distance 12 | *word-analogy 13 | *word2phrase 14 | *word2vec 15 | data/* 16 | *.ps 17 | *.out 18 | *.swp 19 | .classpath 20 | .DS* 21 | .cproject 22 | .project 23 | .settings* 24 | # Java 25 | *.class 26 | *.jar 27 | # Compress files 28 | *.gz 29 | *.zip 30 | # Version control 31 | *CVS* 32 | *.svn* 33 | # Latex 34 | *.aux 35 | *.bbl 36 | *.blg 37 | *.dvi 38 | *.log 39 | *.bak 40 | *.o 41 | # Visual studio, C# 42 | *debug* 43 | *Debug* 44 | *.deps* 45 | *ReSharper* 46 | *~ 47 | *.ncb 48 | *\#* 49 | *LUONGMINHTHANG* 50 | *resharper* 51 | *.suo 52 | # Tmp files 53 | *archive* 54 | *tmp* 55 | *nohup.out* 56 | -------------------------------------------------------------------------------- /analogy/code/run_analogy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Author: Minh-Thang Luong , created on Thu Feb 21 16:32:43 PST 2013 3 | 4 | if [[ ! $# -eq 2 && ! $# -eq 2 ]] 5 | then 6 | echo "`basename $0` modelFile modelFormat" 7 | echo "lang: en or de" 8 | echo "modelFormat : 0 -- Matlab file," 9 | echo " 1 -- text file with a header line . Subsequent lines has ." 10 | echo " 2 -- text file with each line has " 11 | echo " 3 -- assume that there are two files modelFile.We, modelFile.words" 12 | exit 13 | fi 14 | 15 | modelFile=$1 16 | modelFormat=$2 17 | 18 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 19 | cd $DIR 20 | if [ "$modelFormat" -eq 1 ]; then # split We, words 21 | ./splitWordVectorFile.sh $modelFile $modelFile 22 | modelFormat=3 23 | fi 24 | matlab -nodesktop -nodisplay -nosplash -r "evaluateAnalogy('$modelFile', $modelFormat, '../data/', 0, 1);exit;" | tail -n +15 25 | 26 | 27 | -------------------------------------------------------------------------------- /analogy/code/splitWordVectorFile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! $# -eq 2 && ! $# -eq 2 ]] 4 | then 5 | echo "`basename $0` wordVectorFile outPrefix" 6 | exit 7 | fi 8 | 9 | wordVectorFile=$1 10 | outPrefix=$2 11 | outDir=`dirname $outPrefix` 12 | 13 | # check outDir exists 14 | #echo "# outDir $outDir" 15 | if [ ! -d $outDir ] 16 | then 17 | # echo "# Directory exists $outDir" 18 | #else 19 | mkdir -p $outDir 20 | fi 21 | 22 | 23 | inFile=$1 24 | numWords=`tail -1 $inFile | wc -w` 25 | let numDimensions=numWords-1 26 | #echo "numDimensions=$numDimensions" 27 | 28 | numWordsFirstLine=`head -1 $inFile | wc -w` 29 | if [ $numWordsFirstLine -ne $numWords ]; then # remove the first line (needed for output from word2vec where the first line contains the number words and the dimension) 30 | #echo "tail -n +2 $inFile > $inFile.tmp" 31 | tail -n +2 $inFile > $inFile.tmp 32 | inFile=$inFile.tmp 33 | fi 34 | 35 | cut -d " " -f 1 $inFile > $outPrefix.words 36 | cut -d " " -f 2- $inFile > $outPrefix.We 37 | 38 | if [ $numWordsFirstLine -ne $numWords ]; then 39 | rm -rf $inFile 40 | fi 41 | 42 | -------------------------------------------------------------------------------- /cldc/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | simple example bin file 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /cldc/scripts/de2en/prepare-data-klement-4cat-1000-my-embeddings.ch: -------------------------------------------------------------------------------- 1 | datapath=../../data 2 | 3 | prefix=$1 4 | #echo "de2en prepare data all sizes" 5 | #echo [Preparing test set for EN] 6 | java -ea -Xmx2000m -cp ../../bin CollectionPreprocessor --rnnlm --text-dir $datapath/rcv-from-binod/test/en --idf $datapath/idfs/idf.en --word-embeddings $prefix.en --vector-file $prefix.doc.test.en-de.en 7 | 8 | #echo [Preparing train set for DE] 9 | java -ea -Xmx2000m -cp ../../bin CollectionPreprocessor --rnnlm --text-dir $datapath/rcv-from-binod/train/DE1000 --idf $datapath/idfs/idf.de --word-embeddings $prefix.de --vector-file $prefix.doc.train.en-DE1000.de 10 | -------------------------------------------------------------------------------- /cldc/scripts/de2en/run-perceptron-1000-my-embeddings.ch: -------------------------------------------------------------------------------- 1 | datapath=../../data 2 | 3 | prefix=$1 4 | #echo "Training on DE1000 $prefix" 5 | java -ea -Xmx2000m -cp ../../bin ApLearn --train-set $prefix.doc.train.en-DE1000.de --model-name $prefix.classifiers.avperc.en-de.en --epoch-num 10 6 | java -ea -Xmx2000m -cp ../../bin ApClassify --test-set $prefix.doc.test.en-de.en --model-name $prefix.classifiers.avperc.en-de.en 7 | 8 | -------------------------------------------------------------------------------- /cldc/scripts/en2de/prepare-data-klement-4cat-1000-my-embeddings.ch: -------------------------------------------------------------------------------- 1 | datapath=../../data 2 | 3 | prefix=$1 4 | #echo "en2de prepare data all sizes" 5 | #echo [Preparing test set for DE] 6 | java -ea -Xmx2000m -cp ../../bin CollectionPreprocessor --rnnlm --text-dir $datapath/rcv-from-binod/test/de --idf $datapath/idfs/idf.de --word-embeddings $prefix.de --vector-file $prefix.doc.test.de-en.de 7 | 8 | #echo [Preparing train set for EN] 9 | java -ea -Xmx2000m -cp ../../bin CollectionPreprocessor --rnnlm --text-dir $datapath/rcv-from-binod/train/EN1000 --idf $datapath/idfs/idf.en --word-embeddings $prefix.en --vector-file $prefix.doc.train.de-EN1000.en 10 | 11 | -------------------------------------------------------------------------------- /cldc/scripts/en2de/run-perceptron-1000-my-embeddings.ch: -------------------------------------------------------------------------------- 1 | datapath=../../data 2 | 3 | prefix=$1 4 | #echo "Training on EN1000 $prefix" 5 | java -ea -Xmx2000m -cp ../../bin ApLearn --train-set $prefix.doc.train.de-EN1000.en --model-name $prefix.classifiers.avperc.de-en.de --epoch-num 10 6 | java -ea -Xmx2000m -cp ../../bin ApClassify --test-set $prefix.doc.test.de-en.de --model-name $prefix.classifiers.avperc.de-en.de 7 | 8 | -------------------------------------------------------------------------------- /demo-bi-cbow-neg.sh: -------------------------------------------------------------------------------- 1 | make -f makefile clean 2 | make -f makefile 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | command="./bivec -src-train data/data.10k.de -src-lang de -tgt-train data/data.10k.en -tgt-lang en -align data/data.10k.align -output output/vectors -cbow 1 -size 200 -window 5 -negative 5 -hs 0 -sample 1e-3 -tgt-sample 1e-3 -threads 1 -binary 0 -eval 1 -iter 3 -align-opt 1" 8 | echo "time $command" 9 | time $command 10 | 11 | -------------------------------------------------------------------------------- /demo-bi-cbow.sh: -------------------------------------------------------------------------------- 1 | make -f makefile clean 2 | make -f makefile 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | command="./bivec -src-train data/data.10k.de -src-lang de -tgt-train data/data.10k.en -tgt-lang en -align data/data.10k.align -output output/vectors -cbow 1 -size 200 -window 5 -negative 0 -hs 1 -sample 1e-3 -tgt-sample 1e-3 -threads 1 -binary 0 -eval 1 -iter 3 -align-opt 1" 8 | echo "time $command" 9 | time $command 10 | 11 | -------------------------------------------------------------------------------- /demo-bi-sg-neg.sh: -------------------------------------------------------------------------------- 1 | make -f makefile clean 2 | make -f makefile 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | command="./bivec -src-train data/data.10k.de -src-lang de -tgt-train data/data.10k.en -tgt-lang en -align data/data.10k.align -output output/vectors -cbow 0 -size 200 -window 5 -negative 5 -hs 0 -sample 1e-3 -tgt-sample 1e-3 -threads 1 -binary 0 -eval 1 -iter 3 -align-opt 4" 8 | echo "time $command" 9 | time $command 10 | 11 | -------------------------------------------------------------------------------- /demo-bi-sg.sh: -------------------------------------------------------------------------------- 1 | make -f makefile clean 2 | make -f makefile 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | command="./bivec -src-train data/data.10k.de -src-lang de -tgt-train data/data.10k.en -tgt-lang en -align data/data.10k.align -output output/vectors -cbow 0 -size 200 -window 5 -negative 0 -hs 1 -sample 1e-3 -tgt-sample 1e-3 -threads 1 -binary 0 -eval 1 -iter 3 -bi-weight 1.0 -align-opt 1" 8 | echo "time $command" 9 | time $command 10 | 11 | -------------------------------------------------------------------------------- /demo-mono-cbow-neg.sh: -------------------------------------------------------------------------------- 1 | make clean 2 | make 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | args="-src-train data/data.10k.en -src-lang en -output output/vectors -cbow 1 -size 200 -window 5 -negative 5 -hs 0 -sample 1e-3 -threads 1 -binary 0 -eval 1-iter 3" 8 | echo "time ./bivec $args" 9 | time ./bivec $args 10 | -------------------------------------------------------------------------------- /demo-mono-cbow.sh: -------------------------------------------------------------------------------- 1 | make clean 2 | make 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | args="-src-train data/data.10k.en -src-lang en -output output/vectors -cbow 1 -size 200 -window 5 -negative 0 -hs 1 -sample 1e-3 -threads 1 -binary 0 -eval 1 -iter 3" 8 | echo "time ./bivec $args" 9 | time ./bivec $args 10 | -------------------------------------------------------------------------------- /demo-mono-classes.sh: -------------------------------------------------------------------------------- 1 | make clean 2 | make 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | args="-src-train data/data.10k.en -src-lang en -output output/vectors -cbow 1 -size 200 -window 5 -negative 0 -hs 1 -sample 1e-3 -threads 1 -binary 0 -eval 1 -iter 3 -classes 10" 8 | echo "time ./bivec $args" 9 | time ./bivec $args 10 | -------------------------------------------------------------------------------- /demo-mono-distance.sh: -------------------------------------------------------------------------------- 1 | make clean 2 | make 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | DATA=data/data.10k.en #"/Users/lmthang/RA/sentiment/aclImdb/preprocessed/train.text.tok" # 8 | args="-src-train $DATA -src-lang en -output output/vectors -cbow 1 -size 200 -window 5 -negative 0 -hs 1 -sample 1e-3 -threads 1 -binary 1 -eval 0" 9 | echo "time ./bivec $args" 10 | time ./bivec $args 11 | 12 | echo "./distance output/vectors.en" 13 | ./distance output/vectors.en 14 | -------------------------------------------------------------------------------- /demo-mono-sg-neg.sh: -------------------------------------------------------------------------------- 1 | make clean 2 | make 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | command="./bivec -src-train data/data.10k.en -src-lang en -output output/vectors -cbow 0 -size 200 -window 5 -negative 5 -hs 0 -sample 1e-3 -threads 1 -binary 0 -eval 1 -iter 3" 8 | echo "time $command" 9 | time $command 10 | 11 | -------------------------------------------------------------------------------- /demo-mono-sg.sh: -------------------------------------------------------------------------------- 1 | make clean 2 | make 3 | if [ ! -d "output" ]; then 4 | mkdir output 5 | fi 6 | 7 | command="./bivec -src-train data/data.10k.en -src-lang en -output output/vectors -cbow 0 -size 200 -window 5 -negative 0 -hs 1 -sample 1e-3 -threads 1 -binary 0 -eval 1 -iter 3" 8 | echo "time $command" 9 | time $command 10 | 11 | -------------------------------------------------------------------------------- /git_commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Author: Luong Minh Thang , generated at Sun, 01 Jun 2008 15:21:09 4 | 5 | date 6 | 7 | projName="origin" 8 | branch="master" 9 | if [ $# -gt "0" ] 10 | then 11 | comment=$1 12 | if [ $# -gt "1" ] 13 | then 14 | projName=$2 15 | 16 | if [ $# -gt "2" ] 17 | then 18 | branch=$3 19 | fi 20 | fi 21 | else 22 | echo "Usage ./git_commit.sh [] []" 23 | echo " : optional, default=origin" 24 | echo " : optional (must specify projName before using branch), default=master" 25 | exit 26 | fi 27 | 28 | echo "git add -A ." 29 | git add -A . 30 | 31 | echo "git commit -a -m \"$comment\"" 32 | git commit -a -m "$comment" 33 | 34 | echo "git pull $projName $branch" 35 | git pull $projName $branch 36 | 37 | echo "git push $projName $branch" 38 | git push $projName $branch 39 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | #The -Ofast might not work with older versions of gcc; in that case, use -O2 3 | CFLAGS = -lm -pthread -march=native -Wall -funroll-loops -Ofast -Wno-unused-result 4 | #CFLAGS = -lm -pthread -march=native -Wall -funroll-loops -Ofast -Wno-unused-result -DDEBUG 5 | 6 | all: word2vec bivec word2phrase distance word-analogy compute-accuracy runCLDC 7 | 8 | word2vec : word2vec.c 9 | $(CC) word2vec.c -o word2vec $(CFLAGS) 10 | bivec : bivec.c 11 | $(CC) bivec.c -o bivec $(CFLAGS) 12 | word2phrase : word2phrase.c 13 | $(CC) word2phrase.c -o word2phrase $(CFLAGS) 14 | distance : distance.c 15 | $(CC) distance.c -o distance $(CFLAGS) 16 | word-analogy : word-analogy.c 17 | $(CC) word-analogy.c -o word-analogy $(CFLAGS) 18 | compute-accuracy : compute-accuracy.c 19 | $(CC) compute-accuracy.c -o compute-accuracy $(CFLAGS) 20 | chmod +x *.sh 21 | runCLDC : runCLDC.c 22 | $(CC) runCLDC.c -o runCLDC $(CFLAGS) 23 | 24 | clean: 25 | rm -rf bivec word2phrase distance word-analogy compute-accuracy runCLDC 26 | -------------------------------------------------------------------------------- /run_mono.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -lt 8 || $# -gt 9 ]]; then 4 | echo "`basename $0` remake outputDir trainFile lang dim numIters numThreads neg [otherOpts]" 5 | echo "remake=1: to re-make the code again" 6 | echo "neg=0: use hierarchical softmax" 7 | exit 8 | fi 9 | 10 | remake=$1 11 | outputDir=$2 12 | trainFile=$3 13 | lang=$4 14 | dim=$5 15 | numIter=$6 16 | numThreads=$7 17 | neg=$8 18 | otherOpts="" 19 | if [ $# -ge 9 ]; then 20 | otherOpts=${9} 21 | fi 22 | 23 | if [ $neg -gt 0 ]; then 24 | negStr="-negative $neg -hs 0" 25 | else 26 | negStr="-negative 0 -hs 1" 27 | fi 28 | echo "negStr=$negStr" 29 | 30 | VERBOSE=1 31 | function execute_check { 32 | file=$1 33 | cmd=$2 34 | 35 | if [[ -f $file || -d $file ]]; then 36 | echo "" 37 | echo "! File/directory $file exists. Skip." 38 | else 39 | echo "" 40 | if [ $VERBOSE -eq 1 ]; then 41 | echo "# Executing: $cmd" 42 | fi 43 | 44 | eval $cmd 45 | fi 46 | } 47 | 48 | # check outDir exists 49 | echo "# outputDir=$outputDir" 50 | execute_check $outputDir "mkdir -p $outputDir" 51 | 52 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 53 | echo "# Script dir = $SCRIPT_DIR" 54 | execute_check "" "cd $SCRIPT_DIR" 55 | 56 | if [ $remake -eq 1 ] 57 | then 58 | make clean 59 | make 60 | fi 61 | 62 | execute_check "" "time $SCRIPT_DIR/bivec -src-train $trainFile -src-lang $lang -output $outputDir/model -cbow 0 -size $dim -window 5 $negStr -sample 1e-5 -threads $numThreads -binary 0 -iter $numIter $otherOpts" 63 | -------------------------------------------------------------------------------- /run_word2vec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -lt 8 || $# -gt 9 ]]; then 4 | echo "`basename $0` remake outputDir trainFile lang dim numIters numThreads neg [otherOpts]" 5 | echo "remake=1: to re-make the code again" 6 | echo "neg=0: use hierarchical softmax" 7 | exit 8 | fi 9 | 10 | remake=$1 11 | outputDir=$2 12 | trainFile=$3 13 | lang=$4 14 | dim=$5 15 | numIter=$6 16 | numThreads=$7 17 | neg=$8 18 | otherOpts="" 19 | if [ $# -ge 9 ]; then 20 | otherOpts=${9} 21 | fi 22 | 23 | if [ $neg -gt 0 ]; then 24 | negStr="-negative $neg -hs 0" 25 | else 26 | negStr="-negative 0 -hs 1" 27 | fi 28 | echo "negStr=$negStr" 29 | 30 | VERBOSE=1 31 | function execute_check { 32 | file=$1 33 | cmd=$2 34 | 35 | if [[ -f $file || -d $file ]]; then 36 | echo "" 37 | echo "! File/directory $file exists. Skip." 38 | else 39 | echo "" 40 | if [ $VERBOSE -eq 1 ]; then 41 | echo "# Executing: $cmd" 42 | fi 43 | 44 | eval $cmd 45 | fi 46 | } 47 | 48 | # check outDir exists 49 | echo "# outputDir=$outputDir" 50 | execute_check $outputDir "mkdir -p $outputDir" 51 | 52 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 53 | echo "# Script dir = $SCRIPT_DIR" 54 | execute_check "" "cd $SCRIPT_DIR" 55 | 56 | if [ $remake -eq 1 ] 57 | then 58 | make clean 59 | make 60 | fi 61 | 62 | execute_check "" "time $SCRIPT_DIR/word2vec -train $trainFile -output $outputDir/model -cbow 0 -size $dim -window 5 $negStr -sample 1e-5 -threads $numThreads -binary 0 -iter $numIter $otherOpts" 63 | -------------------------------------------------------------------------------- /wordsim/annotation/de.1.seb.txt: -------------------------------------------------------------------------------- 1 | abuse missbrauch 2 | accommodation unterkunft 3 | activity aktivität 4 | admission eintritt 5 | airport flughafen 6 | alcohol alkohol 7 | aluminum aluminium 8 | american amerikaner 9 | animal tier 10 | announcement ankündigung 11 | antecedent vorgeschichte vorläufer 12 | anxiety angst 13 | approach ansatz 14 | arafat arafat 15 | architecture architektur 16 | archive archivieren archiv 17 | area bereich 18 | arrangement anordnung abmachung 19 | arrival ankunft 20 | article artikel 21 | artifact artefakt 22 | association verein 23 | astronomer astronom 24 | asylum asyl 25 | atmosphere atmosphäre 26 | attempt versuch 27 | attitude haltung 28 | automobile automobil 29 | avenue allee 30 | baby baby 31 | bank bank 32 | baseball baseball 33 | basketball basketball 34 | bed bett 35 | benchmark maßstab 36 | bird vogel 37 | bishop bischof 38 | block block 39 | board vorstand 40 | book buch 41 | boxing boxen 42 | boy junge 43 | brandy brandy 44 | brazil brasilien 45 | bread brot 46 | brother bruder 47 | buck bock (this is the literal translation of buck, i.e. the animal. There is no colloquial expression for dollar in German.) 48 | butter butter 49 | cabbage kohl 50 | calculation berechnung 51 | canyon schlucht 52 | car auto 53 | card karte 54 | carnivore fleischfresser 55 | cash bargeld 56 | cat katze 57 | category kategorie 58 | cd cd 59 | cell zelle handy 60 | cemetery friedhof 61 | center zentrum 62 | century jahrhundert 63 | challenge herausforderung 64 | championship meisterschaft 65 | chance chance 66 | change veränderung 67 | chemistry chemie 68 | children kinder 69 | chord akkord 70 | citizen bürger 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.1.txt: -------------------------------------------------------------------------------- 1 | abuse missbrauch 2 | accommodation unterkunft 3 | activity aktivität 4 | admission eintritt 5 | airport flughafen 6 | alcohol alkohol 7 | aluminum aluminium 8 | american amerikaner 9 | animal tier 10 | announcement ankündigung 11 | antecedent vorgeschichte 12 | anxiety angst 13 | approach ansatz 14 | arafat arafat 15 | architecture architektur 16 | archive archivieren 17 | area bereich 18 | arrangement anordnung 19 | arrival ankunft 20 | article artikel 21 | artifact artefakt 22 | association verein 23 | astronomer astronom 24 | asylum asyl 25 | atmosphere atmosphäre 26 | attempt versuch 27 | attitude haltung 28 | automobile automobil 29 | avenue allee 30 | baby baby 31 | bank bank 32 | baseball baseball 33 | basketball basketball 34 | bed bett 35 | benchmark maßstab 36 | bird vogel 37 | bishop bischof 38 | block block 39 | board board 40 | book buch 41 | boxing boxen 42 | boy junge 43 | brandy brandy 44 | brazil brasilien 45 | bread brot 46 | brother bruder 47 | buck bock 48 | butter butter 49 | cabbage kohl 50 | calculation berechnung 51 | canyon schlucht 52 | car auto 53 | card karte 54 | carnivore fleischfresser 55 | cash bargeld 56 | cat katze 57 | category kategorie 58 | cd cd 59 | cell zelle 60 | cemetery friedhof 61 | center zentrum 62 | century jahrhundert 63 | challenge herausforderung 64 | championship meisterschaft 65 | chance chance 66 | change veränderung 67 | chemistry chemie 68 | children kinder 69 | chord akkord 70 | citizen bürger 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.2.seb.txt: -------------------------------------------------------------------------------- 1 | clinic klinik 2 | closet schrank 3 | clothes kleidung 4 | coast küste 5 | cock hahn 6 | coffee kaffee 7 | cognition erkenntnis 8 | collection sammlung 9 | combination kombination 10 | communication kommunikation 11 | company firma 12 | competition wettbewerb 13 | computation berechnung 14 | computer computer 15 | concert konzert 16 | conclusion abschluss 17 | confidence vertrauen 18 | constellation konstellation 19 | consumer verbraucher 20 | country land 21 | crane kran 22 | credibility glaubwürdigkeit 23 | credit kredit 24 | crew crew 25 | crisis krise 26 | criterion kriterium 27 | critic kritiker 28 | cucumber gurke 29 | culture kultur 30 | cup tasse 31 | currency währung 32 | dawn dämmerung 33 | day tag 34 | death tod 35 | decoration dekoration 36 | defeat niederlage 37 | defeating besiegend 38 | delay verzögerung 39 | departure abfahrt 40 | deployment einsatz stationierung 41 | deposit anzahlung 42 | depression depression 43 | development entwicklung 44 | direction richtung 45 | disability behinderung 46 | disaster katastrophe 47 | discipline disziplin 48 | discovery entdeckung 49 | dividend dividende 50 | doctor arzt 51 | dollar dollar 52 | drink getränk 53 | drought dürre 54 | drug droge 55 | ear ohr 56 | earning ertrags gewinn 57 | eat essen 58 | ecology ökologie 59 | effort anstrengung 60 | egg ei 61 | emergency notfall 62 | energy energie 63 | entity wesen einheit 64 | environment umwelt 65 | equality gleichheit 66 | equipment ausrüstung 67 | evidence beweis 68 | example beispiel 69 | exhibit zeigen ausstellungsstück 70 | experience erfahrung 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.2.txt: -------------------------------------------------------------------------------- 1 | clinic klinik 2 | closet schrank 3 | clothes kleidung 4 | coast küste 5 | cock hahn 6 | coffee kaffee 7 | cognition erkenntnis 8 | collection sammlung 9 | combination kombination 10 | communication kommunikation 11 | company firma 12 | competition wettbewerb 13 | computation berechnung 14 | computer computer 15 | concert konzert 16 | conclusion abschluss 17 | confidence vertrauen 18 | constellation konstellation 19 | consumer verbraucher 20 | country land 21 | crane kran 22 | credibility glaubwürdigkeit 23 | credit kredit 24 | crew crew 25 | crisis krise 26 | criterion kriterium 27 | critic kritiker 28 | cucumber gurke 29 | culture kultur 30 | cup tasse 31 | currency währung 32 | dawn dämmerung 33 | day tag 34 | death tod 35 | decoration dekoration 36 | defeat niederlage 37 | defeating besiegen 38 | delay verzögerung 39 | departure abfahrt 40 | deployment einsatz 41 | deposit anzahlung 42 | depression depression 43 | development entwicklung 44 | direction richtung 45 | disability behinderung 46 | disaster katastrophe 47 | discipline disziplin 48 | discovery entdeckung 49 | dividend dividende 50 | doctor arzt 51 | dollar dollar 52 | drink getränk 53 | drought dürre 54 | drug droge 55 | ear ohr 56 | earning ertrags 57 | eat essen 58 | ecology ökologie 59 | effort anstrengung 60 | egg ei 61 | emergency notfall 62 | energy energie 63 | entity wesen 64 | environment umwelt 65 | equality gleichheit 66 | equipment ausrüstung 67 | evidence beweis 68 | example beispiel 69 | exhibit zeigen 70 | experience erfahrung 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.3.seb.txt: -------------------------------------------------------------------------------- 1 | eye auge 2 | family familie 3 | fauna fauna 4 | fbi fbi 5 | fear angst 6 | feline katzen- katzenartig 7 | fertility fruchtbarkeit 8 | fighting kampf kämpfend 9 | film film 10 | fingerprint fingerabdruck 11 | five fünf 12 | flight flug 13 | flood hochwasser 14 | focus schärfe fokus 15 | food lebensmittel essen 16 | football fußball 17 | forecast prognose 18 | forest wald 19 | freud freud 20 | fruit obst 21 | fuck fick ficken (translation of the verb, not really common as a noun) 22 | furnace ofen 23 | gain gewinnen ertrag 24 | galaxy galaxis galaxie 25 | game spiel 26 | gem juwel edelstein 27 | gender geschlecht 28 | gin gin 29 | girl mädchen 30 | glass glas 31 | government regierung 32 | governor gouverneur 33 | graveyard friedhof 34 | grocery lebensmittelgeschäft 35 | group gruppe 36 | hardware hardware 37 | harvard harvard 38 | health gesundheit 39 | hike wanderung 40 | hill hügel 41 | history geschichte 42 | holy heilig 43 | hospital krankenhaus 44 | hotel hotel 45 | hundred hundert 46 | hypertension hypertonie 47 | image bild 48 | impartiality unparteilichkeit 49 | implement implementieren werkzeug 50 | importance bedeutung 51 | index index 52 | industry industrie 53 | information informationen 54 | infrastructure infrastruktur 55 | inmate insasse 56 | institution institution 57 | insurance versicherung 58 | interest interesse 59 | internet internet 60 | interview interview 61 | investigation untersuchung 62 | investor anleger 63 | isolation isolation 64 | israel israel 65 | issue ausgabe problem 66 | jackson jackson 67 | jaguar jaguar 68 | japanese japanisch japaner 69 | jazz jazz 70 | jerusalem jerusalem 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.3.txt: -------------------------------------------------------------------------------- 1 | eye auge 2 | family familie 3 | fauna fauna 4 | fbi fbi 5 | fear angst 6 | feline katzen- 7 | fertility fruchtbarkeit 8 | fighting kampf 9 | film film 10 | fingerprint fingerabdruck 11 | five fünf 12 | flight flug 13 | flood hochwasser 14 | focus schärfe 15 | food lebensmittel 16 | football fußball 17 | forecast prognose 18 | forest wald 19 | freud freud 20 | fruit obst 21 | fuck fick 22 | furnace ofen 23 | gain gewinnen 24 | galaxy galaxis 25 | game spiel 26 | gem juwel 27 | gender geschlecht 28 | gin gin 29 | girl mädchen 30 | glass glas 31 | government regierung 32 | governor gouverneur 33 | graveyard friedhof 34 | grocery lebensmittelgeschäft 35 | group gruppe 36 | hardware hardware 37 | harvard harvard 38 | health gesundheit 39 | hike wanderung 40 | hill hügel 41 | history geschichte 42 | holy heilig 43 | hospital krankenhaus 44 | hotel hotel 45 | hundred hundert 46 | hypertension hypertonie 47 | image bild 48 | impartiality unparteilichkeit 49 | implement implementieren 50 | importance bedeutung 51 | index index 52 | industry industrie 53 | information informationen 54 | infrastructure infrastruktur 55 | inmate insasse 56 | institution institution 57 | insurance versicherung 58 | interest interesse 59 | internet internet 60 | interview interview 61 | investigation untersuchung 62 | investor anleger 63 | isolation isolation 64 | israel israel 65 | issue ausgabe 66 | jackson jackson 67 | jaguar jaguar 68 | japanese japanisch 69 | jazz jazz 70 | jerusalem jerusalem 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.4.julia.txt: -------------------------------------------------------------------------------- 1 | jewel juwel 2 | journal zeitschrift 3 | journey reise 4 | keyboard tastatur 5 | kilometer kilometer 6 | kind art (this means kind as in "kind of"; the translationg for kind as in "kind person" is "gütig") 7 | king könig 8 | laboratory labor 9 | lad junge 10 | landscape landschaft 11 | laundering wäsche 12 | law gesetz 13 | lawyer anwalt 14 | lesson lektion 15 | liability haftung 16 | library bibliothek 17 | life leben 18 | line linie 19 | liquid flüssigkeit 20 | listing auflistung 21 | live leben 22 | lobster hummer 23 | loss verlust 24 | love liebe (this is the noun form; the verb is "lieben") 25 | lover liebhaber 26 | luxury luxus 27 | madhouse irrenhaus 28 | magician zauberer 29 | maker hersteller 30 | mammal säugetier 31 | man mann 32 | manslaughter totschlag 33 | maradona maradona (what is this? is it a last name?) 34 | marathon marathon (this is the adjective; the noun would be "Marathonlauf") 35 | market markt 36 | marriage ehe 37 | mars mars 38 | match spiel (this is really ambiguous; see http://www.wordreference.com/ende/match for possible options; "spiel" is not a good choice though) 39 | medal medaille 40 | media medien 41 | memorabilia erinnerungsstücke 42 | metal metall 43 | mexico mexiko 44 | midday mittag 45 | mile meile 46 | mind geist 47 | minister minister 48 | ministry ministerium 49 | minority minderheit 50 | money geld 51 | monk mönch 52 | month monat 53 | moon mond 54 | morality moral 55 | mother mutter 56 | motto motto 57 | mouth mund 58 | movie film 59 | murder mord 60 | museum museum 61 | music musik 62 | nation nation 63 | nature natur 64 | network netzwerk 65 | news nachrichten 66 | noon mittag 67 | number anzahl 68 | nurse krankenschwester 69 | object objekt 70 | observation beobachtung 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.4.txt: -------------------------------------------------------------------------------- 1 | jewel juwel 2 | journal zeitschrift 3 | journey reise 4 | keyboard tastatur 5 | kilometer kilometer 6 | kind art 7 | king könig 8 | laboratory labor 9 | lad junge 10 | landscape landschaft 11 | laundering wäsche 12 | law gesetz 13 | lawyer anwalt 14 | lesson lektion 15 | liability haftung 16 | library bibliothek 17 | life leben 18 | line linie 19 | liquid flüssigkeit 20 | listing auflistung 21 | live leben 22 | lobster hummer 23 | loss verlust 24 | love liebe 25 | lover liebhaber 26 | luxury luxus 27 | madhouse irrenhaus 28 | magician zauberer 29 | maker hersteller 30 | mammal säugetier 31 | man mann 32 | manslaughter totschlag 33 | maradona maradona 34 | marathon marathon 35 | market markt 36 | marriage ehe 37 | mars mars 38 | match spiel 39 | medal medaille 40 | media medien 41 | memorabilia erinnerungsstücke 42 | metal metall 43 | mexico mexiko 44 | midday mittag 45 | mile meile 46 | mind geist 47 | minister minister 48 | ministry ministerium 49 | minority minderheit 50 | money geld 51 | monk mönch 52 | month monat 53 | moon mond 54 | morality moral 55 | mother mutter 56 | motto motto 57 | mouth mund 58 | movie film 59 | murder mord 60 | museum museum 61 | music musik 62 | nation nation 63 | nature natur 64 | network netzwerk 65 | news nachrichten 66 | noon mittag 67 | number anzahl 68 | nurse krankenschwester 69 | object objekt 70 | observation beobachtung 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.5.julia.txt: -------------------------------------------------------------------------------- 1 | office büro 2 | oil öl 3 | opec opec 4 | opera oper 5 | operation betrieb 6 | oracle orakel 7 | organism organismus 8 | palestinian palästinenser (this is the noun, "palästinensisch" is the adjective) 9 | paper papier 10 | party partei (this is like political party, for "celebration" one would probably say "Party") 11 | payment zahlung 12 | peace frieden 13 | people menschen 14 | percent prozent 15 | performance leistung (this is as in "performance report", for "dance performance", it's "Vorstellung") 16 | personnel personal 17 | phone telefon 18 | physics physik 19 | place ort 20 | plan plan 21 | plane flugzeug 22 | planet planet 23 | planning planung 24 | popcorn popcorn 25 | population bevölkerung 26 | possession besitz 27 | possibility möglichkeit 28 | potato kartoffel 29 | practice praxis (this is like "doctor's practice"; "to practice cooking" would be "üben") 30 | precedent präzedenzfall 31 | prejudice vorurteil 32 | preparation vorbereitung 33 | preservation erhaltung 34 | president präsident 35 | price preis 36 | problem problem 37 | production produktion 38 | professor professor 39 | profit gewinn 40 | project projekt 41 | prominence bedeutung 42 | property immobilien (this is specifically for real estate; general property is "Eigentum") 43 | proton proton 44 | proximity nähe 45 | psychiatry psychiatrie 46 | psychology psychologie 47 | quarrel streit 48 | queen königin 49 | rabbi rabbiner 50 | racism rassismus 51 | racket schläger 52 | radio radio 53 | reason grund 54 | recess nische (this means "niche", for a recess in court, use "Unterbrechung") 55 | recognition anerkennung 56 | recommendation empfehlung 57 | record rekord 58 | recovery erholung 59 | registration anmeldung 60 | report bericht 61 | reservation reservierung 62 | rock rock (this is like rock music; for stone, use "Fels" or "Stein") 63 | rook turm 64 | rooster hahn 65 | round runde 66 | row reihe 67 | school schule 68 | science wissenschaft 69 | scientist wissenschaftler 70 | sea meer 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.5.txt: -------------------------------------------------------------------------------- 1 | office büro 2 | oil öl 3 | opec opec 4 | opera oper 5 | operation betrieb 6 | oracle orakel 7 | organism organismus 8 | palestinian palästinenser 9 | paper papier 10 | party partei 11 | payment zahlung 12 | peace frieden 13 | people menschen 14 | percent prozent 15 | performance leistung 16 | personnel personal 17 | phone telefon 18 | physics physik 19 | place ort 20 | plan plan 21 | plane flugzeug 22 | planet planet 23 | planning planung 24 | popcorn popcorn 25 | population bevölkerung 26 | possession besitz 27 | possibility möglichkeit 28 | potato kartoffel 29 | practice praxis 30 | precedent präzedenzfall 31 | prejudice vorurteil 32 | preparation vorbereitung 33 | preservation erhaltung 34 | president präsident 35 | price preis 36 | problem problem 37 | production produktion 38 | professor professor 39 | profit gewinn 40 | project projekt 41 | prominence bedeutung 42 | property immobilien 43 | proton proton 44 | proximity nähe 45 | psychiatry psychiatrie 46 | psychology psychologie 47 | quarrel streit 48 | queen königin 49 | rabbi rabbiner 50 | racism rassismus 51 | racket schläger 52 | radio radio 53 | reason grund 54 | recess nische 55 | recognition anerkennung 56 | recommendation empfehlung 57 | record rekord 58 | recovery erholung 59 | registration anmeldung 60 | report bericht 61 | reservation reservierung 62 | rock rock 63 | rook turm 64 | rooster hahn 65 | round runde 66 | row reihe 67 | school schule 68 | science wissenschaft 69 | scientist wissenschaftler 70 | sea meer 71 | -------------------------------------------------------------------------------- /wordsim/annotation/de.6.julia.txt: -------------------------------------------------------------------------------- 1 | seafood meeresfrüchte 2 | season saison 3 | secret geheimnis 4 | secretary sekretärin 5 | seepage durchsickern 6 | senate senat 7 | serial serien- 8 | series serie 9 | seven sieben 10 | sex sex (this is as in intercourse, gender is "Geschlecht") 11 | shore ufer 12 | shower dusche 13 | sign zeichen 14 | similarity ähnlichkeit 15 | situation situation 16 | size größe 17 | skin haut 18 | slave sklave 19 | smart intelligent (also usually "klug") 20 | smile lächeln 21 | soap seife 22 | soccer fußball 23 | software software 24 | space raum 25 | sprint sprint 26 | star stern 27 | start start 28 | stock lager 29 | stove herd 30 | street straße 31 | string schnur 32 | stroke schlaganfall 33 | student schüler 34 | stupid dumm 35 | substance substanz 36 | sugar zucker 37 | summer sommer 38 | sun sonne 39 | surface oberfläche 40 | tableware geschirr 41 | team team 42 | telephone telefon 43 | television fernsehen (this is a verb, should be "fernseher") 44 | tennis tennis 45 | term begriff 46 | territory gebiet 47 | terror terror 48 | theater theater 49 | thunderstorm gewitter 50 | ticket ticket 51 | tiger tiger 52 | tool werkzeug 53 | tournament turnier 54 | trading handel 55 | train zug 56 | travel reise 57 | treatment behandlung 58 | troops truppen 59 | type typ 60 | valor tapferkeit 61 | victim opfer 62 | victory sieg 63 | video video 64 | viewer zuschauer 65 | virtuoso virtuose 66 | vodka wodka 67 | volunteer freiwillige 68 | voyage reise 69 | war krieg 70 | warning warnung 71 | water wasser 72 | wealth reichtum 73 | weapon waffe 74 | weather wetter 75 | wednesday mittwoch 76 | wine wein 77 | withdrawal rückzug 78 | wizard zauberer 79 | woman frau 80 | wood holz 81 | woodland wald 82 | word wort 83 | world welt 84 | yale yale 85 | year jahr 86 | yen yen 87 | zoo zoo 88 | -------------------------------------------------------------------------------- /wordsim/annotation/de.6.txt: -------------------------------------------------------------------------------- 1 | seafood meeresfrüchte 2 | season saison 3 | secret geheimnis 4 | secretary sekretärin 5 | seepage durchsickern 6 | senate senat 7 | serial serien- 8 | series serie 9 | seven sieben 10 | sex sex 11 | shore ufer 12 | shower dusche 13 | sign zeichen 14 | similarity ähnlichkeit 15 | situation situation 16 | size größe 17 | skin haut 18 | slave sklave 19 | smart intelligent 20 | smile lächeln 21 | soap seife 22 | soccer fußball 23 | software software 24 | space raum 25 | sprint sprint 26 | star stern 27 | start start 28 | stock lager 29 | stove herd 30 | street straße 31 | string schnur 32 | stroke schlaganfall 33 | student schüler 34 | stupid dumm 35 | substance substanz 36 | sugar zucker 37 | summer sommer 38 | sun sonne 39 | surface oberfläche 40 | tableware geschirr 41 | team team 42 | telephone telefon 43 | television fernsehen 44 | tennis tennis 45 | term begriff 46 | territory gebiet 47 | terror terror 48 | theater theater 49 | thunderstorm gewitter 50 | ticket ticket 51 | tiger tiger 52 | tool werkzeug 53 | tournament turnier 54 | trading handel 55 | train zug 56 | travel reise 57 | treatment behandlung 58 | troops truppen 59 | type typ 60 | valor tapferkeit 61 | victim opfer 62 | victory sieg 63 | video video 64 | viewer zuschauer 65 | virtuoso virtuose 66 | vodka wodka 67 | volunteer freiwillige 68 | voyage reise 69 | war krieg 70 | warning warnung 71 | water wasser 72 | wealth reichtum 73 | weapon waffe 74 | weather wetter 75 | wednesday mittwoch 76 | wine wein 77 | withdrawal rückzug 78 | wizard zauberer 79 | woman frau 80 | wood holz 81 | woodland wald 82 | word wort 83 | world welt 84 | yale yale 85 | year jahr 86 | yen yen 87 | zoo zoo 88 | -------------------------------------------------------------------------------- /wordsim/annotation/ws353.en-de.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/annotation/ws353.en-de.xlsx -------------------------------------------------------------------------------- /wordsim/code/cell2map.m: -------------------------------------------------------------------------------- 1 | function [map] = cell2map(cell) 2 | %% 3 | % Minh-Thang Luong 4 | % 5 | % Convert a cell (a cell) into a map by mapping cell values into their indices 6 | %% 7 | if isempty(cell) 8 | map = containers.Map(); 9 | else 10 | map = containers.Map(cell, 1:length(cell)); %num2cell(1:length(cell))); 11 | end 12 | -------------------------------------------------------------------------------- /wordsim/code/findUnkStr.m: -------------------------------------------------------------------------------- 1 | function [unkStr, unkIndex] = findUnkStr(vocabMap) 2 | %% 3 | % Find a representation for unknown word in a vocabMap 4 | % Author: Thang Luong 5 | %% 6 | unkStrs = {'UUUNKKK', 'UNKNOWN', '*UNKNOWN*', 'UNK', '', ''}; 7 | 8 | %% unkStr 9 | unkStr = ''; 10 | for ii=1:length(unkStrs) 11 | curUnkStr = unkStrs{ii}; 12 | if isKey(vocabMap, curUnkStr) 13 | if strcmp(unkStr, '') 14 | unkStr = curUnkStr; 15 | break; 16 | end 17 | end 18 | end 19 | 20 | if strcmp(unkStr, '') 21 | fprintf(2, 'No vector representing unknown words\n'); 22 | unkStr = ''; 23 | unkIndex = -1; 24 | else 25 | assert(isKey(vocabMap, unkStr)==1); 26 | unkIndex = vocabMap(unkStr); 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /wordsim/code/getSimScore.m: -------------------------------------------------------------------------------- 1 | function score = getSimScore(word1, word2, We, vocabMap, distType, unkStr) 2 | %% 3 | % word 1 4 | if isKey(vocabMap, word1) 5 | idx1 = vocabMap(word1); 6 | else 7 | idx1 = vocabMap(unkStr); 8 | end 9 | 10 | % word 2 11 | if isKey(vocabMap, word2) 12 | idx2 = vocabMap(word2); 13 | else 14 | idx2 = vocabMap(unkStr); 15 | end 16 | 17 | word1vec = We(:, idx1); 18 | word2vec = We(:, idx2); 19 | score = slmetric_pw(word1vec, word2vec, distType); 20 | end 21 | -------------------------------------------------------------------------------- /wordsim/code/getSimScores.m: -------------------------------------------------------------------------------- 1 | function scores = getSimScores(wordPairs, We, vocabMap, distType, unkStr) 2 | %% 3 | scores = zeros(length(wordPairs),1); 4 | 5 | for i = 1:length(wordPairs) 6 | word1 = wordPairs{i,1}; 7 | word2 = wordPairs{i,2}; 8 | %fprintf(1, '%s\t%s\n', word1, word2); 9 | scores(i) = getSimScore(word1, word2, We, vocabMap, distType, unkStr); 10 | end 11 | 12 | if strcmp(distType, 'corrdist') 13 | scores = 2-scores; 14 | else 15 | scores = -1*scores; 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /wordsim/code/loadWordSimData.m: -------------------------------------------------------------------------------- 1 | %% Load word similarity file and save in Matlab format 2 | %% Assumed format: word1\tword2\tscore[Optional] 3 | function [wordPairs, humanScores] = loadWordSimData(inFile, isHeader, delimiter, numLastLineExcluded, word1Index, word2Index, scoreIndex) 4 | % outFile, 5 | fid = fopen(inFile, 'r'); 6 | fileLines = textscan(fid, '%s', 'delimiter', '\n', 'bufsize', 100000); 7 | fclose(fid); 8 | 9 | if ~exist('numLastLineExcluded', 'var') 10 | numLastLineExcluded = 0; 11 | end 12 | if ~exist('word1Index', 'var') || ~exist('word2Index', 'var') || ~exist('scoreIndex', 'var') 13 | word1Index = 1; 14 | word2Index = 2; 15 | scoreIndex = 3; 16 | end 17 | 18 | if isHeader % remove header 19 | startId = 2; 20 | else % no header 21 | startId = 1; 22 | end 23 | fileLines=fileLines{1}(startId:(end-numLastLineExcluded)); 24 | 25 | wordPairs = cell(length(fileLines), 2); 26 | humanScores = zeros(length(fileLines),1); 27 | 28 | for ii = 1:length(fileLines) 29 | line = regexp(fileLines{ii}, delimiter, 'split'); 30 | line = cellfun(@strtrim,line,'UniformOutput',0); 31 | wordPairs(ii,:) = line([word1Index word2Index]); 32 | humanScores(ii) = str2double(line{scoreIndex}); 33 | end 34 | %save(outFile, 'wordPairs', 'humanScores'); 35 | end 36 | -------------------------------------------------------------------------------- /wordsim/code/run_wordSim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Author: Minh-Thang Luong , created on Thu Feb 21 16:32:43 PST 2013 3 | 4 | if [[ ! $# -eq 3 && ! $# -eq 3 ]] 5 | then 6 | echo "`basename $0` modelFile modelFormat lang" 7 | echo "lang: en or de" 8 | echo "modelFormat : 0 -- Matlab file," 9 | echo " 1 -- text file with a header line . Subsequent lines has ." 10 | echo " 2 -- text file with each line has " 11 | echo " 3 -- assume that there are two files modelFile.We, modelFile.words" 12 | exit 13 | fi 14 | 15 | modelFile=$1 16 | modelFormat=$2 17 | lang=$3 18 | 19 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 20 | cd $DIR 21 | 22 | if [ "$modelFormat" -eq 1 ]; then # split We, words 23 | #echo "./splitWordVectorFile.sh $modelFile $modelFile" 24 | ./splitWordVectorFile.sh $modelFile $modelFile 25 | modelFormat=3 26 | fi 27 | matlab -nodesktop -nodisplay -nosplash -r "evaluateWordSim('$modelFile', $modelFormat, '$lang');exit;" | tail -n +15 28 | 29 | 30 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007, Dahua Lin 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/readme.txt: -------------------------------------------------------------------------------- 1 | Readme on sltoolbox 2 | 3 | Created by Dahua Lin, on Sep 20, 2006 4 | 5 | 1. System Requirement 6 | (1) Windows system, (32bit or 64bit) 7 | (2) All functions are tested in Matlab 2006a (32bit) and Matlab 2006a x64. 8 | (3) All mex files are are compiled and linked with Microsoft Visual Studio 2005 in Matlab 2006a. 9 | (4) Most functions are usable in Matlab 7.0 and 7.04. 10 | 11 | 2. Install 12 | (1) Uncompress the zip file.The file packs two folders: sltoolbox (the codes) and sltdoc (the document) and several auxiliary files: 13 | - readme.txt (This file) 14 | - introduction.txt (A file giving brief introduction of the features and contents of the toolbox) 15 | - tutorial.pdf (Presentation slides in pdf format to give a tutorial on the usage) 16 | (2) Start matlab and switch to the root folder of sltoolbox. 17 | (3) Type the commend "install_paths" to install the paths to matlab search paths. 18 | 19 | 3. Other issues 20 | (1) In normal cases, you can use all functions after you installed the paths without re-compiling the mex files. 21 | (2) If you would like to re-compile the C++ mex files, you can use install_cppcores.m in root directory of sltoolbox. 22 | (3) If you would like to re-compile the C++ mex in ann, you need the source codes of ANN Lib. 23 | It is available (free) in http://www.cs.umd.edu/~mount/ANN/ 24 | (4) A function named slisomap requires the support of Matlab BGL. 25 | It is available (free) in http://www.stanford.edu/~dgleich/programs/matlab_bgl/ 26 | 27 | 4. Documentation 28 | (1) It is the most convenient way to type help to obtain the detailed manual of the function 29 | (2) The introduction.txt gives a completed list of all functions. 30 | (3) A documentation generated by m2html is available in http://www.mydahua.net/sltdoc/index.html 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/@dataset/construct_dataset_filenames.m: -------------------------------------------------------------------------------- 1 | function ds = construct_dataset_fns(ds, name, format, filenames, labels) 2 | %CONSTRUCT_DATASET_FNS Constructs Dataset object from filenames 3 | % 4 | % $ Syntax $ 5 | % - ds = construct_dataset_fns(ds, name, format, filenames, labels) 6 | % 7 | % $ Arguments $ 8 | % - name: the name of the dataset 9 | % - format: the format of file samples 10 | % - filenames: the filenames of the image samples 11 | % - labels: the labels of the corresponding samples 12 | % - ds: the constructed object 13 | % 14 | % $ Description $ 15 | % - ds = construct_dataset_fns(name, format, filenames, labels) 16 | % constructs a dataset object from filenames and corresponding labels 17 | % identifying the class of the samples. 18 | % 19 | % $ Remarks $ 20 | % - The dataset object will be constructed as sample set. 21 | % 22 | % $ History $ 23 | % - Created by Dahua Lin on Jul 26th, 2005 24 | % 25 | 26 | %% parse and verify input arguments 27 | 28 | N = length(filenames); 29 | if length(labels) ~= N 30 | error('The length of labels is not consistent with that of filenames'); 31 | end 32 | 33 | %% construct 34 | 35 | ds.version = '1.00'; 36 | ds.name = name; 37 | ds.unittype = 'Sample'; 38 | ds.format = format; 39 | ds.author = 'unknown'; 40 | ds.description = 'generated by construct_dataset_fns.m'; 41 | ds.attribs = []; 42 | 43 | ds.units = []; 44 | 45 | for i = 1 : N; 46 | ds.units(i).class_id = labels(i); 47 | ds.units(i).filename = filenames{i}; 48 | ds.units(i).attribs = []; 49 | end 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/@dataset/disp.m: -------------------------------------------------------------------------------- 1 | function disp(DS) 2 | %DISP displays the dataset fields 3 | 4 | disp(' [dataset object]'); 5 | disp(struct(DS)) 6 | 7 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/@dataset/display.m: -------------------------------------------------------------------------------- 1 | function display(DS) 2 | %DISPLAY displays the dataset fields. 3 | 4 | if isequal(get(0,'FormatSpacing'),'compact') 5 | disp([inputname(1) ' =']); 6 | disp(DS); 7 | else 8 | disp(' '); 9 | disp([inputname(1) ' =']); 10 | disp(' '); 11 | disp(DS); 12 | end -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/@dataset/subsref.m: -------------------------------------------------------------------------------- 1 | function R = subsref(DS, ss) 2 | %SUBSREF Get the properties by subscription 3 | % 4 | % $ Syntax $ 5 | % - R = DS. 6 | % - R = DS.('') 7 | % 8 | % $ History $ 9 | % - Created by Dahua Lin on Jul 23, 2006 10 | % 11 | 12 | if ss(1).type == '.' && ischar(ss(1).subs) 13 | R = get(DS, ss(1).subs); 14 | if (length(ss) >= 2) 15 | R = subsref(R, ss(2:end)); 16 | end 17 | else 18 | error('dsdml:invalidarg', 'Invalid subscription for dataset'); 19 | end 20 | 21 | 22 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/ds1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/ds2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_buildiidxdict.m: -------------------------------------------------------------------------------- 1 | function Dict = edl_buildiidxdict(S, idxfn) 2 | %EDL_BUILDIIDXDICT Builds a dictionary using internal index 3 | % 4 | % $ Syntax $ 5 | % - Dict = edl_buildiidxdict(S, idxfn) 6 | % 7 | % $ Arguments $ 8 | % - S: a struct array on which the dictionary is built 9 | % - idxfn: the field name of the internal index 10 | % (default = 'internal_index') 11 | % - Dict: the built dictionary 12 | % a cell array, indexed by internal_index 13 | % 14 | % $ Remarks $ 15 | % - The length of the cell array (dict) will be equal to the maximum 16 | % internal index in S. 17 | % - In S, different elements should have different internal indices. 18 | % - For the index corresponding to no element, the corresponding cells 19 | % are empty. 20 | % - The dictionary will not automatically keep track of the change of 21 | % S. If S is changed, the dictonary should be rebuilt in order to 22 | % reflect the updates. 23 | % 24 | % $ History $ 25 | % - Created by Dahua Lin, on Aug 15, 2006 26 | % 27 | 28 | %% parse and verify input arguments 29 | 30 | if ~isstruct(S) 31 | error('sltoolbox:invalidarg', ... 32 | 'The S should be a struct'); 33 | end 34 | 35 | if nargin < 2 || isempty(idxfn) 36 | idxfn = 'internal_index'; 37 | end 38 | 39 | if ~isfield(S, idxfn) 40 | error('sltoolbox:invalidarg', ... 41 | 'The S have no specified internal index field'); 42 | end 43 | 44 | %% Build dictionary 45 | 46 | % gather the internal indices 47 | n = numel(S); 48 | inds = zeros(n, 1); 49 | for i = 1 : n 50 | idx = S(i).(idxfn); 51 | if ischar(idx) 52 | idx = str2double(idx); 53 | end 54 | inds(i) = idx; 55 | end 56 | 57 | % construct dictionary 58 | m = max(inds); 59 | 60 | Dict = cell(m, 1); 61 | 62 | for i = 1 : n 63 | idx = inds(i); 64 | if ~isempty(Dict{idx}) 65 | error('sltoolbox:rterror', ... 66 | 'Repeated index %d is encountered', idx); 67 | end 68 | Dict{idx} = S(i); 69 | end 70 | 71 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_check_internalindices.m: -------------------------------------------------------------------------------- 1 | function cprops = edl_check_internalindices(props) 2 | %EDL_CHECK_INTERNALINDICES Checks the consistency of internal indices 3 | % 4 | % $ Syntax $ 5 | % - cprops = edl_check_internalindices(props) 6 | % 7 | % $ Arguments $ 8 | % - props: the struct array of property entries 9 | % - cprops: the converted array with all indices coverted to 10 | % numeric 11 | % 12 | % $ History $ 13 | % - Created by Dahua Lin, on Aug 14, 2006 14 | % 15 | 16 | 17 | cprops = props; 18 | 19 | if ~isempty(props) 20 | 21 | n = length(props); 22 | 23 | if ~isfield(props, 'internal_index') 24 | error('edl:parseerror', ... 25 | 'The entries do not have the required field: internal_index'); 26 | end 27 | 28 | for i = 1 : n 29 | curidx = str2double(props(i).internal_index); 30 | if curidx ~= i 31 | error('edl:parseerror', ... 32 | 'Internal index inconsistency'); 33 | end 34 | cprops(i).internal_index = curidx; 35 | end 36 | 37 | end -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_initctrlfile.m: -------------------------------------------------------------------------------- 1 | function edl_initctrlfile(filename, guidstr, n) 2 | %EDL_INITCTRLFILE Creates an initial control file 3 | % 4 | % $ Syntax $ 5 | % - edl_initctrlfile(filename, guidstr, n) 6 | % 7 | % $ Arguments $ 8 | % - filename: the destination control filename 9 | % - guidstr: the GUID identifying the corresponding script 10 | % - n: the number of items 11 | % 12 | % $ Description $ 13 | % - edl_initctrlfile(filename, guidstr, n) writes an initial control 14 | % file with all status set to pending. 15 | % 16 | % $ History $ 17 | % - Created by Dahua Lin, on Aug 14th, 2006 18 | % 19 | 20 | %% parse and verify input 21 | 22 | if nargin < 3 23 | raise_lackinput('edl_initctrlfile', 3); 24 | end 25 | 26 | %% Write 27 | 28 | doctag = 'ExpControl'; 29 | attribs.guid = guidstr; 30 | nodetag = 'Entry'; 31 | 32 | props = struct(... 33 | 'internal_index', mat2cell((1:n)', ones(n,1)), ... 34 | 'status', repmat({'pending'}, [n, 1]) ... 35 | ); 36 | 37 | edl_writeprops(doctag, attribs, nodetag, props, filename) -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_readctrlfile.m: -------------------------------------------------------------------------------- 1 | function C = edl_readctrlfile(filename) 2 | %EDL_READCTRLFILE Reads in a control file 3 | % 4 | % $ Description $ 5 | % - C = edl_readctrlfile(filename) 6 | % 7 | % $ Arguments $ 8 | % - filename: the filename of the control file 9 | % - C: the struct of the read information 10 | % - guid: the GUID string 11 | % - status: the n x 1cell array of status 12 | % 13 | % $ Description $ 14 | % - C = edl_readctrlfile(filename) reads in a control file. 15 | % 16 | % $ History $ 17 | % - Created by Dahua Lin, on Aug 14, 2006 18 | % 19 | 20 | %% Read in file 21 | 22 | doctag = 'ExpControl'; 23 | nodetag = 'Entry'; 24 | 25 | S = edl_readprops(filename, nodetag); 26 | 27 | %% Post-Processing 28 | 29 | % doc tag 30 | if ~strcmp(S.tag, doctag) 31 | error('edl:parseerror', ... 32 | 'Invalid document tag %s for control file', S.tag); 33 | end 34 | 35 | % doc attribs 36 | if isempty(S.attribs) 37 | error('edl:parseerror', ... 38 | 'The document element for control file has no attributes'); 39 | end 40 | 41 | attrnames = {'guid'}; 42 | tf = isfield(S.attribs, attrnames); 43 | if ~all(tf) 44 | error('edl:parserror', ... 45 | 'The required header %s does not exist', ... 46 | attrnames{find(~tf, 1)}); 47 | end 48 | 49 | C.guid = S.attribs.guid; 50 | 51 | % entries 52 | 53 | edl_check_internalindices(S.(nodetag)); 54 | C.status = {S.(nodetag).status}; 55 | C.status = C.status(:)'; 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_readenvvars.m: -------------------------------------------------------------------------------- 1 | function S = edl_readenvvars(envfile) 2 | %EDL_READENVVARS Reads in a file with environment variables 3 | % 4 | % $ Syntax $ 5 | % - S = edl_readenvvars(envfile) 6 | % 7 | % $ Arguments $ 8 | % - envfile: the environment filename 9 | % - S: the struct of all environment variables 10 | % 11 | % $ Description $ 12 | % - S = edl_readenvvars(envfile) reads in a set of environment variables 13 | % from an assignment file. The file contains a set of assignment 14 | % string, and some comments (starting with # or % or /). 15 | % 16 | % $ History $ 17 | % - Created by Dahua Lin, on Aug 10th, 2006 18 | % 19 | 20 | %% read file 21 | 22 | T = slreadtext(envfile); 23 | T = slcompresstext(T); 24 | 25 | %% parse assignments 26 | 27 | n = length(T); 28 | S = []; 29 | 30 | for i = 1 : n 31 | 32 | curline = T{i}; 33 | if ~iscomment(curline) 34 | [curname, curval] = slparse_assignment(curline); 35 | S.(curname) = curval; 36 | end 37 | 38 | end 39 | 40 | %% Auxiliary function 41 | 42 | function b = iscomment(line) 43 | 44 | b = (line(1) == '#' || line(1) == '%' || line(1) == '/'); -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_readreport.m: -------------------------------------------------------------------------------- 1 | function report = edl_readreport(filename) 2 | %EDL_READREPORT Reads in a EDL report 3 | % 4 | % $ Syntax $ 5 | % - report = edl_readreport(filename) 6 | % 7 | % $ Description $ 8 | % - report = edl_readreport(filename) reads in a EDL report from 9 | % a report xml file. The returned report is a struct with 10 | % following fields: 11 | % - attribs: the header attributes 12 | % - guid: the GUID string identifying the report 13 | % - entries: the report item entries 14 | % at least have following fields: 15 | % - internal_index: the internal index 16 | % 17 | % $ History $ 18 | % - Created by Dahua Lin, on Aug 14, 2006 19 | % 20 | 21 | %% Read in file 22 | 23 | doctag = 'ExpReport'; 24 | nodetag = 'Entry'; 25 | 26 | S = edl_readprops(filename, nodetag); 27 | 28 | %% Post-Processing 29 | 30 | % doc tag 31 | if ~strcmp(S.tag, doctag) 32 | error('edl:parseerror', ... 33 | 'Invalid document tag %s for report', S.tag); 34 | end 35 | 36 | % doc attribs 37 | if isempty(S.attribs) 38 | error('edl:parseerror', ... 39 | 'The document element for report has no attributes'); 40 | end 41 | 42 | attrnames = {'guid'}; 43 | tf = isfield(S.attribs, attrnames); 44 | if ~all(tf) 45 | error('edl:parserror', ... 46 | 'The required header %s does not exist', ... 47 | attrnames{find(~tf, 1)}); 48 | end 49 | 50 | report.attribs = S.attribs; 51 | 52 | % entries 53 | 54 | report.entries = edl_check_internalindices(S.(nodetag)); 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_readscript.m: -------------------------------------------------------------------------------- 1 | function script = edl_readscript(filename) 2 | %EDL_READSCRIPT Reads in a EDL script 3 | % 4 | % $ Syntax $ 5 | % - script = edl_readscript(filename) 6 | % 7 | % $ Description $ 8 | % - script = edl_readscript(filename) reads in a EDL script from 9 | % a script xml file. The returned script is a struct with 10 | % following fields: 11 | % - attribs: the header attributes 12 | % - guid: the GUID string identifying the script 13 | % - workdir: the root work diretory of experiments 14 | % - ctrlpath: the corresponding control file path 15 | % - entries: the experiment parameter entries 16 | % at least have following fields: 17 | % - internal_index: the internal index 18 | % 19 | % $ History $ 20 | % - Created by Dahua Lin, on Aug 14, 2006 21 | % 22 | 23 | %% Read in file 24 | 25 | doctag = 'ExpScript'; 26 | nodetag = 'Entry'; 27 | 28 | S = edl_readprops(filename, nodetag); 29 | 30 | %% Post-Processing 31 | 32 | % doc tag 33 | if ~strcmp(S.tag, doctag) 34 | error('edl:parseerror', ... 35 | 'Invalid document tag %s for script', S.tag); 36 | end 37 | 38 | % doc attribs 39 | if isempty(S.attribs) 40 | error('edl:parseerror', ... 41 | 'The document element for script has no attributes'); 42 | end 43 | 44 | attrnames = {'guid', 'workdir', 'ctrlpath'}; 45 | tf = isfield(S.attribs, attrnames); 46 | if ~all(tf) 47 | error('edl:parserror', ... 48 | 'The required header %s does not exist', ... 49 | attrnames{find(~tf, 1)}); 50 | end 51 | 52 | script.attribs = struct(... 53 | 'guid', S.attribs.guid, ... 54 | 'workdir', S.attribs.workdir, ... 55 | 'ctrlpath', S.attribs.ctrlpath); 56 | 57 | % entries 58 | 59 | script.entries = edl_check_internalindices(S.(nodetag)); 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_updatectrlfile.m: -------------------------------------------------------------------------------- 1 | function edl_updatectrlfile(guid, filename, idx, status) 2 | %EDL_UPDATECTRLFILE Updates the status in a control file 3 | % 4 | % $ Syntax $ 5 | % - edl_updatectrlfile(guid, filename, idx, status) 6 | % 7 | % $ Arguments $ 8 | % - guid: the expecting GUID of the control file 9 | % - filename: the filename of the control file 10 | % - idx: the internal index of the entry to be updated 11 | % - status: the updated status 12 | % 13 | % $ Description $ 14 | % - edl_updatectrlfile(guid, filename, idx, status) updates a specified 15 | % entry of a control file. 16 | % 17 | % $ History $ 18 | % - Created by Dahua Lin, on Aug 14, 2006 19 | % 20 | 21 | %% parse and verify input 22 | if nargin < 4 23 | raise_lackinput('edl_updatectrlfile', 4); 24 | end 25 | 26 | %% read and verify 27 | 28 | C = edl_readctrlfile(filename); 29 | 30 | if ~strcmpi(C.guid, guid) 31 | error('edl:interperror', ... 32 | 'Inconsistent between the GUID of control file and script on %s', filename); 33 | end 34 | 35 | %% update 36 | 37 | n = length(C.status); 38 | if idx > length(C.status) 39 | error('edl:interperror', ... 40 | 'The index is beyond the number of entries on %s', filename); 41 | end 42 | 43 | if ~ismember(status, {'pending', 'succeed', 'failed'}) 44 | error('edl:interperror', ... 45 | 'Invalid status for control file: %s', status); 46 | end 47 | 48 | C.status{idx} = status; 49 | 50 | %% write 51 | 52 | 53 | doctag = 'ExpControl'; 54 | attribs.guid = guid; 55 | nodetag = 'Entry'; 56 | 57 | props = struct(... 58 | 'internal_index', cell(n, 1), ... 59 | 'status', cell(n, 1) ... 60 | ); 61 | for i = 1 : n 62 | props(i).internal_index = i; 63 | props(i).status = C.status{i}; 64 | end 65 | 66 | 67 | % backup first 68 | copyfile(filename, [filename, '.bak']); 69 | edl_writeprops(doctag, attribs, nodetag, props, filename); 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_writereport.m: -------------------------------------------------------------------------------- 1 | function edl_writereport(filename, guid, props) 2 | %EDL_WRITEREPORT Writes an EDL report 3 | % 4 | % $ Syntax $ 5 | % - edl_writereport(filename, guid, props) 6 | % 7 | % $ Arguments $ 8 | % - filename: the filename of the destination report 9 | % - guid: the guid string assigned to the report 10 | % - props: the properties of the report items 11 | % (no need of internal_index) 12 | % 13 | % $ Description $ 14 | % - edl_writereport(filename, guid, workdir, ctrlpath, props) writes the 15 | % report according to the information provided. It will also add the 16 | % internal index to each entry. 17 | % 18 | % $ History $ 19 | % - Created by Dahua Lin, on Aug 14, 2006 20 | % 21 | 22 | %% parse and verify input 23 | 24 | if nargin < 3 25 | raise_lackinput('edl_writereport', 3); 26 | end 27 | 28 | %% Prepare elements 29 | 30 | doctag = 'ExpReport'; 31 | nodetag = 'Entry'; 32 | 33 | attribs.guid = guid; 34 | 35 | n = length(props); 36 | for i = 1 : n 37 | props(i).internal_index = i; 38 | end 39 | 40 | 41 | %% Write 42 | 43 | edl_writeprops(doctag, attribs, nodetag, props, filename); 44 | 45 | 46 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/edl_writescript.m: -------------------------------------------------------------------------------- 1 | function edl_writescript(filename, guid, workdir, ctrlpath, props) 2 | %EDL_WRITESCRIPT Writes an EDL script 3 | % 4 | % $ Syntax $ 5 | % - edl_writescript(filename, guid, workdir, ctrlpath, props) 6 | % 7 | % $ Arguments $ 8 | % - filename: the filename of the destination script 9 | % - guid: the guid string assigned to the script 10 | % - workdir: the root working directory of the experiments 11 | % - ctrlpath: the path of control file (r.t. script's parent) 12 | % - props: the properties of the experiment parameters 13 | % (no need of internal_index) 14 | % 15 | % $ Description $ 16 | % - edl_writescript(filename, guid, workdir, ctrlpath, props) writes the 17 | % script according to the information provided. It will also add the 18 | % internal index to each entry. 19 | % 20 | % $ Remarks $ 21 | % - The function will also creates the initial control file. 22 | % 23 | % $ History $ 24 | % - Created by Dahua Lin, on Aug 14, 2006 25 | % 26 | 27 | %% parse and verify input 28 | 29 | if nargin < 5 30 | raise_lackinput('edl_writescript', 5); 31 | end 32 | 33 | %% Prepare elements 34 | 35 | doctag = 'ExpScript'; 36 | nodetag = 'Entry'; 37 | 38 | attribs.guid = guid; 39 | attribs.workdir = workdir; 40 | attribs.ctrlpath = ctrlpath; 41 | 42 | n = length(props); 43 | for i = 1 : n 44 | props(i).internal_index = i; 45 | end 46 | 47 | 48 | %% Write 49 | 50 | edl_writeprops(doctag, attribs, nodetag, props, filename); 51 | cpath = sladdpath(ctrlpath, slfilepart(filename, 'parent')); 52 | edl_initctrlfile(cpath, guid, n); 53 | 54 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/example_samplegrps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ExpDL/example_samples.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ann/annsearch_wrapper.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ann/annsearch_wrapper.mexw32 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ann/annsearch_wrapper.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/ann/annsearch_wrapper.mexw64 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwcalc_core.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwcalc_core.mexw32 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwcalc_core.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwcalc_core.mexw64 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwdiff_core.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwdiff_core.mexw32 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwdiff_core.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwdiff_core.mexw64 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwhamming_cimp.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////// 2 | // 3 | // pwhamming_cimp.cpp 4 | // 5 | // The implementation of pairwise hamming metric 6 | // 7 | // Created by Dahua Lin, on Jul 30, 2007 8 | // 9 | ///////////////////////////////////////////////////////////////////// 10 | 11 | #include "mex.h" 12 | 13 | 14 | // The core function to compute hamming distances 15 | // X1: d x n1 (logical) 16 | // X2: d x n2 (logical) 17 | // dists: n1 x n2 (double) 18 | void compute_hamming(const mxLogical* X1, const mxLogical* X2, double* dists, int d, int n1, int n2) 19 | { 20 | const mxLogical* xc2 = X2; 21 | for (int j = 0; j < n2; ++j, xc2 += d) 22 | { 23 | const mxLogical* xc1 = X1; 24 | for (int i = 0; i < n1; ++i, xc1 += d) 25 | { 26 | int s = 0; 27 | for (int k = 0; k < d; ++k) 28 | { 29 | if (xc1[k] != xc2[k]) ++s; 30 | } 31 | *dists ++ = (double)s; 32 | } 33 | } 34 | } 35 | 36 | 37 | // The main entry 38 | // Input 39 | // - X1: d x n1 (logical) 40 | // - X2: d x n2 (logical) 41 | // Output 42 | // - D: n1 x n2 (double) 43 | // 44 | // No argument checking in the function 45 | // 46 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 47 | { 48 | const mxArray* mxX1 = prhs[0]; 49 | const mxArray* mxX2 = prhs[1]; 50 | 51 | int d = (int)mxGetM(mxX1); 52 | int n1 = (int)mxGetN(mxX1); 53 | int n2 = (int)mxGetN(mxX2); 54 | 55 | const mxLogical* X1 = (const mxLogical*)mxGetData(mxX1); 56 | const mxLogical* X2 = (const mxLogical*)mxGetData(mxX2); 57 | 58 | mxArray* mxD = mxCreateDoubleMatrix((mwSize)n1, (mwSize)n2, mxREAL); 59 | double* dists = mxGetPr(mxD); 60 | 61 | compute_hamming(X1, X2, dists, d, n1, n2); 62 | 63 | plhs[0] = mxD; 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwhamming_cimp.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwhamming_cimp.mexw32 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwmetrics_cimp.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/pwmetrics_cimp.mexw32 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/rowcolop_core.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/rowcolop_core.mexw32 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/rowcolop_core.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/rowcolop_core.mexw64 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/sladdrowcols.m: -------------------------------------------------------------------------------- 1 | function Y = sladdrowcols(X, vrow, vcol) 2 | %SLADDROWCOLS Adds the vectors to all rows and all columns 3 | % 4 | % $ Syntax $ 5 | % - Y = sladdrowcols(X, vrow, vcol) 6 | % 7 | % $ Arguments $ 8 | % - X: The input matrix 9 | % - vrow: The row vector to add to all rows 10 | % - vcol: The column vector to add to all columns 11 | % - Y: The resultant matrix 12 | % 13 | % $ Description $ 14 | % - Y = sladdrowcols(X, vrow, vcol) adds vrow to all rows of X and 15 | % adds vcol to all columns of Y. 16 | % 17 | % $ Remarks $ 18 | % - The implementation simply wrapps the mex function rowcolop_core. 19 | % 20 | % $ History $ 21 | % - Created by Dahua Lin, on Sep 10, 2006 22 | % 23 | 24 | Y = rowcolop_core(X, vrow, vcol, 1); % 1 is the opcode of addition -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/sladdvec.m: -------------------------------------------------------------------------------- 1 | function Y = sladdvec(X, v, d) 2 | %SLADDVEC adds a vector to columns or rows of a matrix 3 | % 4 | % $ Syntax $ 5 | % - Y = sladdvec(X, v, d) 6 | % - Y = sladdvec(X, v) 7 | % 8 | % $ Arguments $ 9 | % - X: The original matrix 10 | % - v: The addend vector 11 | % - d: The dimension along which the vector is to add 12 | % - Y: The resultant matrix 13 | % 14 | % $ Description $ 15 | % - Y = sladdvec(X, v, d) selects the most efficienct way to add a 16 | % vector v to every column/row of X. If d == 1, then v should be 17 | % a column vector, and is added to each column of X, if d == 2, 18 | % then v should be a row vector, and is added to each row of X. 19 | % 20 | % - Y = sladdvec(X, v) will automatically determine d according to 21 | % the shape of v. 22 | % 23 | % $ Remarks $ 24 | % - The implementation simply wraps the mex function vecop_core. 25 | % 26 | % $ History $ 27 | % - Created by Dahua Lin, on Sep 10, 2006 28 | % 29 | 30 | if nargin < 3 31 | if size(v, 2) == 1 32 | d = 1; 33 | else 34 | d = 2; 35 | end 36 | end 37 | 38 | Y = vecop_core(X, v, d, 1); % 1 is the opcode of addition in vecop_core 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slclassify_eucnn.m: -------------------------------------------------------------------------------- 1 | function labels = slclassify_eucnn(centers, samples) 2 | %SLCLASSIFY_EUCNN Classifies samples using Euclidena-based NN 3 | % 4 | % $ Syntax $ 5 | % - labels = slclassify_eucnn(centers, samples) 6 | % 7 | % $ Arguments $ 8 | % - centers: the class centers 9 | % - samples: the samples to be classified 10 | % - labels: the classified result 11 | % 12 | % $ Description $ 13 | % - labels = slclassify_eucnn(centers, samples) classifies the samples to 14 | % nearest centers based on Euclidean distances. The output labels 15 | % indicate which nearest center the samples are classified to. 16 | % 17 | % $ History $ 18 | % - Created by Dahua Lin, on Aug 21, 2006 19 | % 20 | 21 | dists = slmetric_pw(centers, samples, 'eucdist'); 22 | labels = slclassify(dists, 1:size(dists,1), 'low'); 23 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slconfine.m: -------------------------------------------------------------------------------- 1 | function Ac = slconfine(A, lb, ub) 2 | %SLCONFINE Confines the values in a range 3 | % 4 | % $ Syntax $ 5 | % - Ac = slconfine(A, lb) 6 | % - Ac = slconfine(A, lb, []) 7 | % - Ac = slconfine(A, [], ub) 8 | % - Ac = slconfine(A, lb, ub) 9 | % 10 | % $ Arguments $ 11 | % - A: the input array 12 | % - lb: the lower bound to be enforced 13 | % - ub: the upper bound to be enforced 14 | % - Ac: the confined array 15 | % 16 | % $ Description $ 17 | % - Ac = slconfine(A, lb) confines the values in A to be no less than the 18 | % lower bound lb. It is equivalent to Ac = slconfine(A, lb, []). 19 | % 20 | % - Ac = slconfine(A, [], ub) confines the values in A to be no much than 21 | % the higher bound ub. 22 | % 23 | % - Ac = slconfine(A, lb, ub) confines the values in A to be within the 24 | % range between lb and ub. 25 | % 26 | % $ Remarks $ 27 | % # The lb and ub can be either a scalar or an array of the same size as 28 | % the input matrix A. 29 | % 30 | % $ History $ 31 | % - Created by Dahua Lin on Nov 18th, 2005 32 | % 33 | 34 | %% parse and verify input arguments 35 | if nargin < 2 36 | raise_lackinput('slconfine', 2); 37 | end 38 | if nargin < 3 39 | ub = []; 40 | end 41 | 42 | %% compute 43 | Ac = A; 44 | if ~isempty(lb) 45 | Ac = max(Ac, lb); 46 | end 47 | if ~isempty(ub) 48 | Ac = min(Ac, ub); 49 | end 50 | 51 | 52 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/sldiff_pw.m: -------------------------------------------------------------------------------- 1 | function D = sldiff_pw(X1, X2, type) 2 | %SLDIFF_PW Measures the pair-wise difference 3 | % 4 | % $ Synatx $ 5 | % - D = sldiff_pw(X1, X2, type) 6 | % 7 | % $ Arguments $ 8 | % - X1, X2: the two sample matrices 9 | % - type: the type of difference measurement 10 | % default = 'abssum' 11 | % 12 | % $ Description $ 13 | % - D = sldiff_pw(X1, X2, type) computes the measurment of differences 14 | % between the samples in X1 and those in X2 in a pairwise manner. 15 | % All samples should be stored in columns. And the samples in X1 and 16 | % X2 should be of the same dimension. If X1 and X2 are of sizes 17 | % dxn1 and dxn2 respectively. Then D is a matrix of size n1 x n2. 18 | % 19 | % - The measurment types supported are listed below 20 | % \* 21 | % \t Table 1. The difference measurement types \\ 22 | % \h name & description \\ 23 | % 'abssum' & sum of absolute values of differences \\ 24 | % 'maxdiff' & maximum of absolute values of differences \\ 25 | % 'mindiff' & minimum of absolute values of differences \\ 26 | % \* 27 | % 28 | % $ History $ 29 | % - Created by Dahua Lin on Dec 06th, 2005 30 | % - Modified by Dahua Lin on Sep 10th, 2006 31 | % - Re-implement the core in C++: pwdiff_core 32 | % - The efficiency is increased by 10 times. 33 | % 34 | 35 | %% parse and verify input arguments 36 | 37 | if nargin < 3 || isempty(type) 38 | type = 'abssum'; 39 | end 40 | 41 | switch type 42 | case 'abssum' 43 | pdmcode = 1; 44 | case 'maxdiff' 45 | pdmcode = 2; 46 | case 'mindiff' 47 | pdmcode = 3; 48 | otherwise 49 | error('sltoolbox:invalidarg', ... 50 | 'Invalid type of pwdiff computation: %s', type); 51 | end 52 | 53 | %% Compute 54 | 55 | D = pwdiff_core(X1, X2, pdmcode); 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slinitarray.m: -------------------------------------------------------------------------------- 1 | function A = slinitarray(type, size) 2 | %SLINITARRAY Initialize an array of specified type and size 3 | % 4 | % $ Syntax $ 5 | % - A = slinitarray(type, size) 6 | % 7 | % $ Arguments $ 8 | % - type the string representing the element type of the array 9 | % - size the vector representing the size of the array 10 | % - A the initialized array 11 | % 12 | % $ Description $ 13 | % - A = slinitarray(type, size) creates an array of specified type and 14 | % given size, with all elements being zeros. 15 | % 16 | % - The typenames supported are listed below: 17 | % - 'double' 18 | % - 'single' 19 | % - 'float' 20 | % - 'uint8' 21 | % - 'uint16' 22 | % - 'uint32' 23 | % - 'uint64' 24 | % - 'int8' 25 | % - 'int16' 26 | % - 'int32' 27 | % - 'int64' 28 | % - 'logical' 29 | % - 'char' 30 | % 31 | % $ History $ 32 | % - Created by Dahua Lin on Dec 7th, 2005 33 | % 34 | 35 | 36 | switch type 37 | case 'double' 38 | A = zeros(size); 39 | case {'single', 'float'} 40 | A = zeros(size, 'single'); 41 | case {'uint8', 'uint16', 'uint32', 'uint64', ... 42 | 'int8', 'int16', 'int32', 'int64'} 43 | A = zeros(size, type); 44 | case 'logical' 45 | A = false(size); 46 | case 'char' 47 | A = char(zeros(size, 'uint8')); 48 | otherwise 49 | error('sltoolbox:invalid_type', ... 50 | 'Unsupported typename %s', typename); 51 | end 52 | 53 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/sllogdet.m: -------------------------------------------------------------------------------- 1 | function r = sllogdet(A) 2 | %SLLOGDET Computes the logarithm of determinant of a matrix in a robust way 3 | % 4 | % $ Syntax $ 5 | % - r = sllogdet(A) 6 | % 7 | % $ Arguments $ 8 | % - A: the square matrix whose log-determinant is to be solved 9 | % - r: the log-determinant of A 10 | % 11 | % $ Description $ 12 | % - r = sllogdet(A) computes the logarithm of (absolute )determinant of a square 13 | % matrix A in a robust way, to reduce the risk of underflow or overflow. 14 | % 15 | % $ Remarks $ 16 | % - If the matrix is singular, inf or -inf would be return. 17 | % 18 | % $ History $ 19 | % - Created by Dahua Lin on Dec 28th, 2005 20 | % 21 | 22 | %% parse and verify input arguments 23 | if ndims(A) ~= 2 24 | error('sltoolbox:invalidarg', 'A should be a 2D matrix'); 25 | end 26 | d = size(A, 1); 27 | if size(A, 2) ~= d 28 | error('sltoolbox:invalidarg', 'A shoule be a square matrix'); 29 | end 30 | 31 | %% compute 32 | 33 | % triangular decomposition 34 | [L, U] = lu(A); 35 | diagU = diag(U); 36 | slignorevars(L); 37 | clear L U; 38 | 39 | % sign controlling 40 | neg_u_entries = find(diagU < 0); 41 | if ~isempty(neg_u_entries) 42 | diagU(neg_u_entries) = -diagU(neg_u_entries); 43 | end 44 | 45 | % log-product 46 | wid = 'MATLAB:log:logOfZero'; 47 | st = warning('query', wid); 48 | st = st.state; 49 | 50 | warning('off', wid); 51 | r = sum(log(diagU)); 52 | warning(st, wid); 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slmax.m: -------------------------------------------------------------------------------- 1 | function S = slmax(A, d) 2 | %SLMAX Compute the maximum of values in subarrays 3 | % 4 | % $ Syntax $ 5 | % - S = slmax(A) 6 | % - S = slmax(A, d) 7 | % - S = slmax(A, [d1 d2 ... dk]) 8 | % 9 | % $ Arguments $ 10 | % - A: the input array 11 | % - d: the dimensions along which the maximum is searched 12 | % - S: the resultant max matrix 13 | % 14 | % $ Description $ 15 | % - S = slmax(A) finds the maximums along column vectors of A. It is 16 | % equivalent to S = max(A) 17 | % 18 | % - S = slmax(A, d) finds the maximums along dimension d. It is 19 | % equivalent to S = max(A, [], d) 20 | % 21 | % - S = slmax(A, [d1 d2 ... dk]) finds the maximum values along dimension 22 | % d1, d2, ... dk. 23 | % 24 | % $ History $ 25 | % - Created by Dahua Lin on Nov 19th, 2005 26 | % 27 | 28 | %% parse and verify input arguments 29 | if nargin < 2 || isempty(d) 30 | d = 1; 31 | end 32 | 33 | %% compute 34 | if isscalar(d) 35 | S = max(A, [], d); 36 | else 37 | k = length(d); 38 | S = A; 39 | for i = 1 : k 40 | S = max(S, [], d(i)); 41 | end 42 | end 43 | 44 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slmetric_pw_blks.m: -------------------------------------------------------------------------------- 1 | function slmetric_pw_blks(X1, X2, ps, dstpath, mtype, varargin) 2 | %SLMETRIC_PW_BLKS Compute the pairwise metrics in a blockwise manner 3 | % 4 | % $ Syntax $ 5 | % - slmetric_pw_blks(X1, X2, ps, dstpath, mtype, ...) 6 | % 7 | % $ Arguments $ 8 | % - X1: the first sample matrix 9 | % - X2: the second sample matrix 10 | % - ps: the partition structure of the score matrix 11 | % - dstpath: the destination path 12 | % - mtype: the metric type 13 | % 14 | % $ Description $ 15 | % - slmetric_pw_blks(X1, X2, ps, dstpath, mtype, ...) computes the 16 | % pairwise metric values for large dataset in blockwise manner. 17 | % Each block of scores are computed respectively and stored in files. 18 | % This function is an extension of slmetric_pw to support 19 | % blockwise score computation. 20 | % Please refer to slmetric_pw and slpwcomp_blks for more information 21 | % on the usage. 22 | % 23 | % $ History $ 24 | % - Created by Dahua Lin, on Aug 9th, 2006 25 | % 26 | 27 | if nargin < 5 28 | raise_lackinput('slmetric_pw_blks', 5); 29 | end 30 | 31 | slpwcomp_blks(X1, X2, ps, dstpath, 'slmetric_pw', mtype, varargin{:}); 32 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slmetric_pw_compile.m: -------------------------------------------------------------------------------- 1 | function slmetric_pw_compile() 2 | %SLMETRIC_PW_COMPILE Compiles the CPP mex files for slmetric_pw 3 | % 4 | % [ History ] 5 | % - Created by Dahua Lin, on Aug 16, 2007 6 | % 7 | 8 | mdir = fileparts(mfilename('fullpath')); 9 | if ~strcmp(pwd(), mdir) 10 | cd(mdir); 11 | end 12 | 13 | disp('compile pwhamming_cimp.cpp'); 14 | mex -O pwhamming_cimp.cpp 15 | 16 | disp('compile pwmetrics_cimp.cpp'); 17 | mex -O pwmetrics_cimp.cpp 18 | 19 | disp('compilation completed.'); -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slmin.m: -------------------------------------------------------------------------------- 1 | function S = slmin(A, d) 2 | %SLMIN Compute the minimum of values in subarrays 3 | % 4 | % $ Syntax $ 5 | % - S = slmin(A) 6 | % - S = slmin(A, d) 7 | % - S = slmin(A, [d1 d2 ... dk]) 8 | % 9 | % $ Arguments $ 10 | % - A: the input array 11 | % - d: the dimensions along which the minimum is searched 12 | % - S: the resultant min matrix 13 | % 14 | % $ Description $ 15 | % - S = slmin(A) finds the minimums along column vectors of A. It is 16 | % equivalent to S = min(A) 17 | % 18 | % - S = slmin(A, d) finds the minimums along dimension d. It is 19 | % equivalent to S = min(A, [], d) 20 | % 21 | % - S = slmin(A, [d1 d2 ... dk]) finds the minimum values along dimension 22 | % d1, d2, ... dk. 23 | % 24 | % $ History $ 25 | % - Created by Dahua Lin on Nov 19th, 2005 26 | % 27 | 28 | %% parse and verify input arguments 29 | if nargin < 2 || isempty(d) 30 | d = 1; 31 | end 32 | 33 | %% compute 34 | if isscalar(d) 35 | S = min(A, [], d); 36 | else 37 | k = length(d); 38 | S = A; 39 | for i = 1 : k 40 | S = min(S, [], d(i)); 41 | end 42 | end 43 | 44 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slmulrowcols.m: -------------------------------------------------------------------------------- 1 | function Y = slmulrowcols(X, vrow, vcol) 2 | %SLMULROWCOLS Multiplies the vectors to all rows and all columns 3 | % 4 | % $ Syntax $ 5 | % - Y = slmulrowcols(X, vrow, vcol) 6 | % 7 | % $ Arguments $ 8 | % - X: The input matrix 9 | % - vrow: The row vector to multiply to all rows 10 | % - vcol: The column vector to multiply to all columns 11 | % - Y: The resultant matrix 12 | % 13 | % $ Description $ 14 | % - Y = slmulrowcols(X, vrow, vcol) multiplies vrow to all rows of X and 15 | % adds vcol to all columns of Y. 16 | % 17 | % $ Remarks $ 18 | % - The implementation simply wrapps the mex function rowcolop_core. 19 | % 20 | % $ History $ 21 | % - Created by Dahua Lin, on Sep 10, 2006 22 | % 23 | 24 | Y = rowcolop_core(X, vrow, vcol, 2); % 2 is the opcode of multiplication -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slmulvec.m: -------------------------------------------------------------------------------- 1 | function Y = slmulvec(X, v, d) 2 | %SLMULVEC multiplies a vector to columns or rows of a matrix 3 | % 4 | % $ Syntax $ 5 | % - Y = slmulvec(X, v, d) 6 | % - Y = slmulvec(X, v) 7 | % 8 | % $ Arguments $ 9 | % - X: The original matrix 10 | % - v: The addend vector 11 | % - d: The dimension along which the vector is to add 12 | % - Y: The resultant matrix 13 | % 14 | % $ Description $ 15 | % - Y = slmulvec(X, v, d) selects the most efficienct way to multiple a 16 | % vector v to every column/row of X. If d == 1, then v should be 17 | % a column vector, and is multiplied to each column of X, if d == 2, 18 | % then v should be a row vector, and is multiplied to each row of X. 19 | % 20 | % - Y = slmulvec(X, v) will automatically determine d according to 21 | % the shape of v. 22 | % 23 | % $ Remarks $ 24 | % - The implementation simply wraps the mex function vecop_core. 25 | % 26 | % $ History $ 27 | % - Created by Dahua Lin, on Sep 10, 2006 28 | % 29 | 30 | if nargin < 3 31 | if size(v, 2) == 1 32 | d = 1; 33 | else 34 | d = 2; 35 | end 36 | end 37 | 38 | Y = vecop_core(X, v, d, 2); % 2 is the opcode of multiplication in vecop_core -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slnormalize.m: -------------------------------------------------------------------------------- 1 | function An = slnormalize(A, p, d) 2 | %SLNORMALIZE Normalize the sub-arrays 3 | % 4 | % $ Syntax $ 5 | % - An = slnormalize(A) 6 | % - An = slnormalize(A, p) 7 | % - An = slnormalize(A, [], d) 8 | % - An = slnormalize(A, p, d) 9 | % 10 | % $ Arguments $ 11 | % - A: the input array 12 | % - p: the order of the norm (default = 2) 13 | % - d: the dimension of subarrays (default = 1, column vectors) 14 | % - An: the normalized array 15 | % 16 | % $ Description $ 17 | % - An = slnormalize(A) normalizes the column vectors of A by 2nd-order. 18 | % 19 | % - An = slnormalize(A, p) normalizes the column vectors of a by 20 | % pth-order. 21 | % 22 | % - An = slnormalize(A, [], d) normalizes the subarrays of A along 23 | % dimensions specified by d by 2nd-order. 24 | % 25 | % - An = slnormalize(A, p, d) normalizes the subarrays of A along 26 | % dimensions specified by d by pth-order. 27 | % 28 | % $ Remarks $ 29 | % # Normalize an array by pth order means dividing the elements of 30 | % the array by its p-th norm. 31 | % # p can be inf or -inf. If p = inf, then the Lp norm is simply the 32 | % maximum magnitude value; while if p = -inf, then the Lp norm is the 33 | % minimum magnitude value. 34 | % 35 | % $ History $ 36 | % - Created by Dahua Lin on Nov 19th, 2005 37 | % - Modified by Dahua Lin on Sep 10th, 2006 38 | % - replace slmul by slmulvec to increase efficiency 39 | % 40 | 41 | %% parse and verify input arguments 42 | if nargin < 2 || isempty(p) 43 | p = 2; 44 | end 45 | if nargin < 3 || isempty(d) 46 | d = 1; 47 | end 48 | if ~isscalar(p) 49 | error('sltoolbox:notscalar', 'p should be a scalar'); 50 | end 51 | if p == 0 52 | error('sltoolbox:zeroerr', 'p should not be zero'); 53 | end 54 | 55 | %% compute 56 | nrms = slnorm(A, p, d); 57 | nrms = slenforce(nrms, 'positive'); 58 | An = slmulvec(A, 1 ./ nrms); 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slpwcalc.m: -------------------------------------------------------------------------------- 1 | function M = slpwcalc(v1, v2, op) 2 | %SLPWCALC Calculates a table pairwisely on two set of scalars 3 | % 4 | % $ Syntax $ 5 | % - M = slpwcalc(v1, v2, op) 6 | % 7 | % $ Arguments $ 8 | % - v1: The vector of the first set of numbers (length n1) 9 | % - v2: The vector of the second set of numbers (length n2) 10 | % - op: The calculation type 11 | % - M: The calculated table (n1 x n2) 12 | % 13 | % $ Description $ 14 | % - M = slpwcalc(v1, v2, op) calculates theon the scalars in v1 and v2 15 | % pairwisely to make the result table M. op is the string indicating 16 | % the calculation type to take. Available op include: 17 | % 'add': addition: M(i, j) = v1(i) + v2(j) 18 | % 'mul': multiplication: M(i, j) = v1(i) * v2(j) 19 | % 'absdiff': absolute diff: M(i, j) = abs(v1(i) - v2(j)) 20 | % 'max': maximum value: M(i, j) = max(v1(i), v2(j)) 21 | % 'min': minimum value: M(i, j) = min(v1(i), v2(j)) 22 | % 23 | % $ Remarks $ 24 | % - It simply wraps the core mex: pwcalc_core 25 | % 26 | % - both v1 and v2 should be vectors 27 | % 28 | % $ History $ 29 | % - Created by Dahua Lin, on Sep 11st, 2006 30 | % 31 | 32 | %% parse and verify input 33 | 34 | if nargin < 3 35 | raise_lackinput('slpwcalc', 3); 36 | end 37 | 38 | if ~isvector(v1) || ~isvector(v2) 39 | error('sltoolbox:invalidarg', 'both v1 and v2 should be vectors'); 40 | end 41 | 42 | switch op 43 | case 'add' 44 | opcode = 1; 45 | case 'mul' 46 | opcode = 2; 47 | case 'absdiff' 48 | opcode = 3; 49 | case 'max' 50 | opcode = 4; 51 | case 'min' 52 | opcode = 5; 53 | otherwise 54 | error('sltoolbox:invalidarg', 'Invalid op type for pwcalc: %s', op); 55 | end 56 | 57 | %% main 58 | 59 | M = pwcalc_core(v1, v2, opcode); 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slsum.m: -------------------------------------------------------------------------------- 1 | function S = slsum(A, d) 2 | %SLSUM Compute the sum of values in subarrays 3 | % 4 | % $ Syntax $ 5 | % - S = slsum(A) 6 | % - S = slsum(A, d) 7 | % - S = slsum(A, [d1 d2 ... dk]) 8 | % 9 | % $ Arguments $ 10 | % - A: the input array 11 | % - d: the dimensions along which the sum is performed 12 | % - S: the resultant sum matrix 13 | % 14 | % $ Description $ 15 | % - S = slsum(A) sums up the values in column vectors of A. It is 16 | % equivalent to S = sum(A) 17 | % 18 | % - S = slsum(A, d) sums up the values along dimension d. It is 19 | % equivalent to S = sum(A, d) 20 | % 21 | % - S = slsum(A, [d1 d2 ... dk]) sums up the values along dimension 22 | % d1, d2, ... dk. 23 | % 24 | % $ History $ 25 | % - Created by Dahua Lin on Nov 18th, 2005 26 | % 27 | 28 | %% parse and verify input arguments 29 | if nargin < 2 || isempty(d) 30 | d = 1; 31 | end 32 | 33 | %% compute 34 | if isscalar(d) 35 | S = sum(A, d); 36 | else 37 | k = length(d); 38 | S = A; 39 | for i = 1 : k 40 | S = sum(S, d(i)); 41 | end 42 | end 43 | 44 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/vecop_core.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/vecop_core.mexw32 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/vecop_core.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/vecop_core.mexw64 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/discrete/histmetricpw_core.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/discrete/histmetricpw_core.mexw32 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/discrete/histmetricpw_core.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/discrete/histmetricpw_core.mexw64 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/close.m: -------------------------------------------------------------------------------- 1 | function logger = close(logger) 2 | %CLOSE Closes the logger 3 | % 4 | % $ Syntax $ 5 | % - logger = close(logger) 6 | % 7 | % $ Description $ 8 | % - logger = close(logger) closes the logger by closing all filehandles 9 | % and set the winshow to false 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin, on Aug 12nd, 2006 13 | % 14 | 15 | logger.winshow = false; 16 | 17 | if ~isempty(logger.files) 18 | nf = length(logger.files); 19 | F = logger.files; 20 | 21 | for i = 1 : nf 22 | fclose(F(i).fid); 23 | end 24 | 25 | logger.files = []; 26 | end 27 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/decindent.m: -------------------------------------------------------------------------------- 1 | function logger = decindent(logger, d) 2 | %INCINDENT Decreases the indent by a specified amount 3 | % 4 | % $ Syntax $ 5 | % - logger = decindent(logger, d) 6 | % 7 | % $ Arguments $ 8 | % - logger: the target logger 9 | % - d: the number of levels of indent to be decreased 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin, on Aug 12nd, 2006 13 | % 14 | 15 | newindent = max(logger.indent - d, 0); 16 | 17 | logger.indent = newindent; -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/detachfiles.m: -------------------------------------------------------------------------------- 1 | function logger = detachfiles(logger, files) 2 | %DETACHFILES Detachs the logger from some added files 3 | % 4 | % $ Syntax $ 5 | % - logger = detachfiles(logger, file) 6 | % - logger = detachfiles(logger, files) 7 | % 8 | % $ Argument $ 9 | % - logger: the logger to be processed 10 | % - file: the filename of the file to be detached 11 | % - files: the cell array of filenames to be detached 12 | % 13 | % $ Description $ 14 | % - logger = detachfiles(logger, file) detach a file from the logger 15 | % list. 16 | % 17 | % - logger = detachfiles(logger, files) detach a set of filenames from 18 | % the logger list. 19 | % 20 | % $ History $ 21 | % - Created by Dahua Lin, on Aug 12nd, 2006 22 | % 23 | 24 | if ischar(files) 25 | 26 | [tf, idx] = isattached(logger, files); 27 | if ~tf 28 | error('sltoolbox:invalidarg', ... 29 | 'The file %s has not been added to the file list', fp); 30 | end 31 | 32 | fclose(files(idx).fid); 33 | 34 | elseif iscell(files) 35 | 36 | n = numel(files); 37 | for i = 1 : n 38 | logger = detachfiles(logger, files{i}); 39 | end 40 | 41 | else 42 | error('sltoolbox:invalidarg', ... 43 | 'The files should be either a filename or a cell array of filenames'); 44 | end 45 | 46 | 47 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/get.m: -------------------------------------------------------------------------------- 1 | function R = get(logger, propname) 2 | %GET Gets properties of a logger 3 | % 4 | % $ Syntax $ 5 | % - R = get(logger, propname) 6 | % 7 | % $ Description $ 8 | % - R = get(logger, propname) gets the property of specified name for 9 | % the logger. 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin, on Aug 12nd, 2006 13 | % 14 | 15 | switch propname 16 | case 'rootpath' 17 | R = logger.rootpath; 18 | case 'indent' 19 | R = logger.indent; 20 | case 'numfiles' 21 | R = length(logger.files); 22 | case 'filepaths' 23 | R = {logger.files.filepath}'; 24 | case 'winshow' 25 | R = logger.winshow; 26 | case 'files' 27 | R = logger.files; 28 | case 'timestamp' 29 | R = logger.timestamp; 30 | otherwise 31 | error('sltoolbox:invalidarg', ... 32 | 'Invalid property name %s for sllog', propname); 33 | end 34 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/incindent.m: -------------------------------------------------------------------------------- 1 | function logger = incindent(logger, d) 2 | %INCINDENT Increases the indent by a specified amount 3 | % 4 | % $ Syntax $ 5 | % - logger = incindent(logger, d) 6 | % 7 | % $ Arguments $ 8 | % - logger: the target logger 9 | % - d: the number of levels of indent to be increased 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin, on Aug 12nd, 2006 13 | % 14 | 15 | newindent = max(logger.indent + d, 0); 16 | 17 | logger.indent = newindent; 18 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/isactive.m: -------------------------------------------------------------------------------- 1 | function b = isactive(logger, filename) 2 | %ISACTIVE Queries whether a log file is active 3 | % 4 | % $ Syntax $ 5 | % - b = isactive(logger, filename) 6 | % 7 | % $ Description $ 8 | % - b = isactive(logger, filename) queries whether a log file is active. 9 | % 10 | % $ History $ 11 | % - Created by Dahua Lin, on Aug 12, 2006 12 | % 13 | 14 | [tf, idx] = isattached(logger, filename); 15 | 16 | if tf 17 | b = logger.files(idx).isactive; 18 | else 19 | error('sltoolbox:invalidarg', ... 20 | 'The file %s has not been added to the file list', fp); 21 | end 22 | 23 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/isattached.m: -------------------------------------------------------------------------------- 1 | function [tf, idx] = isattached(logger, filename) 2 | %ISATTACHED Judges whether the file is attached to the logger 3 | % 4 | % $ Syntax $ 5 | % - [tf, idx] = isattached(logger, filename) 6 | % 7 | % $ Arguments $ 8 | % - logger: the logger to be queried 9 | % - filename: the filename to be queried 10 | % - tf: the boolean variable indicating whether attach 11 | % - idx: the index of the found file 12 | % 13 | % $ Description $ 14 | % - [tf, idx] = isattached(logger, filename) judges whether a file 15 | % is currently attached to the logger. The filename should be 16 | % given as relative path to the logger's root path. 17 | % 18 | % $ History $ 19 | % - Created by Dahua Lin, on Aug 12nd, 2006 20 | % 21 | 22 | tf = false; 23 | idx = 0; 24 | 25 | if ~isempty(logger.files) 26 | 27 | fp = sladdpath(filename, logger.rootpath); 28 | 29 | n = length(logger.files); 30 | for i = 1 : n 31 | if strcmpi(fp, logger.files(i).filepath) 32 | tf = true; 33 | idx = i; 34 | break; 35 | end 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/setactive.m: -------------------------------------------------------------------------------- 1 | function logger = setactive(logger, files, s) 2 | %SETACTIVE Sets a set of files active/inactive 3 | % 4 | % $ Syntax $ 5 | % - logger = setactive(logger, file, s) 6 | % - logger = setactive(logger, files, s) 7 | % 8 | % $ Description $ 9 | % - logger = setactive(logger, file, s) sets the state of the specified 10 | % file in the logger to be s (true/false). 11 | % 12 | % - logger = setactive(logger, file, s) sets the state of the specified 13 | % cell array of files in the logger to be s (true/false). 14 | % 15 | % $ History $ 16 | % - Created by Dahua Lin, on Aug 12nd, 2006 17 | % 18 | 19 | if ischar(files) 20 | 21 | [tf, idx] = isattached(logger, files); 22 | 23 | if tf 24 | logger.files(idx).isactive = s; 25 | else 26 | error('sltoolbox:invalidarg', ... 27 | 'The file %s has not been added to the file list', files); 28 | end 29 | 30 | elseif iscell(files) 31 | 32 | n = length(files); 33 | for i = 1 : n 34 | logger = setactive(logger, files{i}, s); 35 | end 36 | 37 | else 38 | 39 | error('sltoolbox:invalidarg', ... 40 | 'The files should be a string or a cell array'); 41 | end 42 | 43 | 44 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/sllog.m: -------------------------------------------------------------------------------- 1 | function logger = sllog(varargin) 2 | %SLLOG Constructs a logger 3 | % 4 | % $ Syntax $ 5 | % - logger = sllog(...) 6 | % 7 | % $ Description $ 8 | % - logger = sllog(...) constructs a logger using the specified 9 | % properties. 10 | % \* 11 | % \t The Logger Properties 12 | % \h name & description \\ 13 | % 'rootpath' & The root path of the log filename, default = '' 14 | % 'files' & the cell array of log filenames, default = {} 15 | % 'winshow' & whether to show to matlab window, default = true 16 | % 'timestamp' & whether to add time-stamp to records, 17 | % default = true 18 | % 'timeformat' & the format string for time-stamp 19 | % can be either a number or a string 20 | % refer to datastr for detail. 21 | % default = '[yyyy-mm-dd HH:MM:SS]' 22 | % \* 23 | % 24 | % $ History $ 25 | % - Created by Dahua Lin, on Aug 12nd, 2006 26 | % 27 | 28 | %% parse and verify input arguments 29 | 30 | opts.rootpath = ''; 31 | opts.files = {}; 32 | opts.winshow = true; 33 | opts.timestamp = true; 34 | opts.timeformat = '[yyyy-mm-dd HH:MM:SS]'; 35 | 36 | opts = slparseprops(opts, varargin{:}); 37 | 38 | %% construction 39 | 40 | logger = struct(... 41 | 'rootpath', opts.rootpath, ... 42 | 'files', [], ... 43 | 'winshow', opts.winshow, ... 44 | 'indent', 0, ... 45 | 'timestamp', true, ... 46 | 'timeformat', opts.timeformat ... 47 | ); 48 | logger = class(logger, 'sllog'); 49 | 50 | %% open file handles 51 | 52 | logger = addfiles(logger, opts.files); 53 | 54 | 55 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/subsref.m: -------------------------------------------------------------------------------- 1 | function R = subsref(logger, ss) 2 | %SUBSREF Get the properties by subscription 3 | % 4 | % $ Syntax $ 5 | % - R = logger. 6 | % - R = logger.('') 7 | % 8 | % $ History $ 9 | % - Created by Dahua Lin on Aug 12nd, 2006 10 | % 11 | 12 | 13 | if ss(1).type == '.' && ischar(ss(1).subs) 14 | R = get(logger, ss(1).subs); 15 | if (length(ss) >= 2) 16 | R = subsref(R, ss(2:end)); 17 | end 18 | else 19 | error('sltoolbox:invalidarg', 'Invalid subscription for dataset'); 20 | end -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/write.m: -------------------------------------------------------------------------------- 1 | function write(logger, varargin) 2 | %WRITE Writes message to a logger 3 | % 4 | % $ Syntax $ 5 | % - write(logger, ...) 6 | % 7 | % $ Description $ 8 | % - write(logger, ...) writes message to a logger. The contents given 9 | % should be as sprintf. 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin, on Aug 12nd, 2006 13 | % 14 | 15 | 16 | if ~logger.winshow && isempty(logger.files) 17 | return; 18 | end 19 | 20 | % generate string 21 | 22 | indent_step = 4; 23 | ns = max(logger.indent, 0); 24 | 25 | if logger.timestamp 26 | tstr = datestr(now(), logger.timeformat); 27 | nblanks = ns * indent_step + 2; 28 | str = [tstr, blanks(nblanks), sprintf(varargin{:})]; 29 | else 30 | if ns == 0 31 | str = sprintf(varargin{:}); 32 | else 33 | nblanks = ns * indent_step; 34 | str = [blanks(nblanks), sprintf(varargin{:})]; 35 | end 36 | end 37 | 38 | % write it 39 | 40 | if logger.winshow 41 | disp(str); 42 | end 43 | 44 | if ~isempty(logger.files) 45 | 46 | F = logger.files; 47 | nf = length(F); 48 | for i = 1 : nf 49 | if F(i).isactive 50 | fprintf(F(i).fid, '%s\n', str); 51 | end 52 | end 53 | 54 | end 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/writeblank.m: -------------------------------------------------------------------------------- 1 | function writeblank(logger) 2 | %WRITEBLANK Writes a blank line to log 3 | % 4 | % $ Syntax $ 5 | % - writeblank(logger) 6 | % 7 | % $ Description $ 8 | % - writeblank(logger) writes one blank line to logging output. 9 | % 10 | % $ History $ 11 | % - Created by Dahua Lin, on Aug 13, 2006 12 | % 13 | 14 | if logger.winshow 15 | disp(' '); 16 | end 17 | 18 | if ~isempty(logger.files) 19 | 20 | F = logger.files; 21 | nf = length(F); 22 | for i = 1 : nf 23 | if F(i).isactive 24 | fprintf(F(i).fid, ' \n'); 25 | end 26 | end 27 | 28 | end -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/@sllog/writeinfo.m: -------------------------------------------------------------------------------- 1 | function writeinfo(logger, varargin) 2 | %WRITEINFO Writes information to logger without time-stamp 3 | % 4 | % $ Syntax $ 5 | % - writeinfo(logger, ...) 6 | % 7 | % $ Description $ 8 | % - writeinfo(logger, ...). The usage is the same as write, except that 9 | % the time stamp becoming blank during writing. 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin, on Aug 13, 2006 13 | % 14 | 15 | if logger.timestamp 16 | tstr = datestr(now(), logger.timeformat); 17 | logger.timeformat = blanks(length(tstr)); 18 | write(logger, varargin{:}); 19 | else 20 | write(logger, varargin{:}); 21 | end 22 | 23 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/array_fileformat.txt: -------------------------------------------------------------------------------- 1 | The format of Array file 2 | 3 | The first 4 bytes (offset 0 - 3): the tag chars: 'a', 'r', 'r', '\0' (char(0)) 4 | 5 | The next byte (offset 4) indicates the value type 6 | 1: double 7 | 2: single 8 | 3: logical 9 | 4: char 10 | 5: int8 11 | 6: uint8 12 | 7: int16 13 | 8: uint16 14 | 9: int32 15 | 10: uint32 16 | 11: int64 17 | 12: uint64 18 | 19 | The next byte (offset 5) indicates the number of dimensions 20 | 21 | The size bytes (from offset 8, 4 * d bytes) use d uint32 numbers to 22 | characterize the sizes along all dimensions 23 | 24 | From offset 8+4*d, is the data region, continuously in column-major order. 25 | 26 | The whole file size 27 | 28 | 8 + 4 * d + bytes/element * element number 29 | 30 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/slchangefilepart.m: -------------------------------------------------------------------------------- 1 | function newfp = slchangefilepart(fp, varargin) 2 | %SLCHANGEFILEPART Changes some parts of the file path 3 | % 4 | % $ Syntax $ 5 | % - newfp = slchangefilepart(fp, partname1, part1, ...) 6 | % 7 | % $ Description $ 8 | % - newfp = slchangefilepart(fp, partname1, part1, ...) changes the 9 | % specified part of a path to a new value to form a new path. 10 | % Please refer to slfilepart for part names 11 | % 12 | % $ Remarks $ 13 | % - If you specify the name, then you should be specify title and ext. 14 | % 15 | % $ History $ 16 | % - Created by Dahua Lin, on Aug 12nd, 2006 17 | % 18 | 19 | %% Main body 20 | 21 | if isempty(varargin) 22 | newfp = fp; 23 | else 24 | 25 | opts.parent = ''; 26 | opts.name = ''; 27 | opts.title = ''; 28 | opts.ext = ''; 29 | opts = slparseprops(opts, varargin{:}); 30 | 31 | if ~isempty(opts.ext) 32 | if opts.ext(1) ~= '.' 33 | error('sltoolbox:invalidarg', ... 34 | 'The extension string should start with a dot . '); 35 | end 36 | end 37 | 38 | [p.parent, p.title, p.ext] = fileparts(fp); 39 | 40 | if isempty(opts.name) 41 | p = updatefields(p, opts, {'parent', 'title', 'ext'}); 42 | newfp = fullfile(p.parent, [p.title, p.ext]); 43 | else 44 | if ~isempty(opts.title) || ~isempty(opts.ext) 45 | error('sltoolbox:invalidarg', ... 46 | 'When name is specified, title and ext should not be'); 47 | end 48 | p = updatefields(p, opts, {'parent', 'name'}); 49 | newfp = fullfile(p.parent, p.name); 50 | end 51 | 52 | end 53 | 54 | 55 | %% Auxiliary functions 56 | 57 | function S = updatefields(S, newS, fns) 58 | 59 | nf = length(fns); 60 | for i = 1 : nf 61 | f = fns{i}; 62 | if ~isempty(newS.(f)) 63 | S.(f) = newS.(f); 64 | end 65 | end 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/slfilepart.m: -------------------------------------------------------------------------------- 1 | function s = slfilepart(fp, partname) 2 | %SLFILEPARTS Extracts a specified part of a file path string 3 | % 4 | % $ Syntax $ 5 | % - s = slfilepart(fp, partname) 6 | % 7 | % $ Arguments $ 8 | % - fp: the path string 9 | % - partname: the name of the querying part 10 | % - s: the string of that part 11 | % 12 | % $ Description $ 13 | % - s = slfilepart(fp, partname) extracts the corresponding part. 14 | % The partname can be either of the following: 15 | % - 'name': title.ext 16 | % - 'ext': .ext 17 | % - 'title' title 18 | % - 'parent' parent path string 19 | % 20 | % $ History $ 21 | % - Created by Dahua Lin, on Aug 12nd, 2006 22 | % 23 | 24 | if nargin < 2 25 | raise_lackinput('slfilepart', 2); 26 | end 27 | 28 | [p.parent, p.title, p.ext] = fileparts(fp); 29 | 30 | switch partname 31 | case 'name' 32 | s = [p.title, p.ext]; 33 | case 'ext' 34 | s = p.ext; 35 | case 'title' 36 | s = p.title; 37 | case 'parent' 38 | s = p.parent; 39 | otherwise 40 | error('sltoolbox:invalidarg', ... 41 | 'Invalid part name for a path: %s', partname); 42 | end 43 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/slisabspath.m: -------------------------------------------------------------------------------- 1 | function b = slisabspath(pstr) 2 | %SLISABSPATH Judges whether the path string is a absolute path 3 | % 4 | % $ Syntax $ 5 | % - b = slisabspath(pstr) 6 | % 7 | % $ Arguments $ 8 | % - pstr: the path string 9 | % - b: a bool variable indicating whether it is a full path 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin, on Aug 13, 2006 13 | % 14 | 15 | b = (length(pstr) >= 2 && ... 16 | (pstr(2) == ':' || pstr(1) == '\' || pstr(1) == '/')); -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/slmkdir.m: -------------------------------------------------------------------------------- 1 | function dirpath = slmkdir(dirname, parentpath) 2 | %SLMKDIR Makes a directory if it does not exist 3 | % 4 | % $ Syntax $ 5 | % - dirpath = slmkdir(dirname) 6 | % - dirpath = slmkdir(dirname, parentpath) 7 | % 8 | % $ Arguments $ 9 | % - dirname: the name (relative path) of the diretory (r.t parent) 10 | % - parentpath: the path of the parent directory 11 | % - dirpath: the path of the created directory (r.t. '') 12 | % 13 | % $ Description $ 14 | % - dirpath = slmkdir(dirname) makes a diretory of given name if it 15 | % does not exist. 16 | % 17 | % - dirpath = slmkdir(dirname, parentpath) makes a diectory of given 18 | % name if it does not exist, relative to parent path. 19 | % 20 | % $ History $ 21 | % - Created by Dahua Lin, on Aug 12nd, 2006 22 | % 23 | 24 | if isempty(dirname) 25 | return; 26 | end 27 | 28 | if nargin < 2 29 | parentpath = ''; 30 | end 31 | 32 | dirpath = sladdpath(dirname, parentpath); 33 | if ~exist(dirpath, 'dir') 34 | mkdir(dirpath); 35 | end 36 | 37 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/slreadarray.m: -------------------------------------------------------------------------------- 1 | function A = slreadarray(filename) 2 | %SLREADARRAY Reads an array from an array file 3 | % 4 | % $ Syntax $ 5 | % - A = slreadarray(filename) 6 | % 7 | % $ Arguments $ 8 | % - filename: the filename of the array file 9 | % - A: the array read 10 | % 11 | % $ Description $ 12 | % - A = slreadarray(filename) reads an array from an array file and 13 | % returns it by A. 14 | % 15 | % $ History $ 16 | % - Created by Dahua Lin, on Jul 26th, 2006 17 | % 18 | 19 | value_types = { ... 20 | 'double', ... 21 | 'single', ... 22 | 'logical', ... 23 | 'char', ... 24 | 'int8', ... 25 | 'uint8', ... 26 | 'int16', ... 27 | 'uint16', ... 28 | 'int32', ... 29 | 'uint32', ... 30 | 'int64', ... 31 | 'uint64'}; 32 | 33 | %% open file 34 | fid = fopen(filename, 'r'); 35 | if fid <= 0 36 | error('sltoolbox:filefail', ... 37 | 'Fail to open file %s', filename); 38 | end 39 | 40 | 41 | %% read header 42 | 43 | % read and verify tag 44 | tag = fread(fid, 4, '*char')'; 45 | if ~isequal(tag, ['arr', 0]) 46 | error('sltoolbox:parseerror', ... 47 | 'The file tag is invalid'); 48 | end 49 | 50 | % read the value type 51 | typeidx = fread(fid, 1, 'uint8'); 52 | valtype = value_types{typeidx}; 53 | 54 | % read the dimension 55 | d = fread(fid, 1, 'uint8'); 56 | 57 | %% read size 58 | 59 | fseek(fid, 8, -1); 60 | siz = fread(fid, d, 'uint32')'; 61 | 62 | 63 | %% read data 64 | A = fread(fid, prod(siz), ['*', valtype]); 65 | if length(siz) == 1 66 | siz = [siz, 1]; 67 | end 68 | A = reshape(A, siz); 69 | 70 | 71 | %% close file 72 | fclose(fid); 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/slreadtext.m: -------------------------------------------------------------------------------- 1 | function T = slreadtext(filename) 2 | %SLREADTEXT Reads in a text file into a cell array 3 | % 4 | % $ Syntax $ 5 | % T = slreadtext(filename) 6 | % 7 | % $ Description $ 8 | % - T = slreadtext(filename) Reads in a text file to a cell array with 9 | % each cell storing a line string. 10 | % 11 | % $ Remarks $ 12 | % 1. No extra operations will be performed on the strings besides deleting 13 | % the trailing spaces in end of lines. 14 | % 15 | % $ History $ 16 | % Created by Dahua Lin, on 2005-06-02 17 | % 18 | 19 | fid = fopen(filename, 'r'); 20 | if (fid <= 0) 21 | error(['Fail to open file ', filename]); 22 | end 23 | 24 | T = {}; 25 | icount = 0; 26 | strline = fgets(fid); 27 | while ~isequal(strline, -1) 28 | icount = icount + 1; 29 | T{icount, 1} = deblank(strline); 30 | strline = fgets(fid); 31 | end 32 | 33 | fclose(fid); -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/slrmdir.m: -------------------------------------------------------------------------------- 1 | function slrmdir(dirname, parentpath) 2 | %SLMKDIR Makes a directory if it does not exist 3 | % 4 | % $ Syntax $ 5 | % - slrmdir(dirname) 6 | % - slrmdir(dirname, parentpath) 7 | % 8 | % $ Arguments $ 9 | % - dirname: the name (relative path) of the diretory (r.t parent) 10 | % - parentpath: the path of the parent directory 11 | % - dirpath: the path of the created directory (r.t. '') 12 | % 13 | % $ Description $ 14 | % - dirpath = slmkdir(dirname) deletes a diretory of given name if it 15 | % exists. 16 | % 17 | % - dirpath = slmkdir(dirname, parentpath) deletes a diectory of given 18 | % name if it exists, relative to parent path. 19 | % 20 | % $ Remarks $ 21 | % - This function recursively deletes all sub-folders. 22 | % 23 | % $ History $ 24 | % - Created by Dahua Lin, on Aug 12nd, 2006 25 | % 26 | 27 | if isempty(dirname) 28 | return; 29 | end 30 | 31 | if nargin < 2 32 | parentpath = ''; 33 | end 34 | 35 | dirpath = sladdpath(dirname, parentpath); 36 | 37 | if exist(dirpath, 'dir') 38 | rmdir(dirpath, 's'); 39 | end 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/slwritearray.m: -------------------------------------------------------------------------------- 1 | function slwritearray(A, filename) 2 | %SLWRITEARRAY Writes an array to an array file 3 | % 4 | % $ Syntax $ 5 | % - slwritearray(A, filename) 6 | % 7 | % $ Arguments $ 8 | % - A: The array to be written 9 | % - filename: The filename of the array file 10 | % 11 | % $ Description $ 12 | % - slwritearray(A, filename) writes an array A to the array file. 13 | % 14 | % $ History $ 15 | % - Created by Dahua Lin, on Jul 26th, 2006 16 | % 17 | 18 | 19 | value_types = { ... 20 | 'double', ... 21 | 'single', ... 22 | 'logical', ... 23 | 'char', ... 24 | 'int8', ... 25 | 'uint8', ... 26 | 'int16', ... 27 | 'uint16', ... 28 | 'int32', ... 29 | 'uint32', ... 30 | 'int64', ... 31 | 'uint64'}; 32 | 33 | 34 | %% open file 35 | 36 | fid = fopen(filename, 'w'); 37 | if fid <= 0 38 | error('sltoolbox:filefail', ... 39 | 'Fail to open file %s', filename); 40 | end 41 | 42 | %% write header 43 | 44 | % write tag 45 | fwrite(fid, ['arr', 0], 'char'); 46 | 47 | % write value type and dimension number 48 | [tf, typeidx] = ismember(class(A), value_types); 49 | if ~tf 50 | error('Unknown type for A: %s', class(A)); 51 | end 52 | d = ndims(A); 53 | info = uint8([typeidx, d, 0, 0]); 54 | fwrite(fid, info, 'uint8'); 55 | 56 | %% write size 57 | 58 | siz = size(A); 59 | fwrite(fid, uint32(siz), 'uint32'); 60 | 61 | %% write data 62 | 63 | fwrite(fid, A, class(A)); 64 | 65 | %% close file 66 | 67 | fclose(fid); 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/fileio/slwritetext.m: -------------------------------------------------------------------------------- 1 | function slwritetext(T, filename) 2 | %SLWRITETEXT Writes a text to file 3 | % 4 | % $ Syntax $ 5 | % - slwritetext(T, filename) 6 | % 7 | % $ Arguments $ 8 | % - T the cell array representing the text 9 | % - filename the path of the file to write to 10 | % 11 | % $ Description $ 12 | % - slwritetext(T, filename) Writes in a text file stored in a cell array 13 | % to a text file specified by filename. 14 | % 15 | % $ History $ 16 | % Created by Dahua Lin, on 2005-06-02 17 | % 18 | 19 | if ~iscell(T) 20 | error('T should be a text cell array'); 21 | end 22 | fid = fopen(filename, 'w'); 23 | if (fid <= 0) 24 | error(['Fail to open ', filename]); 25 | end 26 | 27 | n = length(T); 28 | for i = 1 : n 29 | fprintf(fid, '%s\r\n', T{i}); 30 | end 31 | 32 | fclose(fid); -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/graph/sladjlist2edgeset.m: -------------------------------------------------------------------------------- 1 | function edges = sladjlist2edgeset(targets, sch) 2 | %SLADJLIST2EDGESET Converts the adjacency list to edge set 3 | % 4 | % $ Syntax $ 5 | % - edges = sladjlist2edgeset(targets, sch) 6 | % 7 | % $ Arguments $ 8 | % - targets: The targets in adj list (length-n cell array) 9 | % - sch: The scheme of conversion 10 | % - 0: no value -> no value 11 | % - 1: no value -> has value 12 | % - 2: has value -> no value 13 | % - 3: has value -> has value 14 | % - edges: The edge set (nedges x 2 or nedges x 3 matrix) 15 | % 16 | % $ Remarks $ 17 | % - an internal function for graph representation conversion. 18 | % no checking of input arguments would be performed. 19 | % 20 | % $ History $ 21 | % - Created by Dahua Lin, on Sep 9, 2006 22 | % 23 | 24 | %% get J and V 25 | 26 | n = length(targets); 27 | jv = vertcat(targets{:}); 28 | 29 | if ~isempty(jv) 30 | if sch == 1 31 | nedges = size(jv, 1); 32 | jv = [jv, ones(nedges, 1)]; 33 | elseif sch == 2 34 | jv = jv(:,1); 35 | end 36 | else 37 | edges =[]; 38 | return; 39 | end 40 | 41 | %% add I 42 | 43 | nums = zeros(n, 1); 44 | for i = 1 : n 45 | cinds = targets{i}; 46 | if ~isempty(cinds) 47 | nums(i) = size(cinds, 1); 48 | end 49 | end 50 | ic = slexpand(nums); 51 | edges = [ic, jv]; 52 | 53 | 54 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/graph/sledgeset2adjlist.m: -------------------------------------------------------------------------------- 1 | function targets = sledgeset2adjlist(n, edges, sch) 2 | %SLEDGESET2ADJLIST Converts edge set to adjacency list 3 | % 4 | % $ Syntax $ 5 | % - targets = sledgeset2adjlist(n, edges, sch) 6 | % 7 | % $ Arguments $ 8 | % - n: The number of (source) nodes 9 | % - edges: The set of edges (nedges x 2 or nedges x 3) 10 | % - sch: The id of scheme of conversion to take 11 | % - 0: no value -> no value 12 | % - 1: no value -> has value 13 | % - 2: has value -> no value 14 | % - 3: has value -> has value 15 | % - targets: The cell array of targets in adj list 16 | % 17 | % $ Remarks $ 18 | % - an internal function for graph representation conversion. 19 | % no checking of input arguments would be performed. 20 | % 21 | % $ History $ 22 | % - Created by Dahua Lin, on Sep 9, 2006 23 | % 24 | 25 | %% prepare storage 26 | 27 | targets = cell(n, 1); 28 | 29 | %% sort edges 30 | 31 | I = edges(:, 1); 32 | J = edges(:, 2); 33 | 34 | [I, si] = sort(I); 35 | J = J(si); 36 | 37 | if sch == 3 38 | V = edges(si, 3); 39 | elseif sch == 1 40 | nedges = length(I); 41 | V = ones(nedges, 1); 42 | end 43 | 44 | %% group targets 45 | 46 | nums = slcount(I); 47 | ni = length(nums); 48 | [spos, epos] = slnums2bounds(nums); 49 | 50 | if sch == 1 || sch == 3 51 | for i = 1 : ni 52 | s = spos(i); e = epos(i); 53 | if s <= e 54 | targets{I(s)} = [J(s:e), V(s:e)]; 55 | end 56 | end 57 | else 58 | for i = 1 : ni 59 | s = spos(i); e = epos(i); 60 | if s <= e 61 | targets{I(s)} = J(s:e); 62 | end 63 | end 64 | end 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/imgproc/slbenchmark_batchfilter.m: -------------------------------------------------------------------------------- 1 | function recs = slbenchmark_batchfilter(imgsiz, nimgs, filtersiz, nfilters) 2 | %SLBENCHMARK_BATCHFILTER Compares the efficiency of batch filter 3 | % 4 | % Input: 5 | % imgsiz: the size of each image 6 | % nimgs: the number of images 7 | % filtersiz: The size of each filter 8 | % nfilters: the list of numbers of filters 9 | % 10 | % History 11 | % - Created by Dahua Lin, on Sep 2nd, 2006 12 | 13 | 14 | imgs = rand([imgsiz, nimgs]); 15 | fb = rand([filtersiz, max(nfilters)]); 16 | 17 | names = {'imfilter', 'slapplyfilerband'}; 18 | methods = {@test_imfilter, @test_slband}; 19 | nmethods = length(names); 20 | 21 | recs = zeros(length(nfilters), nmethods); 22 | 23 | for k = 1 : nmethods 24 | 25 | curname = names{k}; 26 | curmethod = methods{k}; 27 | 28 | disp(['Test ', curname]); 29 | 30 | for i = 1 : length(nfilters) 31 | nf = nfilters(i); 32 | tic; 33 | curmethod(imgs, fb(:,:,1:nf)); 34 | recs(i, k) = toc; 35 | end 36 | end 37 | 38 | recs = recs / nimgs; 39 | 40 | 41 | function test_imfilter(imgs, fb) 42 | 43 | nf = size(fb ,3); 44 | R = zeros([size(imgs), nf]); 45 | for i = 1 : nf 46 | R(:,:,:,i) = imfilter(imgs, fb(:,:,i), 'replicate'); 47 | end 48 | clear R; 49 | 50 | function test_slband(imgs, fb) 51 | 52 | fh = size(fb, 1); 53 | fw = size(fb, 2); 54 | R = slapplyfilterband(imgs, fb, [fh, fw]); 55 | clear R; 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/imgproc/slgaborbands.m: -------------------------------------------------------------------------------- 1 | function FB = slgaborbands(w, scales, orientations) 2 | %SLGABORBANDS Generates a set of Gabor kernels 3 | % 4 | % $ Syntax $ 5 | % - FB = slgaborbands(w, scales, radians) 6 | % 7 | % $ Arguments $ 8 | % - w: the kernel window size is wxw 9 | % - scales: the scales (number of scales is m) 10 | % - orientations: the orientations (number of orientations is o) 11 | % - FB: the array of filter banks 12 | % 13 | % $ Description $ 14 | % - Generates a set of complex filter banks for Gabor, with the 15 | % scales and orientations of the filter specified. If there are 16 | % m scales and n orientations, it will product an w x w x m x n 17 | % array containing m x n kernels. 18 | % 19 | % $ References $ 20 | % - C. Liu and H. Wechsler, ''Gabor Feature Based Classification Using the 21 | % Enhanced Fisher Linear Discriminant Model for Face Recognition'', IEEE 22 | % Trans. on Imag. Proc, Vol. 11, No. 4, Apr, 2002. 23 | % 24 | % $ History $ 25 | % - Created by Dahua Lin on Feb 25th, 2006. 26 | % - Modified by Dahua Lin on Aug 4th, 2006. 27 | % 28 | 29 | 30 | m = length(scales); 31 | n = length(orientations); 32 | FB = zeros(w, w, m, n); 33 | 34 | for i = 1 : m 35 | for j = 1 : n 36 | FB(:,:,i,j) = single_gabor_kernel(w, scales(i), orientations(j)); 37 | end 38 | end 39 | 40 | function M = single_gabor_kernel(w, v, u) 41 | % v - scale, u - orientation 42 | 43 | mincoord = fix(- w / 2); 44 | coords = mincoord + (0 : w-1); 45 | [X, Y] = meshgrid(coords, coords); 46 | 47 | kmax = pi / 2; 48 | f = sqrt(2); 49 | sigma = 2 * pi; 50 | 51 | k_v = kmax / f^v; 52 | phi_u = pi * u / 8; 53 | k_uv = k_v * exp(i * phi_u); 54 | 55 | F1 = (k_v^2) / (sigma^2) * exp(-k_v^2 * abs(X.^2 + Y.^2) / (2*sigma^2)) ; 56 | F2 = exp(i * (real(k_uv) * X + imag(k_uv) * Y)) - exp(-sigma^2/2); 57 | M = F1 .* F2; 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/imgproc/slresizeimg.m: -------------------------------------------------------------------------------- 1 | function rimgs = slresizeimg(imgs, newsiz, interpker) 2 | %SLRESIZEIMG Resizes the images by interpolation 3 | % 4 | % $ Syntax $ 5 | % - rimgs = slresizeimg(imgs, newsiz, interpker) 6 | % 7 | % $ Arguments $ 8 | % - imgs: The set of images 9 | % - newsiz: The new image size to be resized to 10 | % It can be in two forms: 11 | % - [new_height, new_width] 12 | % - ratio to the original size 13 | % - interpker: The interpolation kernel (default = 'linear') 14 | % - rimgs: The resized images 15 | % 16 | % $ Description $ 17 | % - rimgs = slresizeimg(imgs, newsiz, interpker) resizes the image 18 | % to new size by interpolation. 19 | % 20 | % $ Remarks $ 21 | % - The implementation is based on slimginterp. 22 | % 23 | % $ History $ 24 | % - Created by Dahua Lin, on Sep 3, 2006 25 | % 26 | 27 | %% parse and verify input 28 | 29 | if nargin < 2 30 | raise_lackinput('slresizeimg', 2); 31 | end 32 | h0 = size(imgs, 1); 33 | w0 = size(imgs, 2); 34 | 35 | if isnumeric(newsiz) 36 | if length(newsiz) == 1 37 | h = newsiz * h0; 38 | w = newsiz * w0; 39 | elseif length(newsiz) == 2 40 | [h, w] = sltakeval(newsiz); 41 | else 42 | error('sltoolbox:invalidarg', 'The newsiz is invalid'); 43 | end 44 | else 45 | error('sltoolbox:invalidarg', 'The newsiz is invalid'); 46 | end 47 | 48 | if nargin < 3 || isempty(interpker) 49 | interpker = 'linear'; 50 | end 51 | 52 | %% generate coordinate map 53 | 54 | I = linspace(1, h0, h)'; 55 | J = linspace(1, w0, w); 56 | I = I(:, ones(1, w)); 57 | J = J(ones(h, 1), :); 58 | 59 | %% Do interpolation 60 | 61 | rimgs = slimginterp(imgs, I, J, interpker); 62 | 63 | 64 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/imgproc/slvecfilters.m: -------------------------------------------------------------------------------- 1 | function vfb = slvecfilters(fb) 2 | %SLVECFILTERS Vectorizes the filter band 3 | % 4 | % $ Syntax $ 5 | % - vfb = slvecfilters(fb) 6 | % 7 | % $ Arguments $ 8 | % - fb: The filter band 9 | % - vfb: The vectorized filter band 10 | % 11 | % $ Description $ 12 | % - vfb = slvecfilters(fb) vectorizes the filter band. A set of filter 13 | % band is an array of size (ph x pw x ...). In its vectorized form, 14 | % each filter is vectorized as a row vector. Then for a set of 15 | % filter band with same size, vfb is a matrix of size k x d, here 16 | % d = ph x pw, while k is the number of filters. 17 | % 18 | % $ History $ 19 | % - Created by Dahua Lin on Sep 2nd, 2006 20 | % 21 | 22 | fbsiz = size(fb); 23 | if ndims(fb) == 2 24 | k = 1; 25 | else 26 | k = prod(fbsiz(3:end)); 27 | end 28 | d = prod(fbsiz(1:2)); 29 | 30 | vfb = reshape(fb, [d, k])'; 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/install_cppcores.m: -------------------------------------------------------------------------------- 1 | function install_cppcores() 2 | % mex ALL cpp cores in sltoolbox 3 | % Note those relying on third-party libraries are not involved here 4 | % such as annsearch, which need to be mex separately. 5 | 6 | % core\pwcalc_core.cpp 7 | % core\pwdiff_core.cpp 8 | % core\rowcolop_core.cpp 9 | % core\vecop_core.cpp 10 | % discrete\histmetricpw_core.cpp 11 | % utils_ex\win32guid_core.cpp 12 | 13 | srcs = { ... 14 | 'core', 'pwcalc_core.cpp'; ... 15 | 'core', 'pwdiff_core.cpp'; ... 16 | 'core', 'rowcolop_core.cpp'; ... 17 | 'core', 'vecop_core.cpp'; ... 18 | 'discrete', 'histmetricpw_core.cpp'; ... 19 | 'utils_ex', 'win32guid_core.cpp'}; 20 | 21 | n = size(srcs, 1); 22 | for i = 1 : n 23 | subdir = srcs{i, 1}; 24 | srcfn = srcs{i, 2}; 25 | 26 | fprintf('Processing %s\\%s ...\n', subdir, srcfn); 27 | 28 | cd(subdir); 29 | mex('-O', srcfn); 30 | cd('..'); 31 | 32 | end 33 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/install_paths.m: -------------------------------------------------------------------------------- 1 | function install_paths() 2 | %THE SCRIPT to install the sltoolbox paths to matlab system 3 | 4 | fp = mfilename('fullpath'); 5 | rootdir = fileparts(fp); 6 | 7 | subfolders = { ... 8 | 'ann'; ... 9 | 'cluster'; ... 10 | 'core'; ... 11 | 'discrete'; ... 12 | 'ExpDL'; ... 13 | 'fileio'; ... 14 | 'graph'; ... 15 | 'imgproc'; ... 16 | 'interp'; ... 17 | 'kernel'; ... 18 | 'learn'; ... 19 | 'manifold'; ... 20 | 'perfeval'; ... 21 | 'regression'; ... 22 | 'smallmat'; ... 23 | 'stat'; ... 24 | 'subspace'; ... 25 | 'subspace_ex'; ... 26 | 'tensor'; ... 27 | 'text'; ... 28 | 'utils'; ... 29 | 'utils_ex'; ... 30 | 'visualize'; ... 31 | 'xmlkits'}; 32 | 33 | n = length(subfolders); 34 | folderpaths = cell(1, n); 35 | 36 | for i = 1 : n 37 | folderpaths{i} = fullfile(rootdir, subfolders{i}); 38 | fprintf('Add path: %s\n', folderpaths{i}); 39 | end 40 | 41 | addpath(folderpaths{:}); 42 | savepath; 43 | 44 | disp('All paths have been added.'); 45 | disp(' '); % a blank line 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/kernel/sldists2kernels.m: -------------------------------------------------------------------------------- 1 | function K = sldists2kernels(D, ty) 2 | %SLDISTS2KERNELS Computes the inner products from distances 3 | % 4 | % $ Syntax $ 5 | % - K = sldists2kernels(D) 6 | % - K = sldists2kernels(D, 'sqr') 7 | % 8 | % $ Arguments $ 9 | % - D: The pairwise distance matrix 10 | % - K: The pairwise inner product matrix (kernel matrix) 11 | % 12 | % $ Description $ 13 | % - K = sldists2kernels(D) computes the inner products between samples 14 | % pairwisely with the pairwise norms given. Assume that the samples 15 | % are in an Euclidean linear space, and are centralized. 16 | % 17 | % - K = sldists2kernels(D, 'sqr') performs the calculation with the 18 | % input D matrix containing the square distances. 19 | % 20 | % $ History $ 21 | % - Created by Dahua Lin, on Sep 8th, 2006 22 | % 23 | 24 | %% parse and verify input 25 | 26 | if isempty(D) 27 | K = []; 28 | return; 29 | end 30 | 31 | if ~isnumeric(D) || ndims(D) ~= 2 || size(D,1) ~= size(D,2) 32 | error('sltoolbox:invalidarg', ... 33 | 'D should be a square matrix'); 34 | end 35 | 36 | if nargin >= 2 && strcmpi(ty, 'sqr') 37 | is_sqr = true; 38 | else 39 | is_sqr = false; 40 | end 41 | 42 | %% compute 43 | 44 | % preprocess 45 | 46 | if ~is_sqr 47 | K = D .* D; % make squares 48 | else 49 | K = D; 50 | end 51 | K = 0.5 * (K + K'); % enforce symmetry 52 | 53 | % compute 54 | n = size(K, 1); 55 | 56 | s = sum(K, 1); 57 | t = sum(s); 58 | 59 | s = s / n; 60 | t = t / (n*n); 61 | 62 | for i = 1 : n 63 | K(i,:) = K(i,:) - s(i); 64 | end 65 | for i = 1 : n 66 | K(:,i) = K(:,i) - s(i); 67 | end 68 | K = K + t; 69 | 70 | K = (-0.5) * K; 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/kernel/slkernels2dists.m: -------------------------------------------------------------------------------- 1 | function D = slkernels2dists(K, ty) 2 | %SLKERNELS2DISTS Computes Euclidean distances from inner products 3 | % 4 | % $ Syntax $ 5 | % - D = slkernels2dists(K) 6 | % - D = slkernels2dists(K, 'sqr') 7 | % 8 | % $ Arguments $ 9 | % - K: The inner product matrix (kernel matrix) 10 | % - D: The pairwise distance matrix 11 | % 12 | % $ Description $ 13 | % - D = slkernels2dists(K) computes the pairwise distances between 14 | % samples based the pairwise inner products between them. The samples 15 | % are assumed to be in an Euclidean linear space. 16 | % 17 | % - D = slkernels2dists(K, 'sqr') outputs the square of the distances. 18 | % 19 | % $ History $ 20 | % - Created by Dahua Lin, on Sep 8th, 2006 21 | % 22 | 23 | %% parse and verify input 24 | 25 | if isempty(K) 26 | D = []; 27 | return; 28 | end 29 | 30 | if ~isnumeric(K) || ndims(K) ~= 2 || size(K,1) ~= size(K,2) 31 | error('sltoolbox:invalidarg', ... 32 | 'K should be a square matrix'); 33 | end 34 | 35 | if nargin >= 2 && strcmpi(ty, 'sqr') 36 | is_sqr = true; 37 | else 38 | is_sqr = false; 39 | end 40 | 41 | %% compute 42 | 43 | D = -(K + K'); 44 | 45 | n = size(D, 1); 46 | s = diag(K); 47 | 48 | for i = 1 : n 49 | D(i,:) = D(i,:) + s(i); 50 | end 51 | for i = 1 : n 52 | D(:,i) = D(:,i) + s(i); 53 | end 54 | 55 | D(D < 0) = 0; % enforce non-negative 56 | 57 | if ~is_sqr 58 | D = sqrt(D); 59 | end 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/kernel/slkernelscatter.m: -------------------------------------------------------------------------------- 1 | function S = slkernelscatter(K, type, varargin) 2 | %SLKERNELSCATTER Compute the kernelized scatter matrix 3 | % 4 | % $ Syntax $ 5 | % - S = slkernelscatter(K, type, ...) 6 | % 7 | % $ Arguments $ 8 | % - K: the kernel gram matrix of the samples 9 | % - type: the type of the scatter matrix 10 | % - S: the resulting scatter matrix 11 | % 12 | % $ Description $ 13 | % - S = slkernelscatter(K, type, ...) computes the kernelized scatter 14 | % matrix of K. It can be shown that the computation of the kernelized 15 | % scatter matrix is equivalent to the computation of conventional 16 | % scatter matrix with the sample matrix replaced by the gram matrix. 17 | % Thus this function simply invoke slscatter with K replacing X. 18 | % The usage can be referred to function slscatter. 19 | % 20 | % $ Remarks $ 21 | % -# The so-called kernel scatter matrix is an n x n matrix defined by 22 | % following formula: 23 | % S = Phi^T * scatter(phi_1, phi_2, ..., phi_n) * Phi 24 | % here scatter(.) is the scatter matrix defined like for conventional 25 | % scatter but on the nonlinearly mapped features. Phi is the set of 26 | % nonlinearly mapped features. The kernelized scatter matrix plays 27 | % a core role in kernelized discrminant analysis. 28 | % 29 | % $ History $ 30 | % - Created by Dahua Lin on May 03, 2006 31 | % 32 | 33 | %% parse and verify input arguments 34 | 35 | if nargin < 2 36 | raise_lackinput('slkernelscatter', 2); 37 | end 38 | 39 | if ndims(K) ~= 2 || size(K, 1) ~= size(K, 2) 40 | error('sltoolbox:invaliddims', ... 41 | 'The gram matrix K should be a square matrix'); 42 | end 43 | 44 | %% delegate to slscatter for computation 45 | 46 | S = slscatter(K, type, varargin{:}); 47 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/manifold/slisomap.m: -------------------------------------------------------------------------------- 1 | function [X, spectrum] = slisomap(G, d) 2 | %SLISOMAP Performs ISOMAP manifold embedding 3 | % 4 | % $ Syntax $ 5 | % - X = slisomap(G, d) 6 | % - [X, spectrum] = slisomap(G, d) 7 | % 8 | % $ Arguments $ 9 | % - G: The distance graph for neighbors 10 | % - d: The dimension of embedded space 11 | % - X: The embedded coordinates of the samples 12 | % - spectrum: The eigenvalues of the embedded dimensions 13 | % 14 | % $ Description $ 15 | % - X = slisomap(G, d) performs ISOMAP manifold embedding to pursue 16 | % an embedding which best preserves the geodesic distances between 17 | % samples. 18 | % 19 | % - [X, spectrum] = slisomap(G, d) additionally outputs the 20 | % eigen-spectrum of the embedded space. 21 | % 22 | % $ Remarks $ 23 | % - In current implementation, the third-party toolbox: Matlab BGL is 24 | % required for computing the geodesics. 25 | % 26 | % $ History $ 27 | % - Created by Dahua Lin, on Sep 8, 2006 28 | % 29 | 30 | %% parse and verify input 31 | 32 | if nargin < 2 33 | raise_lackinput('slisomap', 2); 34 | end 35 | 36 | G = sladjmat(G, 'sparse', true); 37 | n = size(G, 1); 38 | if d >= n 39 | error('sltoolbox:exceedbound', ... 40 | 'The embedded dimension d should be less than the number of samples'); 41 | end 42 | 43 | 44 | %% compute 45 | 46 | % compute geodesics 47 | G = slsymgraph(G); 48 | D = all_shortest_paths(G); 49 | 50 | is_inf_dists = isinf(D); 51 | is_inf_dists = is_inf_dists(:); 52 | if any(is_inf_dists) 53 | error('sltoolbox:rterror', ... 54 | 'The graph has multiple disconnected components'); 55 | end 56 | clear is_inf_dists; 57 | 58 | % perform MDS on D 59 | [X, spectrum] = slcmds(D, d); 60 | 61 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/manifold/swiss_roll_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/manifold/swiss_roll_data.mat -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/perfeval/slcorrectrate.m: -------------------------------------------------------------------------------- 1 | function cr = slcorrectrate(scores, clabels, qlabels, op, varargin) 2 | %SLCORRECTRATE Computes the correct rate of classification 3 | % 4 | % $ Syntax $ 5 | % - cr = slcorrectrate(scores, clabels, qlabels, op, ...) 6 | % 7 | % $ Arguments $ 8 | % - scores: the scores to support the classification 9 | % - clabels: the labels of classes 10 | % - qlabels: the groundtruth of the labels of query samples 11 | % - op: the option of the score 12 | % - cr: the correct rate of the score-based classification 13 | % 14 | % $ Description $ 15 | % - cr = slcorrectrate(scores, clabels, slabels, op, ...) 16 | % Computes the classification correct rate. Suppose we want to 17 | % classify n samples into m classes, then scores will be an m x n 18 | % matrix, with the entry at i-th row, j-th column representing the 19 | % score of the j-th sample in the i-th class. 20 | % For op, it can take either of the two values: 'high' and 'low'. 21 | % If op is 'high' then it means that the sample will be classified 22 | % to the class where it has the highest score value, vice versa 23 | % for 'low'. 24 | % 25 | % $ History $ 26 | % - Created by Dahua Lin on Jun 10th, 2005 27 | % - Modified by Dahua Lin on May 1st, 2005 28 | % - To base on the sltoolbox v4. 29 | % - Modified by Dahua Lin on Aug 9th, 2006 30 | % - Extract slclassify as independent function and base on it 31 | % - Modified by Dahua Lin on Aug 16th, 2006 32 | % - Based on new slclassify to support multiple schemes 33 | % 34 | 35 | %% parse and verify input arguments 36 | 37 | if nargin < 4 38 | raise_lackinput('slcorrectrate', 4); 39 | end 40 | 41 | 42 | %% Make decision 43 | 44 | decisions = slclassify(scores, clabels, op, varargin{:}); 45 | 46 | %% Evaluate correct rate 47 | 48 | qlabels = qlabels(:)'; 49 | cr = sum(decisions == qlabels) / length(qlabels); 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/perfeval/slcorrectrate_blks.m: -------------------------------------------------------------------------------- 1 | function cr = slcorrectrate_blks(scores, blocks, clabels, qlabels, op, varargin) 2 | %SLCORRECTRATE_BLKS Computes the correct rate based on blockwise scores 3 | % 4 | % $ Syntax $ 5 | % - cr = slcorrectrate_blks(scores, blocks, clabels, qlabels, op, ...) 6 | % 7 | % $ Arguments $ 8 | % - scores: the score matrix 9 | % - blocks: the cell array of block limits 10 | % - clabels: the class labels of reference samples 11 | % - qlabels: the query labels of query samples 12 | % - op: the score attribute 13 | % - cr: the computed classification correct rate 14 | % 15 | % $ Remarks $ 16 | % - An extension of slcorrectrate to support blockwise scores 17 | % 18 | % $ History $ 19 | % - Created by Dahua Lin, on Aug 9th, 2006 20 | % - Modified by Dahua Lin on Aug 16th, 2006 21 | % - Based on new slclassify to support multiple schemes 22 | % 23 | 24 | %% parse and verify input arguments 25 | 26 | if nargin < 5 27 | raise_lackinput('slcorrectrate_blks', 5); 28 | end 29 | 30 | 31 | %% Make decision 32 | 33 | n = length(qlabels); 34 | decisions = slclassify_blks(scores, n, blocks, clabels, op, varargin{:}); 35 | 36 | %% Evaluate correct rate 37 | 38 | qlabels = qlabels(:)'; 39 | cr = sum(decisions == qlabels) / length(qlabels); 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/regression/sllinrega.m: -------------------------------------------------------------------------------- 1 | function [A, b] = sllinrega(X, Y, varargin) 2 | %SLLINREGA Performs Augmented Multivariate Linear Regression 3 | % 4 | % $ Syntax $ 5 | % - [A, b] = sllinrega(X, Y, ...) 6 | % 7 | % $ Arguments $ 8 | % - X: The sample matrix of x 9 | % - Y: The sample matrix of y 10 | % - A: The solved transform matrix 11 | % - b: The solved shift vector 12 | % 13 | % $ Description $ 14 | % - [A, b] = sllinrega(X, Y, ...) solves the regression problem given 15 | % by the following formula: 16 | % y = A * x + b 17 | % in least square error sense. The samples are stored in X and Y 18 | % in column-wise manner. 19 | % You can specify properties for regression as in sllinreg. 20 | % 21 | % $ Remarks $ 22 | % - The implementation is based on sllinreg with an augmented 23 | % formulation as follows: 24 | % y = [A, b] * [x; 1] 25 | % 26 | % $ History $ 27 | % - Created by Dahua Lin, on Sep 15th, 2006 28 | % 29 | 30 | %% parse and verify input arguments 31 | 32 | if nargin < 2 33 | raise_lackinput('sllinrega', 2); 34 | end 35 | 36 | if ~isnumeric(X) || ~isnumeric(Y) || ndims(X) ~= 2 || ndims(Y) ~= 2 37 | error('sltoolbox:invalidarg', ... 38 | 'The X and Y should be both 2D numeric matrices'); 39 | end 40 | 41 | %% main 42 | 43 | % augment formulation 44 | [dx, nx] = size(X); 45 | Xa = [X; ones(1, nx)]; 46 | 47 | % solve 48 | Aa = sllinreg(Xa, Y, varargin{:}); 49 | clear Xa; 50 | 51 | % extract 52 | A = Aa(:, 1:dx); 53 | b = Aa(:, dx+1); 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/smallmat/sldet2x2.m: -------------------------------------------------------------------------------- 1 | function r = sldet2x2(Ms) 2 | %SLDET2X2 Computes the determinant of 2 x 2 matrices in a fast way 3 | % 4 | % $ Syntax $ 5 | % - r = sldet2x2(Ms) 6 | % 7 | % $ Arguments $ 8 | % - Ms: the 2 x 2 matrix (matrices) 9 | % - r: the resultant determinant(s) 10 | % 11 | % $ Description $ 12 | % - r = sldet2x2(Ms) computes the determinant of 2x2 matrices. If Ms is 13 | % a 2 x 2 matrix, then r is a scalar representing its determinant. 14 | % Or, if Ms is a 2 x 2 x ... array, then r would be a ... array 15 | % storing the determinant of all 2 x 2 matrices. 16 | % 17 | % $ Remarks $ 18 | % - The function uses the following formula for fast calculation of 19 | % determinant of 2 x 2 matrices: 20 | % det = a11 * a22 - a12 * a21 21 | % 22 | % $ History $ 23 | % - Created by Dahua Lin on Apr 22nd, 2006 24 | % 25 | 26 | %% parse and verify input arguments 27 | 28 | if size(Ms, 1) ~= 2 || size(Ms, 2) ~= 2 29 | error('sltoolbox:invalidarg', 'Ms should be set of 2 x 2 matrices'); 30 | end 31 | 32 | %% compute 33 | 34 | if ndims(Ms) == 2 % single matrix 35 | r = Ms(1) * Ms(4) - Ms(2) * Ms(3); 36 | 37 | else % a set of matrices 38 | r = Ms(1,1,:) .* Ms(2,2,:) - Ms(1,2,:) .* Ms(2,1,:); 39 | 40 | siz = size(Ms); 41 | 42 | if ndims(Ms) == 3 43 | siz_r = [siz(3), 1]; 44 | else 45 | siz_r = siz(3:end); 46 | end 47 | 48 | r = reshape(r, siz_r); 49 | 50 | end 51 | 52 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/smallmat/slinv2x2.m: -------------------------------------------------------------------------------- 1 | function IMs = slinv2x2(Ms) 2 | %SLINV2X2 Computes inverse matrices for 2 x 2 matrices in a fast way 3 | % 4 | % $ Syntax $ 5 | % - IMs = slinv2x2(Ms) 6 | % 7 | % $ Arguments $ 8 | % - Ms: the 2 x 2 matrix (matrices) 9 | % - IMs: the computed inverse matrix (matrices) 10 | % 11 | % $ Description $ 12 | % - IMs = slinv2x2(Ms) computes the inverse of 2x2 matrices. If Ms is 13 | % a 2 x 2 matrix, then r is its inverse. 14 | % Or, if Ms is a 2 x 2 x ... array, then r would be a 2 x 2 x ... array 15 | % storing the inverse matrices. 16 | % 17 | % $ Remarks $ 18 | % - The function uses the following formula for fast calculation of 19 | % inverse of 2 x 2 matrices: 20 | % inv(A) = [a22, -a12; -a21, a11] / det(A) 21 | % 22 | % $ History $ 23 | % - Created by Dahua Lin on Apr 22nd, 2006 24 | % 25 | 26 | %% parse and verify input arguments 27 | 28 | if size(Ms, 1) ~= 2 || size(Ms, 2) ~= 2 29 | error('sltoolbox:invalidarg', 'Ms should be set of 2 x 2 matrices'); 30 | end 31 | 32 | %% compute 33 | 34 | if ndims(Ms) == 2 % single matrix 35 | IMs = [Ms(4), -Ms(2); -Ms(3), Ms(1)] / (Ms(1) * Ms(4) - Ms(2) * Ms(3)); 36 | 37 | else % a set of matrices 38 | 39 | IMs = zeros(size(Ms)); 40 | 41 | % compute adjacent matrix 42 | IMs(1,1,:) = Ms(2,2,:); 43 | IMs(1,2,:) = -Ms(1,2,:); 44 | IMs(2,1,:) = -Ms(2,1,:); 45 | IMs(2,2,:) = Ms(1,1,:); 46 | 47 | % compute the determinants 48 | d = sldet2x2(Ms); 49 | 50 | % scale 51 | d = reshape(d, [1, 1, size(d)]); 52 | IMs = slmul(IMs, 1 ./ d); 53 | 54 | end 55 | 56 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/smallmat/slrotmat.m: -------------------------------------------------------------------------------- 1 | function R = slrotmat(theta) 2 | %SLROTMAT Get the 2x2 rotation matrix 3 | % 4 | % $ Syntax $ 5 | % - R = slrotmat(theta) 6 | % 7 | % $ Arguments $ 8 | % - theta: the radian of rotation 9 | % - R: the rotation matrix 10 | % 11 | % $ Description $ 12 | % - R = slrotmat(theta) computes the 2x2 rotation matrix R which 13 | % rotates a 2D point anti-clockwisely by radian of theta. 14 | % If theta is a scalar, then R will be a 2x2 matrix, if 15 | % theta is an n1 x n2 x ... array, then R will be a set of 16 | % matrices stored in an 2 x 2 x n1 x n2 x ... array. 17 | % 18 | % $ Remarks $ 19 | % - The R is given by following formula: 20 | % R = [ cos(theta) -sin(theta); 21 | % sin(theta) cos(theta) ]; 22 | % 23 | % $ History $ 24 | % - Created by Dahua Lin on Apr 23, 2006 25 | % 26 | 27 | if isscalar(theta) % single 28 | R = [cos(theta), -sin(theta); 29 | sin(theta), cos(theta)]; 30 | else % multiple 31 | TM = reshape(theta, [1, 1, size(theta)]); 32 | CM = cos(TM); 33 | SM = sin(TM); 34 | R = [CM, -SM; 35 | SM, CM]; 36 | end 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/smallmat/sltrace2x2.m: -------------------------------------------------------------------------------- 1 | function r = sltrace2x2(Ms) 2 | %SLTRACE2X2 Computes the trace of 2 x 2 matrices in a fast way 3 | % 4 | % $ Syntax $ 5 | % - r = sltrace2x2(Ms) 6 | % 7 | % $ Arguments $ 8 | % - Ms: the 2 x 2 matrix (matrices) 9 | % - r: the resultant trace(s) 10 | % 11 | % $ Description $ 12 | % - r = sltrace2x2(Ms) computes the trace of 2x2 matrices. If Ms is 13 | % a 2 x 2 matrix, then r is a scalar representing its trace. 14 | % Or, if Ms is a 2 x 2 x ... array, then r would be a ... array 15 | % storing the trace of all 2 x 2 matrices. 16 | % 17 | % $ Remarks $ 18 | % - The function uses the following formula for fast calculation of 19 | % trace of 2 x 2 matrices: 20 | % det = a11 + a22 21 | % 22 | % $ History $ 23 | % - Created by Dahua Lin on Apr 22nd, 2006 24 | % 25 | 26 | %% parse and verify input arguments 27 | 28 | if size(Ms, 1) ~= 2 || size(Ms, 2) ~= 2 29 | error('sltoolbox:invalidarg', 'Ms should be set of 2 x 2 matrices'); 30 | end 31 | 32 | %% compute 33 | 34 | if ndims(Ms) == 2 % single matrix 35 | r = Ms(1) + Ms(4); 36 | 37 | else % a set of matrices 38 | r = Ms(1,1,:) + Ms(2,2,:); 39 | 40 | siz = size(Ms); 41 | 42 | if ndims(Ms) == 3 43 | siz_r = [siz(3), 1]; 44 | else 45 | siz_r = siz(3:end); 46 | end 47 | 48 | r = reshape(r, siz_r); 49 | 50 | end 51 | 52 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/stat/gaussexample.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/stat/gaussexample.mat -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/stat/slpoolcov.m: -------------------------------------------------------------------------------- 1 | function C = slpoolcov(Cs, w) 2 | %SLPOOLCOV Compute the pooled covariance 3 | % 4 | % $ Syntax $ 5 | % - C = slpoolcov(Cs) 6 | % - C = slpoolcov(Cs, w) 7 | % 8 | % $ Arguments $ 9 | % - Cs the stack of covariance matrices for all components 10 | % - w: the weights for components 11 | % - C: the pooled covariance matrix 12 | % 13 | % $ Description $ 14 | % - C = slpoolcov(Cs) computes the average covariance matrix. 15 | % 16 | % - C = slpoolcov(Cs, w) computes the weighted pooled covariance matrix 17 | % with the component weights specified in w. 18 | % 19 | % $ History $ 20 | % - Created by Dahua Lin on Dec 19th, 2004 21 | % - Modified by Dahua Lin on Apr 22nd, 2004 22 | % - Give an much more efficient implementation using matrix product 23 | % and reshaping. 24 | % 25 | 26 | %% parse and verify input arguments 27 | [d1, d2, n] = size(Cs); 28 | if d1 ~= d2 29 | error('sltoolbox:notsquaremat', ... 30 | 'the covariance matrices should be square'); 31 | end 32 | d = d1; 33 | if nargin < 2 || isempty(w) 34 | isweighted = false; 35 | else 36 | isweighted = true; 37 | if numel(w) ~= n 38 | error('sltoolbox:argmismatch', ... 39 | 'the size of w does not match that of Cs'); 40 | end 41 | end 42 | 43 | %% compute 44 | if n == 1 45 | C = Cs; 46 | else 47 | if ~isweighted 48 | Cs = reshape(Cs, [d*d, n]); 49 | C = reshape(sum(Cs, 2), [d, d]); 50 | else 51 | w = w(:) / sum(w(:)); 52 | Cs = reshape(Cs, [d*d, n]); 53 | C = reshape(Cs * w, [d, d]); 54 | end 55 | end 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/stat/slwhiten_from_cov.m: -------------------------------------------------------------------------------- 1 | function W = slwhiten_from_cov(C, method, varargin) 2 | %SLWHITEN_FROM_COV Compute the whitening transform from covariance matrix 3 | % 4 | % $ Syntax $ 5 | % - W = slwhiten_from_cov(C) 6 | % - W = slwhiten_from_cov(C, method, ...) 7 | % 8 | % $ Arguments $ 9 | % - C: the covariance matrix 10 | % - method: the method for computing the whitening transform 11 | % - W: the computed whitening transform matrix 12 | % 13 | % $ Description $ 14 | % - W = slwhiten_from_cov(C) computes the whitening matrix from C using 15 | % default method ('std'). 16 | % - W = slwhiten_from_cov(C, method, r) computes the whitening matrix 17 | % from C using specific method and the extra parameters. Please 18 | % refer to slinvevals for the available methods and corresponding 19 | % parameters. 20 | % 21 | % $ Remarks $ 22 | % - C should be a positive semidefinite matrix. 23 | % 24 | % $ History $ 25 | % - Created by Dahua Lin on Apr 30th, 2006 26 | % - Modified by Dahua Lin on Sep 10, 2006 27 | % - replace slmul by slmulvec to increase efficiency 28 | % 29 | 30 | %% parse and verify input arguments 31 | 32 | if ndims(C) ~= 2 || size(C, 1) ~= size(C, 2) 33 | error('sltoolbox:invaliddims', 'C should be a square matrix'); 34 | end 35 | 36 | if nargin < 2 37 | method = 'std'; 38 | params = {}; 39 | else 40 | params = varargin; 41 | end 42 | 43 | 44 | %% compute 45 | 46 | [evs, U] = slsymeig(C); 47 | revs = slinvevals(evs, method, params{:})'; 48 | 49 | if strcmp(method, 'std') 50 | si = find(revs > 0); 51 | revs = revs(si); 52 | U = U(:, si); 53 | end 54 | 55 | W = slmulvec(U, sqrt(revs), 2); 56 | 57 | 58 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/subspace/pca_struct.txt: -------------------------------------------------------------------------------- 1 | Specification of representation of PCA model in SLToolbox 2 | 3 | $ History $ 4 | - Created by Dahua Lin on Apr 24, 2006 5 | - Modified by Dahua Lin on Aug 17, 2006 6 | - add a field: energyratio 7 | 8 | In SLToolbox, a PCA model is represented by a struct with following 9 | fields: 10 | - sampledim: the dimension of original sample space 11 | - feadim: the dimension of feature space (the number of principal components) 12 | - support: the total weight of training samples supporting the PCA model 13 | (in non-weighted training, support is the number of training samples, 14 | that is the weight of every sample is 1) 15 | - vmean: the mean vector 16 | - P: the projection matrix, for each sample, the feature can be 17 | obtained by y = P' * x 18 | - eigvals: the eigenvalues of all preserved dimensions 19 | - residue: the residue energy: the energy of the orthogonal complement 20 | to the principal subspace. (It is equal to the sum of all 21 | eigenvalues of discarded eigenvectors). 22 | - energyratio: the ratio of energy preserved in the principal subspace 23 | 24 | Suppose a PCA model is based on d-dimensional sample space, and preserve 25 | k principal components, then following conditions would be satisfied: 26 | 1. sampledim = d 27 | 2. feadim = k 28 | 3. vmean is a d x 1 vector 29 | 3. P is a d x k matrix 30 | 4. eigvals is a k x 1 vector 31 | 32 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/subspace/slapplypca.m: -------------------------------------------------------------------------------- 1 | function Y = slapplypca(S, X) 2 | %SLAPPLYPCA Applies PCA model to samples 3 | % 4 | % $ Syntax $ 5 | % Y = slapplypca(S, X) 6 | % 7 | % $ Arguments $ 8 | % - S: the struct representing the PCA model 9 | % - X: the sample matrix 10 | % - Y: the principal component vectors of the samples 11 | % 12 | % $ Description $ 13 | % - Y = slapplypca(S, X) applies the PCA model S to reduce the 14 | % vector dimensions of samples X. It outputs the PCA features by Y. 15 | % The formula for transform for each sample x in X is: 16 | % y = S.P' * (x - S.vmean) 17 | % 18 | % $ History $ 19 | % - Created by Dahua Lin on May 1st, 2006 20 | % - Modified by Dahua Lin, on Sep 10, 2006 21 | % - change sladd to sladdvec 22 | % 23 | 24 | %% parse and verify input arguments 25 | if nargin < 2 26 | raise_lackinput('slapplypca', 2); 27 | end 28 | 29 | if ndims(X) ~= 2 30 | error('sltoolbox:invaliddims', ... 31 | 'The sample matrix X should be a 2D matrix'); 32 | end 33 | 34 | if size(X, 1) ~= S.sampledim 35 | error('sltoolbox:sizmismatch', ... 36 | 'The sample dimension does not match that of PCA model'); 37 | end 38 | 39 | %% compute 40 | Y = S.P' * sladdvec(X, -S.vmean, 1); 41 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/subspace/slcovpca.m: -------------------------------------------------------------------------------- 1 | function S = slcovpca(vmean, C, preserve) 2 | %SLCOVPCA Trains a PCA with the covariance matrix given 3 | % 4 | % $ Syntax $ 5 | % - S = slcovpca(vmean, C) 6 | % - S = slcovpca(vmean, C, preserve) 7 | % 8 | % $ Arguments $ 9 | % - vmean: the mean vector 10 | % (set vmean to zero indicates a zero mean vector) 11 | % - C: the covariance matrix 12 | % - preserve: the scheme of determinaton of the subspace dimension 13 | % default = {'rank'} 14 | % - S: the struct of PCA model 15 | % 16 | % $ History $ 17 | % - Created by Dahua Lin, on Aug 17, 2006 18 | % 19 | 20 | 21 | [evals, evecs] = slsymeig(C); 22 | 23 | evals = max(evals, 0); 24 | if nargin < 3 || isempty(preserve) 25 | k = sldim_by_eigval(evals); 26 | else 27 | k = sldim_by_eigval(evals, preserve{:}); 28 | end 29 | 30 | d = size(C, 1); 31 | total_energy = sum(evals); 32 | if k < d 33 | evals = evals(1:k); 34 | evecs = evecs(:, 1:k); 35 | prin_energy = sum(evals); 36 | else 37 | prin_energy = total_energy; 38 | end 39 | 40 | 41 | S.sampledim = d; 42 | S.feadim = k; 43 | S.support = []; 44 | if isequal(vmean, 0) 45 | S.vmean = zeros(d, 1); 46 | else 47 | S.vmean = vmean; 48 | end 49 | S.P = evecs; 50 | S.eigvals = evals; 51 | S.residue = total_energy - prin_energy; 52 | S.energyratio = prin_energy / total_energy; 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/subspace/slnullspace.m: -------------------------------------------------------------------------------- 1 | function [V, Vc] = slnullspace(tar, varargin) 2 | %SLRANGESPACE Determines the null-space of the range of X 3 | % 4 | % $ Syntax $ 5 | % - V = slnullspace(tar) 6 | % - V = slnullspace(tar, ...) 7 | % - [V, Vc] = slnullspace(...) 8 | % 9 | % $ Arguments $ 10 | % - tar: the target, can be a sample matrix or covariance 11 | % - V: the basis for the null space 12 | % - Vc: the basis for the orthogonal complement of the null space. 13 | % 14 | % $ Description $ 15 | % - V = slnullspace(tar) determines the null space of tar in default 16 | % settings. Note that tar can have two forms: a sample matrix or a 17 | % covariance given by the syntax {'cov', C}. 18 | % 19 | % - V = slrangespace(tar, ...) determines the range space of X using 20 | % the specified dimension determination schemes. The arguments 21 | % input following X will be delivered to sldim_by_eigval for dimension 22 | % determination of principal space (the orthogonal complement to V) 23 | % 24 | % - [V, Vc] = slrangespace(...) also returns orthogonal complement of V. 25 | % 26 | % $ History $ 27 | % - Created by Dahua Lin on Apr 25, 2005 28 | % 29 | 30 | [Vc, V] = slrangespace(tar, varargin{:}); 31 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/subspace/slpcarecon.m: -------------------------------------------------------------------------------- 1 | function X = slpcarecon(S, Y) 2 | %SLPCARECON Reconstructs the samples in original space 3 | % 4 | % $ Syntax $ 5 | % - Xr = slpcarecon(S, Y) 6 | % 7 | % $ Arguments $ 8 | % - S: the PCA model struct 9 | % - Y: the principal component features 10 | % - Xr: the reconstructed samples 11 | % 12 | % $ Description $ 13 | % - Xr = slpcarecon(S, Y) reconstructs the original samples approximately 14 | % using the principal components Y. If the dimension of Y is less than 15 | % the subspace dimension, the leading space dimensions will be used. 16 | % 17 | % $ History $ 18 | % - Created by Dahua Lin, on Aug 17, 2006 19 | % - Modified by Dahua Lin, on Sep 10, 2006 20 | % - replace sladd by sladdvec to increase efficiency 21 | % 22 | 23 | %% parse and verify input 24 | 25 | if ~isstruct(S) 26 | error('sltoolbox:invalidarg', ... 27 | 'S should be a PCA model struct'); 28 | end 29 | 30 | if ~isnumeric(Y) || ndims(Y) ~= 2 31 | error('sltoolbox:invalidarg', ... 32 | 'The features Y should be a 2D numeric matrix'); 33 | end 34 | 35 | dy = size(Y, 1); 36 | if dy > S.feadim 37 | error('sltoolbox:sizmismatch', ... 38 | 'The feature dimension of Y exceeds the subspace dimension preserved in model'); 39 | end 40 | 41 | %% reconstruct 42 | 43 | if dy == S.feadim 44 | X = S.P * Y; 45 | else 46 | X = S.P(:, 1:dy) * Y; 47 | end 48 | 49 | X = sladdvec(X, S.vmean, 1); 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/subspace_ex/sl2dpca_construct.m: -------------------------------------------------------------------------------- 1 | function X = sl2dpca_construct(Mm, PL, PR, Y) 2 | %SL2DPCA_CONSTRUCT Constructs the matrix from 2D feature 3 | % 4 | % $ Syntax $ 5 | % - X = sl2dpca_construct(Mm, PL, PR, Y) 6 | % 7 | % $ Arguments $ 8 | % - Mm: the mean matrix 9 | % - PL: the left projection matrix 10 | % - PR: the right projection matrix 11 | % - Y: the extracted 2D features 12 | % - X: the constructed matrices 13 | % 14 | % $ Description $ 15 | % - X = sl2dpca_construct(Mm, PL, PR, Y) constructs the matrices in 16 | % original size using a 2D PCA model characterized by mean matrix and 17 | % the left and right projection matrices. 18 | % 19 | % $ History $ 20 | % - Created by Dahua Lin, on Jul 31st, 2006 21 | % 22 | 23 | %% Parse and verify input arguments 24 | 25 | if ndims(Mm) ~= 2 26 | error('sltoolbox:invalidarg', ... 27 | 'Mm should be a 2D matrix'); 28 | end 29 | [d1, d2] = size(Mm); 30 | if size(PL, 1) ~= d1 || size(PR, 1) ~= d2 31 | error('sltoolbox:sizmismatch', ... 32 | 'Inconsistent size for 2D PCA model'); 33 | end 34 | k1 = size(PL, 2); 35 | k2 = size(PR, 2); 36 | if size(Y, 1) ~= k1 || size(Y, 2) ~= k2 37 | error('sltoolbox:sizmismatch', ... 38 | 'The feature size is inconsistent with the 2D PCA model'); 39 | end 40 | 41 | %% Construct 42 | 43 | n = size(Y, 3); 44 | X = zeros(d1, d2, n); 45 | PRT = PR'; 46 | 47 | for i = 1 : n 48 | X(:,:,i) = PL * Y(:,:,i) * PRT + Mm; 49 | end 50 | 51 | 52 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/tensor/sltensor_dot.m: -------------------------------------------------------------------------------- 1 | function d = sltensor_dot(T1, T2) 2 | %SLTENSOR_DOT Computes the dot product between two tensors 3 | % 4 | % $ Syntax $ 5 | % - d = sltensor_dot(T1, T2) 6 | % 7 | % $ Description $ 8 | % - d = sltensor_dot(T1, T2) Computes the dot product between two tensors 9 | % T1 and T2. 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin on June 6th, 2005 13 | % 14 | 15 | d = sum(T1(:) .* T2(:)); 16 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/tensor/sltensor_fold.m: -------------------------------------------------------------------------------- 1 | function T = sltensor_fold(M, dims, k) 2 | %SLTENSOR_FOLD Folds a matrix into a tensor 3 | % 4 | % $ Syntax $ 5 | % - T = sltensor_fold(M, dims, k) 6 | % 7 | % $ Arguments $ 8 | % - M: the unfolded matrix of the tensor 9 | % - dims: the dimension sizes of the tensor 10 | % - k: the dimension along which the tensor is folded 11 | % - T: the resultant tensor 12 | % 13 | % $ Description $ 14 | % - T = sltensor_fold(M, dims, k) folds the matrix M to a tensor with 15 | % its mode dimensions specified in dims along the k-th mode. 16 | % 17 | % $ History $ 18 | % - Created by Dahua Lin on Dec 17th, 2005 19 | % 20 | 21 | %% parse and verify 22 | if nargin < 2 23 | raise_lackinput('sltensor_fold', 3); 24 | end 25 | n = length(dims); 26 | if k < 1 27 | error('sltoolbox:invalidarg', ... 28 | 'The mode index should be positive'); 29 | elseif k > n 30 | error('sltoolbox:argmismatch', ... 31 | 'The mode index exceeds the tensor order'); 32 | end 33 | if numel(M) ~= prod(dims) 34 | error('sltoolbox:argmismatch', ... 35 | 'The size of matrix and the dimensions of tensor do not match'); 36 | end 37 | 38 | %% compute 39 | if k == 1 40 | T = reshape(M, dims); 41 | else 42 | if k < n 43 | pdims = [k, 1:k-1, k+1:n]; 44 | else 45 | pdims = [k, 1:k-1]; 46 | end 47 | T = reshape(M, dims(pdims)); 48 | T = ipermute(T, pdims); 49 | end 50 | 51 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/tensor/sltensor_norm.m: -------------------------------------------------------------------------------- 1 | function nrm = sltensor_norm(T) 2 | %SLTENSOR_NORM Computes the Frobenius norm of a tensor T 3 | % 4 | % $ Syntax $ 5 | % - nrm = sltensor_norm(T) 6 | % 7 | % $ Arguments $ 8 | % - T: the tensor 9 | % - nrm: the Frobenius norm of the tensor 10 | % 11 | % $ Description $ 12 | % - nrm = sltensor_norm(T) Computes the Frobenius norm of a tensor T 13 | % 14 | % Copyright Dahua Lin, The MMLab, CUHK 15 | % $Date: 2006/08/13 04:42:42 $ 16 | % 17 | 18 | nrm = sqrt(sum(T(:).* T(:))); -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/tensor/sltensor_unfold.m: -------------------------------------------------------------------------------- 1 | function M = sltensor_unfold(T, k) 2 | %SLTENSOR_UNFOLD Unfolds a tensor to a matrix 3 | % 4 | % $ Syntax $ 5 | % - M = sltensor_unfold(T, k) 6 | % 7 | % $ Arguments $ 8 | % - T: the tensor 9 | % - k: the dimension along which the tensor is unfolded 10 | % - M: the matrix obtained by unfolding the tensor 11 | % 12 | % $ Description $ 13 | % - M = sltensor_unfold(T, k) Unfolds a tensor T to the matrix M along 14 | % the k-th dimension. 15 | % 16 | % $ History $ 17 | % - Created by Dahua Lin on Dec 17th, 2005 18 | % 19 | 20 | %% parse and verify 21 | if nargin < 2 22 | raise_lackinput('sltensor_unfold', 2); 23 | end 24 | 25 | %% compute 26 | n = ndims(T); 27 | if k == 1 28 | M = T(1:end, :); 29 | elseif k <= n 30 | if k < n 31 | pdims = [k, 1:k-1, k+1:n]; 32 | else 33 | pdims = [k, 1:k-1]; 34 | end 35 | M = permute(T, pdims); 36 | M = M(1:end, :); 37 | else 38 | M = T(:)'; 39 | end 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/text/slfiltertext.m: -------------------------------------------------------------------------------- 1 | function Tf = slfiltertext(T, f, varargin) 2 | %SLFILTERTEXT Processes the lines of text 3 | % 4 | % $ Syntax $ 5 | % - Tf = slfiltertext(T, f, ...) 6 | % 7 | % $ Arguments $ 8 | % - T: the text to be filtered 9 | % - f: the filter function 10 | % - Tf the filtered text 11 | % 12 | % $ Description $ 13 | % - Tf = slfiltertext(T, f, ...) processes (filters) every line 14 | % of the text T, in form of cell array of strings, and generated the 15 | % cell array of processed text Tf. the filtering is run as 16 | % filtered_line = f(source_line, ...) 17 | % 18 | % $ Remarks $ 19 | % - You can specify f as empty, then the original text will be simply 20 | % returned without processing 21 | % 22 | % $ History $ 23 | % - Created by Dahua Lin, on Aug 9th, 2006 24 | % 25 | 26 | %% parse and verify arguments 27 | 28 | if nargin < 2 29 | raise_lackinput('slfiltertext', 2); 30 | end 31 | 32 | 33 | %% filter 34 | if ~isempty(T) 35 | if ~isempty(f) 36 | nlines = length(T); 37 | Tf = cell(nlines, 1); 38 | for i = 1 : nlines 39 | curline = T{i}; 40 | procline = feval(f, curline, varargin{:}); 41 | Tf{i} = procline; 42 | end 43 | else 44 | Tf = T; 45 | end 46 | else 47 | Tf = {}; 48 | end 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/text/slshowtext.m: -------------------------------------------------------------------------------- 1 | function slshowtext(T) 2 | %SLSHOWTEXT Displays the text 3 | % 4 | % $ Syntax $ 5 | % - slshowtext(T) 6 | % 7 | % $ Description $ 8 | % - slshowtext(T) shows the text in cell array of lines. 9 | % 10 | % $ History $ 11 | % - Created by Dahua Lin, on Aug 9th, 2006 12 | % 13 | 14 | if ~isempty(T) 15 | nlines = length(T); 16 | for i = 1 : nlines 17 | curline = T{i}; 18 | if isempty(curline); 19 | disp(' '); 20 | else 21 | disp(curline); 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/text/slstrsplit.m: -------------------------------------------------------------------------------- 1 | function strs = slstrsplit(srcstr, delimiters) 2 | %SLSTRSPLIT splits a string into cell array of strings by delimiters 3 | % 4 | % $ Syntax $ 5 | % - strs = slstrsplit(srcstr, delimiters) 6 | % 7 | % $ Arguments $ 8 | % - srcstr: the source string 9 | % - delimiters: the array of delimiting chars 10 | % 11 | % $ Description $ 12 | % - strs = slstrsplit(srcstr, delimiters) splits the source string into 13 | % a cell array of parts, which are delimited by the chars in 14 | % delimiters. 15 | % 16 | % $ Remarks $ 17 | % - If for adjacent delimiters, the between will not will extracted. 18 | % - No further processing is applied, you can use functions like 19 | % slcompresstext to achieve these goals. 20 | % 21 | % $ History $ 22 | % - Created by Dahua Lin, on Aug 13, 2006 23 | % 24 | 25 | %% determine delimiter positions 26 | 27 | n0 = length(srcstr); 28 | is_delimiter = false(n0, 1); 29 | 30 | nd = length(delimiters); 31 | for i = 1 : nd 32 | ch = delimiters(i); 33 | is_delimiter(srcstr == ch) = true; 34 | end 35 | 36 | dps = find(is_delimiter); 37 | dps = dps(:)'; 38 | 39 | %% extract parts 40 | 41 | if isempty(dps) 42 | strs = {srcstr}; 43 | else 44 | sps = [1, dps+1]; 45 | eps = [dps-1, n0]; 46 | fv = find(sps <= eps); 47 | if ~isempty(fv) 48 | sps = sps(fv); 49 | eps = eps(fv); 50 | np = length(fv); 51 | strs = cell(np, 1); 52 | for i = 1 : np 53 | strs{i} = srcstr(sps(i):eps(i)); 54 | end 55 | else 56 | strs = {}; 57 | end 58 | end 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/raise_lackinput.m: -------------------------------------------------------------------------------- 1 | function raise_lackinput(funcname, nmin) 2 | %RAISE_LACKINPUT Raises an error indicating lack of input argument 3 | % 4 | % $ Syntax $ 5 | % - raise_lackinput(funcname, nmin) 6 | % 7 | % $ Arguments $ 8 | % - funcname: the name of invoking function 9 | % - nmin: the minimum number of input arguments 10 | % 11 | % $ Description $ 12 | % - raise_lackinput(funcname, nmin) raises an error message indicating 13 | % that the number of arguments input to the function specified by 14 | % funcname is not enough. (It should be at least nmin) 15 | % 16 | % $ History $ 17 | % - Created by Dahua Lin on Nov 18th, 2005 18 | % 19 | 20 | error('sltoolbox:lackinput', ... 21 | 'The number of input argument to %s should be at least %d.', ... 22 | funcname, nmin); 23 | 24 | 25 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/sladdpath.m: -------------------------------------------------------------------------------- 1 | function paths = sladdpath(filenames, dirpath) 2 | %SLADDPATH Adds dirpath to precede the filenames 3 | % 4 | % $ Syntax $ 5 | % - paths = sladdpath(filenames, dirpath) 6 | % 7 | % $ Arguments $ 8 | % - filenames: the filenames without root path 9 | % - dirpath: the preceding dirpath to be added 10 | % - paths: the full names after the dirpath is added 11 | % 12 | % $ Description $ 13 | % - paths = sladdpath(filenames, dirpath) adds directory path in front 14 | % of the filenames to form full paths. 15 | % 16 | % $ History $ 17 | % - Created by Dahua Lin, on Jul 27th, 2006 18 | % 19 | 20 | %% Parse and verify input arguments 21 | 22 | if nargin < 2 23 | raise_lackinput('sladdpath', 2); 24 | end 25 | 26 | if iscell(filenames) 27 | ismulti = true; 28 | elseif ischar(filenames) 29 | ismulti = false; 30 | else 31 | error('sltoolbox:invalidarg', ... 32 | 'The filenames should be either a single char string of the filename or a cell array of strings'); 33 | end 34 | 35 | 36 | %% Main skeleton 37 | 38 | if ~ismulti 39 | if ~isempty(dirpath) 40 | paths = internal_addpath(filenames, dirpath); 41 | else 42 | paths = filenames; 43 | end 44 | else 45 | if ~isempty(dirpath) 46 | n = numel(filenames); 47 | paths = cell(size(filenames)); 48 | for i = 1 : n 49 | paths{i} = internal_addpath(filenames{i}, dirpath); 50 | end 51 | else 52 | paths = filenames; 53 | end 54 | end 55 | 56 | 57 | %% Sub-functions 58 | 59 | function pathstr = internal_addpath(filename, dirpath) 60 | % precondition: dirpath is not empty 61 | 62 | if dirpath(end) ~= '\' 63 | pathstr = [dirpath, '\', filename]; 64 | else 65 | pathstr = [dirpath, filename]; 66 | end 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slallcombs.m: -------------------------------------------------------------------------------- 1 | function A = slallcombs(nums) 2 | %SLALLCOMBS Generate all combination of numbers 3 | % 4 | % $ Syntax $ 5 | % - A = slallcombs(nums) 6 | % 7 | % $ Arguments $ 8 | % - nums: the numbers of component sets 9 | % - A: the resultant indices matrix 10 | % 11 | % $ Description $ 12 | % - A = slallcombs(nums) generates the set of all possible index-vectors 13 | % for a d1 x d2 x ... x dK array, where d1, d2, ... dK are stored in 14 | % the K-dim vector nums. Then the resultant matrix A would be of size 15 | % K x dK x ... d2 x d1. 16 | % 17 | % $ Remarks $ 18 | % # If the number in some dimensions equals zero, then an empty array 19 | % will be returned. 20 | % 21 | % $ Examples $ 22 | % - Generate all indices for 3D array, 23 | % \{ 24 | % A = slallcombs([3 2 4]); 25 | % \} 26 | % Then A is a 3 x 3 x 2 x 4 matrix, with 27 | % A(:, i3, i2, i1) = [i1 i2 i3]' 28 | % 29 | % $ History $ 30 | % - Created by Dahua Lin on Nov 19th, 2005 31 | % 32 | 33 | %% parse input arguments 34 | nums = nums(:); 35 | K = length(nums); 36 | n = prod(nums); 37 | if n == 0 38 | A = []; 39 | return; 40 | end 41 | 42 | %% prepare storage 43 | A = zeros(K, n); 44 | 45 | %% get organization tables 46 | cprods = cumprod(nums); 47 | n_grps = [1; cprods(1:end-1)]; 48 | n_ins = cprods(end) ./ cprods; 49 | 50 | %% organize 51 | for i = 1 : K 52 | 53 | r = n_ins(i); 54 | s = nums(i); 55 | g = n_grps(i); 56 | 57 | P = (1:s); 58 | P = P(ones(r, 1), :); 59 | P = P(:); 60 | P = P(:, ones(1, g)); 61 | 62 | A(i, :) = P(:)'; 63 | end 64 | 65 | A = reshape(A, [K, nums(end:-1:1)']); 66 | 67 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slallsubinds.m: -------------------------------------------------------------------------------- 1 | function S = slallsubinds(arrsiz) 2 | %SLALLSUBINDS Generate all sub-indices for all elements of the array 3 | % 4 | % $ Syntax $ 5 | % - S = slallsubinds(arrsiz) 6 | % 7 | % $ Arguments $ 8 | % - arrsiz: the size of the array 9 | % - S: the array of all sub indices 10 | % 11 | % $ Description $ 12 | % - S = slallsubinds(arrsiz) generates all sub-indices for all elements 13 | % of the array. Suppose arrsiz is n1, n2, ..., nd. Then the output S 14 | % would be a d x n1 x n2 x ... x nd array, with each d-length column 15 | % corresponding to the sub-index of an element. 16 | % 17 | % $ History $ 18 | % - Created by Dahua Lin on Jul 29th, 2006 19 | % 20 | 21 | 22 | arrsiz = arrsiz(:)'; 23 | d = length(arrsiz); 24 | 25 | if d == 1 26 | S = (1:arrsiz)'; 27 | 28 | else 29 | totalnum = prod(arrsiz); 30 | ms = cumprod([1, arrsiz(1:d-1)]); 31 | ns = totalnum ./ (arrsiz .* ms); 32 | 33 | S = zeros(d, totalnum); 34 | for i = 1 : d 35 | 36 | M = 1 : arrsiz(i); 37 | M = M(ones(1, ms(i)), M, ones(1, ns(i))); 38 | 39 | S(i, :) = reshape(M, [1, totalnum]); 40 | end 41 | 42 | S = reshape(S, [d, arrsiz]); 43 | end 44 | 45 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slcartprod.m: -------------------------------------------------------------------------------- 1 | function P = slcartprod(varargin) 2 | %SLCARTPROD Get the Cartesian product of a series of sets 3 | % 4 | % $ Syntax $ 5 | % - P = slcartprod(S1, S2, ...) 6 | % 7 | % $ Arguments $ 8 | % - S1, S2, ...: the component sets in form of cell arrays 9 | % - P: the cartesian product of these sets 10 | % 11 | % $ Description $ 12 | % - P = slcartprod(S1, S2, ...) computes the cartesian product of the 13 | % sets S1, S2, .... These sets should be in form of cell arrays. If 14 | % S1, S2, ..., SK respectively have n1, n2, ..., nK elements. Then P 15 | % will be an K x nK x ... x n2 x n1 cell array. 16 | % 17 | % $ Reamrks $ 18 | % - If the number of sets is zero, or any set is empty, then P = {} 19 | % will be returned. 20 | % 21 | % $ Examples $ 22 | % - Produce the cartesian product of three sets 23 | % \{ 24 | % S1 = {'a', 'b', 'c'}; 25 | % S2 = {1, 2}; 26 | % S3 = {'A', 'B', 'C', 'D'} 27 | % P = slcartprod(S1, S2, S3); 28 | % \} 29 | % Then P would be a 3 x 4 x 2 x 3 cell array, and P(:, i3, i2, i1) 30 | % would be a cell array as {S1{i1}, S2{i2}, S3{i3}}. 31 | % 32 | % $ History $ 33 | % - Created by Dahua Lin on Nov 20th, 2005 34 | % 35 | 36 | %% parse and verify input arguments 37 | K = length(varargin); 38 | if K == 0 39 | P = {}; 40 | return; 41 | end 42 | S = cell(K, 1); 43 | nums = zeros(K, 1); 44 | for i = 1 : K 45 | if isempty(varargin{i}) 46 | P = {}; 47 | return; 48 | end 49 | curset = varargin{i}; 50 | S{i} = curset(:)'; % make it as a row cell array 51 | nums(i) = length(S{i}); 52 | end 53 | 54 | %% generate indices 55 | Inds = slallcombs(nums); 56 | Inds = Inds(:, 1:end); 57 | 58 | %% get product set 59 | P = cell([K, nums(end:-1:1)']); 60 | for i = 1 : K 61 | P(i, :) = S{i}(Inds(i, 1:end)); 62 | end 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slequalpar2D.m: -------------------------------------------------------------------------------- 1 | function ps = slequalpar2D(siz, maxblk) 2 | %SLEQUALPAR Partition a 2D array with balances for width and height 3 | % 4 | % $ Syntax $ 5 | % - ps = slequalpar2D(siz, maxblk) 6 | % 7 | % $ Arguments $ 8 | % - siz: The size of the 2D array to be partitioned 9 | % - maxblk: The maximum number of elements in each block 10 | % - ps: The partition structure 11 | % 12 | % $ Description $ 13 | % - ps = slequalpar2D(siz, maxblk) partitions the 2D array into blocks 14 | % such that for each block the height and width should be as close 15 | % as possible. 16 | % 17 | % $ History $ 18 | % - Created by Dahua Lin, on Sep 8th, 2006 19 | % 20 | 21 | m = siz(1); 22 | n = siz(2); 23 | ne = m * n; 24 | 25 | if ne <= maxblk % not partitioned 26 | ps = struct('sinds', {1, 1}, 'einds', {m, n}); 27 | else 28 | b = max(sqrt(maxblk), 1); 29 | if b <= m && b <= n 30 | bm = b; 31 | bn = b; 32 | elseif b > m 33 | bm = m; 34 | bn = maxblk / m; 35 | else 36 | bn = n; 37 | bm = maxblk / n; 38 | end 39 | nm = ceil(m / bm); 40 | nn = ceil(n / bn); 41 | ps = slpartition(siz, 'numblks', [nm, nn]); 42 | end 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slevalfunctor.m: -------------------------------------------------------------------------------- 1 | function varargout = slevalfunctor(functor, varargin) 2 | %SLEVALFUNCTOR Evaluates a functor 3 | % 4 | % $ Syntax $ 5 | % - [O1, O2, ...] = slevalfunctor(functor, I1, I2, ...) 6 | % 7 | % $ Description $ 8 | % - [O1, O2, ...] = slevalfunctor(functor, I1, I2, ...) evaluates 9 | % the functor. Here, a functor refers to a function that can be 10 | % invokable with parameters. A functor is typically used in a 11 | % framework function that need to invoke other functions with 12 | % both the variables generated inside the framework and the 13 | % variables offered from external environment. 14 | % If there is no external parameters, the functor can be 15 | % given in the form of a function name, function handle or 16 | % inline object; if there are external parameters the functor 17 | % can be given in form of a cell array with the first cell being 18 | % the callable function while the other cells containing the 19 | % external parameters. 20 | % 21 | % $ Remarks $ 22 | % - For an empty functor, it simply does nothing and returns. 23 | % 24 | % $ History $ 25 | % - Created by Dahua Lin, on Aug 30, 2006 26 | % 27 | 28 | if isempty(functor) 29 | return; 30 | end 31 | 32 | if iscell(functor) 33 | func = functor{1}; 34 | if length(functor) > 1 35 | params = functor(2:end); 36 | else 37 | params = {}; 38 | end 39 | else 40 | func = functor; 41 | params = {}; 42 | end 43 | 44 | if isempty(func) 45 | return; 46 | end 47 | 48 | if nargout == 0 49 | feval(func, varargin{:}, params{:}); 50 | else 51 | varargout = cell(1, nargout); 52 | [varargout{:}] = feval(func, varargin{:}, params{:}); 53 | end 54 | 55 | 56 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slgridsamples.m: -------------------------------------------------------------------------------- 1 | function X = slgridsamples(varargin) 2 | %SLGRIDSAMPLES Generate the sample vectors on grid points 3 | % 4 | % $ Syntax $ 5 | % - X = slgridsamples(x1, x2, ..., xd) 6 | % - X = slgridsamples({x1, x2, ..., xd}) 7 | % 8 | % $ Description $ 9 | % - X = slgridsamples(x1, x2, ..., xd) generates a d x (n1xn2x...xnd) 10 | % sample matrix, provided that x1, x2, ... xd are vectors storing the 11 | % the sampled values along dimensions with lengths n1, n2, ..., nd. 12 | % 13 | % - X = slgridsamples({x1, x2, ..., xd}) is similar to the previous 14 | % syntax, except that the dimension sample value vectors are groupped 15 | % into a cell array. 16 | % 17 | % $ Remarks $ 18 | % - The orders of the samples are determined in following manner that 19 | % the indices of the grids are generated by slallcombs. 20 | % - If input arguments are empty, the resulting X would be empty. 21 | % 22 | % $ History $ 23 | % - Created by Dahua Lin on Dec 28th, 2005 24 | % 25 | 26 | %% parse and verify input arguments 27 | if nargin == 0 28 | X = []; 29 | return; 30 | end 31 | if iscell(varargin{1}) 32 | vars = varargin{1}; 33 | else 34 | vars = varargin; 35 | end 36 | 37 | %% Prepare 38 | d = length(vars); 39 | ns = zeros(1, d); 40 | for i = 1 : d 41 | ns(i) = length(vars{i}); 42 | end 43 | ntotal = prod(ns); 44 | X = zeros(d, ntotal); 45 | if ntotal == 0 46 | return; 47 | end 48 | 49 | %% Genertae 50 | inds = slallcombs(ns); 51 | for i = 1 : d 52 | X(i, :) = vars{i}(inds(i, :)); 53 | end 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slignorevars.m: -------------------------------------------------------------------------------- 1 | function slignorevars(varargin) 2 | %SLIGNOREVARS Ignores the input variables 3 | % 4 | % $ Syntax $ 5 | % - slignorevars(v1, v2, ...) 6 | % 7 | % $ Description $ 8 | % - slignorevars(v1, v2, ...) In high version of Matlab, the editor 9 | % will produce a warning when it does not find the using of a 10 | % defined variable. However, it is sometimes necessary for some 11 | % designs. This function provides a way for you to plugin input 12 | % variables, by this way, in your function, it will be apparent to 13 | % editor that the variables are used. 14 | % 15 | % $ History $ 16 | % - Created by Dahua Lin, on Aug 14, 2006 17 | % 18 | 19 | 20 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slimg2mat.m: -------------------------------------------------------------------------------- 1 | function M = slimg2mat(img) 2 | %SLIMG2MAT Converts an image array to a double matrix 3 | % 4 | % $ Syntax $ 5 | % - M = slimg2mat(img) 6 | % 7 | % % Arguments $ 8 | % - img: the image 9 | % - M: the converted matrix 10 | % 11 | % $ Description $ 12 | % - M = slimg2mat(img) converts a variety of image arrays to a double 13 | % 2D matrix. In detail, the RGB image will be turned to a grayscale 14 | % image, in addition, the value of uint8 or other integer types will 15 | % be converted to double value with range [0, 1] by im2double. 16 | % 17 | % $ History $ 18 | % - Created by Dahua Lin, on Jul 25th, 2006 19 | % 20 | 21 | 22 | % color processing 23 | d = ndims(img); 24 | n = size(img, 3); 25 | if d > 3 || n == 2 || n > 3 26 | error('sltoolbox:invalidimg', ... 27 | 'The image should be 1-channel gray image or 2-channel RGB image'); 28 | end 29 | if n == 3 30 | img = rgb2gray(img); 31 | end 32 | 33 | % type conversion 34 | if isa(img, 'double') 35 | M = img; 36 | else 37 | M = im2double(img); 38 | end 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slisfields.m: -------------------------------------------------------------------------------- 1 | function tf = slisfields(S, fns) 2 | %SLISFIELDS Judges whether the specified fieldnames are fields of S 3 | % 4 | % $ Syntax $ 5 | % - tf = slisfields(S, fns) 6 | % 7 | % $ Arguments $ 8 | % - S: the struct 9 | % - fns: the field names 10 | % - tf: the boolean array 11 | % 12 | % $ Description $ 13 | % - tf = slisfields(S, fns) judges whether the names in fns are 14 | % fieldnames of S. If fns is a char array, then tf is a boolean 15 | % variable indicating whether fns is a field of S, or if fns is 16 | % a cell array of field names with k cells, then fns is an array 17 | % with the same size of fns, and each of its element indicating 18 | % whether the corresponding field name is the field of S. 19 | % 20 | % $ History $ 21 | % - Created by Dahua Lin, on Aug 27, 2006 22 | % 23 | 24 | if ~isstruct(S) 25 | error('sltoolbox:invalidarg', ... 26 | 'S should be a struct in order to have fields'); 27 | end 28 | 29 | if ischar(fns) 30 | tf = isfield(S, fns); 31 | elseif iscell(fns) 32 | tf = false(size(fns)); 33 | n = numel(fns); 34 | for i = 1 : n 35 | tf(i) = isfield(S, fns{i}); 36 | end 37 | else 38 | error('sltoolbox:invalidarg', ... 39 | 'fns should be either a char string or a cell array'); 40 | end 41 | 42 | 43 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/sllabelinds.m: -------------------------------------------------------------------------------- 1 | function Inds = sllabelinds(labels, labelset) 2 | %SLLABELINDS Extract indices corresponding to specified labels 3 | % 4 | % $ Syntax $ 5 | % - Inds = sllabelinds(labels, labelset) 6 | % 7 | % $ Arguments $ 8 | % - labels: The labels of samples 9 | % - labelset: The set of labels whose indices to be extracted 10 | % - Inds: The cell array of indices extracted for labelset 11 | % 12 | % $ Description $ 13 | % - Inds = sllabelinds(labels, labelset) extracts the indices 14 | % corresponding to the labels specified in labelset. Suppose the 15 | % labelset is given by [l1, l2, ...], then Inds would be like 16 | % {[i11, i12, ...], [i21, i22, ...], ...}, where [i11, i12, ...] is 17 | % a row vector of indices corresponding to l1, so that 18 | % labels(i11) = labels(i12) = ... = l1. 19 | % 20 | % $ History $ 21 | % - Created by Dahua Lin, on Aug 31, 2006 22 | % 23 | 24 | %% parse and verify input 25 | 26 | if ~isvector(labels) || ~isnumeric(labels) 27 | error('sltoolbox:invalidarg', ... 28 | 'labels should be a numeric vector'); 29 | end 30 | 31 | if size(labels, 1) ~= 1 32 | labels = labels(:)'; 33 | end 34 | 35 | %% re-arrange 36 | 37 | [labels, si] = sort(labels, 2, 'ascend'); 38 | [nums, labelfound] = slcount(labels); 39 | [sinds, einds] = slnums2bounds(nums); 40 | [sfound, smap] = ismember(labelset, labelfound); 41 | 42 | %% extract 43 | 44 | c = length(labelset); 45 | Inds = cell(1, c); 46 | for i = 1 : c 47 | if sfound(i) 48 | mi = smap(i); 49 | curinds = si(sinds(mi):einds(mi)); 50 | Inds{i} = curinds; 51 | else 52 | Inds{i} = []; 53 | end 54 | end 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slnums2bounds.m: -------------------------------------------------------------------------------- 1 | function [spos, epos] = slnums2bounds(nums) 2 | %SLNUMS2BOUNDS Compute the index-boundaries from section sizes 3 | % 4 | % $ Syntax $ 5 | % - [spos, epos] = slnums2bounds(nums) 6 | % - spos = slnums2bounds(nums) 7 | % 8 | % $ Description $ 9 | % - [spos, epos] = slnums2bounds(nums) obtains the start positions and 10 | % end positions of the sections given the number of elements in 11 | % the sections. 12 | % 13 | % - spos = slnums2bounds(nums) only retrieves the start positions. 14 | % 15 | % $ Reamrks $ 16 | % # nums can be either a row vector or a column vector. then the results 17 | % will be row vector or column vector correspondingly. 18 | % 19 | % $ Examples $ 20 | % - Get boundaries for a 3-section-array 21 | % \{ 22 | % [s, e] = slnums2bounds([3 2 4]) 23 | % 24 | % s = 25 | % 1 4 6 26 | % e = 27 | % 3 5 9 28 | % \} 29 | % 30 | % $ History $ 31 | % - Created by Dahua Lin on Nov 20th, 2005 32 | % 33 | 34 | %% parse and verify input arguments 35 | [d1, d2] = size(nums); 36 | if d1 == 1 % row vector 37 | iscol = false; 38 | elseif d2 == 1 % column vector 39 | iscol = true; 40 | else 41 | error('sltoolbox:notvector', 'nums should be a row/column vector'); 42 | end 43 | 44 | 45 | %% compute 46 | cs = cumsum(nums); 47 | if iscol 48 | spos = [1; cs(1:end-1)+1]; 49 | else 50 | spos = [1, cs(1:end-1)+1]; 51 | end 52 | if nargout >= 2 53 | epos = cs; 54 | end 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slparblocks.m: -------------------------------------------------------------------------------- 1 | function blocks = slparblocks(ps) 2 | %SLPARBLOCKS Gets the blocks from partition structure 3 | % 4 | % $ Syntax $ 5 | % - blocks = slparblocks(ps) 6 | % 7 | % $ Arguments $ 8 | % - ps: the partition structure generated from slpartition 9 | % - blocks: the cell array of block ranges 10 | % 11 | % $ Description $ 12 | % - blocks = slparblocks(ps) gets the a cell array of blocks 13 | % corresponding to the partition structure. If there are d dimensions 14 | % and m1, m2, ..., md partitions along each dimension. Then an 15 | % m1 x m2 x ... x md cell array will be returned, with each cell 16 | % containing a 2 x d array, in the form of 17 | % [s1, s2, ..., sd; e1, e2, ..., ed]. It means that the block of 18 | % data will be extracted from an whole array A as 19 | % A(s1:e1, s2:e2, ..., sd:ed). 20 | % 21 | % $ History $ 22 | % - Created by Dahua Lin, on Jul 29th, 2006 23 | % 24 | 25 | 26 | % calculate block numbers 27 | 28 | d = length(ps); 29 | 30 | blknums = zeros(1, d); 31 | for i = 1 : d 32 | blknums(i) = length(ps(i).sinds); 33 | end 34 | 35 | % get block ranges 36 | 37 | blkinds = slallsubinds(blknums); 38 | NBlks = prod(blknums); 39 | blkinds = reshape(blkinds, [d, NBlks]); 40 | 41 | Smat = zeros(d, NBlks); 42 | Emat = zeros(d, NBlks); 43 | for i = 1 : d 44 | Smat(i, :) = ps(i).sinds(blkinds(i, 1:NBlks)); 45 | Emat(i, :) = ps(i).einds(blkinds(i, 1:NBlks)); 46 | end 47 | 48 | 49 | % convert from block range array to block cell array 50 | 51 | Smat = reshape(Smat, [1, d*NBlks]); 52 | Emat = reshape(Emat, [1, d*NBlks]); 53 | Bmat = [Smat; Emat]; 54 | clear Smat Emat; 55 | 56 | tempd = zeros(1, NBlks); 57 | tempd(:) = d; 58 | blocks = mat2cell(Bmat, 2, tempd); 59 | 60 | if d == 1 61 | blocks = blocks(:); 62 | else 63 | blocks = reshape(blocks, blknums); 64 | end 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slrange2indcells.m: -------------------------------------------------------------------------------- 1 | function C = slrange2indcells(range) 2 | %SLRANGE2INDCELLS Converts a range array to indices cell array 3 | % 4 | % $ Syntax $ 5 | % - C = slrange2indcells(range) 6 | % 7 | % $ Arguments $ 8 | % - range: the 2 x d array specifying the range 9 | % - C: the 1 x d indices array 10 | % 11 | % $ Description $ 12 | % - C = slrange2indcells(range) converts an range array to a cell array 13 | % of indices. 14 | % For example, for a range array in the form: 15 | % [s1, s2, ..., sd; e1, e2, ..., ed], it will outputs the cell array as 16 | % C = {s1:e1, s2:e2, ..., sd:ed}. 17 | % So that A(C{:}) will give A(s1:e1, s2:e2, ..., sd:ed). 18 | % 19 | % $ History $ 20 | % - Created by Dahua Lin, on Jul 29th, 2006 21 | % 22 | 23 | d = size(range, 2); 24 | C = cell(1, d); 25 | 26 | for i = 1 : d 27 | C{i} = range(1, i) : range(2, i); 28 | end 29 | 30 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slsharedisp_attach.m: -------------------------------------------------------------------------------- 1 | function slsharedisp_attach(name, varargin) 2 | %SLSHAREDISP_ATTACH Attachs to global display options 3 | % 4 | % $ Syntax $ 5 | % - slsharedisp_attach(name, ...) 6 | % 7 | % $ Arguments $ 8 | % - name: the name of the invoker 9 | % 10 | % $ Description $ 11 | % - slsharedisp_attach(name, ...) attachs the current function to 12 | % the global display. You can specify the following properties 13 | % - 'show': whether to show process information 14 | % (default = true) 15 | % - 'indent': the relative indent (default = 0) 16 | % Please note that the actual properties set to the current displayer 17 | % is determined by both the properties set here and the properties 18 | % of the previous displayer in stack: 19 | % new.show = current.show && previous.show; 20 | % new.indent = current.indent + previous.indent; 21 | % 22 | % $ History $ 23 | % - Created by Dahua Lin, on Aug 29, 2006 24 | % 25 | 26 | %% parse and verify input arguments 27 | 28 | opts.show = true; 29 | opts.indent = 0; 30 | opts = slparseprops(opts, varargin{:}); 31 | opts.name = name; 32 | 33 | %% Main 34 | 35 | global GLOBAL_SHARE_DISPLAYER; 36 | 37 | s = GLOBAL_SHARE_DISPLAYER; 38 | 39 | if isempty(s) 40 | s = create_displayer([], opts); 41 | else 42 | n = length(s); 43 | s(n+1, 1) = create_displayer(s(n), opts); 44 | end 45 | 46 | GLOBAL_SHARE_DISPLAYER = s; 47 | 48 | 49 | 50 | %% Core function 51 | 52 | function dp = create_displayer(prevdp, curdp) 53 | 54 | dp.name = curdp.name; 55 | 56 | if isempty(prevdp) 57 | dp.indent = curdp.indent; 58 | dp.show = curdp.show; 59 | dp.indentstep = 4; 60 | else 61 | dp.indent = prevdp.indent + curdp.indent; 62 | dp.show = prevdp.show && curdp.show; 63 | dp.indentstep = prevdp.indentstep; 64 | end 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slsharedisp_decindent.m: -------------------------------------------------------------------------------- 1 | function slsharedisp_decindent(nsteps) 2 | %SLSHAREDISP_DECINDENT Decreases the indent of the displayer 3 | % 4 | % $ Syntax $ 5 | % - slsharedisp_decindent() 6 | % - slsharedisp_decindent(nsteps) 7 | % 8 | % $ Description $ 9 | % - slsharedisp_decindent() decreases the indent by one step. 10 | % 11 | % - slsharedisp_decindent(nsteps) decreases the indent by specified 12 | % number of steps. 13 | % 14 | % $ History $ 15 | % - Created by Dahua Lin, on Aug 29, 2006 16 | % 17 | 18 | global GLOBAL_SHARE_DISPLAYER; 19 | 20 | if isempty(GLOBAL_SHARE_DISPLAYER) 21 | error('sltoolbox:gdisperr', ... 22 | 'The global displayer is not open'); 23 | end 24 | 25 | if nargin == 0 26 | nsteps = 1; 27 | end 28 | 29 | GLOBAL_SHARE_DISPLAYER(end).indent = ... 30 | GLOBAL_SHARE_DISPLAYER(end).indent - nsteps; -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slsharedisp_detach.m: -------------------------------------------------------------------------------- 1 | function slsharedisp_detach() 2 | %SLSHAREDISP_DETACH Detachs current function from global display 3 | % 4 | % $ Syntax $ 5 | % - slsharedisp_detach() 6 | % 7 | % $ History $ 8 | % - Created by Dahua Lin, on Aug 29, 2006 9 | % 10 | 11 | global GLOBAL_SHARE_DISPLAYER; 12 | 13 | if ~isempty(GLOBAL_SHARE_DISPLAYER) 14 | if length(GLOBAL_SHARE_DISPLAYER) == 1 15 | GLOBAL_SHARE_DISPLAYER = []; 16 | else 17 | GLOBAL_SHARE_DISPLAYER(end) = []; 18 | end 19 | end 20 | 21 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slsharedisp_incindent.m: -------------------------------------------------------------------------------- 1 | function slsharedisp_incindent(nsteps) 2 | %SLSHAREDISP_INCINDENT Increases the indent of the displayer 3 | % 4 | % $ Syntax $ 5 | % - slsharedisp_incindent() 6 | % - slsharedisp_incindent(nsteps) 7 | % 8 | % $ Description $ 9 | % - slsharedisp_incindent() increases the indent by one step. 10 | % 11 | % - slsharedisp_incindent(nsteps) increases the indent by specified 12 | % number of steps. 13 | % 14 | % $ History $ 15 | % - Created by Dahua Lin, on Aug 29, 2006 16 | % 17 | 18 | global GLOBAL_SHARE_DISPLAYER; 19 | 20 | if isempty(GLOBAL_SHARE_DISPLAYER) 21 | error('sltoolbox:gdisperr', ... 22 | 'The global displayer is not open'); 23 | end 24 | 25 | if nargin == 0 26 | nsteps = 1; 27 | end 28 | 29 | GLOBAL_SHARE_DISPLAYER(end).indent = ... 30 | GLOBAL_SHARE_DISPLAYER(end).indent + nsteps; 31 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slsharedisp_reset.m: -------------------------------------------------------------------------------- 1 | function slsharedisp_reset() 2 | %SLSHAREDISP_RESET Resets the global display options 3 | % 4 | % $ Syntax $ 5 | % - slsharedisp_reset() 6 | % 7 | % $ History $ 8 | % - Created by Dahua Lin, on Aug 29, 2006 9 | % 10 | 11 | global GLOBAL_SHARE_DISPLAYER; 12 | global GLOBAL_SHARE_DISPLAYER_LINEBREAK; 13 | 14 | GLOBAL_SHARE_DISPLAYER = []; 15 | GLOBAL_SHARE_DISPLAYER_LINEBREAK = []; 16 | 17 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slsharedisp_word.m: -------------------------------------------------------------------------------- 1 | function slsharedisp_word(varargin) 2 | %SLSHAREDISP_WORD Displays message without line breaking 3 | % 4 | % $ Syntax $ 5 | % - slsharedisp_word(...) 6 | % 7 | % $ History $ 8 | % - Created by Dahua Lin, on Aug 31, 2006 9 | % 10 | 11 | global GLOBAL_SHARE_DISPLAYER; 12 | global GLOBAL_SHARE_DISPLAYER_LINEBREAK; 13 | 14 | if isempty(GLOBAL_SHARE_DISPLAYER) 15 | error('sltoolbox:gdisperr', ... 16 | 'The global displayer is not open'); 17 | end 18 | 19 | if isempty(GLOBAL_SHARE_DISPLAYER_LINEBREAK) 20 | GLOBAL_SHARE_DISPLAYER_LINEBREAK = true; 21 | end 22 | 23 | s = GLOBAL_SHARE_DISPLAYER(end); 24 | 25 | if s.show && ~isempty(varargin) 26 | nblanks = s.indent * s.indentstep; 27 | if length(varargin) == 1 28 | strmsg = varargin{1}; 29 | else 30 | strmsg = sprintf(varargin{:}); 31 | end 32 | if nblanks > 0 && GLOBAL_SHARE_DISPLAYER_LINEBREAK 33 | strmsg = [blanks(nblanks), strmsg]; 34 | end 35 | fprintf('%s', strmsg); 36 | end 37 | 38 | GLOBAL_SHARE_DISPLAYER_LINEBREAK = false; -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/sltakeval.m: -------------------------------------------------------------------------------- 1 | function varargout = sltakeval(A) 2 | %SLTAKEVAL Extracts the values in an array/cell array to output 3 | % 4 | % $ Syntax $ 5 | % -[O1, O2, ..., On] = sltakeval(A) 6 | % 7 | % $ Description $ 8 | % -[O1, O2, ..., On] = sltakeval(A) takes the values in the array 9 | % or cell array A and assigns them to output variables. 10 | % The number of elements in A should be equal to the number of 11 | % output arguments. 12 | % 13 | % $ History $ 14 | % - Created by Dahua Lin, on Sep 1st, 2006 15 | % 16 | 17 | n = numel(A); 18 | if nargout ~= n 19 | error('sltoolbox:sizmismatch', ... 20 | 'The number of elements in A is not equal to the number of outputs'); 21 | end 22 | 23 | 24 | 25 | if n > 0 26 | if iscell(A) 27 | if isequal(size(A), [1, n]) 28 | varargout = A; 29 | else 30 | varargout = reshape(A, 1, n); 31 | end 32 | else 33 | varargout = cell(1, n); 34 | for i = 1 : n 35 | varargout{i} = A(i); 36 | end 37 | end 38 | end -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/sltypesize.m: -------------------------------------------------------------------------------- 1 | function s = sltypesize(typename) 2 | %SLTYPESIZE Gets the element size of a specified type 3 | % 4 | % $ Syntax $ 5 | % - s = sltypesize(typename) 6 | % 7 | % $ Arguments $ 8 | % - typename: the name of a type 9 | % - s: the number of bytes in each element of the specified type 10 | % 11 | % $ Description $ 12 | % 13 | % - s = sltypesize(typename) returns the number of bytes of each element 14 | % in the type specified by typename. 15 | % 16 | % - The typenames supported are listed below: 17 | % - 'double' 18 | % - 'single' 19 | % - 'float' 20 | % - 'uint8' 21 | % - 'uint16' 22 | % - 'uint32' 23 | % - 'uint64' 24 | % - 'int8' 25 | % - 'int16' 26 | % - 'int32' 27 | % - 'int64' 28 | % - 'logical' 29 | % - 'char' 30 | % 31 | % $ History $ 32 | % - Created by Dahua Lin on Dec 7th, 2005 33 | % 34 | 35 | switch typename 36 | case 'double' 37 | s = 8; 38 | case {'single', 'float'} 39 | s = 4; 40 | case {'uint8', 'int8'} 41 | s = 1; 42 | case {'uint16', 'int16'} 43 | s = 2; 44 | case {'uint32', 'int32'} 45 | s = 4; 46 | case {'uint64', 'int64'} 47 | s = 8; 48 | case {'char', 'logical'} 49 | s = 1; 50 | otherwise 51 | error('sltoolbox:invalid_type', ... 52 | 'Unsupported typename %s', typename); 53 | end 54 | 55 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils/slverifyroc_par.m: -------------------------------------------------------------------------------- 1 | function slverifyroc_par() -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils_ex/slguid.m: -------------------------------------------------------------------------------- 1 | function gid = slguid() 2 | %SLGUID Generates a GUID (Global Unique Identifier) 3 | % 4 | % $ Syntax $ 5 | % - gid = slguid() 6 | % 7 | % $ Description $ 8 | % - gid = slguid() generates a 128-bit GUID, which is represented by 9 | % a 16 x 1 UINT8 array. If it succeeds, an 1 x 16 array is returned 10 | % otherwise an error is reported. 11 | % 12 | % $ Remarks $ 13 | % - In current implementation, it is based on win32guid_core mex 14 | % cpp function, thus only Win32 or compatible platform is supported. 15 | % 16 | % $ History $ 17 | % - Created by Dahua Lin, on Aug 12, 2006 18 | % 19 | 20 | if ~strcmpi(computer(), 'PCWIN') && ~strcmpi(computer(), 'PCWIN64') 21 | error('sltoolbox:notsupportplatform', ... 22 | 'Only win32 or x64 platform is supported for slguid'); 23 | end 24 | 25 | [b, gid] = win32guid_core(); 26 | 27 | if ~b 28 | error('sltoolbox:rterror', ... 29 | 'Fail to generate GUID'); 30 | end 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils_ex/slguidstr.m: -------------------------------------------------------------------------------- 1 | function str = slguidstr(gid) 2 | %SLGUIDSTR Converts a guid to a string 3 | % 4 | % $ Syntax $ 5 | % - str = slguidstr(gid) 6 | % 7 | % $ Description $ 8 | % - str = slguidstr(gid) converts a GUID represented by a 1 x 16 uint8 9 | % array to a string in Win32 Registry Format. 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin, on Aug 12nd, 2006 13 | % 14 | 15 | if ~slisguid(gid) 16 | error('sltoolbox:invalidarg', ... 17 | 'The input variable should be a GUID'); 18 | end 19 | 20 | numpat = '%02X'; 21 | 22 | str = sprintf('%s-%s-%s-%s-%s', ... 23 | sprintf(numpat, gid(1:4)), ... 24 | sprintf(numpat, gid(5:6)), ... 25 | sprintf(numpat, gid(7:8)), ... 26 | sprintf(numpat, gid(9:10)), ... 27 | sprintf(numpat, gid(11:16)) ... 28 | ); 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils_ex/slisguid.m: -------------------------------------------------------------------------------- 1 | function b = slisguid(v) 2 | %SLISGUID Judges whether the input can represent a GUID 3 | % 4 | % $ Syntax $ 5 | % - b = slisguid(v) 6 | % 7 | % $ Description $ 8 | % - b = slisguid(v) judges whether the input v conforms to the 9 | % matlab representation of GUID (1 x 16 uint8 array). 10 | % 11 | % $ History $ 12 | % - Created by Dahua Lin, on Aug 12nd, 2006 13 | % 14 | 15 | b = isa(v, 'uint8') && isequal(size(v), [1 16]); 16 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils_ex/win32guid_core.cpp: -------------------------------------------------------------------------------- 1 | // The mex function to generate GUID (Global Unique Identifier) 2 | // 3 | // This function is based on Win32 Platform SDK on COM. 4 | // It is essentaily wrapping the API function: CoCreateGuid 5 | // 6 | // History: 7 | // - Created by Dahua Lin, on Aug 12nd, 2006 8 | // 9 | 10 | #include 11 | #include 12 | 13 | #include "mex.h" 14 | 15 | 16 | // 17 | // No Input 18 | // Output two variables 19 | // - output var 1: logical, indicate whether succeed 20 | // - output var 2: a 1 x 16 uint8 array storing the 128-bit GUID 21 | // if not successful, it is an empty array 22 | // 23 | void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) 24 | { 25 | if (nrhs > 0) 26 | { 27 | mexErrMsgTxt("No input variables are allowed for win32guid_core"); 28 | } 29 | if (nlhs != 2) 30 | { 31 | mexErrMsgTxt("The number of outputs should be exactly 2"); 32 | } 33 | 34 | // generate the GUID 35 | GUID gid; 36 | HRESULT ret = CoCreateGuid(&gid); 37 | 38 | // output 39 | if (ret == S_OK) 40 | { 41 | mxArray *parrGuid = mxCreateNumericMatrix(1, 16, mxUINT8_CLASS, mxREAL); 42 | unsigned char* pBuffer = (unsigned char*)mxGetData(parrGuid); 43 | 44 | memcpy(pBuffer, &gid, 16); 45 | 46 | mxArray *pRet = mxCreateLogicalScalar((mxLogical)1); 47 | 48 | plhs[0] = pRet; 49 | plhs[1] = parrGuid; 50 | } 51 | else 52 | { 53 | mxArray *parrGuid = mxCreateNumericMatrix(0, 0, mxUINT8_CLASS, mxREAL); 54 | mxArray *pRet = mxCreateLogicalScalar((mxLogical)0); 55 | 56 | plhs[0] = pRet; 57 | plhs[1] = parrGuid; 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils_ex/win32guid_core.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils_ex/win32guid_core.mexw32 -------------------------------------------------------------------------------- /wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils_ex/win32guid_core.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmthang/bivec/8949591382a42f4e15c8d785414e01b2d124ec0f/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/utils_ex/win32guid_core.mexw64 -------------------------------------------------------------------------------- /wordsim/code/splitWordVectorFile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! $# -eq 2 && ! $# -eq 2 ]] 4 | then 5 | echo "`basename $0` wordVectorFile outPrefix" 6 | exit 7 | fi 8 | 9 | wordVectorFile=$1 10 | outPrefix=$2 11 | outDir=`dirname $outPrefix` 12 | 13 | # check outDir exists 14 | #echo "# outDir $outDir" 15 | if [ ! -d $outDir ] 16 | then 17 | # echo "# Directory exists $outDir" 18 | #else 19 | mkdir -p $outDir 20 | fi 21 | 22 | 23 | inFile=$1 24 | numWords=`tail -1 $inFile | wc -w` 25 | let numDimensions=numWords-1 26 | #echo "numDimensions=$numDimensions" 27 | 28 | numWordsFirstLine=`head -1 $inFile | wc -w` 29 | if [ $numWordsFirstLine -ne $numWords ]; then # remove the first line (needed for output from word2vec where the first line contains the number words and the dimension) 30 | #echo "tail -n +2 $inFile > $inFile.tmp" 31 | tail -n +2 $inFile > $inFile.tmp 32 | inFile=$inFile.tmp 33 | fi 34 | 35 | cut -d " " -f 1 $inFile > $outPrefix.words 36 | cut -d " " -f 2- $inFile > $outPrefix.We 37 | 38 | if [ $numWordsFirstLine -ne $numWords ]; then 39 | rm -rf $inFile 40 | fi 41 | 42 | -------------------------------------------------------------------------------- /wordsim/data/MC.txt: -------------------------------------------------------------------------------- 1 | car automobile 3.92 2 | gem jewel 3.84 3 | journey voyage 3.84 4 | boy lad 3.76 5 | coast shore 3.7 6 | asylum madhouse 3.61 7 | magician wizard 3.5 8 | midday noon 3.42 9 | furnace stove 3.11 10 | food fruit 3.08 11 | bird cock 3.05 12 | bird crane 2.97 13 | tool implement 2.95 14 | brother monk 2.82 15 | crane implement 1.68 16 | lad brother 1.66 17 | journey car 1.16 18 | monk oracle 1.1 19 | cemetery woodland 0.95 20 | food rooster 0.89 21 | coast hill 0.87 22 | forest graveyard 0.84 23 | shore woodland 0.63 24 | monk slave 0.55 25 | coast forest 0.42 26 | lad wizard 0.42 27 | chord smile 0.13 28 | glass magician 0.11 29 | rooster voyage 0.08 30 | noon string 0.08 31 | -------------------------------------------------------------------------------- /wordsim/data/RG.txt: -------------------------------------------------------------------------------- 1 | cord smile 0.02 2 | rooster voyage 0.04 3 | noon string 0.04 4 | fruit furnace 0.05 5 | autograph shore 0.06 6 | automobile wizard 0.11 7 | mound stove 0.14 8 | grin implement 0.18 9 | asylum fruit 0.19 10 | asylum monk 0.39 11 | graveyard madhouse 0.42 12 | glass magician 0.44 13 | boy rooster 0.44 14 | cushion jewel 0.45 15 | monk slave 0.57 16 | asylum cemetery 0.79 17 | coast forest 0.85 18 | grin lad 0.88 19 | shore woodland 0.9 20 | monk oracle 0.91 21 | boy sage 0.96 22 | automobile cushion 0.97 23 | mound shore 0.97 24 | lad wizard 0.99 25 | forest graveyard 1 26 | food rooster 1.09 27 | cemetery woodland 1.18 28 | shore voyage 1.24 29 | bird woodland 1.24 30 | coast hill 1.26 31 | furnace implement 1.37 32 | crane rooster 1.41 33 | hill woodland 1.48 34 | car journey 1.56 35 | cemetery mound 1.69 36 | glass jewel 1.78 37 | magician oracle 1.82 38 | crane implement 2.37 39 | brother lad 2.41 40 | sage wizard 2.46 41 | oracle sage 2.61 42 | bird crane 2.63 43 | bird cock 2.63 44 | food fruit 2.69 45 | brother monk 2.74 46 | asylum madhouse 3.04 47 | furnace stove 3.11 48 | magician wizard 3.21 49 | hill mound 3.29 50 | cord string 3.41 51 | glass tumbler 3.45 52 | grin smile 3.46 53 | serf slave 3.46 54 | journey voyage 3.58 55 | autograph signature 3.59 56 | coast shore 3.6 57 | forest woodland 3.65 58 | implement tool 3.66 59 | cock rooster 3.68 60 | boy lad 3.82 61 | cushion pillow 3.84 62 | cemetery graveyard 3.88 63 | automobile car 3.92 64 | midday noon 3.91 65 | gem jewel 3.94 66 | --------------------------------------------------------------------------------