├── .gitignore ├── LICENSE ├── README.md ├── bin └── StructED_1.0.1.jar ├── img ├── heat_map.png ├── hitmap_orig.png └── validation_error.png ├── lib ├── hamcrest-core-1.3.jar ├── jheatchart-0.6.jar ├── jsc.jar ├── junit-4.12.jar └── xchart-2.5.0.jar ├── src └── com │ └── structed │ ├── constants │ ├── Char2Idx.java │ ├── Consts.java │ └── ErrorConstants.java │ ├── dal │ ├── LazyReader.java │ ├── OcrReader.java │ ├── RankReader.java │ ├── RankWriter.java │ ├── Reader.java │ ├── StandardReader.java │ ├── StandardWriter.java │ └── Writer.java │ ├── data │ ├── CacheVowelData.java │ ├── Factory.java │ ├── InstancesContainer.java │ ├── LazyInstancesContainer.java │ ├── Logger.java │ ├── entities │ │ ├── Example.java │ │ ├── Example1D.java │ │ ├── Example2D.java │ │ ├── PredictedLabels.java │ │ └── Vector.java │ └── featurefunctions │ │ ├── FeatureFunctionsDummy.java │ │ ├── FeatureFunctionsOCR.java │ │ ├── FeatureFunctionsRank.java │ │ ├── FeatureFunctionsSparse.java │ │ ├── FeatureFunctionsVowelDuration.java │ │ └── IFeatureFunctions.java │ ├── main │ └── APITest.java │ ├── models │ ├── Classifier.java │ ├── ClassifierData.java │ ├── StructEDModel.java │ ├── algorithms │ │ ├── CRF.java │ │ ├── DirectLoss.java │ │ ├── IUpdateRule.java │ │ ├── MultiClassReject.java │ │ ├── OrbitLoss.java │ │ ├── PassiveAggressive.java │ │ ├── Perceptron.java │ │ ├── ProbitLoss.java │ │ ├── RampLoss.java │ │ ├── RankSVM.java │ │ └── SVM.java │ ├── inference │ │ ├── IInference.java │ │ ├── InferenceDummyData.java │ │ ├── InferenceMultiClass.java │ │ ├── InferenceMultiClassOld.java │ │ ├── InferenceOCR.java │ │ ├── InferenceRanking.java │ │ └── InferenceVowelDurationData.java │ ├── kernels │ │ ├── IKernel.java │ │ ├── Poly2Kernel.java │ │ ├── RBF2Kernel.java │ │ └── RBF3Kernel.java │ └── loss │ │ ├── ITaskLoss.java │ │ ├── TaskLossDummyData.java │ │ ├── TaskLossMultiClass.java │ │ ├── TaskLossOCR.java │ │ ├── TaskLossRank.java │ │ └── TaskLossVowelDuration.java │ ├── tests │ ├── dal │ │ ├── LazyReaderTest.java │ │ ├── OcrReaderTest.java │ │ └── StandardReaderTest.java │ ├── models │ │ ├── algorithms │ │ │ └── AlgorithmsTests.java │ │ └── loss │ │ │ ├── TaskLossDummyDataTest.java │ │ │ ├── TaskLossMultiClassTest.java │ │ │ └── TaskLossVowelDurationTest.java │ ├── tests_data │ │ ├── dummy │ │ │ ├── test.txt │ │ │ └── train.txt │ │ ├── ocr │ │ │ ├── test.data │ │ │ └── val.data │ │ ├── real_db │ │ │ ├── C01B1.data │ │ │ └── C01B1.labels │ │ ├── test1.txt │ │ ├── test2.txt │ │ ├── test3.txt │ │ └── test4.txt │ └── utils │ │ ├── ConverterHelplersTest.java │ │ ├── LazyInstancesContainerTest.java │ │ ├── MathHelpersTest.java │ │ └── ModelHandlerTest.java │ ├── tutorials │ ├── DummyTutorial.java │ ├── MultiClassTutorial.java │ ├── OCRTutorial.java │ ├── RejectMultiClass.java │ └── VowelDurationTutorial.java │ ├── utils │ ├── ConverterHelplers.java │ ├── MathHelpers.java │ ├── ModelHandler.java │ └── comperators │ │ ├── MapKeyComparatorAscending.java │ │ ├── MapValueComparatorAscending.java │ │ ├── MapValueComparatorDescending.java │ │ └── MapValueComparatorDescending_IntKey.java │ └── view │ └── Graph.java └── tutorials-code ├── dummy ├── DummyTutorial.java ├── FeatureFunctionsDummy.java ├── InferenceDummyData.java ├── TaskLossDummyData.java ├── compile_and_run_dummy.sh └── data │ ├── test.txt │ └── train.txt ├── multiclass ├── FeatureFunctionsSparse.java ├── InferenceMultiClass.java ├── MulticlassIRIS.java ├── MulticlassMNIST.java ├── TaskLossMultiClass.java ├── compile_and_run_iris.sh ├── compile_and_run_mnist.sh ├── data │ ├── MNIST │ │ ├── test.data.txt │ │ ├── train.txt │ │ └── val.data.txt │ └── iris │ │ ├── iris.test.txt │ │ └── iris.train.txt └── img │ └── validation_error.png ├── ocr ├── FeatureFunctionsOCR.java ├── InferenceOCR.java ├── OCRTutorial.java ├── TaskLossOCR.java ├── compile_and_run_ocr.sh └── data │ ├── README.txt │ └── all.letter.data ├── save_load ├── SaveLoad.java ├── compile_and_run_save_load.sh └── data │ ├── test.txt │ └── train.txt └── vowel ├── FeatureFunctionsVowelDuration.java ├── InferenceVowelDurationData.java ├── TaskLossVowelDuration.java ├── VowelDurationTutorial.java ├── compile_and_run_vowel.sh └── data └── vowel ├── new_data ├── tbtw-1v1-s002-Beak_NounRelated.data ├── tbtw-1v1-s002-Beak_NounRelated.labels ├── tbtw-1v1-s002-Bed_VerbUnrelated.data ├── tbtw-1v1-s002-Bed_VerbUnrelated.labels ├── tbtw-1v1-s002-Bell_VerbRelated.data ├── tbtw-1v1-s002-Bell_VerbRelated.labels ├── tbtw-1v1-s002-Boat_NounUnrelated.data ├── tbtw-1v1-s002-Boat_NounUnrelated.labels ├── tbtw-1v1-s002-Bomb_NounRelated.data ├── tbtw-1v1-s002-Bomb_NounRelated.labels ├── tbtw-1v1-s002-Boot_VerbUnrelated.data ├── tbtw-1v1-s002-Boot_VerbUnrelated.labels ├── tbtw-1v1-s002-Bowl_VerbRelated.data ├── tbtw-1v1-s002-Bowl_VerbRelated.labels ├── tbtw-1v1-s002-Coat_NounUnrelated.data ├── tbtw-1v1-s002-Coat_NounUnrelated.labels ├── tbtw-1v1-s002-Doll_NounRelated.data ├── tbtw-1v1-s002-Doll_NounRelated.labels ├── tbtw-1v1-s002-Goose_VerbUnrelated.data ├── tbtw-1v1-s002-Goose_VerbUnrelated.labels ├── tbtw-1v1-s002-Hat_VerbRelated.data ├── tbtw-1v1-s002-Hat_VerbRelated.labels ├── tbtw-1v1-s002-Head_NounUnrelated.data ├── tbtw-1v1-s002-Head_NounUnrelated.labels ├── tbtw-1v1-s002-Heel_NounRelated.data ├── tbtw-1v1-s002-Heel_NounRelated.labels ├── tbtw-1v1-s002-Lock_VerbUnrelated.data ├── tbtw-1v1-s002-Lock_VerbUnrelated.labels ├── tbtw-1v1-s002-Moon_VerbRelated.data ├── tbtw-1v1-s002-Moon_VerbRelated.labels ├── tbtw-1v1-s002-Moose_NounUnrelated.data ├── tbtw-1v1-s002-Moose_NounUnrelated.labels ├── tbtw-1v1-s002-Nose_NounRelated.data ├── tbtw-1v1-s002-Nose_NounRelated.labels ├── tbtw-1v1-s002-Peel_VerbRelated.data ├── tbtw-1v1-s002-Peel_VerbRelated.labels ├── tbtw-1v1-s002-Pen_NounUnrelated.data ├── tbtw-1v1-s002-Pen_NounUnrelated.labels ├── tbtw-1v1-s002-Rat_VerbUnrelated.data ├── tbtw-1v1-s002-Rat_VerbUnrelated.labels ├── tbtw-1v1-s002-Tack_NounUnrelated.data ├── tbtw-1v1-s002-Tack_NounUnrelated.labels ├── tbtw-1v1-s002-beak_Target.data ├── tbtw-1v1-s002-beak_Target.labels ├── tbtw-1v1-s002-bed_Target.data ├── tbtw-1v1-s002-bed_Target.labels ├── tbtw-1v1-s002-bell_Target.data ├── tbtw-1v1-s002-bell_Target.labels ├── tbtw-1v1-s002-boat_Target.data ├── tbtw-1v1-s002-boat_Target.labels ├── tbtw-1v1-s002-bomb_Target.data ├── tbtw-1v1-s002-bomb_Target.labels ├── tbtw-1v1-s002-boot_Target.data ├── tbtw-1v1-s002-boot_Target.labels ├── tbtw-1v1-s002-bowl_Target.data ├── tbtw-1v1-s002-bowl_Target.labels ├── tbtw-1v1-s002-coat_Target.data ├── tbtw-1v1-s002-coat_Target.labels ├── tbtw-1v1-s002-doll_Target.data ├── tbtw-1v1-s002-doll_Target.labels ├── tbtw-1v1-s002-goose_Target.data ├── tbtw-1v1-s002-goose_Target.labels ├── tbtw-1v1-s002-hat_Target.data ├── tbtw-1v1-s002-hat_Target.labels ├── tbtw-1v1-s002-head_Target.data ├── tbtw-1v1-s002-head_Target.labels ├── tbtw-1v1-s002-heel_Target.data ├── tbtw-1v1-s002-heel_Target.labels ├── tbtw-1v1-s002-lock_Target.data ├── tbtw-1v1-s002-lock_Target.labels ├── tbtw-1v1-s002-moon_Target.data ├── tbtw-1v1-s002-moon_Target.labels ├── tbtw-1v1-s002-moose_Target.data ├── tbtw-1v1-s002-moose_Target.labels ├── tbtw-1v1-s002-nose_Target.data ├── tbtw-1v1-s002-nose_Target.labels ├── tbtw-1v1-s002-peel_Target.data ├── tbtw-1v1-s002-peel_Target.labels ├── tbtw-1v1-s002-pen_Target.data ├── tbtw-1v1-s002-pen_Target.labels ├── tbtw-1v1-s002-rat_Target.data ├── tbtw-1v1-s002-rat_Target.labels ├── tbtw-1v1-s002-seal_Target.data ├── tbtw-1v1-s002-seal_Target.labels ├── tbtw-1v1-s002-tack_Target.data ├── tbtw-1v1-s002-tack_Target.labels ├── tbtw-1v1-s006-Beak_NounRelated.data ├── tbtw-1v1-s006-Beak_NounRelated.labels ├── tbtw-1v1-s006-Bed_VerbUnrelated.data ├── tbtw-1v1-s006-Bed_VerbUnrelated.labels ├── tbtw-1v1-s006-Bell_VerbRelated.data ├── tbtw-1v1-s006-Bell_VerbRelated.labels ├── tbtw-1v1-s006-Boat_NounUnrelated.data ├── tbtw-1v1-s006-Boat_NounUnrelated.labels ├── tbtw-1v1-s006-Bomb_NounRelated.data ├── tbtw-1v1-s006-Bomb_NounRelated.labels ├── tbtw-1v1-s006-Boot_VerbUnrelated.data ├── tbtw-1v1-s006-Boot_VerbUnrelated.labels ├── tbtw-1v1-s006-Bowl_VerbRelated.data ├── tbtw-1v1-s006-Bowl_VerbRelated.labels ├── tbtw-1v1-s006-Coat_NounUnrelated.data ├── tbtw-1v1-s006-Coat_NounUnrelated.labels ├── tbtw-1v1-s006-Doll_NounRelated.data ├── tbtw-1v1-s006-Doll_NounRelated.labels ├── tbtw-1v1-s006-Goose_VerbUnrelated.data ├── tbtw-1v1-s006-Goose_VerbUnrelated.labels ├── tbtw-1v1-s006-Hat_VerbRelated.data ├── tbtw-1v1-s006-Hat_VerbRelated.labels ├── tbtw-1v1-s006-Head_NounUnrelated.data ├── tbtw-1v1-s006-Head_NounUnrelated.labels ├── tbtw-1v1-s006-Heel_NounRelated.data ├── tbtw-1v1-s006-Heel_NounRelated.labels ├── tbtw-1v1-s006-Lock_VerbUnrelated.data ├── tbtw-1v1-s006-Lock_VerbUnrelated.labels ├── tbtw-1v1-s006-Moon_VerbRelated.data ├── tbtw-1v1-s006-Moon_VerbRelated.labels ├── tbtw-1v1-s006-Moose_NounUnrelated.data ├── tbtw-1v1-s006-Moose_NounUnrelated.labels ├── tbtw-1v1-s006-Nose_NounRelated.data ├── tbtw-1v1-s006-Nose_NounRelated.labels ├── tbtw-1v1-s006-Peel_VerbRelated.data ├── tbtw-1v1-s006-Peel_VerbRelated.labels ├── tbtw-1v1-s006-Pen_NounUnrelated.data ├── tbtw-1v1-s006-Pen_NounUnrelated.labels ├── tbtw-1v1-s006-Rat_VerbUnrelated.data ├── tbtw-1v1-s006-Rat_VerbUnrelated.labels ├── tbtw-1v1-s006-Seal_VerbRelated.data ├── tbtw-1v1-s006-Seal_VerbRelated.labels ├── tbtw-1v1-s006-Tack_NounUnrelated.data ├── tbtw-1v1-s006-Tack_NounUnrelated.labels ├── tbtw-1v1-s006-beak_Target.data ├── tbtw-1v1-s006-beak_Target.labels ├── tbtw-1v1-s006-bed_Target.data ├── tbtw-1v1-s006-bed_Target.labels ├── tbtw-1v1-s006-bell_Target.data ├── tbtw-1v1-s006-bell_Target.labels ├── tbtw-1v1-s006-boat_Target.data ├── tbtw-1v1-s006-boat_Target.labels ├── tbtw-1v1-s006-bomb_Target.data ├── tbtw-1v1-s006-bomb_Target.labels ├── tbtw-1v1-s006-boot_Target.data ├── tbtw-1v1-s006-boot_Target.labels ├── tbtw-1v1-s006-bowl_Target.data ├── tbtw-1v1-s006-bowl_Target.labels ├── tbtw-1v1-s006-coat_Target.data ├── tbtw-1v1-s006-coat_Target.labels ├── tbtw-1v1-s006-doll_Target.data ├── tbtw-1v1-s006-doll_Target.labels ├── tbtw-1v1-s006-goose_Target.data ├── tbtw-1v1-s006-goose_Target.labels ├── tbtw-1v1-s006-hat_Target.data ├── tbtw-1v1-s006-hat_Target.labels ├── tbtw-1v1-s006-head_Target.data ├── tbtw-1v1-s006-head_Target.labels ├── tbtw-1v1-s006-heel_Target.data ├── tbtw-1v1-s006-heel_Target.labels ├── tbtw-1v1-s006-lock_Target.data ├── tbtw-1v1-s006-lock_Target.labels ├── tbtw-1v1-s006-moon_Target.data ├── tbtw-1v1-s006-moon_Target.labels ├── tbtw-1v1-s006-moose_Target.data ├── tbtw-1v1-s006-moose_Target.labels ├── tbtw-1v1-s006-nose_Target.data ├── tbtw-1v1-s006-nose_Target.labels ├── tbtw-1v1-s006-peel_Target.data ├── tbtw-1v1-s006-peel_Target.labels ├── tbtw-1v1-s006-pen_Target.data ├── tbtw-1v1-s006-pen_Target.labels ├── tbtw-1v1-s006-rat_Target.data ├── tbtw-1v1-s006-rat_Target.labels ├── tbtw-1v1-s006-seal_Target.data ├── tbtw-1v1-s006-seal_Target.labels ├── tbtw-1v1-s006-tack_Target.data ├── tbtw-1v1-s006-tack_Target.labels ├── tbtw-1v1-s019-Beak_NounRelated.data ├── tbtw-1v1-s019-Beak_NounRelated.labels ├── tbtw-1v1-s019-Bed_VerbUnrelated.data ├── tbtw-1v1-s019-Bed_VerbUnrelated.labels ├── tbtw-1v1-s019-Bell_VerbRelated.data ├── tbtw-1v1-s019-Bell_VerbRelated.labels ├── tbtw-1v1-s019-Boat_NounUnrelated.data ├── tbtw-1v1-s019-Boat_NounUnrelated.labels ├── tbtw-1v1-s019-Bomb_NounRelated.data ├── tbtw-1v1-s019-Bomb_NounRelated.labels ├── tbtw-1v1-s019-Boot_VerbUnrelated.data ├── tbtw-1v1-s019-Boot_VerbUnrelated.labels ├── tbtw-1v1-s019-Bowl_VerbRelated.data ├── tbtw-1v1-s019-Bowl_VerbRelated.labels ├── tbtw-1v1-s019-Coat_NounUnrelated.data ├── tbtw-1v1-s019-Coat_NounUnrelated.labels ├── tbtw-1v1-s019-Doll_NounRelated.data ├── tbtw-1v1-s019-Doll_NounRelated.labels ├── tbtw-1v1-s019-Goose_VerbUnrelated.data ├── tbtw-1v1-s019-Goose_VerbUnrelated.labels ├── tbtw-1v1-s019-Hat_VerbRelated.data ├── tbtw-1v1-s019-Hat_VerbRelated.labels ├── tbtw-1v1-s019-Head_NounUnrelated.data ├── tbtw-1v1-s019-Head_NounUnrelated.labels ├── tbtw-1v1-s019-beak_Target.data ├── tbtw-1v1-s019-beak_Target.labels ├── tbtw-1v1-s019-bed_Target.data ├── tbtw-1v1-s019-bed_Target.labels ├── tbtw-1v1-s019-bell_Target.data ├── tbtw-1v1-s019-bell_Target.labels ├── tbtw-1v1-s019-boat_Target.data ├── tbtw-1v1-s019-boat_Target.labels ├── tbtw-1v1-s019-bomb_Target.data ├── tbtw-1v1-s019-bomb_Target.labels ├── tbtw-1v1-s019-boot_Target.data ├── tbtw-1v1-s019-boot_Target.labels ├── tbtw-1v1-s019-bowl_Target.data ├── tbtw-1v1-s019-bowl_Target.labels ├── tbtw-1v1-s019-coat_Target.data ├── tbtw-1v1-s019-coat_Target.labels ├── tbtw-1v1-s019-doll_Target.data ├── tbtw-1v1-s019-doll_Target.labels ├── tbtw-1v1-s019-goose_Target.data ├── tbtw-1v1-s019-goose_Target.labels ├── tbtw-1v1-s019-hat_Target.data └── tbtw-1v1-s019-hat_Target.labels ├── test.vowel.txt └── train.vowel.txt /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | META-INF/ 3 | StructED_Package-github.iml 4 | .idea/ 5 | .DS_Store 6 | api/ 7 | tutorials-code/vowel/data/vowel/jordana/ 8 | *.model 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | StructED - Machine Learning Package for Structured Prediction 4 | 5 | Copyright (c) 2015, Yossi Adi, yossiadidrum@gmail.com 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | README 2 | ====== 3 | 4 | StructED 1.0.1 5 | 6 | Structured tasks are distinctive: each task has its own measure of performance, such as the word error rate in speech recognition, the BLEU score in machine translation, the NDCG score in information retrieval, or the intersection-over-union score in visual object segmentation. StructED is a software package for learning structured prediction models with training methods that are aimed at optimizing the task measure of performance. The package was written in Java and was released under the MIT license. 7 | 8 | Keywords: structured prediction, structured SVM, CRF, direct loss minimization, structured ramp loss, structured probit Loss, structured passive aggressive 9 | 10 | Usage: 11 | In order to use StructED in your own project all you need to do is open new project and add StructED jar to your project’s build path. Documentations and more extensive usage examples can be found at: http://adiyoss.github.io/StructED/. 12 | 13 | If you find our work useful please cite: 14 | [StructED: risk minimization in structured prediction] (http://www.jmlr.org/papers/volume17/15-531/15-531.pdf) 15 | ``` 16 | @article{adi2016structed, 17 | title={StructED: risk minimization in structured prediction}, 18 | author={Adi, Yossi and Keshet, Joseph}, 19 | journal={Journal of Machine Learning Research}, 20 | volume={17}, 21 | number={64}, 22 | pages={1--5}, 23 | year={2016} 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /bin/StructED_1.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/bin/StructED_1.0.1.jar -------------------------------------------------------------------------------- /img/heat_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/img/heat_map.png -------------------------------------------------------------------------------- /img/hitmap_orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/img/hitmap_orig.png -------------------------------------------------------------------------------- /img/validation_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/img/validation_error.png -------------------------------------------------------------------------------- /lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /lib/jheatchart-0.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/lib/jheatchart-0.6.jar -------------------------------------------------------------------------------- /lib/jsc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/lib/jsc.jar -------------------------------------------------------------------------------- /lib/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/lib/junit-4.12.jar -------------------------------------------------------------------------------- /lib/xchart-2.5.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/lib/xchart-2.5.0.jar -------------------------------------------------------------------------------- /src/com/structed/constants/Char2Idx.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.constants; 28 | 29 | import java.util.HashMap; 30 | 31 | /** 32 | * Created by yossiadi on 20/12/2015. 33 | * This class converts between english character to its index and vice verse 34 | */ 35 | public class Char2Idx { 36 | final static public HashMap char2id = new HashMap(){ 37 | {put('$', 0);}{put('a', 1);}{put('b', 2);}{put('c', 3);}{put('d', 4);}{put('e', 5);} 38 | {put('f', 6);}{put('g', 7);}{put('h', 8);}{put('i', 9);}{put('j', 10);}{put('k', 11);} 39 | {put('l', 12);}{put('m', 13);}{put('n', 14);}{put('o', 15);}{put('p', 16);}{put('q', 17);} 40 | {put('r', 18);}{put('s', 19);}{put('t', 20);}{put('u', 21);}{put('v', 22);}{put('w', 23);}{put('x', 24);} 41 | {put('y', 25);}{put('z', 26);} 42 | }; 43 | final static public HashMap id2char = new HashMap(){ 44 | {put(0, '$');}{put(1, 'a');}{put(2, 'b');}{put(3, 'c');}{put(4, 'd');}{put(5, 'e');} 45 | {put(6, 'f');}{put(7, 'g');}{put(8, 'h');}{put(9, 'i');}{put(10, 'j');}{put(11, 'k');} 46 | {put(12, 'l');}{put(13, 'm');}{put(14, 'n');}{put(15, 'o');}{put(16, 'p');}{put(17, 'q');} 47 | {put(18, 'r');}{put(19, 's');}{put(20, 't');}{put(21, 'u');}{put(22, 'v');}{put(23, 'w');}{put(24, 'x');} 48 | {put(25, 'y');}{put(26, 'z');} 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /src/com/structed/constants/Consts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.constants; 28 | 29 | /** 30 | * this class holds all the program constants 31 | */ 32 | public class Consts { 33 | 34 | // GENERALS 35 | public static final String SPACE = " "; 36 | public static final String TAB = "\t"; 37 | public static final String COMMA_NOTE = ","; 38 | public static final String CLASSIFICATION_SPLITTER = "-"; 39 | public static final String COLON_SPLITTER = ":"; 40 | public static final String PARAMS_SPLITTER = ";"; 41 | public static final String NEW_LINE = "line.separator"; 42 | public static final int ERROR_NUMBER = -1; 43 | 44 | // DUMMY 45 | public static final int MIN_GAP_START_DUMMY = 3; 46 | public static final int MIN_GAP_END_DUMMY = 3; 47 | 48 | // VOWEL DURATION 49 | public static final int MIN_VOWEL = 9; //min training set: 45 frames 50 | public static final int MAX_VOWEL = 92; //max training set: 459 frames 51 | public static final int MIN_GAP_START = 10; 52 | public static final int MIN_GAP_END = 10; 53 | 54 | public static final double MEAN_VOWEL_LENGTH = 41.787; //pre calculated from the training set 55 | public static final double STD_VOWEL_LENGTH = 12.918; //pre calculated from the training set 56 | public static final double MAX_VOWEL_LENGTH = 38; //pre calculated from the training set 57 | 58 | // MODELS NUMBER OF PARAMETERS 59 | public static final int PA_PARAMS_SIZE = 1; //The number params 4 PA 60 | public static final int SVM_PARAMS_SIZE = 2; //The number params 4 SVM 61 | public static final int DL_PARAMS_SIZE = 2; //The number params 4 Direct Loss 62 | public static final int CRF_PARAMS_SIZE = 2; //The number params 4 CRF 63 | public static final int RL_PARAMS_SIZE = 2; //The number params 4 Ramp Loss 64 | public static final int PL_PARAMS_SIZE = 6; //The number params 4 Probit Loss 65 | public static final int SP_PARAMS_SIZE = 0; //The number params 0 Perceptron 66 | public static final int ORBIT_PARAMS_SIZE = 2; //The number params 4 orbit 67 | public static final int MULTICLASS_REGECT_SIZE = 4; //The number params 4 multiclass regect 68 | 69 | // KERNEL DEFAULT PARAMETERS 70 | public static double SIGMA = 1; 71 | 72 | //OCR 73 | public static final String END_NOTE = "$"; 74 | } -------------------------------------------------------------------------------- /src/com/structed/constants/ErrorConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.constants; 28 | 29 | /** 30 | * this class stores all the types of errors 31 | */ 32 | public class ErrorConstants { 33 | 34 | public static final String GENERAL_ERROR = "Error: "; 35 | public static final String RAW_DATA_EMPTY_ERROR = "Raw data is empty"; 36 | public static final String VECTOR_CONVERT_ERROR = "Error converting vector: "; 37 | public static final String PARSE_CLASSIFICATION_ERROR = "Error with the classification of example: "; 38 | public static final String PHI_VECTOR_DATA = "Phi vector data empty"; 39 | 40 | public static final String MULTIPLE_VECTORS_SIZE_ERROR = "The vectors doesn't have the same size"; 41 | public static final String MULTIPLE_VECTORS_EMPTY_ERROR = "The vectors are empty"; 42 | 43 | public static final String UPDATE_ARGUMENTS_ERROR = "Size of arguments is not valid"; 44 | public static final String UPDATE_DIVIDE_ZERO_ERROR = "Phi difference multiple return 0"; 45 | 46 | public static final String PHI_DATA_ERROR = "Phi data is null"; 47 | public static final String EPOCH_ERROR = "Epoch is a negative number"; 48 | 49 | public static final String SIZE_OF_TRAIN_ERROR = "Train size is 0"; 50 | public static final String GAP_START_SIZE_ERROR = "Gap start can not be 0"; 51 | public static final String GAP_END_SIZE_ERROR = "Gap end can not be 0"; 52 | public static final String ZERO_DIVIDING = "Can not divide by zero"; 53 | 54 | public static final String CONFIG_ERROR = "Can not convert config file"; 55 | public static final String CONFIG_ARGUMENTS_ERROR = "Invalid number of arguments"; 56 | public static final String CONFIG_ARGUMENTS_TYPE_ERROR = "Invalid type of arguments"; 57 | 58 | public static final String WRONG_TEST_VALUES = "Invalid test values"; 59 | public static final String WRONG_TRAIN_VALUES = "Invalid train values"; 60 | 61 | public static final String WEIGHTS_VALUES = "Error converting weights file."; 62 | public static final String SORT_ERROR = "Error, sorting the scores map."; 63 | } 64 | -------------------------------------------------------------------------------- /src/com/structed/dal/LazyReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.dal; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.data.entities.Example; 31 | import com.structed.data.Factory; 32 | import com.structed.data.InstancesContainer; 33 | import com.structed.data.entities.Vector; 34 | import com.structed.data.Logger; 35 | import com.structed.utils.ConverterHelplers; 36 | 37 | import java.util.ArrayList; 38 | 39 | /** 40 | * This class reads the examples on demand 41 | * It gets as input a file with the paths to all the data and reads each example by the algorithm's demand 42 | */ 43 | public class LazyReader extends StandardReader { 44 | 45 | /** 46 | * a Lazy reader, it reads only the paths to the data and not the data itself 47 | * this reader will read the actual data on demand 48 | * @param path the path to the data 49 | * @param dataSpliter the splitter between the data values 50 | * @param valueSpliter the separator between the index of the feature to the feature value 51 | * @return an InstanceContainer object which contains all the data 52 | */ 53 | @Override 54 | public InstancesContainer readData(String path, String dataSpliter, String valueSpliter) 55 | { 56 | ArrayList> data = readFile(path, dataSpliter); 57 | InstancesContainer instances = Factory.getInstanceContainer(1); 58 | instances.setPaths(data); 59 | return instances; 60 | } 61 | 62 | /** 63 | * read only one example and it's labels 64 | * @param paths the paths to the data and to the label files 65 | * @return an Example object contains the data 66 | * @throws Exception 67 | */ 68 | public Example readExample(ArrayList paths) throws Exception{ 69 | 70 | ArrayList> features = readFile(paths.get(0), Consts.SPACE); 71 | ArrayList> labels = readFile(paths.get(1), Consts.SPACE); 72 | 73 | Example example = Factory.getExample(1); 74 | 75 | //extract the labels 76 | String label = labels.get(1).get(0)+Consts.CLASSIFICATION_SPLITTER+labels.get(1).get(1); 77 | example.setLabel(label); 78 | 79 | //extract the features 80 | for (int i=0 ; i> readFile(String path, String spliter); 41 | InstancesContainer readData(String path, String dataSpliter, String valueSpliter); 42 | } 43 | -------------------------------------------------------------------------------- /src/com/structed/dal/Writer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.dal; 28 | 29 | import java.util.ArrayList; 30 | import java.util.Map; 31 | 32 | /** 33 | * An interface for writing the data/models 34 | */ 35 | public interface Writer { 36 | void writeData2File(String path, ArrayList data, boolean isNewLine); 37 | void writeHashMap2File(String path, Map data); 38 | void writeScoresFile(String exampleName ,String path, Map data, int maxElements2Display); 39 | void clearPrevResult(String path); 40 | } 41 | -------------------------------------------------------------------------------- /src/com/structed/data/CacheVowelData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data; 28 | 29 | import com.structed.data.entities.Example; 30 | 31 | import java.util.ArrayList; 32 | import java.util.HashMap; 33 | 34 | /** 35 | * preforms caching for computing the feature functions 36 | * Can be used only at the vowel duration task at the moment 37 | */ 38 | public class CacheVowelData { 39 | 40 | private static HashMap>> cache = new HashMap>>(); 41 | 42 | /** 43 | * get the cumulative value for a given feature from a given example 44 | * @param example the example to calculate the features for 45 | * @param frameIndex get the cumulative value until this index 46 | * @param featureNumber the feature number to get the cumulative data for 47 | * @return the cumulative value 48 | */ 49 | public static double getCumulativeValue(Example example, int frameIndex, int featureNumber) 50 | { 51 | double res = 0; 52 | if(frameIndex <= 0) 53 | res = cache.get(example.hashCode()).get(0).get(featureNumber); 54 | else if(frameIndex >= cache.get(example.hashCode()).size()) 55 | res = cache.get(example.hashCode()).get(cache.get(example.hashCode()).size()-1).get(featureNumber); 56 | else if(cache.containsKey(example.hashCode())) 57 | res = cache.get(example.hashCode()).get(frameIndex).get(featureNumber); 58 | 59 | return res; 60 | } 61 | 62 | /** 63 | * update the cache for the given example 64 | * @param example a given example to cache 65 | */ 66 | public static void updateCache(Example example) 67 | { 68 | if(!cache.containsKey(example.hashCode())) 69 | { 70 | ArrayList> cumulativeValues = new ArrayList>(); 71 | ArrayList tmp = new ArrayList(); 72 | 73 | int size = example.getFeatures2D().get(0).size(); 74 | for(int i=0 ; i vector = new ArrayList(); 82 | for(int j=0 ; j instances; 40 | ArrayList> paths; 41 | int size; 42 | 43 | //C'tor 44 | public InstancesContainer() { 45 | instances = new ArrayList(); 46 | paths = new ArrayList>(); 47 | size = 0; 48 | } 49 | 50 | //get the requested example 51 | public Example getInstance(int index) 52 | { 53 | try{ 54 | return instances.get(index); 55 | } catch (Exception e){ 56 | e.printStackTrace(); 57 | return null; 58 | } 59 | } 60 | 61 | //======Setters and getters=====// 62 | public ArrayList getInstances() { 63 | return instances; 64 | } 65 | 66 | public void setInstances(ArrayList instances) { 67 | this.instances = instances; 68 | this.size = instances.size(); 69 | } 70 | 71 | public ArrayList> getPaths() { 72 | return paths; 73 | } 74 | 75 | public void setPaths(ArrayList> paths) { 76 | this.paths = paths; 77 | this.size = paths.size(); 78 | } 79 | 80 | 81 | public int getSize() { 82 | if(this.size != 0) 83 | return this.size; 84 | this.size = (instances.size() != 0) ? instances.size() : paths.size(); 85 | return this.size; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/com/structed/data/LazyInstancesContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data; 28 | 29 | import com.structed.data.entities.Example; 30 | import com.structed.dal.LazyReader; 31 | 32 | import java.io.File; 33 | 34 | /** 35 | * Lazy instance container that loads the examples by demand 36 | * The standard container loads all the data, this container gets as input all the paths to the raw data and loads it when needed 37 | * 38 | */ 39 | public class LazyInstancesContainer extends InstancesContainer{ 40 | 41 | LazyReader reader = new LazyReader(); 42 | 43 | //C'tor 44 | public LazyInstancesContainer(){ 45 | super(); 46 | } 47 | 48 | @Override 49 | //get the requested example 50 | public Example getInstance(int index) { 51 | try { 52 | File file = new File(paths.get(index).get(0)); 53 | if(file.exists()) { 54 | Example example = reader.readExample(paths.get(index)); 55 | CacheVowelData.updateCache(example); 56 | example.path = paths.get(index).get(0); 57 | return example; 58 | } 59 | return null; 60 | } catch (Exception e){ 61 | e.printStackTrace(); 62 | return null; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/com/structed/data/entities/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data.entities; 28 | 29 | import java.util.ArrayList; 30 | 31 | /** 32 | * this class will store the raw data and the desired label 33 | */ 34 | public abstract class Example { 35 | 36 | public String path; 37 | private String label; 38 | private int fold; 39 | public int sizeOfVector; 40 | 41 | //C'tor 42 | public Example() { 43 | label = ""; 44 | sizeOfVector = 0; 45 | } 46 | 47 | //===========GETTERS AND SETTERS=========// 48 | public Vector getFeatures(){return null;} 49 | public void setFeatures(Vector features){} 50 | 51 | public ArrayList getFeatures2D(){return null;} 52 | public void setFeatures2D(ArrayList features){} 53 | public ArrayList getLabels2D(){return null;} 54 | public void setLabels2D(ArrayList rankLabels){} 55 | 56 | public String getLabel() { 57 | return label; 58 | } 59 | public void setLabel(String label) { 60 | this.label = label; 61 | } 62 | 63 | public int getFold() { return fold; } 64 | public void setFold(int fold) { this.fold = fold; } 65 | } 66 | -------------------------------------------------------------------------------- /src/com/structed/data/entities/Example1D.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data.entities; 28 | 29 | /** 30 | * this class will store the raw data and the desired label 31 | * the raw data here will be presented as 1D array 32 | */ 33 | public class Example1D extends Example { 34 | 35 | private Vector features; 36 | 37 | public Example1D(){ 38 | features = new Vector(); 39 | } 40 | 41 | //Current functions 42 | public Vector getFeatures() { 43 | return features; 44 | } 45 | public void setFeatures(Vector features) { 46 | this.features = features; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/structed/data/entities/Example2D.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data.entities; 28 | 29 | import java.util.ArrayList; 30 | 31 | /** 32 | * this class will store the raw data and the desired label 33 | * the raw data here will be presented as 2D array 34 | */ 35 | public class Example2D extends Example { 36 | 37 | private ArrayList features2D; 38 | private ArrayList labels2D; 39 | 40 | 41 | public Example2D(){ 42 | features2D = new ArrayList(); 43 | labels2D = new ArrayList(); 44 | 45 | } 46 | 47 | public ArrayList getFeatures2D() { 48 | return features2D; 49 | } 50 | 51 | public void setFeatures2D(ArrayList features) { 52 | this.features2D = features; 53 | } 54 | 55 | public ArrayList getLabels2D() { return labels2D; } 56 | 57 | public void setLabels2D(ArrayList labels2D) { this.labels2D = labels2D; } 58 | } 59 | -------------------------------------------------------------------------------- /src/com/structed/data/entities/PredictedLabels.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data.entities; 28 | 29 | import com.structed.utils.comperators.MapKeyComparatorAscending; 30 | import com.structed.utils.comperators.MapValueComparatorAscending; 31 | import com.structed.utils.comperators.MapValueComparatorDescending; 32 | 33 | import java.util.TreeMap; 34 | 35 | /** 36 | * this class is used for name alias 37 | * this PredictedLabels class represents a TreeMap between the label to its score 38 | */ 39 | public class PredictedLabels extends TreeMap{ 40 | 41 | //default c'tor 42 | public PredictedLabels(){ 43 | } 44 | 45 | public PredictedLabels(MapValueComparatorAscending vc){ 46 | super(vc); 47 | } 48 | 49 | public PredictedLabels(MapValueComparatorDescending vc){ 50 | super(vc); 51 | } 52 | 53 | public PredictedLabels(MapKeyComparatorAscending vc){ 54 | super(vc); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/structed/data/entities/Vector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data.entities; 28 | 29 | import java.io.Serializable; 30 | import java.util.HashMap; 31 | 32 | /** 33 | * this class is used for name alias 34 | * this Vector class represents a HashMap between the feature index to its value 35 | */ 36 | public class Vector extends HashMap implements Serializable{ 37 | 38 | private static final long serialVersionUID = 1L; 39 | private int maxIndex; 40 | public Vector(){this.maxIndex = -1;} 41 | public Vector(Vector v){ 42 | super(v); 43 | } 44 | 45 | @Override 46 | public Double put(Integer key, Double value){ 47 | super.put(key, value); 48 | if(maxIndex < key) maxIndex = key; 49 | return value; 50 | } 51 | 52 | // getter 53 | public int getMaxIndex() { 54 | return maxIndex; 55 | } 56 | public void resetMaxIndex(){ 57 | this.maxIndex = -1; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/com/structed/data/featurefunctions/FeatureFunctionsRank.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data.featurefunctions; 28 | 29 | import com.structed.models.kernels.IKernel; 30 | import com.structed.data.entities.Example; 31 | import com.structed.data.Factory; 32 | import com.structed.data.entities.Vector; 33 | 34 | public class FeatureFunctionsRank implements IFeatureFunctions { 35 | 36 | public Example convert(Example vector, String label, IKernel kernel) 37 | { 38 | try{ 39 | //initialize result object 40 | Example phiData = Factory.getExample(0); 41 | 42 | int intLabel = Integer.parseInt(label); 43 | phiData.setLabel(label); 44 | Vector features; 45 | features = vector.getFeatures2D().get(intLabel); 46 | 47 | if(kernel != null) 48 | features = kernel.convertVector(vector.getFeatures2D().get(intLabel), vector.getFeatures2D().get(intLabel).size()); 49 | 50 | phiData.setFeatures(features); 51 | return phiData; 52 | 53 | } catch(Exception e){ 54 | e.printStackTrace(); 55 | return null; 56 | } 57 | } 58 | 59 | @Override 60 | public int getSizeOfVector() { 61 | return 0; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/com/structed/data/featurefunctions/FeatureFunctionsSparse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data.featurefunctions; 28 | 29 | import com.structed.models.kernels.IKernel; 30 | import com.structed.data.entities.Example; 31 | import com.structed.data.Factory; 32 | import com.structed.data.entities.Vector; 33 | 34 | public class FeatureFunctionsSparse implements IFeatureFunctions { 35 | 36 | // data members 37 | private int maxFeatures; 38 | private int numOfClasses; 39 | private int sizeOfVector; 40 | 41 | /** 42 | * Constructor 43 | * @param numOfClasses - the number target of classes 44 | * @param maxNumFeatures - the number of features 45 | */ 46 | public FeatureFunctionsSparse(int numOfClasses, int maxNumFeatures){ 47 | this.numOfClasses = numOfClasses; 48 | this.maxFeatures = maxNumFeatures; 49 | this.sizeOfVector = this.maxFeatures*this.numOfClasses; 50 | } 51 | 52 | @Override 53 | public Example convert(Example vector, String label, IKernel kernel) { 54 | try{ 55 | //parse the label 56 | int intLabel = Integer.parseInt(label); 57 | Example newVector = Factory.getExample(0); 58 | newVector.sizeOfVector = sizeOfVector; 59 | Vector tmpVector = new Vector(); 60 | 61 | //run the phi function 62 | for(Integer feature : vector.getFeatures().keySet()) 63 | tmpVector.put(feature+intLabel*maxFeatures,vector.getFeatures().get(feature)); 64 | 65 | if(kernel !=null) 66 | tmpVector = kernel.convertVector(tmpVector, vector.sizeOfVector); 67 | 68 | newVector.setFeatures(tmpVector); 69 | 70 | return newVector; 71 | 72 | } catch (Exception e){ 73 | e.printStackTrace(); 74 | return null; 75 | } 76 | } 77 | 78 | @Override 79 | public int getSizeOfVector() { 80 | return this.sizeOfVector; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/com/structed/data/featurefunctions/IFeatureFunctions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data.featurefunctions; 28 | 29 | import com.structed.models.kernels.IKernel; 30 | import com.structed.data.entities.Example; 31 | 32 | /** 33 | * IFeatureFunctions interface - inorder to add new feature functions in you own task you should implement this interface 34 | */ 35 | public interface IFeatureFunctions { 36 | Example convert(Example vector, String label, IKernel kernel); 37 | int getSizeOfVector(); 38 | } 39 | -------------------------------------------------------------------------------- /src/com/structed/models/ClassifierData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models; 28 | 29 | import com.structed.models.algorithms.IUpdateRule; 30 | import com.structed.models.kernels.IKernel; 31 | import com.structed.models.inference.IInference; 32 | import com.structed.models.loss.ITaskLoss; 33 | import com.structed.data.featurefunctions.IFeatureFunctions; 34 | 35 | import java.util.List; 36 | 37 | /** 38 | * data structure class 39 | * this class contains all the relevant data to the classifier 40 | */ 41 | public class ClassifierData { 42 | 43 | public ITaskLoss taskLoss; 44 | public IUpdateRule updateRule; 45 | public IInference inference; 46 | public IKernel kernel; 47 | public IFeatureFunctions phi; 48 | public List arguments; 49 | public int iteration = 0; 50 | public String verbose = ""; 51 | } 52 | -------------------------------------------------------------------------------- /src/com/structed/models/algorithms/IUpdateRule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.algorithms; 28 | 29 | import com.structed.models.ClassifierData; 30 | import com.structed.data.entities.Example; 31 | import com.structed.data.entities.Vector; 32 | 33 | import java.util.ArrayList; 34 | 35 | /** 36 | * IUpdateRule interface - inorder to add new update rule in you own task you should implement this interface 37 | * this interface enable us to set many update versions and compare between them 38 | */ 39 | public interface IUpdateRule { 40 | //the arguments would be different from update to update 41 | Vector update(Vector currentWeights, Example example, ClassifierData classifierData); 42 | void init(ArrayList args); 43 | } 44 | -------------------------------------------------------------------------------- /src/com/structed/models/algorithms/MultiClassReject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.algorithms; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.constants.ErrorConstants; 31 | import com.structed.data.Logger; 32 | import com.structed.data.entities.Example; 33 | import com.structed.data.entities.Vector; 34 | import com.structed.models.ClassifierData; 35 | import com.structed.utils.MathHelpers; 36 | 37 | import java.util.ArrayList; 38 | import java.util.Map; 39 | 40 | /** 41 | * Created by yossiadi on 10/12/15. 42 | * 43 | */ 44 | 45 | public class MultiClassReject implements IUpdateRule { 46 | 47 | //data members 48 | double eta; 49 | double lambda; 50 | double beta; 51 | double p; 52 | double threshold_1; // ln(p*beta/(1-p)) 53 | double threshold_2; // ln(beta) 54 | final double logConst = 0.5* threshold_2 - Math.log(0.5); 55 | final double ZERO = 0.000000000000000001; 56 | 57 | @Override 58 | public void init(ArrayList args) { 59 | if(args.size() != Consts.MULTICLASS_REGECT_SIZE){ 60 | Logger.error(ErrorConstants.UPDATE_ARGUMENTS_ERROR); 61 | return; 62 | } 63 | //initialize the parameters 64 | this.eta = args.get(0); 65 | this.lambda = args.get(1); 66 | this.beta = args.get(2); 67 | this.p = args.get(3); 68 | 69 | this.threshold_1 = Math.log(beta * p / (1 - p)); 70 | this.threshold_1 = Math.log(beta); 71 | } 72 | 73 | @Override 74 | public Vector update(Vector currentWeights, Example example, ClassifierData classifierData) { 75 | double newEta = eta/Math.sqrt(classifierData.iteration); 76 | Example phiRealLabel = classifierData.phi.convert(example, example.getLabel(), classifierData.kernel); 77 | double f = MathHelpers.multipleVectors(currentWeights, phiRealLabel.getFeatures()); 78 | Vector newW = MathHelpers.mulScalarWithVectors(currentWeights, (1 - newEta * lambda)); 79 | 80 | if(f < threshold_1) 81 | newW = MathHelpers.add2Vectors(newW, MathHelpers.mulScalarWithVectors(phiRealLabel.getFeatures(), eta*(1-p))); 82 | else if(f >= threshold_1 && f < threshold_2) 83 | newW = MathHelpers.add2Vectors(newW, MathHelpers.mulScalarWithVectors(phiRealLabel.getFeatures(), eta * beta / (beta + Math.exp(f)))); 84 | else { 85 | double l = -0.5 * f + this.logConst; 86 | if (l > 0) 87 | newW = MathHelpers.add2Vectors(newW, MathHelpers.mulScalarWithVectors(phiRealLabel.getFeatures(), eta / 2 )); 88 | } 89 | 90 | // normalize w using z-score 91 | //mean 92 | double mean = 0, std = 0; 93 | for (Double val: newW.values()) 94 | mean += val; 95 | mean /= newW.size(); 96 | //std 97 | for(Double val :newW.values()) 98 | std += (mean-val)*(mean-val); 99 | std /= Math.sqrt(newW.size()); 100 | if (std < ZERO) 101 | std = 1.0; 102 | 103 | for (Map.Entry entry : newW.entrySet()) 104 | newW.put(entry.getKey(), (entry.getValue() - mean) / std); 105 | 106 | return newW; 107 | } 108 | 109 | public double getThreshold(){ return this.threshold_1; } 110 | } 111 | -------------------------------------------------------------------------------- /src/com/structed/models/algorithms/OrbitLoss.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.algorithms; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.models.ClassifierData; 31 | import com.structed.constants.ErrorConstants; 32 | import com.structed.data.entities.Example; 33 | import com.structed.data.entities.Vector; 34 | import com.structed.data.Logger; 35 | import com.structed.utils.MathHelpers; 36 | 37 | import java.util.ArrayList; 38 | 39 | /** 40 | * Created by yossiadi on 5/4/15. 41 | * Orbit Loss algorithm 42 | */ 43 | public class OrbitLoss implements IUpdateRule { 44 | 45 | //data members 46 | double lambda; 47 | double eta; 48 | 49 | @Override 50 | public void init(ArrayList args) { 51 | if(args.size() != Consts.ORBIT_PARAMS_SIZE){ 52 | Logger.error(ErrorConstants.UPDATE_ARGUMENTS_ERROR); 53 | return; 54 | } 55 | //initialize the parameters 56 | this.eta = args.get(0); 57 | this.lambda = args.get(1); 58 | } 59 | 60 | /** 61 | * Implementation of the update rule 62 | * @param currentWeights - the current weights 63 | * @param example - a single example 64 | * @param classifierData - all the additional data that needed such as: loss function, inference, etc. 65 | * @return the new set of weights 66 | */ 67 | @Override 68 | //in SVM the lambda value would be in the first cell of the arguments attribute 69 | //the second cell of the arguments attribute would be the eta 70 | public Vector update(Vector currentWeights, Example example, ClassifierData classifierData) { 71 | 72 | try{ 73 | //get the prediction 74 | String prediction; 75 | 76 | //if there's a problem with the predict return the previous weights 77 | try{ 78 | prediction = classifierData.inference.predictForTest(example,currentWeights,example.getLabel(),classifierData,1).firstKey(); 79 | } catch (Exception e){ 80 | return currentWeights; 81 | } 82 | 83 | // feature functions 84 | Example phiRealLabel = classifierData.phi.convert(example,example.getLabel(), classifierData.kernel); 85 | Example phiPrediction = classifierData.phi.convert(example, prediction, classifierData.kernel); 86 | 87 | //compute the phi difference 88 | Vector phiDifference = MathHelpers.subtract2Vectors(phiRealLabel.getFeatures(), phiPrediction.getFeatures()); 89 | 90 | // get the loss value and update the learning rate 91 | double loss = classifierData.taskLoss.computeTaskLoss(prediction, example.getLabel(), classifierData.arguments); 92 | double newEta = eta; 93 | double coefficientFirstArgument = (1-(lambda*newEta)); 94 | 95 | // update the weights 96 | Vector firstArgument = MathHelpers.mulScalarWithVectors(currentWeights, coefficientFirstArgument); 97 | Vector secondArgument = MathHelpers.mulScalarWithVectors(phiDifference, newEta*loss); 98 | 99 | return MathHelpers.add2Vectors(firstArgument, secondArgument); 100 | 101 | } catch (Exception e) { 102 | e.printStackTrace(); 103 | return null; 104 | } 105 | } 106 | } -------------------------------------------------------------------------------- /src/com/structed/models/algorithms/PassiveAggressive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.algorithms; 28 | 29 | import java.util.ArrayList; 30 | 31 | import com.structed.constants.Consts; 32 | import com.structed.models.ClassifierData; 33 | import com.structed.constants.ErrorConstants; 34 | import com.structed.data.entities.Example; 35 | import com.structed.data.entities.Vector; 36 | import com.structed.data.Logger; 37 | import com.structed.utils.MathHelpers; 38 | 39 | /** 40 | * Passive Aggressive algorithm 41 | * http://machinelearning.wustl.edu/mlpapers/paper_files/NIPS2003_LT21.pdf 42 | */ 43 | public class PassiveAggressive implements IUpdateRule { 44 | 45 | //data members 46 | double cValue; 47 | 48 | @Override 49 | public void init(ArrayList args){ 50 | if(args.size() != Consts.PA_PARAMS_SIZE){ 51 | Logger.error(ErrorConstants.UPDATE_ARGUMENTS_ERROR); 52 | return; 53 | } 54 | //initialize the parameters 55 | this.cValue = args.get(0); 56 | } 57 | 58 | /** 59 | * Implementation of the update rule 60 | * @param currentWeights - the current weights 61 | * @param example - a single example 62 | * @param classifierData - all the additional data that needed such as: loss function, inference, etc. 63 | * @return the new set of weights 64 | */ 65 | @Override 66 | //the first cell of the arguments attribute would be the C value 67 | public Vector update(Vector currentWeights, Example example, ClassifierData classifierData) { 68 | 69 | try{ 70 | //get the prediction 71 | String prediction = classifierData.inference.predictForTrain(example, currentWeights, example.getLabel(), classifierData,1).firstKey(); 72 | 73 | Example phiRealLabel = classifierData.phi.convert(example, example.getLabel(), classifierData.kernel); 74 | Example phiPrediction = classifierData.phi.convert(example, prediction, classifierData.kernel); 75 | 76 | //compute the phi difference 77 | Vector phiDifference = MathHelpers.subtract2Vectors(phiRealLabel.getFeatures(), phiPrediction.getFeatures()); 78 | 79 | double taskLossValue = classifierData.taskLoss.computeTaskLoss(prediction, example.getLabel(), classifierData.arguments); 80 | double multipleVectors = MathHelpers.multipleVectors(currentWeights , phiDifference); 81 | double denominator = MathHelpers.multipleVectors(phiDifference, phiDifference); 82 | 83 | double tau = 0; 84 | if(denominator != 0){ 85 | tau = (taskLossValue - multipleVectors)/denominator; 86 | } 87 | 88 | if(tau > cValue) 89 | tau = cValue; 90 | 91 | classifierData.verbose = String.format(", Tau = %.3f", tau); 92 | 93 | if(tau < 0) { 94 | Logger.error("Y: "+example.getLabel()+" ,Y_hat: "+prediction); 95 | Logger.error("Loss < 0!, prediction search can't get to the target label."); 96 | } 97 | 98 | Vector updateVector = MathHelpers.mulScalarWithVectors(phiDifference, tau); 99 | Vector result = MathHelpers.add2Vectors(currentWeights, updateVector); 100 | 101 | return result; 102 | 103 | } catch (Exception e) { 104 | e.printStackTrace(); 105 | return null; 106 | } 107 | } 108 | } 109 | 110 | 111 | -------------------------------------------------------------------------------- /src/com/structed/models/algorithms/Perceptron.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.algorithms; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.models.ClassifierData; 31 | import com.structed.constants.ErrorConstants; 32 | import com.structed.data.entities.Example; 33 | import com.structed.data.entities.Vector; 34 | import com.structed.data.Logger; 35 | import com.structed.utils.MathHelpers; 36 | 37 | import java.util.ArrayList; 38 | 39 | /** 40 | * Created by adiyoss on 3/4/15. 41 | * Structured Perceptron 42 | * http://www.cs.columbia.edu/~mcollins/papers/tagperc.pdf 43 | */ 44 | public class Perceptron implements IUpdateRule { 45 | 46 | @Override 47 | public void init(ArrayList args) { 48 | if(args.size() != Consts.SP_PARAMS_SIZE) 49 | Logger.error(ErrorConstants.UPDATE_ARGUMENTS_ERROR); 50 | } 51 | 52 | /** 53 | * Implementation of the update rule 54 | * @param currentWeights - the current weights 55 | * @param example - a single example 56 | * @param classifierData - all the additional data that needed such as: loss function, inference, etc. 57 | * @return the new set of weights 58 | */ 59 | @Override 60 | // Structured Perceptron has no attributes 61 | public Vector update(Vector currentWeights, Example example, ClassifierData classifierData) { 62 | try{ 63 | String prediction; 64 | //if there's a problem with the predict return the previous weights 65 | try{ 66 | prediction = classifierData.inference.predictForTest(example,currentWeights,example.getLabel(),classifierData,1).firstKey(); 67 | } catch (Exception e){ 68 | return currentWeights; 69 | } 70 | 71 | Example phiRealLabel = classifierData.phi.convert(example,example.getLabel(), classifierData.kernel); 72 | Example phiPrediction = classifierData.phi.convert(example,prediction, classifierData.kernel); 73 | 74 | //compute the phi difference 75 | Vector phiDifference = MathHelpers.subtract2Vectors(phiRealLabel.getFeatures(), phiPrediction.getFeatures()); 76 | //update the weights vector 77 | Vector result = MathHelpers.add2Vectors(currentWeights, phiDifference); 78 | return result; 79 | 80 | } catch (Exception e) { 81 | e.printStackTrace(); 82 | return null; 83 | } 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /src/com/structed/models/algorithms/RampLoss.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.algorithms; 28 | 29 | import java.util.ArrayList; 30 | 31 | import com.structed.constants.Consts; 32 | import com.structed.models.ClassifierData; 33 | import com.structed.constants.ErrorConstants; 34 | import com.structed.data.entities.Example; 35 | import com.structed.data.entities.Vector; 36 | import com.structed.data.Logger; 37 | import com.structed.utils.MathHelpers; 38 | 39 | /** 40 | * Ramp Loss Minimization 41 | * http://papers.nips.cc/paper/4268-generalization-bounds-and-consistency-for-latent-structural-probit-and-ramp-loss.pdf 42 | */ 43 | public class RampLoss implements IUpdateRule { 44 | 45 | //data members 46 | double lambda; 47 | double eta; 48 | 49 | @Override 50 | public void init(ArrayList args) { 51 | if(args.size() != Consts.RL_PARAMS_SIZE){ 52 | Logger.error(ErrorConstants.UPDATE_ARGUMENTS_ERROR); 53 | return; 54 | } 55 | //initialize the parameters 56 | this.eta = args.get(0); 57 | this.lambda = args.get(1); 58 | } 59 | 60 | /** 61 | * Implementation of the update rule 62 | * @param currentWeights - the current weights 63 | * @param example - a single example 64 | * @param classifierData - all the additional data that needed such as: loss function, inference, etc. 65 | * @return the new set of weights 66 | */ 67 | 68 | @Override 69 | //the eta variable in is the first cell 70 | //the lambda variable s in the second cell 71 | public Vector update(Vector currentWeights, Example example, ClassifierData classifierData) { 72 | 73 | try{ 74 | double algorithmIteration = classifierData.iteration; 75 | double newEta = eta/Math.sqrt(algorithmIteration); 76 | 77 | //get the prediction 78 | String prediction = classifierData.inference.predictForTrain(example, currentWeights, example.getLabel(), classifierData, 0).firstKey(); 79 | //get the prediction with the task loss 80 | String predictionLoss = classifierData.inference.predictForTrain(example, currentWeights, example.getLabel(), classifierData, 1).firstKey(); 81 | 82 | Example phiPredictionNoLoss = classifierData.phi.convert(example,prediction,classifierData.kernel); 83 | Example phiPredictionWithLoss= classifierData.phi.convert(example,predictionLoss,classifierData.kernel); 84 | 85 | 86 | //compute the ramp loss 87 | Vector rampLoss = MathHelpers.subtract2Vectors(phiPredictionNoLoss.getFeatures(), phiPredictionWithLoss.getFeatures()); 88 | 89 | //perform the update 90 | Vector lossArg = MathHelpers.mulScalarWithVectors(rampLoss, newEta); 91 | Vector newWeights = MathHelpers.mulScalarWithVectors(currentWeights, 1-lambda*newEta); 92 | 93 | return MathHelpers.add2Vectors(newWeights, lossArg); 94 | 95 | } catch (Exception e) { 96 | e.printStackTrace(); 97 | return null; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/com/structed/models/algorithms/SVM.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.algorithms; 28 | 29 | import java.util.ArrayList; 30 | 31 | import com.structed.constants.Consts; 32 | import com.structed.models.ClassifierData; 33 | import com.structed.constants.ErrorConstants; 34 | import com.structed.data.entities.Example; 35 | import com.structed.data.entities.Vector; 36 | import com.structed.data.Logger; 37 | import com.structed.utils.MathHelpers; 38 | 39 | /** 40 | * Structured SVM 41 | * http://link.springer.com/article/10.1007/s10107-010-0420-4#page-1 42 | */ 43 | public class SVM implements IUpdateRule { 44 | 45 | //data members 46 | double eta; 47 | double lambda; 48 | 49 | @Override 50 | public void init(ArrayList args) { 51 | if(args.size() != Consts.SVM_PARAMS_SIZE){ 52 | Logger.error(ErrorConstants.UPDATE_ARGUMENTS_ERROR); 53 | return; 54 | } 55 | //initialize the parameters 56 | this.eta = args.get(0); 57 | this.lambda = args.get(1); 58 | } 59 | 60 | /** 61 | * Implementation of the update rule 62 | * @param currentWeights - the current weights 63 | * @param example - a single example 64 | * @param classifierData - all the additional data that needed such as: loss function, inference, etc. 65 | * @return the new set of weights 66 | */ 67 | 68 | @Override 69 | //in SVM the lambda value would be in the first cell of the arguments attribute 70 | //the second cell of the arguments attribute would be the eta 71 | public Vector update(Vector currentWeights, Example example, ClassifierData classifierData) { 72 | 73 | try{ 74 | double algorithmIteration = classifierData.iteration; 75 | 76 | //get the prediction 77 | String prediction; 78 | 79 | //if there's a problem with the predict return the previous weights 80 | try{ 81 | prediction = classifierData.inference.predictForTrain(example,currentWeights,example.getLabel(),classifierData,1).firstKey(); 82 | } catch (Exception e){ 83 | return currentWeights; 84 | } 85 | 86 | Example phiRealLabel = classifierData.phi.convert(example,example.getLabel(), classifierData.kernel); 87 | Example phiPrediction = classifierData.phi.convert(example,prediction, classifierData.kernel); 88 | 89 | //compute the phi difference 90 | Vector phiDifference = MathHelpers.subtract2Vectors(phiRealLabel.getFeatures(), phiPrediction.getFeatures()); 91 | 92 | double newEta = eta/Math.sqrt(algorithmIteration); 93 | 94 | double coefficientFirstArgument = (1-(lambda*newEta)); 95 | 96 | Vector firstArgument = MathHelpers.mulScalarWithVectors(currentWeights, coefficientFirstArgument); 97 | Vector secondArgument = MathHelpers.mulScalarWithVectors(phiDifference, newEta); 98 | 99 | Vector result = MathHelpers.add2Vectors(firstArgument, secondArgument); 100 | 101 | return result; 102 | 103 | } catch (Exception e) { 104 | e.printStackTrace(); 105 | return null; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/com/structed/models/inference/IInference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.inference; 28 | 29 | import com.structed.models.ClassifierData; 30 | import com.structed.data.entities.Example; 31 | import com.structed.data.entities.PredictedLabels; 32 | import com.structed.data.entities.Vector; 33 | 34 | /** 35 | * IInference interface - inorder to add new inference in you own task you should implement this interface 36 | */ 37 | public interface IInference { 38 | PredictedLabels predictForTrain(Example vector, Vector W, String realClass, ClassifierData classifierData, double epsilonArgMax); 39 | PredictedLabels predictForTest(Example vector, Vector W, String realClass, ClassifierData classifierData, int returnAll); 40 | } 41 | -------------------------------------------------------------------------------- /src/com/structed/models/inference/InferenceDummyData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.inference; 28 | 29 | import com.structed.models.ClassifierData; 30 | import com.structed.constants.Consts; 31 | import com.structed.constants.ErrorConstants; 32 | import com.structed.data.entities.Example; 33 | import com.structed.data.entities.PredictedLabels; 34 | import com.structed.data.entities.Vector; 35 | import com.structed.utils.comperators.MapValueComparatorDescending; 36 | import com.structed.utils.MathHelpers; 37 | 38 | /** 39 | * Dummy data inference example 40 | */ 41 | public class InferenceDummyData implements IInference { 42 | 43 | @Override 44 | // predict function 45 | // argmax(yS,yE) (W*Phi(Xi,yS,yE)) + Task Loss 46 | // this function assumes that the argument vector has already been converted to phi vector 47 | // return null on error 48 | public PredictedLabels predictForTrain(Example vector, Vector W, String realClass, ClassifierData classifierData, double epsilonArgMax) 49 | { 50 | try{ 51 | PredictedLabels tree = new PredictedLabels(); 52 | 53 | //validation 54 | if(vector.sizeOfVector<=0) 55 | { 56 | System.err.println(ErrorConstants.PHI_VECTOR_DATA); 57 | return null; 58 | } 59 | 60 | //loop over all the classifications of this specific example 61 | for(int i=Consts.MIN_GAP_START_DUMMY-1 ; i) expansion 55 | int loc = 0; 56 | double tmp_coef; 57 | expansionVector.put(loc, exp2_coef); 58 | loc++; 59 | 60 | //============================================// 61 | tmp_coef = 1/sigma; 62 | for (int j=0 ; j params); 37 | } 38 | -------------------------------------------------------------------------------- /src/com/structed/models/loss/TaskLossDummyData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.loss; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.data.Logger; 31 | 32 | import java.util.List; 33 | 34 | /** 35 | * Dummy Task Loss example 36 | */ 37 | public class TaskLossDummyData implements ITaskLoss { 38 | 39 | @Override 40 | //max{0,|ys-ye - y's-y'e|-epsilon} 41 | public double computeTaskLoss(String predictClass, String actualClass, List params) { 42 | try { 43 | double epsilon = params.get(0); 44 | String predictValues[] = predictClass.split(Consts.CLASSIFICATION_SPLITTER); 45 | String actualClassValues[] = actualClass.split(Consts.CLASSIFICATION_SPLITTER); 46 | 47 | //calculate difference of each classification 48 | double predictRes = Double.parseDouble(predictValues[0]) - Double.parseDouble(predictValues[1]); 49 | double actualRes = Double.parseDouble(actualClassValues[0]) - Double.parseDouble(actualClassValues[1]); 50 | 51 | //subtract the epsilon 52 | double absRes = Math.abs(predictRes - actualRes) - epsilon; 53 | 54 | //get the max from the absolute result minus epsilon and 0 55 | if (absRes > 0) 56 | return absRes; 57 | return 0; 58 | } catch (Exception e) { 59 | Logger.error("Problem with the loss function parameters."); 60 | return 0; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/com/structed/models/loss/TaskLossMultiClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.loss; 28 | 29 | import java.util.List; 30 | 31 | /** 32 | * MNIST Task Loss example - 0/1 implementation 33 | */ 34 | public class TaskLossMultiClass implements ITaskLoss { 35 | 36 | @Override 37 | public double computeTaskLoss(String predictClass, String actualClass, List params) { 38 | if(predictClass.equalsIgnoreCase(actualClass)) 39 | return 0; 40 | return 1; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/structed/models/loss/TaskLossOCR.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.loss; 28 | 29 | import java.util.List; 30 | 31 | /** 32 | * Loss function for the OCR task 33 | * Created by yossiadi on 7/18/15. 34 | */ 35 | public class TaskLossOCR implements ITaskLoss { 36 | 37 | @Override 38 | public double computeTaskLoss(String predictClass, String actualClass, List params) { 39 | 40 | // get the minimum length 41 | int len = ((predictClass.length() < actualClass.length()) ? predictClass.length() : actualClass.length()) - 2; 42 | double loss = 0.0; 43 | 44 | // compute the character error rate 45 | for(int i=0 ; i params) { 35 | try { 36 | double r = Double.parseDouble(predictClass); 37 | double s = Double.parseDouble(actualClass); 38 | if(1 - r + s < 0) 39 | return 0; 40 | return (1 - r + s); 41 | } catch (Exception e){ 42 | e.printStackTrace(); 43 | return 0; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/structed/models/loss/TaskLossVowelDuration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.loss; 28 | 29 | import com.structed.constants.Consts; 30 | 31 | import java.util.List; 32 | 33 | /** 34 | * Vowel Duration Task Loss example 35 | * The implementation is: max{0, |ys - ys'| - epsilon} + max{0, |ye - ye'| - epsilon} 36 | */ 37 | public class TaskLossVowelDuration implements ITaskLoss { 38 | 39 | @Override 40 | //max{0, |ys - ys'| - epsilon} + max{0, |ye - ye'| - epsilon} 41 | public double computeTaskLoss(String predictClass, String actualClass, List params) { 42 | try { 43 | Double epsilon_onset = params.get(0); 44 | Double epsilon_offset = params.get(1); 45 | 46 | String predictValues[] = predictClass.split(Consts.CLASSIFICATION_SPLITTER); 47 | String actualClassValues[] = actualClass.split(Consts.CLASSIFICATION_SPLITTER); 48 | 49 | double predictResStart = Double.parseDouble(predictValues[0]); 50 | double actualResStart = Double.parseDouble(actualClassValues[0]); 51 | 52 | double predictResEnd = Double.parseDouble(predictValues[1]); 53 | double actualResEnd = Double.parseDouble(actualClassValues[1]); 54 | 55 | double diffStart = Math.abs(predictResStart - actualResStart); 56 | double diffEnd = Math.abs(predictResEnd - actualResEnd); 57 | 58 | //subtract the epsilon 59 | double absRes = 0; 60 | if(diffStart >= epsilon_onset) 61 | absRes += diffStart; 62 | if(diffEnd >= epsilon_offset) 63 | absRes += diffEnd; 64 | 65 | //get the max from the absolute result minus epsilon and 0 66 | return absRes; 67 | 68 | } catch (Exception e){ 69 | e.printStackTrace(); 70 | return 0; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/com/structed/tests/dal/LazyReaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.tests.dal; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.data.Factory; 31 | import com.structed.data.InstancesContainer; 32 | import com.structed.data.LazyInstancesContainer; 33 | import com.structed.dal.Reader; 34 | import junit.framework.TestCase; 35 | import static org.junit.Assert.assertThat; 36 | import static org.hamcrest.CoreMatchers.instanceOf; 37 | 38 | /* 39 | Unit tests for the Vowel Duration Reader class 40 | */ 41 | public class LazyReaderTest extends TestCase { 42 | 43 | public void testReadData() throws Exception { 44 | InstancesContainer instances; 45 | Reader reader = Factory.getReader(2); 46 | 47 | // Test 1 48 | instances = reader.readData("src/com/structed/tests/tests_data/test2.txt", Consts.SPACE, Consts.COLON_SPLITTER); 49 | assertEquals("Number of examples must be: 16",16,instances.getSize()); 50 | assertThat(instances, instanceOf(LazyInstancesContainer.class)); 51 | 52 | // Test 2 53 | instances = reader.readData("src/com/structed/tests/tests_data/test4.txt", Consts.SPACE, Consts.COLON_SPLITTER); 54 | assertEquals("Number of examples must be: 36", 36, instances.getSize()); 55 | assertThat(instances, instanceOf(LazyInstancesContainer.class)); 56 | } 57 | } -------------------------------------------------------------------------------- /src/com/structed/tests/dal/OcrReaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.tests.dal; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.dal.Reader; 31 | import com.structed.data.Factory; 32 | import com.structed.data.InstancesContainer; 33 | import junit.framework.TestCase; 34 | 35 | import java.util.ArrayList; 36 | 37 | /** 38 | * Test class for the OCR Reader 39 | * Created by yossiadi on 7/18/15. 40 | */ 41 | public class OcrReaderTest extends TestCase { 42 | 43 | public void testReadFile() throws Exception { 44 | Reader reader = Factory.getReader(3); 45 | ArrayList> data = reader.readFile("src/com/structed/tests/tests_data/ocr/val.data", Consts.TAB); 46 | assertEquals("Data size should be: 999", 999, data.size()); 47 | for(int i=0 ; i params = new ArrayList(){{add(5.0);}}; 42 | double lossValue; 43 | TaskLossDummyData loss = new TaskLossDummyData(); 44 | 45 | // #Test 1 46 | lossValue = loss.computeTaskLoss(values[0], values[1], params); 47 | assertEquals("The loss should be: 0", 0.0, lossValue); 48 | 49 | // #Test 2 50 | lossValue = loss.computeTaskLoss(values[0], values[2], params); 51 | assertEquals("The loss should be: 3", 3.0, lossValue); 52 | 53 | // #Test 3 54 | lossValue = loss.computeTaskLoss(values[2], values[3], params); 55 | assertEquals("The loss should be: 0", 0.0, lossValue); 56 | 57 | // #Test 4 58 | lossValue = loss.computeTaskLoss(values[0], values[4], params); 59 | assertEquals("The loss should be: 0", 0.0, lossValue); 60 | 61 | // #Test 5 62 | lossValue = loss.computeTaskLoss(values[2], values[4], params); 63 | assertEquals("The loss should be: 5", 5.0, lossValue); 64 | 65 | // #Test 6 66 | lossValue = loss.computeTaskLoss(values[2], values[5], params); 67 | assertEquals("The loss should be: 0", 0.0, lossValue); 68 | 69 | // #Test 7 70 | lossValue = loss.computeTaskLoss(values[4], values[5], params); 71 | assertEquals("The loss should be: 9", 9.0, lossValue); 72 | } 73 | } -------------------------------------------------------------------------------- /src/com/structed/tests/models/loss/TaskLossMultiClassTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.tests.models.loss; 28 | 29 | import com.structed.models.loss.TaskLossMultiClass; 30 | import junit.framework.TestCase; 31 | 32 | /** 33 | * Created by yossiadi on 7/6/15. 34 | */ 35 | public class TaskLossMultiClassTest extends TestCase { 36 | 37 | public void testComputeTaskLoss() throws Exception { 38 | String values[] = {"1","2","3","4","5","6","7","8","9"}; 39 | double lossValue; 40 | TaskLossMultiClass loss = new TaskLossMultiClass(); 41 | 42 | for(int i=0 ; i params = new ArrayList(){{add(5.0); add(7.0);}}; 42 | double lossValue; 43 | TaskLossVowelDuration loss = new TaskLossVowelDuration(); 44 | 45 | // #Test 1 46 | lossValue = loss.computeTaskLoss(values[0], values[1], params); 47 | assertEquals("The loss should be: 10", 10.0, lossValue); 48 | 49 | // #Test 2 50 | lossValue = loss.computeTaskLoss(values[0], values[2], params); 51 | assertEquals("The loss should be: 32", 32.0, lossValue); 52 | 53 | // #Test 3 54 | lossValue = loss.computeTaskLoss(values[2], values[3], params); 55 | assertEquals("The loss should be: 0", 0.0, lossValue); 56 | 57 | // #Test 4 58 | lossValue = loss.computeTaskLoss(values[0], values[4], params); 59 | assertEquals("The loss should be: 5", 5.0, lossValue); 60 | 61 | // #Test 5 62 | lossValue = loss.computeTaskLoss(values[2], values[4], params); 63 | assertEquals("The loss should be: 22", 22.0, lossValue); 64 | 65 | // #Test 6 66 | lossValue = loss.computeTaskLoss(values[2], values[5], params); 67 | assertEquals("The loss should be: 20", 20.0, lossValue); 68 | 69 | // #Test 7 70 | lossValue = loss.computeTaskLoss(values[4], values[5], params); 71 | assertEquals("The loss should be: 7", 7.0, lossValue); 72 | } 73 | } -------------------------------------------------------------------------------- /src/com/structed/tests/tests_data/dummy/test.txt: -------------------------------------------------------------------------------- 1 | 6-11 0:0 1:0 2:0 3:0 4:0 5:0 6:1 7:1 8:1 9:1 10:1 11:0 12:0 13:0 14:0 15:0 16:0 2 | 4-6 0:0 1:0 2:0 3:0 4:1 5:1 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:1 14:0 15:0 3 | 19-22 0:0 1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:1 20:1 21:1 22:0 23:0 24:0 25:0 26:0 4 | 3-15 0:0 1:0 2:0 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 11:1 12:1 13:1 14:1 15:0 16:0 17:0 18:0 19:0 5 | 5-10 0:0 1:0 2:0 3:0 4:0 5:1 6:1 7:1 8:1 9:1 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0 22:0 6 | 8-16 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:1 10:1 11:1 12:0 13:1 14:1 15:1 16:0 17:0 18:0 19:0 -------------------------------------------------------------------------------- /src/com/structed/tests/tests_data/dummy/train.txt: -------------------------------------------------------------------------------- 1 | 3-5 0:0 1:0 2:0 3:1 4:1 5:0 6:0 7:0 8:0 9:0 2 | 6-9 0:0 1:0 2:0 3:0 4:0 5:0 6:1 7:1 8:1 9:0 10:0 11:0 12:0 13:0 14:0 15:0 3 | 9-14 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:1 11:1 12:1 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 4 | 4-7 0:0 1:0 2:0 3:0 4:1 5:1 6:1 7:0 8:0 9:0 5 | 3-8 0:0 1:0 2:0 3:1 4:1 5:1 6:1 7:1 8:0 9:0 10:0 11:0 6 | 5-8 0:0 1:0 2:0 3:0 4:0 5:1 6:1 7:1 8:0 9:0 10:0 11:0 12:0 13:0 7 | 3-9 0:0 1:1 2:0 3:1 4:1 5:1 6:1 7:1 8:1 9:0 10:0 11:0 12:0 13:0 8 | 12-15 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:1 13:1 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:0 9 | 8-17 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:1 10:1 11:0 12:1 13:1 14:1 15:1 16:1 17:0 18:0 19:0 10 | 8-14 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:1 10:1 11:0 12:1 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0 22:0 23:0 24:0 11 | 16-24 0:0 1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:1 17:1 18:1 19:1 20:1 21:1 22:1 23:1 24:0 25:0 26:0 27:0 28:0 29:0 12 | 9-12 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:1 11:1 12:0 13:0 14:0 15:0 13 | 3-6 0:0 1:0 2:0 3:1 4:1 5:1 6:0 7:0 8:0 14 | 4-10 0:0 1:0 2:0 3:0 4:1 5:1 6:1 7:1 8:1 9:1 10:0 11:0 12:0 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/com/structed/tests/tests_data/real_db/C01B1.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 90 150 3 | -------------------------------------------------------------------------------- /src/com/structed/tests/tests_data/test1.txt: -------------------------------------------------------------------------------- 1 | 6-11 0:0 1:0 2:0 3:0 4:0 5:0 6:1 7:1 8:1 9:1 10:1 11:0 12:0 13:0 14:0 15:0 16:0 2 | 4-6 0:0 1:0 2:0 3:0 4:1 5:1 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:1 14:0 15:0 3 | 19-22 0:0 1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:1 20:1 21:1 22:0 23:0 24:0 25:0 26:0 4 | 3-15 0:0 1:0 2:0 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 11:1 12:1 13:1 14:1 15:0 16:0 17:0 18:0 19:0 5 | 5-10 0:0 1:0 2:0 3:0 4:0 5:1 6:1 7:1 8:1 9:1 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0 22:0 6 | 8-16 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:1 10:1 11:1 12:0 13:1 14:1 15:1 16:0 17:0 18:0 19:0 -------------------------------------------------------------------------------- /src/com/structed/tests/tests_data/test2.txt: -------------------------------------------------------------------------------- 1 | data/tests/db/real_db/C01B1.data data/tests/db/real_db/C01B1.labels 2 | data/tests/db/real_db/C01B111.data data/tests/db/real_db/C01B111.labels 3 | data/tests/db/real_db/C01B115.data data/tests/db/real_db/C01B115.labels 4 | data/tests/db/real_db/C01B117.data data/tests/db/real_db/C01B117.labels 5 | data/tests/db/real_db/C01B118.data data/tests/db/real_db/C01B118.labels 6 | data/tests/db/real_db/C01B124.data data/tests/db/real_db/C01B124.labels 7 | data/tests/db/real_db/C01B125.data data/tests/db/real_db/C01B125.labels 8 | data/tests/db/real_db/C01B128.data data/tests/db/real_db/C01B128.labels 9 | data/tests/db/real_db/C01B131.data data/tests/db/real_db/C01B131.labels 10 | data/tests/db/real_db/C01B133.data data/tests/db/real_db/C01B133.labels 11 | data/tests/db/real_db/C01B135.data data/tests/db/real_db/C01B135.labels 12 | data/tests/db/real_db/C01B137.data data/tests/db/real_db/C01B137.labels 13 | data/tests/db/real_db/C01B140.data data/tests/db/real_db/C01B140.labels 14 | data/tests/db/real_db/C01B145.data data/tests/db/real_db/C01B145.labels 15 | data/tests/db/real_db/C01B146.data data/tests/db/real_db/C01B146.labels 16 | data/tests/db/real_db/C01B147.data data/tests/db/real_db/C01B147.labels -------------------------------------------------------------------------------- /src/com/structed/tests/tests_data/test3.txt: -------------------------------------------------------------------------------- 1 | 3-5 0:0 1:0 2:0 3:1 4:1 5:0 6:0 7:0 8:0 9:0 2 | 6-9 0:0 1:0 2:0 3:0 4:0 5:0 6:1 7:1 8:1 9:0 10:0 11:0 12:0 13:0 14:0 15:0 3 | 9-14 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:1 11:1 12:1 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 4 | 4-7 0:0 1:0 2:0 3:0 4:1 5:1 6:1 7:0 8:0 9:0 5 | 3-8 0:0 1:0 2:0 3:1 4:1 5:1 6:1 7:1 8:0 9:0 10:0 11:0 6 | 5-8 0:0 1:0 2:0 3:0 4:0 5:1 6:1 7:1 8:0 9:0 10:0 11:0 12:0 13:0 7 | 3-9 0:0 1:1 2:0 3:1 4:1 5:1 6:1 7:1 8:1 9:0 10:0 11:0 12:0 13:0 8 | 12-15 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:1 13:1 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:0 9 | 8-17 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:1 10:1 11:0 12:1 13:1 14:1 15:1 16:1 17:0 18:0 19:0 10 | 8-14 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:1 10:1 11:0 12:1 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0 22:0 23:0 24:0 11 | 16-24 0:0 1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:1 17:1 18:1 19:1 20:1 21:1 22:1 23:1 24:0 25:0 26:0 27:0 28:0 29:0 12 | 9-12 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:1 11:1 12:0 13:0 14:0 15:0 13 | 3-6 0:0 1:0 2:0 3:1 4:1 5:1 6:0 7:0 8:0 14 | 4-10 0:0 1:0 2:0 3:0 4:1 5:1 6:1 7:1 8:1 9:1 10:0 11:0 12:0 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/com/structed/tests/tests_data/test4.txt: -------------------------------------------------------------------------------- 1 | data/db/real_db/C01B1.data data/db/real_db/C01B1.labels 2 | data/db/real_db/C01B3.data data/db/real_db/C01B3.labels 3 | data/db/real_db/C01B5.data data/db/real_db/C01B5.labels 4 | data/db/real_db/C01B7.data data/db/real_db/C01B7.labels 5 | data/db/real_db/C01B10.data data/db/real_db/C01B10.labels 6 | data/db/real_db/C01B15.data data/db/real_db/C01B15.labels 7 | data/db/real_db/C01B21.data data/db/real_db/C01B21.labels 8 | data/db/real_db/C01B25.data data/db/real_db/C01B25.labels 9 | data/db/real_db/C01B27.data data/db/real_db/C01B27.labels 10 | data/db/real_db/C01B32.data data/db/real_db/C01B32.labels 11 | data/db/real_db/C01B33.data data/db/real_db/C01B33.labels 12 | data/db/real_db/C01B34.data data/db/real_db/C01B34.labels 13 | data/db/real_db/C01B38.data data/db/real_db/C01B38.labels 14 | data/db/real_db/C01B40.data data/db/real_db/C01B40.labels 15 | data/db/real_db/C01B43.data data/db/real_db/C01B43.labels 16 | data/db/real_db/C01B45.data data/db/real_db/C01B45.labels 17 | data/db/real_db/C01B46.data data/db/real_db/C01B46.labels 18 | data/db/real_db/C01B50.data data/db/real_db/C01B50.labels 19 | data/db/real_db/C01B52.data data/db/real_db/C01B52.labels 20 | data/db/real_db/C01B54.data data/db/real_db/C01B54.labels 21 | data/db/real_db/C01B55.data data/db/real_db/C01B55.labels 22 | data/db/real_db/C01B57.data data/db/real_db/C01B57.labels 23 | data/db/real_db/C01B61.data data/db/real_db/C01B61.labels 24 | data/db/real_db/C01B68.data data/db/real_db/C01B68.labels 25 | data/db/real_db/C01B81.data data/db/real_db/C01B81.labels 26 | data/db/real_db/C01B82.data data/db/real_db/C01B82.labels 27 | data/db/real_db/C01B83.data data/db/real_db/C01B83.labels 28 | data/db/real_db/C01B87.data data/db/real_db/C01B87.labels 29 | data/db/real_db/C01B89.data data/db/real_db/C01B89.labels 30 | data/db/real_db/C01B91.data data/db/real_db/C01B91.labels 31 | data/db/real_db/C01B93.data data/db/real_db/C01B93.labels 32 | data/db/real_db/C01B94.data data/db/real_db/C01B94.labels 33 | data/db/real_db/C01B98.data data/db/real_db/C01B98.labels 34 | data/db/real_db/C01B99.data data/db/real_db/C01B99.labels 35 | data/db/real_db/C01B105.data data/db/real_db/C01B105.labels 36 | data/db/real_db/C01B107.data data/db/real_db/C01B107.labels -------------------------------------------------------------------------------- /src/com/structed/tests/utils/ConverterHelplersTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.tests.utils; 28 | 29 | import com.structed.utils.ConverterHelplers; 30 | import junit.framework.TestCase; 31 | 32 | import java.util.Random; 33 | 34 | /** 35 | * Created by yossiadi on 7/7/15. 36 | */ 37 | public class ConverterHelplersTest extends TestCase { 38 | 39 | public void testTryParseInt() throws Exception { 40 | Random random = new Random(); 41 | for(int i=0 ; i<10 ; i++) { 42 | Double num = random.nextDouble(); 43 | assertEquals("Should be double", true, ConverterHelplers.tryParseDouble(num.toString())); 44 | assertEquals("Should not be double", false, ConverterHelplers.tryParseDouble(num.toString()+"_")); 45 | } 46 | } 47 | 48 | public void testTryParseDouble() throws Exception { 49 | Random random = new Random(); 50 | for(int i=0 ; i<10 ; i++) { 51 | Integer num = random.nextInt(); 52 | assertEquals("Should be double", true, ConverterHelplers.tryParseInt(num.toString())); 53 | assertEquals("Should not be double", false, ConverterHelplers.tryParseInt(num.toString() + "_")); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/com/structed/tests/utils/LazyInstancesContainerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.tests.utils; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.data.entities.Example2D; 31 | import com.structed.data.Factory; 32 | import com.structed.data.InstancesContainer; 33 | import com.structed.data.LazyInstancesContainer; 34 | import com.structed.dal.Reader; 35 | import junit.framework.TestCase; 36 | 37 | import static org.hamcrest.CoreMatchers.instanceOf; 38 | import static org.junit.Assert.assertThat; 39 | 40 | /* 41 | Unit test for the LazyInstanceContainer class 42 | */ 43 | public class LazyInstancesContainerTest extends TestCase{ 44 | 45 | public void testGetInstance() throws Exception { 46 | Reader reader = Factory.getReader(2); 47 | InstancesContainer instances_train; 48 | instances_train = reader.readData("src/com/structed/tests/tests_data/test4.txt", Consts.SPACE, Consts.COLON_SPLITTER); 49 | assertThat(instances_train, instanceOf(LazyInstancesContainer.class)); 50 | assertEquals("Must return null because there is no such files",instances_train.getInstance(0), null); 51 | 52 | InstancesContainer instances_test; 53 | instances_test = reader.readData("src/com/structed/tests/tests_data/test2.txt", Consts.SPACE, Consts.COLON_SPLITTER); 54 | assertThat(instances_test, instanceOf(LazyInstancesContainer.class)); 55 | assertThat(instances_test.getInstance(0), instanceOf(Example2D.class)); 56 | } 57 | } -------------------------------------------------------------------------------- /src/com/structed/tests/utils/ModelHandlerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.tests.utils; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.dal.Reader; 31 | import com.structed.data.Factory; 32 | import com.structed.data.InstancesContainer; 33 | import com.structed.data.entities.Vector; 34 | import com.structed.utils.ModelHandler; 35 | import junit.framework.TestCase; 36 | 37 | import java.util.ArrayList; 38 | 39 | /** 40 | * Created by yossiadi on 7/7/15. 41 | */ 42 | public class ModelHandlerTest extends TestCase { 43 | 44 | 45 | public void testConvert2Weights() throws Exception { 46 | double[] values = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.1}; 47 | ArrayList w = new ArrayList(); 48 | for(int i=0 ; i> new_w = new ArrayList>(); 51 | new_w.add(w); 52 | 53 | Vector double_w = ModelHandler.convert2Weights(new_w); 54 | for(int i=0 ; i> tmp) 65 | // { 66 | // //get the offset 67 | // for(int i=0 ; i { 33 | 34 | Map base; 35 | 36 | public MapKeyComparatorAscending(Map base) { 37 | this.base = base; 38 | } 39 | 40 | @Override 41 | public int compare(String a, String b) { 42 | if (a.compareToIgnoreCase(b)>0) { 43 | return 1; 44 | } else { 45 | return -1; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/structed/utils/comperators/MapValueComparatorAscending.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.utils.comperators; 28 | 29 | import java.util.Comparator; 30 | import java.util.Map; 31 | 32 | public class MapValueComparatorAscending implements Comparator{ 33 | 34 | Map base; 35 | 36 | public MapValueComparatorAscending(Map base) { 37 | this.base = base; 38 | } 39 | 40 | @Override 41 | public int compare(String a, String b) { 42 | if (base.get(a) > base.get(b)) { 43 | return 1; 44 | } else { 45 | return -1; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/structed/utils/comperators/MapValueComparatorDescending.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.utils.comperators; 28 | 29 | import java.util.Comparator; 30 | import java.util.Map; 31 | 32 | public class MapValueComparatorDescending implements Comparator{ 33 | 34 | Map base; 35 | 36 | public MapValueComparatorDescending(Map base) { 37 | this.base = base; 38 | } 39 | 40 | @Override 41 | public int compare(String a, String b) { 42 | if (base.get(a) <= base.get(b)) { 43 | return 1; 44 | } else { 45 | return -1; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/structed/utils/comperators/MapValueComparatorDescending_IntKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.utils.comperators; 28 | 29 | import java.util.Comparator; 30 | import java.util.Map; 31 | 32 | public class MapValueComparatorDescending_IntKey implements Comparator { 33 | 34 | Map base; 35 | 36 | public MapValueComparatorDescending_IntKey(Map base) { 37 | this.base = base; 38 | } 39 | 40 | @Override 41 | public int compare(Integer a, Integer b) { 42 | if (base.get(a) <= base.get(b)) { 43 | return 1; 44 | } else { 45 | return -1; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tutorials-code/dummy/InferenceDummyData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.inference; 28 | 29 | import com.structed.models.ClassifierData; 30 | import com.structed.constants.Consts; 31 | import com.structed.constants.ErrorConstants; 32 | import com.structed.data.entities.Example; 33 | import com.structed.data.entities.PredictedLabels; 34 | import com.structed.data.entities.Vector; 35 | import com.structed.utils.comperators.MapValueComparatorDescending; 36 | import com.structed.utils.MathHelpers; 37 | 38 | /** 39 | * Dummy data inference example 40 | */ 41 | public class InferenceDummyData implements IInference { 42 | 43 | // predict function 44 | // argmax(yS,yE) (W*Phi(Xi,yS,yE)) + Task Loss 45 | // this function assumes that the argument vector has already been converted to phi vector 46 | // return null on error 47 | public PredictedLabels predictForTrain(Example vector, Vector W, String realClass, ClassifierData classifierData, double epsilonArgMax) 48 | { 49 | try{ 50 | PredictedLabels tree = new PredictedLabels(); 51 | 52 | //validation 53 | if(vector.sizeOfVector<=0) 54 | { 55 | System.err.println(ErrorConstants.PHI_VECTOR_DATA); 56 | return null; 57 | } 58 | 59 | //loop over all the classifications of this specific example 60 | for(int i=Consts.MIN_GAP_START_DUMMY-1 ; i params) { 42 | try { 43 | double epsilon = params.get(0); 44 | String predictValues[] = predictClass.split(Consts.CLASSIFICATION_SPLITTER); 45 | String actualClassValues[] = actualClass.split(Consts.CLASSIFICATION_SPLITTER); 46 | 47 | //calculate difference of each classification 48 | double predictRes = Double.parseDouble(predictValues[0]) - Double.parseDouble(predictValues[1]); 49 | double actualRes = Double.parseDouble(actualClassValues[0]) - Double.parseDouble(actualClassValues[1]); 50 | 51 | //subtract the epsilon 52 | double absRes = Math.abs(predictRes - actualRes) - epsilon; 53 | 54 | //get the max from the absolute result minus epsilon and 0 55 | if (absRes > 0) 56 | return absRes; 57 | return 0; 58 | } catch (Exception e) { 59 | Logger.error("Problem with the loss function parameters."); 60 | return 0; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tutorials-code/dummy/compile_and_run_dummy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -d bin ]; then 3 | rm -rf bin 4 | fi 5 | mkdir bin 6 | javac -d bin -sourcepath . -cp ../../bin/StructED_1.0.1.jar DummyTutorial.java 7 | java -cp bin:../../bin/StructED_1.0.1.jar com.tutorials.DummyTutorial -------------------------------------------------------------------------------- /tutorials-code/dummy/data/test.txt: -------------------------------------------------------------------------------- 1 | 6-11 0:0 1:0 2:0 3:0 4:0 5:0 6:1 7:1 8:1 9:1 10:1 11:0 12:0 13:0 14:0 15:0 16:0 2 | 4-6 0:0 1:0 2:0 3:0 4:1 5:1 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:1 14:0 15:0 3 | 19-22 0:0 1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:1 20:1 21:1 22:0 23:0 24:0 25:0 26:0 4 | 3-15 0:0 1:0 2:0 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 11:1 12:1 13:1 14:1 15:0 16:0 17:0 18:0 19:0 5 | 5-10 0:0 1:0 2:0 3:0 4:0 5:1 6:1 7:1 8:1 9:1 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0 22:0 6 | 8-16 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:1 10:1 11:1 12:0 13:1 14:1 15:1 16:0 17:0 18:0 19:0 -------------------------------------------------------------------------------- /tutorials-code/dummy/data/train.txt: -------------------------------------------------------------------------------- 1 | 3-5 0:0 1:0 2:0 3:1 4:1 5:0 6:0 7:0 8:0 9:0 2 | 6-9 0:0 1:0 2:0 3:0 4:0 5:0 6:1 7:1 8:1 9:0 10:0 11:0 12:0 13:0 14:0 15:0 3 | 9-14 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:1 11:1 12:1 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 4 | 4-7 0:0 1:0 2:0 3:0 4:1 5:1 6:1 7:0 8:0 9:0 5 | 3-8 0:0 1:0 2:0 3:1 4:1 5:1 6:1 7:1 8:0 9:0 10:0 11:0 6 | 5-8 0:0 1:0 2:0 3:0 4:0 5:1 6:1 7:1 8:0 9:0 10:0 11:0 12:0 13:0 7 | 3-9 0:0 1:1 2:0 3:1 4:1 5:1 6:1 7:1 8:1 9:0 10:0 11:0 12:0 13:0 8 | 12-15 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:1 13:1 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:0 9 | 8-17 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:1 10:1 11:0 12:1 13:1 14:1 15:1 16:1 17:0 18:0 19:0 10 | 8-14 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:1 10:1 11:0 12:1 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0 22:0 23:0 24:0 11 | 16-24 0:0 1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:1 17:1 18:1 19:1 20:1 21:1 22:1 23:1 24:0 25:0 26:0 27:0 28:0 29:0 12 | 9-12 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:1 11:1 12:0 13:0 14:0 15:0 13 | 3-6 0:0 1:0 2:0 3:1 4:1 5:1 6:0 7:0 8:0 14 | 4-10 0:0 1:0 2:0 3:0 4:1 5:1 6:1 7:1 8:1 9:1 10:0 11:0 12:0 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tutorials-code/multiclass/FeatureFunctionsSparse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.data.featurefunctions; 28 | 29 | import com.structed.models.kernels.IKernel; 30 | import com.structed.data.entities.Example; 31 | import com.structed.data.Factory; 32 | import com.structed.data.entities.Vector; 33 | 34 | public class FeatureFunctionsSparse implements IFeatureFunctions { 35 | 36 | // data members 37 | private int maxFeatures; 38 | private int numOfClasses; 39 | private int sizeOfVector; 40 | 41 | /** 42 | * Constructor 43 | * @param numOfClasses - the number target of classes 44 | * @param maxNumFeatures - the number of features 45 | */ 46 | public FeatureFunctionsSparse(int numOfClasses, int maxNumFeatures){ 47 | this.numOfClasses = numOfClasses; 48 | this.maxFeatures = maxNumFeatures; 49 | this.sizeOfVector = this.maxFeatures*this.numOfClasses; 50 | } 51 | 52 | @Override 53 | public Example convert(Example vector, String label, IKernel kernel) { 54 | try{ 55 | //parse the label 56 | int intLabel = Integer.parseInt(label); 57 | Example newVector = Factory.getExample(0); 58 | newVector.sizeOfVector = maxFeatures; 59 | Vector tmpVector = new Vector(); 60 | 61 | //run the phi function 62 | for(Integer feature : vector.getFeatures().keySet()) 63 | tmpVector.put(feature+intLabel*maxFeatures,vector.getFeatures().get(feature)); 64 | 65 | if(kernel !=null) 66 | tmpVector = kernel.convertVector(tmpVector, vector.sizeOfVector); 67 | 68 | newVector.setFeatures(tmpVector); 69 | 70 | return newVector; 71 | 72 | } catch (Exception e){ 73 | e.printStackTrace(); 74 | return null; 75 | } 76 | } 77 | 78 | @Override 79 | public int getSizeOfVector() { 80 | return this.sizeOfVector; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tutorials-code/multiclass/MulticlassIRIS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.tutorials; 28 | 29 | import com.structed.constants.Consts; 30 | import com.structed.dal.Reader; 31 | import com.structed.data.InstancesContainer; 32 | import com.structed.data.Logger; 33 | import com.structed.data.entities.PredictedLabels; 34 | import com.structed.data.entities.Vector; 35 | import com.structed.data.featurefunctions.FeatureFunctionsSparse; 36 | import com.structed.models.StructEDModel; 37 | import com.structed.models.algorithms.PassiveAggressive; 38 | import com.structed.models.algorithms.SVM; 39 | import com.structed.models.inference.InferenceMultiClassOld; 40 | import com.structed.models.loss.TaskLossMultiClass; 41 | 42 | import java.util.ArrayList; 43 | 44 | import static com.structed.data.Factory.getReader; 45 | 46 | /** 47 | * Created by yossiadi on 6/29/15. 48 | * Tutorial about the multiclass classifications using MNIST and Iris datasets 49 | */ 50 | public class MulticlassIRIS { 51 | public static void main(String[] args) throws Exception { 52 | // ============================ MNIST DATA ============================ // 53 | Logger.info("Loading IRIS dataset."); 54 | 55 | // ============================ IRIS DATA ============================= // 56 | // === PARAMETERS === // 57 | String trainPath = "data/iris/iris.train.txt"; // 58 | String testPath = "data/iris/iris.test.txt"; // 59 | int epochNum = 10; 60 | int isAvg = 1; 61 | int numExamples2Display = 3; 62 | int numOfClasses = 3; 63 | int maxFeatures = 4; 64 | int readerType = 0; 65 | Reader reader = getReader(readerType); 66 | // ================== // 67 | 68 | // load the data 69 | InstancesContainer irisTrainInstances = reader.readData(trainPath, Consts.COMMA_NOTE, Consts.COLON_SPLITTER); 70 | InstancesContainer irisTestInstances = reader.readData(testPath, Consts.COMMA_NOTE, Consts.COLON_SPLITTER); 71 | // ======= PA ====== // 72 | Vector W = new Vector() {{put(0, 0.0);}}; // init the first weight vector to be zeros 73 | ArrayList arguments = new ArrayList() {{add(1.0);}}; // model parameters 74 | 75 | // build the model 76 | StructEDModel iris_model = new StructEDModel(W, new PassiveAggressive(), new TaskLossMultiClass(), 77 | new InferenceMultiClassOld(numOfClasses), null, new FeatureFunctionsSparse(numOfClasses, maxFeatures), arguments); 78 | // train 79 | iris_model.train(irisTrainInstances, null, null, epochNum, isAvg, true); 80 | // predict 81 | ArrayList iris_labels = iris_model.predict(irisTestInstances, null, numExamples2Display, true); 82 | 83 | // printing the predictions 84 | for(int i=0 ; i 57 | String testPath = "data/MNIST/test.data.txt"; // 58 | String valPath = "data/MNIST/val.data.txt"; // 59 | int epochNum = 1; 60 | int readerType = 0; 61 | int isAvg = 1; 62 | int numExamples2Display = 3; 63 | int numOfClasses = 10; 64 | int maxFeatures = 784; 65 | Reader reader = getReader(readerType); 66 | // ================== // 67 | 68 | // load the data 69 | InstancesContainer mnistTrainInstances = reader.readData(trainPath, Consts.SPACE, Consts.COLON_SPLITTER); 70 | InstancesContainer mnistDevelopInstances = reader.readData(valPath, Consts.SPACE, Consts.COLON_SPLITTER); 71 | InstancesContainer mnistTestInstances = reader.readData(testPath, Consts.SPACE, Consts.COLON_SPLITTER); 72 | if (mnistTrainInstances.getSize() == 0) return; 73 | 74 | // ======= SVM ====== // 75 | Vector W = new Vector() {{put(0, 0.0);}}; // init the first weight vector 76 | ArrayList arguments = new ArrayList() {{add(0.1);add(0.1);}}; // model parameters 77 | 78 | // build the model 79 | StructEDModel mnist_model = new StructEDModel(W, new SVM(), new TaskLossMultiClass(), 80 | new InferenceMultiClassOld(numOfClasses), null, new FeatureFunctionsSparse(numOfClasses, maxFeatures), arguments); 81 | // train 82 | mnist_model.train(mnistTrainInstances, null, mnistDevelopInstances, epochNum, isAvg, true); 83 | // predict 84 | mnist_model.predict(mnistTestInstances, null, numExamples2Display, true); 85 | // plot the error on the validation set 86 | // the true flag indicates that we saves the image to img folder in the project directory 87 | // if the img directory does not exists it will create it 88 | mnist_model.plotValidationError(true); 89 | // ==================================================================== // 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /tutorials-code/multiclass/TaskLossMultiClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.loss; 28 | 29 | import java.util.List; 30 | 31 | /** 32 | * Multiclass Task Loss - 0/1 loss 33 | */ 34 | public class TaskLossMultiClass implements ITaskLoss { 35 | 36 | @Override 37 | public double computeTaskLoss(String predictClass, String actualClass, List params) { 38 | if(predictClass.equalsIgnoreCase(actualClass)) 39 | return 0; 40 | return 1; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tutorials-code/multiclass/compile_and_run_iris.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir bin 3 | javac -d bin -sourcepath . -cp ../../bin/StructED_1.0.1.jar MulticlassIRIS.java 4 | java -Xms2048m -Xmx2048m -cp bin:../../bin/StructED_1.0.1.jar com.tutorials.MulticlassIRIS -------------------------------------------------------------------------------- /tutorials-code/multiclass/compile_and_run_mnist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir bin 3 | javac -d bin -sourcepath . -cp ../../bin/StructED_1.0.1.jar MulticlassMNIST.java 4 | java -Xms2048m -Xmx2048m -cp bin:../../bin/StructED_1.0.1.jar com.tutorials.MulticlassMNIST -------------------------------------------------------------------------------- /tutorials-code/multiclass/data/iris/iris.test.txt: -------------------------------------------------------------------------------- 1 | 0,0:5.0,1:3.5,2:1.3,3:0.3 2 | 0,0:4.5,1:2.3,2:1.3,3:0.3 3 | 0,0:4.4,1:3.2,2:1.3,3:0.2 4 | 0,0:5.0,1:3.5,2:1.6,3:0.6 5 | 0,0:5.1,1:3.8,2:1.9,3:0.4 6 | 0,0:4.8,1:3.0,2:1.4,3:0.3 7 | 0,0:5.1,1:3.8,2:1.6,3:0.2 8 | 0,0:4.6,1:3.2,2:1.4,3:0.2 9 | 0,0:5.3,1:3.7,2:1.5,3:0.2 10 | 0,0:5.0,1:3.3,2:1.4,3:0.2 11 | 1,0:5.5,1:2.6,2:4.4,3:1.2 12 | 1,0:6.1,1:3.0,2:4.6,3:1.4 13 | 1,0:5.8,1:2.6,2:4.0,3:1.2 14 | 1,0:5.0,1:2.3,2:3.3,3:1.0 15 | 1,0:5.6,1:2.7,2:4.2,3:1.3 16 | 1,0:5.7,1:3.0,2:4.2,3:1.2 17 | 1,0:5.7,1:2.9,2:4.2,3:1.3 18 | 1,0:6.2,1:2.9,2:4.3,3:1.3 19 | 1,0:5.1,1:2.5,2:3.0,3:1.1 20 | 1,0:5.7,1:2.8,2:4.1,3:1.3 21 | 2,0:6.7,1:3.1,2:5.6,3:2.4 22 | 2,0:6.9,1:3.1,2:5.1,3:2.3 23 | 2,0:5.8,1:2.7,2:5.1,3:1.9 24 | 2,0:6.8,1:3.2,2:5.9,3:2.3 25 | 2,0:6.7,1:3.3,2:5.7,3:2.5 26 | 2,0:6.7,1:3.0,2:5.2,3:2.3 27 | 2,0:6.3,1:2.5,2:5.0,3:1.9 28 | 2,0:6.5,1:3.0,2:5.2,3:2.0 29 | 2,0:6.2,1:3.4,2:5.4,3:2.3 30 | 2,0:5.9,1:3.0,2:5.1,3:1.8 -------------------------------------------------------------------------------- /tutorials-code/multiclass/data/iris/iris.train.txt: -------------------------------------------------------------------------------- 1 | 0,0:5.1,1:3.5,2:1.4,3:0.2 2 | 0,0:4.9,1:3.0,2:1.4,3:0.2 3 | 0,0:4.7,1:3.2,2:1.3,3:0.2 4 | 0,0:4.6,1:3.1,2:1.5,3:0.2 5 | 0,0:5.0,1:3.6,2:1.4,3:0.2 6 | 0,0:5.4,1:3.9,2:1.7,3:0.4 7 | 0,0:4.6,1:3.4,2:1.4,3:0.3 8 | 0,0:5.0,1:3.4,2:1.5,3:0.2 9 | 0,0:4.4,1:2.9,2:1.4,3:0.2 10 | 0,0:4.9,1:3.1,2:1.5,3:0.1 11 | 0,0:5.4,1:3.7,2:1.5,3:0.2 12 | 0,0:4.8,1:3.4,2:1.6,3:0.2 13 | 0,0:4.8,1:3.0,2:1.4,3:0.1 14 | 0,0:4.3,1:3.0,2:1.1,3:0.1 15 | 0,0:5.8,1:4.0,2:1.2,3:0.2 16 | 0,0:5.7,1:4.4,2:1.5,3:0.4 17 | 0,0:5.4,1:3.9,2:1.3,3:0.4 18 | 0,0:5.1,1:3.5,2:1.4,3:0.3 19 | 0,0:5.7,1:3.8,2:1.7,3:0.3 20 | 0,0:5.1,1:3.8,2:1.5,3:0.3 21 | 0,0:5.4,1:3.4,2:1.7,3:0.2 22 | 0,0:5.1,1:3.7,2:1.5,3:0.4 23 | 0,0:4.6,1:3.6,2:1.0,3:0.2 24 | 0,0:5.1,1:3.3,2:1.7,3:0.5 25 | 0,0:4.8,1:3.4,2:1.9,3:0.2 26 | 0,0:5.0,1:3.0,2:1.6,3:0.2 27 | 0,0:5.0,1:3.4,2:1.6,3:0.4 28 | 0,0:5.2,1:3.5,2:1.5,3:0.2 29 | 0,0:5.2,1:3.4,2:1.4,3:0.2 30 | 0,0:4.7,1:3.2,2:1.6,3:0.2 31 | 0,0:4.8,1:3.1,2:1.6,3:0.2 32 | 0,0:5.4,1:3.4,2:1.5,3:0.4 33 | 0,0:5.2,1:4.1,2:1.5,3:0.1 34 | 0,0:5.5,1:4.2,2:1.4,3:0.2 35 | 0,0:4.9,1:3.1,2:1.5,3:0.1 36 | 0,0:5.0,1:3.2,2:1.2,3:0.2 37 | 0,0:5.5,1:3.5,2:1.3,3:0.2 38 | 0,0:4.9,1:3.1,2:1.5,3:0.1 39 | 0,0:4.4,1:3.0,2:1.3,3:0.2 40 | 0,0:5.1,1:3.4,2:1.5,3:0.2 41 | 1,0:7.0,1:3.2,2:4.7,3:1.4 42 | 1,0:6.4,1:3.2,2:4.5,3:1.5 43 | 1,0:6.9,1:3.1,2:4.9,3:1.5 44 | 1,0:5.5,1:2.3,2:4.0,3:1.3 45 | 1,0:6.5,1:2.8,2:4.6,3:1.5 46 | 1,0:5.7,1:2.8,2:4.5,3:1.3 47 | 1,0:6.3,1:3.3,2:4.7,3:1.6 48 | 1,0:4.9,1:2.4,2:3.3,3:1.0 49 | 1,0:6.6,1:2.9,2:4.6,3:1.3 50 | 1,0:5.2,1:2.7,2:3.9,3:1.4 51 | 1,0:5.0,1:2.0,2:3.5,3:1.0 52 | 1,0:5.9,1:3.0,2:4.2,3:1.5 53 | 1,0:6.0,1:2.2,2:4.0,3:1.0 54 | 1,0:6.1,1:2.9,2:4.7,3:1.4 55 | 1,0:5.6,1:2.9,2:3.6,3:1.3 56 | 1,0:6.7,1:3.1,2:4.4,3:1.4 57 | 1,0:5.6,1:3.0,2:4.5,3:1.5 58 | 1,0:5.8,1:2.7,2:4.1,3:1.0 59 | 1,0:6.2,1:2.2,2:4.5,3:1.5 60 | 1,0:5.6,1:2.5,2:3.9,3:1.1 61 | 1,0:5.9,1:3.2,2:4.8,3:1.8 62 | 1,0:6.1,1:2.8,2:4.0,3:1.3 63 | 1,0:6.3,1:2.5,2:4.9,3:1.5 64 | 1,0:6.1,1:2.8,2:4.7,3:1.2 65 | 1,0:6.4,1:2.9,2:4.3,3:1.3 66 | 1,0:6.6,1:3.0,2:4.4,3:1.4 67 | 1,0:6.8,1:2.8,2:4.8,3:1.4 68 | 1,0:6.7,1:3.0,2:5.0,3:1.7 69 | 1,0:6.0,1:2.9,2:4.5,3:1.5 70 | 1,0:5.7,1:2.6,2:3.5,3:1.0 71 | 1,0:5.5,1:2.4,2:3.8,3:1.1 72 | 1,0:5.5,1:2.4,2:3.7,3:1.0 73 | 1,0:5.8,1:2.7,2:3.9,3:1.2 74 | 1,0:6.0,1:2.7,2:5.1,3:1.6 75 | 1,0:5.4,1:3.0,2:4.5,3:1.5 76 | 1,0:6.0,1:3.4,2:4.5,3:1.6 77 | 1,0:6.7,1:3.1,2:4.7,3:1.5 78 | 1,0:6.3,1:2.3,2:4.4,3:1.3 79 | 1,0:5.6,1:3.0,2:4.1,3:1.3 80 | 1,0:5.5,1:2.5,2:4.0,3:1.3 81 | 2,0:6.3,1:3.3,2:6.0,3:2.5 82 | 2,0:5.8,1:2.7,2:5.1,3:1.9 83 | 2,0:7.1,1:3.0,2:5.9,3:2.1 84 | 2,0:6.3,1:2.9,2:5.6,3:1.8 85 | 2,0:6.5,1:3.0,2:5.8,3:2.2 86 | 2,0:7.6,1:3.0,2:6.6,3:2.1 87 | 2,0:4.9,1:2.5,2:4.5,3:1.7 88 | 2,0:7.3,1:2.9,2:6.3,3:1.8 89 | 2,0:6.7,1:2.5,2:5.8,3:1.8 90 | 2,0:7.2,1:3.6,2:6.1,3:2.5 91 | 2,0:6.5,1:3.2,2:5.1,3:2.0 92 | 2,0:6.4,1:2.7,2:5.3,3:1.9 93 | 2,0:6.8,1:3.0,2:5.5,3:2.1 94 | 2,0:5.7,1:2.5,2:5.0,3:2.0 95 | 2,0:5.8,1:2.8,2:5.1,3:2.4 96 | 2,0:6.4,1:3.2,2:5.3,3:2.3 97 | 2,0:6.5,1:3.0,2:5.5,3:1.8 98 | 2,0:7.7,1:3.8,2:6.7,3:2.2 99 | 2,0:7.7,1:2.6,2:6.9,3:2.3 100 | 2,0:6.0,1:2.2,2:5.0,3:1.5 101 | 2,0:6.9,1:3.2,2:5.7,3:2.3 102 | 2,0:5.6,1:2.8,2:4.9,3:2.0 103 | 2,0:7.7,1:2.8,2:6.7,3:2.0 104 | 2,0:6.3,1:2.7,2:4.9,3:1.8 105 | 2,0:6.7,1:3.3,2:5.7,3:2.1 106 | 2,0:7.2,1:3.2,2:6.0,3:1.8 107 | 2,0:6.2,1:2.8,2:4.8,3:1.8 108 | 2,0:6.1,1:3.0,2:4.9,3:1.8 109 | 2,0:6.4,1:2.8,2:5.6,3:2.1 110 | 2,0:7.2,1:3.0,2:5.8,3:1.6 111 | 2,0:7.4,1:2.8,2:6.1,3:1.9 112 | 2,0:7.9,1:3.8,2:6.4,3:2.0 113 | 2,0:6.4,1:2.8,2:5.6,3:2.2 114 | 2,0:6.3,1:2.8,2:5.1,3:1.5 115 | 2,0:6.1,1:2.6,2:5.6,3:1.4 116 | 2,0:7.7,1:3.0,2:6.1,3:2.3 117 | 2,0:6.3,1:3.4,2:5.6,3:2.4 118 | 2,0:6.4,1:3.1,2:5.5,3:1.8 119 | 2,0:6.0,1:3.0,2:4.8,3:1.8 120 | 2,0:6.9,1:3.1,2:5.4,3:2.1 -------------------------------------------------------------------------------- /tutorials-code/multiclass/img/validation_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adiyoss/StructED/6e785c72831c9c99c480d93b65e9d3155fc13216/tutorials-code/multiclass/img/validation_error.png -------------------------------------------------------------------------------- /tutorials-code/ocr/TaskLossOCR.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * StructED - Machine Learning Package for Structured Prediction 5 | * 6 | * Copyright (c) 2015 Yossi Adi, E-Mail: yossiadidrum@gmail.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package com.structed.models.loss; 28 | 29 | import java.util.List; 30 | 31 | /** 32 | * Computing Character Error Rate (CER) loss function for the OCR task 33 | * Created by yossiadi on 7/18/15. 34 | */ 35 | public class TaskLossCER implements ITaskLoss { 36 | 37 | @Override 38 | public double computeTaskLoss(String predictClass, String actualClass, List params) { 39 | 40 | // get the minimum length 41 | int len = ((predictClass.length() < actualClass.length()) ? predictClass.length() : actualClass.length()) - 2; 42 | double loss = 0.0; 43 | 44 | // compute the character error rate 45 | for(int i=0 ; i params) { 41 | try { 42 | Double epsilon_onset = params.get(0); 43 | Double epsilon_offset = params.get(1); 44 | 45 | String predictValues[] = predictClass.split(Consts.CLASSIFICATION_SPLITTER); 46 | String actualClassValues[] = actualClass.split(Consts.CLASSIFICATION_SPLITTER); 47 | 48 | double predictResStart = Double.parseDouble(predictValues[0]); 49 | double actualResStart = Double.parseDouble(actualClassValues[0]); 50 | 51 | double predictResEnd = Double.parseDouble(predictValues[1]); 52 | double actualResEnd = Double.parseDouble(actualClassValues[1]); 53 | 54 | double diffStart = Math.abs(predictResStart - actualResStart); 55 | double diffEnd = Math.abs(predictResEnd - actualResEnd); 56 | 57 | //subtract the epsilon 58 | double absRes = 0; 59 | if(diffStart >= epsilon_onset) 60 | absRes += diffStart; 61 | if(diffEnd >= epsilon_offset) 62 | absRes += diffEnd; 63 | 64 | //get the max from the absolute result minus epsilon and 0 65 | return absRes; 66 | 67 | } catch (Exception e){ 68 | e.printStackTrace(); 69 | return 0; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /tutorials-code/vowel/compile_and_run_vowel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -d bin ]; then 3 | rm -rf bin 4 | fi 5 | mkdir bin 6 | javac -d bin -sourcepath . -cp ../../bin/StructED_1.0.1.jar VowelDurationTutorial.java 7 | java -cp bin:../../bin/StructED_1.0.1.jar com.tutorials.VowelDurationTutorial -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Beak_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 59 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Bed_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 68 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Bell_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 63 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Boat_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 64 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Bomb_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 66 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Boot_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 62 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Bowl_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Coat_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Doll_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 71 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Goose_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 61 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Hat_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 63 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Head_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 62 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Heel_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 54 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Lock_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Moon_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 70 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Moose_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 65 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Nose_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 85 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Peel_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 51 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Pen_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 51 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Rat_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 67 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-Tack_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 61 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-beak_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-bed_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 63 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-bell_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 49 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-boat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 68 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-bomb_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 69 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-boot_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-bowl_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 68 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-coat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 57 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-doll_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 77 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-goose_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-hat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 56 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-head_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 57 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-heel_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 54 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-lock_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 64 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-moon_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 76 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-moose_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 64 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-nose_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 83 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-peel_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 51 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-pen_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 45 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-rat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 64 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-seal_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 51 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s002-tack_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Beak_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 54 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Bed_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 65 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Bell_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 79 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Boat_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 69 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Bomb_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 69 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Boot_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Bowl_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 65 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Coat_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 56 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Doll_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 63 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Goose_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 64 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Hat_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 65 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Head_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 62 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Heel_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 60 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Lock_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 66 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Moon_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 84 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Moose_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 60 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Nose_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 76 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Peel_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 51 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Pen_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Rat_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 59 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Seal_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 64 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-Tack_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 72 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-beak_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 59 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-bed_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 60 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-bell_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 64 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-boat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 64 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-bomb_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 67 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-boot_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 56 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-bowl_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 65 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-coat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 61 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-doll_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 61 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-goose_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 56 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-hat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 61 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-head_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 61 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-heel_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 48 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-lock_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 59 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-moon_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 61 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-moose_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-nose_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 74 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-peel_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 58 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-pen_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 52 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-rat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 63 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-seal_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 57 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s006-tack_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 60 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Beak_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 61 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Bed_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 71 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Bell_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 56 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Boat_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 60 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Bomb_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 71 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Boot_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 57 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Bowl_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 53 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Coat_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 55 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Doll_NounRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 66 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Goose_VerbUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 62 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Hat_VerbRelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 56 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-Head_NounUnrelated.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 55 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-beak_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 53 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-bed_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 69 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-bell_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 60 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-boat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 53 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-bomb_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 63 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-boot_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 56 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-bowl_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 77 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-coat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 51 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-doll_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 67 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-goose_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 64 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/new_data/tbtw-1v1-s019-hat_Target.labels: -------------------------------------------------------------------------------- 1 | 1 2 2 | 30 59 3 | -------------------------------------------------------------------------------- /tutorials-code/vowel/data/vowel/test.vowel.txt: -------------------------------------------------------------------------------- 1 | data/vowel/new_data/tbtw-1v1-s019-Bed_VerbUnrelated.data data/vowel/new_data/tbtw-1v1-s019-Bed_VerbUnrelated.labels 2 | data/vowel/new_data/tbtw-1v1-s019-bell_Target.data data/vowel/new_data/tbtw-1v1-s019-bell_Target.labels 3 | data/vowel/new_data/tbtw-1v1-s019-Bell_VerbRelated.data data/vowel/new_data/tbtw-1v1-s019-Bell_VerbRelated.labels 4 | data/vowel/new_data/tbtw-1v1-s019-Boat_NounUnrelated.data data/vowel/new_data/tbtw-1v1-s019-Boat_NounUnrelated.labels 5 | data/vowel/new_data/tbtw-1v1-s019-boat_Target.data data/vowel/new_data/tbtw-1v1-s019-boat_Target.labels 6 | data/vowel/new_data/tbtw-1v1-s019-Bomb_NounRelated.data data/vowel/new_data/tbtw-1v1-s019-Bomb_NounRelated.labels 7 | data/vowel/new_data/tbtw-1v1-s019-bomb_Target.data data/vowel/new_data/tbtw-1v1-s019-bomb_Target.labels 8 | data/vowel/new_data/tbtw-1v1-s019-boot_Target.data data/vowel/new_data/tbtw-1v1-s019-boot_Target.labels 9 | data/vowel/new_data/tbtw-1v1-s019-Boot_VerbUnrelated.data data/vowel/new_data/tbtw-1v1-s019-Boot_VerbUnrelated.labels 10 | data/vowel/new_data/tbtw-1v1-s019-bowl_Target.data data/vowel/new_data/tbtw-1v1-s019-bowl_Target.labels 11 | data/vowel/new_data/tbtw-1v1-s019-Bowl_VerbRelated.data data/vowel/new_data/tbtw-1v1-s019-Bowl_VerbRelated.labels 12 | data/vowel/new_data/tbtw-1v1-s019-Coat_NounUnrelated.data data/vowel/new_data/tbtw-1v1-s019-Coat_NounUnrelated.labels 13 | data/vowel/new_data/tbtw-1v1-s019-coat_Target.data data/vowel/new_data/tbtw-1v1-s019-coat_Target.labels 14 | data/vowel/new_data/tbtw-1v1-s019-Doll_NounRelated.data data/vowel/new_data/tbtw-1v1-s019-Doll_NounRelated.labels 15 | data/vowel/new_data/tbtw-1v1-s019-doll_Target.data data/vowel/new_data/tbtw-1v1-s019-doll_Target.labels 16 | data/vowel/new_data/tbtw-1v1-s019-goose_Target.data data/vowel/new_data/tbtw-1v1-s019-goose_Target.labels 17 | data/vowel/new_data/tbtw-1v1-s019-Goose_VerbUnrelated.data data/vowel/new_data/tbtw-1v1-s019-Goose_VerbUnrelated.labels 18 | data/vowel/new_data/tbtw-1v1-s019-hat_Target.data data/vowel/new_data/tbtw-1v1-s019-hat_Target.labels 19 | data/vowel/new_data/tbtw-1v1-s019-Hat_VerbRelated.data data/vowel/new_data/tbtw-1v1-s019-Hat_VerbRelated.labels 20 | data/vowel/new_data/tbtw-1v1-s019-Head_NounUnrelated.data data/vowel/new_data/tbtw-1v1-s019-Head_NounUnrelated.labels --------------------------------------------------------------------------------