├── .gitignore ├── LICENSE ├── README.md ├── assignments(pdf) ├── ex1.pdf ├── ex2.pdf ├── ex3.pdf ├── ex4.pdf ├── ex5.pdf ├── ex6.pdf ├── ex7.pdf └── ex8.pdf ├── build.sbt ├── project └── build.properties └── src └── main ├── resources ├── ex1 │ ├── ex1data1.txt │ └── ex1data2.txt ├── ex2 │ ├── ex2data1.txt │ └── ex2data2.txt ├── ex3 │ ├── ex3data1.mat │ └── ex3weights.mat ├── ex4 │ ├── ex4data1.mat │ └── ex4weights.mat ├── ex5 │ └── ex5data1.mat ├── ex6 │ ├── emailSample1.txt │ ├── emailSample2.txt │ ├── ex6data1.mat │ ├── ex6data2.mat │ ├── ex6data3.mat │ ├── spamSample1.txt │ ├── spamSample2.txt │ ├── spamTest.mat │ ├── spamTrain.mat │ └── vocab.txt ├── ex7 │ ├── bird_small.mat │ ├── bird_small.png │ ├── ex7data1.mat │ ├── ex7data2.mat │ └── ex7faces.mat └── ex8 │ ├── ex8_movieParams.mat │ ├── ex8_movies.mat │ ├── ex8data1.mat │ ├── ex8data2.mat │ └── movie_ids.txt └── scala └── com └── cpuheater ├── ml ├── Ex1.scala ├── Ex2.scala ├── Ex3.scala ├── Ex4.scala ├── Ex5.scala ├── Ex6.scala ├── Ex7.scala └── Ex8.scala └── util └── Loader.scala /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | # sbt specific 4 | .cache 5 | .history 6 | .lib/ 7 | dist/* 8 | target/ 9 | lib_managed/ 10 | src_managed/ 11 | project/boot/ 12 | project/plugins/project/ 13 | 14 | .idea/ 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #### Solutions in Scala to Andrew Ng's Machine Learning course on Coursera. 2 | 3 | Dependencies 4 | 5 | - Nd4j - for linear algebra 6 | - DataVec 7 | - matsim 8 | 9 | No other optimization library is used, just vanilla gradient descent. 10 | -------------------------------------------------------------------------------- /assignments(pdf)/ex1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/assignments(pdf)/ex1.pdf -------------------------------------------------------------------------------- /assignments(pdf)/ex2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/assignments(pdf)/ex2.pdf -------------------------------------------------------------------------------- /assignments(pdf)/ex3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/assignments(pdf)/ex3.pdf -------------------------------------------------------------------------------- /assignments(pdf)/ex4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/assignments(pdf)/ex4.pdf -------------------------------------------------------------------------------- /assignments(pdf)/ex5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/assignments(pdf)/ex5.pdf -------------------------------------------------------------------------------- /assignments(pdf)/ex6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/assignments(pdf)/ex6.pdf -------------------------------------------------------------------------------- /assignments(pdf)/ex7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/assignments(pdf)/ex7.pdf -------------------------------------------------------------------------------- /assignments(pdf)/ex8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/assignments(pdf)/ex8.pdf -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | name := "ml-coursera-scala" 2 | organization := "com.cpuheater" 3 | version := "0.0.1" 4 | scalaVersion in ThisBuild := "2.11.8" 5 | 6 | resolvers += 7 | "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots" 8 | 9 | val nd4jVersion = "0.9.1" 10 | 11 | libraryDependencies ++= Seq( 12 | "org.nd4j" % "nd4j-native-platform" % nd4jVersion, 13 | "org.nd4j" %% "nd4s" % nd4jVersion, 14 | "org.datavec" % "datavec-api" % nd4jVersion, 15 | "org.deeplearning4j" % "deeplearning4j-core" % nd4jVersion, 16 | "com.diffplug.matsim" % "matfilerw" % "3.0.1" 17 | ) 18 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.15 2 | -------------------------------------------------------------------------------- /src/main/resources/ex1/ex1data1.txt: -------------------------------------------------------------------------------- 1 | 6.1101,17.592 2 | 5.5277,9.1302 3 | 8.5186,13.662 4 | 7.0032,11.854 5 | 5.8598,6.8233 6 | 8.3829,11.886 7 | 7.4764,4.3483 8 | 8.5781,12 9 | 6.4862,6.5987 10 | 5.0546,3.8166 11 | 5.7107,3.2522 12 | 14.164,15.505 13 | 5.734,3.1551 14 | 8.4084,7.2258 15 | 5.6407,0.71618 16 | 5.3794,3.5129 17 | 6.3654,5.3048 18 | 5.1301,0.56077 19 | 6.4296,3.6518 20 | 7.0708,5.3893 21 | 6.1891,3.1386 22 | 20.27,21.767 23 | 5.4901,4.263 24 | 6.3261,5.1875 25 | 5.5649,3.0825 26 | 18.945,22.638 27 | 12.828,13.501 28 | 10.957,7.0467 29 | 13.176,14.692 30 | 22.203,24.147 31 | 5.2524,-1.22 32 | 6.5894,5.9966 33 | 9.2482,12.134 34 | 5.8918,1.8495 35 | 8.2111,6.5426 36 | 7.9334,4.5623 37 | 8.0959,4.1164 38 | 5.6063,3.3928 39 | 12.836,10.117 40 | 6.3534,5.4974 41 | 5.4069,0.55657 42 | 6.8825,3.9115 43 | 11.708,5.3854 44 | 5.7737,2.4406 45 | 7.8247,6.7318 46 | 7.0931,1.0463 47 | 5.0702,5.1337 48 | 5.8014,1.844 49 | 11.7,8.0043 50 | 5.5416,1.0179 51 | 7.5402,6.7504 52 | 5.3077,1.8396 53 | 7.4239,4.2885 54 | 7.6031,4.9981 55 | 6.3328,1.4233 56 | 6.3589,-1.4211 57 | 6.2742,2.4756 58 | 5.6397,4.6042 59 | 9.3102,3.9624 60 | 9.4536,5.4141 61 | 8.8254,5.1694 62 | 5.1793,-0.74279 63 | 21.279,17.929 64 | 14.908,12.054 65 | 18.959,17.054 66 | 7.2182,4.8852 67 | 8.2951,5.7442 68 | 10.236,7.7754 69 | 5.4994,1.0173 70 | 20.341,20.992 71 | 10.136,6.6799 72 | 7.3345,4.0259 73 | 6.0062,1.2784 74 | 7.2259,3.3411 75 | 5.0269,-2.6807 76 | 6.5479,0.29678 77 | 7.5386,3.8845 78 | 5.0365,5.7014 79 | 10.274,6.7526 80 | 5.1077,2.0576 81 | 5.7292,0.47953 82 | 5.1884,0.20421 83 | 6.3557,0.67861 84 | 9.7687,7.5435 85 | 6.5159,5.3436 86 | 8.5172,4.2415 87 | 9.1802,6.7981 88 | 6.002,0.92695 89 | 5.5204,0.152 90 | 5.0594,2.8214 91 | 5.7077,1.8451 92 | 7.6366,4.2959 93 | 5.8707,7.2029 94 | 5.3054,1.9869 95 | 8.2934,0.14454 96 | 13.394,9.0551 97 | 5.4369,0.61705 98 | -------------------------------------------------------------------------------- /src/main/resources/ex1/ex1data2.txt: -------------------------------------------------------------------------------- 1 | 2104,3,399900 2 | 1600,3,329900 3 | 2400,3,369000 4 | 1416,2,232000 5 | 3000,4,539900 6 | 1985,4,299900 7 | 1534,3,314900 8 | 1427,3,198999 9 | 1380,3,212000 10 | 1494,3,242500 11 | 1940,4,239999 12 | 2000,3,347000 13 | 1890,3,329999 14 | 4478,5,699900 15 | 1268,3,259900 16 | 2300,4,449900 17 | 1320,2,299900 18 | 1236,3,199900 19 | 2609,4,499998 20 | 3031,4,599000 21 | 1767,3,252900 22 | 1888,2,255000 23 | 1604,3,242900 24 | 1962,4,259900 25 | 3890,3,573900 26 | 1100,3,249900 27 | 1458,3,464500 28 | 2526,3,469000 29 | 2200,3,475000 30 | 2637,3,299900 31 | 1839,2,349900 32 | 1000,1,169900 33 | 2040,4,314900 34 | 3137,3,579900 35 | 1811,4,285900 36 | 1437,3,249900 37 | 1239,3,229900 38 | 2132,4,345000 39 | 4215,4,549000 40 | 2162,4,287000 41 | 1664,2,368500 42 | 2238,3,329900 43 | 2567,4,314000 44 | 1200,3,299000 45 | 852,2,179900 46 | 1852,4,299900 47 | 1203,3,239500 48 | -------------------------------------------------------------------------------- /src/main/resources/ex2/ex2data1.txt: -------------------------------------------------------------------------------- 1 | 34.62365962451697,78.0246928153624,0 2 | 30.28671076822607,43.89499752400101,0 3 | 35.84740876993872,72.90219802708364,0 4 | 60.18259938620976,86.30855209546826,1 5 | 79.0327360507101,75.3443764369103,1 6 | 45.08327747668339,56.3163717815305,0 7 | 61.10666453684766,96.51142588489624,1 8 | 75.02474556738889,46.55401354116538,1 9 | 76.09878670226257,87.42056971926803,1 10 | 84.43281996120035,43.53339331072109,1 11 | 95.86155507093572,38.22527805795094,0 12 | 75.01365838958247,30.60326323428011,0 13 | 82.30705337399482,76.48196330235604,1 14 | 69.36458875970939,97.71869196188608,1 15 | 39.53833914367223,76.03681085115882,0 16 | 53.9710521485623,89.20735013750205,1 17 | 69.07014406283025,52.74046973016765,1 18 | 67.94685547711617,46.67857410673128,0 19 | 70.66150955499435,92.92713789364831,1 20 | 76.97878372747498,47.57596364975532,1 21 | 67.37202754570876,42.83843832029179,0 22 | 89.67677575072079,65.79936592745237,1 23 | 50.534788289883,48.85581152764205,0 24 | 34.21206097786789,44.20952859866288,0 25 | 77.9240914545704,68.9723599933059,1 26 | 62.27101367004632,69.95445795447587,1 27 | 80.1901807509566,44.82162893218353,1 28 | 93.114388797442,38.80067033713209,0 29 | 61.83020602312595,50.25610789244621,0 30 | 38.78580379679423,64.99568095539578,0 31 | 61.379289447425,72.80788731317097,1 32 | 85.40451939411645,57.05198397627122,1 33 | 52.10797973193984,63.12762376881715,0 34 | 52.04540476831827,69.43286012045222,1 35 | 40.23689373545111,71.16774802184875,0 36 | 54.63510555424817,52.21388588061123,0 37 | 33.91550010906887,98.86943574220611,0 38 | 64.17698887494485,80.90806058670817,1 39 | 74.78925295941542,41.57341522824434,0 40 | 34.1836400264419,75.2377203360134,0 41 | 83.90239366249155,56.30804621605327,1 42 | 51.54772026906181,46.85629026349976,0 43 | 94.44336776917852,65.56892160559052,1 44 | 82.36875375713919,40.61825515970618,0 45 | 51.04775177128865,45.82270145776001,0 46 | 62.22267576120188,52.06099194836679,0 47 | 77.19303492601364,70.45820000180959,1 48 | 97.77159928000232,86.7278223300282,1 49 | 62.07306379667647,96.76882412413983,1 50 | 91.56497449807442,88.69629254546599,1 51 | 79.94481794066932,74.16311935043758,1 52 | 99.2725269292572,60.99903099844988,1 53 | 90.54671411399852,43.39060180650027,1 54 | 34.52451385320009,60.39634245837173,0 55 | 50.2864961189907,49.80453881323059,0 56 | 49.58667721632031,59.80895099453265,0 57 | 97.64563396007767,68.86157272420604,1 58 | 32.57720016809309,95.59854761387875,0 59 | 74.24869136721598,69.82457122657193,1 60 | 71.79646205863379,78.45356224515052,1 61 | 75.3956114656803,85.75993667331619,1 62 | 35.28611281526193,47.02051394723416,0 63 | 56.25381749711624,39.26147251058019,0 64 | 30.05882244669796,49.59297386723685,0 65 | 44.66826172480893,66.45008614558913,0 66 | 66.56089447242954,41.09209807936973,0 67 | 40.45755098375164,97.53518548909936,1 68 | 49.07256321908844,51.88321182073966,0 69 | 80.27957401466998,92.11606081344084,1 70 | 66.74671856944039,60.99139402740988,1 71 | 32.72283304060323,43.30717306430063,0 72 | 64.0393204150601,78.03168802018232,1 73 | 72.34649422579923,96.22759296761404,1 74 | 60.45788573918959,73.09499809758037,1 75 | 58.84095621726802,75.85844831279042,1 76 | 99.82785779692128,72.36925193383885,1 77 | 47.26426910848174,88.47586499559782,1 78 | 50.45815980285988,75.80985952982456,1 79 | 60.45555629271532,42.50840943572217,0 80 | 82.22666157785568,42.71987853716458,0 81 | 88.9138964166533,69.80378889835472,1 82 | 94.83450672430196,45.69430680250754,1 83 | 67.31925746917527,66.58935317747915,1 84 | 57.23870631569862,59.51428198012956,1 85 | 80.36675600171273,90.96014789746954,1 86 | 68.46852178591112,85.59430710452014,1 87 | 42.0754545384731,78.84478600148043,0 88 | 75.47770200533905,90.42453899753964,1 89 | 78.63542434898018,96.64742716885644,1 90 | 52.34800398794107,60.76950525602592,0 91 | 94.09433112516793,77.15910509073893,1 92 | 90.44855097096364,87.50879176484702,1 93 | 55.48216114069585,35.57070347228866,0 94 | 74.49269241843041,84.84513684930135,1 95 | 89.84580670720979,45.35828361091658,1 96 | 83.48916274498238,48.38028579728175,1 97 | 42.2617008099817,87.10385094025457,1 98 | 99.31500880510394,68.77540947206617,1 99 | 55.34001756003703,64.9319380069486,1 100 | 74.77589300092767,89.52981289513276,1 101 | -------------------------------------------------------------------------------- /src/main/resources/ex2/ex2data2.txt: -------------------------------------------------------------------------------- 1 | 0.051267,0.69956,1 2 | -0.092742,0.68494,1 3 | -0.21371,0.69225,1 4 | -0.375,0.50219,1 5 | -0.51325,0.46564,1 6 | -0.52477,0.2098,1 7 | -0.39804,0.034357,1 8 | -0.30588,-0.19225,1 9 | 0.016705,-0.40424,1 10 | 0.13191,-0.51389,1 11 | 0.38537,-0.56506,1 12 | 0.52938,-0.5212,1 13 | 0.63882,-0.24342,1 14 | 0.73675,-0.18494,1 15 | 0.54666,0.48757,1 16 | 0.322,0.5826,1 17 | 0.16647,0.53874,1 18 | -0.046659,0.81652,1 19 | -0.17339,0.69956,1 20 | -0.47869,0.63377,1 21 | -0.60541,0.59722,1 22 | -0.62846,0.33406,1 23 | -0.59389,0.005117,1 24 | -0.42108,-0.27266,1 25 | -0.11578,-0.39693,1 26 | 0.20104,-0.60161,1 27 | 0.46601,-0.53582,1 28 | 0.67339,-0.53582,1 29 | -0.13882,0.54605,1 30 | -0.29435,0.77997,1 31 | -0.26555,0.96272,1 32 | -0.16187,0.8019,1 33 | -0.17339,0.64839,1 34 | -0.28283,0.47295,1 35 | -0.36348,0.31213,1 36 | -0.30012,0.027047,1 37 | -0.23675,-0.21418,1 38 | -0.06394,-0.18494,1 39 | 0.062788,-0.16301,1 40 | 0.22984,-0.41155,1 41 | 0.2932,-0.2288,1 42 | 0.48329,-0.18494,1 43 | 0.64459,-0.14108,1 44 | 0.46025,0.012427,1 45 | 0.6273,0.15863,1 46 | 0.57546,0.26827,1 47 | 0.72523,0.44371,1 48 | 0.22408,0.52412,1 49 | 0.44297,0.67032,1 50 | 0.322,0.69225,1 51 | 0.13767,0.57529,1 52 | -0.0063364,0.39985,1 53 | -0.092742,0.55336,1 54 | -0.20795,0.35599,1 55 | -0.20795,0.17325,1 56 | -0.43836,0.21711,1 57 | -0.21947,-0.016813,1 58 | -0.13882,-0.27266,1 59 | 0.18376,0.93348,0 60 | 0.22408,0.77997,0 61 | 0.29896,0.61915,0 62 | 0.50634,0.75804,0 63 | 0.61578,0.7288,0 64 | 0.60426,0.59722,0 65 | 0.76555,0.50219,0 66 | 0.92684,0.3633,0 67 | 0.82316,0.27558,0 68 | 0.96141,0.085526,0 69 | 0.93836,0.012427,0 70 | 0.86348,-0.082602,0 71 | 0.89804,-0.20687,0 72 | 0.85196,-0.36769,0 73 | 0.82892,-0.5212,0 74 | 0.79435,-0.55775,0 75 | 0.59274,-0.7405,0 76 | 0.51786,-0.5943,0 77 | 0.46601,-0.41886,0 78 | 0.35081,-0.57968,0 79 | 0.28744,-0.76974,0 80 | 0.085829,-0.75512,0 81 | 0.14919,-0.57968,0 82 | -0.13306,-0.4481,0 83 | -0.40956,-0.41155,0 84 | -0.39228,-0.25804,0 85 | -0.74366,-0.25804,0 86 | -0.69758,0.041667,0 87 | -0.75518,0.2902,0 88 | -0.69758,0.68494,0 89 | -0.4038,0.70687,0 90 | -0.38076,0.91886,0 91 | -0.50749,0.90424,0 92 | -0.54781,0.70687,0 93 | 0.10311,0.77997,0 94 | 0.057028,0.91886,0 95 | -0.10426,0.99196,0 96 | -0.081221,1.1089,0 97 | 0.28744,1.087,0 98 | 0.39689,0.82383,0 99 | 0.63882,0.88962,0 100 | 0.82316,0.66301,0 101 | 0.67339,0.64108,0 102 | 1.0709,0.10015,0 103 | -0.046659,-0.57968,0 104 | -0.23675,-0.63816,0 105 | -0.15035,-0.36769,0 106 | -0.49021,-0.3019,0 107 | -0.46717,-0.13377,0 108 | -0.28859,-0.060673,0 109 | -0.61118,-0.067982,0 110 | -0.66302,-0.21418,0 111 | -0.59965,-0.41886,0 112 | -0.72638,-0.082602,0 113 | -0.83007,0.31213,0 114 | -0.72062,0.53874,0 115 | -0.59389,0.49488,0 116 | -0.48445,0.99927,0 117 | -0.0063364,0.99927,0 118 | 0.63265,-0.030612,0 119 | -------------------------------------------------------------------------------- /src/main/resources/ex3/ex3data1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex3/ex3data1.mat -------------------------------------------------------------------------------- /src/main/resources/ex3/ex3weights.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex3/ex3weights.mat -------------------------------------------------------------------------------- /src/main/resources/ex4/ex4data1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex4/ex4data1.mat -------------------------------------------------------------------------------- /src/main/resources/ex4/ex4weights.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex4/ex4weights.mat -------------------------------------------------------------------------------- /src/main/resources/ex5/ex5data1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex5/ex5data1.mat -------------------------------------------------------------------------------- /src/main/resources/ex6/emailSample1.txt: -------------------------------------------------------------------------------- 1 | > Anyone knows how much it costs to host a web portal ? 2 | > 3 | Well, it depends on how many visitors you're expecting. 4 | This can be anywhere from less than 10 bucks a month to a couple of $100. 5 | You should checkout http://www.rackspace.com/ or perhaps Amazon EC2 6 | if youre running something big.. 7 | 8 | To unsubscribe yourself from this mailing list, send an email to: 9 | groupname-unsubscribe@egroups.com 10 | 11 | -------------------------------------------------------------------------------- /src/main/resources/ex6/emailSample2.txt: -------------------------------------------------------------------------------- 1 | Folks, 2 | 3 | my first time posting - have a bit of Unix experience, but am new to Linux. 4 | 5 | 6 | Just got a new PC at home - Dell box with Windows XP. Added a second hard disk 7 | for Linux. Partitioned the disk and have installed Suse 7.2 from CD, which went 8 | fine except it didn't pick up my monitor. 9 | 10 | I have a Dell branded E151FPp 15" LCD flat panel monitor and a nVidia GeForce4 11 | Ti4200 video card, both of which are probably too new to feature in Suse's default 12 | set. I downloaded a driver from the nVidia website and installed it using RPM. 13 | Then I ran Sax2 (as was recommended in some postings I found on the net), but 14 | it still doesn't feature my video card in the available list. What next? 15 | 16 | Another problem. I have a Dell branded keyboard and if I hit Caps-Lock twice, 17 | the whole machine crashes (in Linux, not Windows) - even the on/off switch is 18 | inactive, leaving me to reach for the power cable instead. 19 | 20 | If anyone can help me in any way with these probs., I'd be really grateful - 21 | I've searched the 'net but have run out of ideas. 22 | 23 | Or should I be going for a different version of Linux such as RedHat? Opinions 24 | welcome. 25 | 26 | Thanks a lot, 27 | Peter 28 | 29 | -- 30 | Irish Linux Users' Group: ilug@linux.ie 31 | http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information. 32 | List maintainer: listmaster@linux.ie 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/ex6/ex6data1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex6/ex6data1.mat -------------------------------------------------------------------------------- /src/main/resources/ex6/ex6data2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex6/ex6data2.mat -------------------------------------------------------------------------------- /src/main/resources/ex6/ex6data3.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex6/ex6data3.mat -------------------------------------------------------------------------------- /src/main/resources/ex6/spamSample1.txt: -------------------------------------------------------------------------------- 1 | Do You Want To Make $1000 Or More Per Week? 2 | 3 | 4 | 5 | If you are a motivated and qualified individual - I 6 | will personally demonstrate to you a system that will 7 | make you $1,000 per week or more! This is NOT mlm. 8 | 9 | 10 | 11 | Call our 24 hour pre-recorded number to get the 12 | details. 13 | 14 | 15 | 16 | 000-456-789 17 | 18 | 19 | 20 | I need people who want to make serious money. Make 21 | the call and get the facts. 22 | 23 | Invest 2 minutes in yourself now! 24 | 25 | 26 | 27 | 000-456-789 28 | 29 | 30 | 31 | Looking forward to your call and I will introduce you 32 | to people like yourself who 33 | are currently making $10,000 plus per week! 34 | 35 | 36 | 37 | 000-456-789 38 | 39 | 40 | 41 | 3484lJGv6-241lEaN9080lRmS6-271WxHo7524qiyT5-438rjUv5615hQcf0-662eiDB9057dMtVl72 42 | 43 | -------------------------------------------------------------------------------- /src/main/resources/ex6/spamSample2.txt: -------------------------------------------------------------------------------- 1 | Best Buy Viagra Generic Online 2 | 3 | Viagra 100mg x 60 Pills $125, Free Pills & Reorder Discount, Top Selling 100% Quality & Satisfaction guaranteed! 4 | 5 | We accept VISA, Master & E-Check Payments, 90000+ Satisfied Customers! 6 | http://medphysitcstech.ru 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/resources/ex6/spamTest.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex6/spamTest.mat -------------------------------------------------------------------------------- /src/main/resources/ex6/spamTrain.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex6/spamTrain.mat -------------------------------------------------------------------------------- /src/main/resources/ex6/vocab.txt: -------------------------------------------------------------------------------- 1 | 1 aa 2 | 2 ab 3 | 3 abil 4 | 4 abl 5 | 5 about 6 | 6 abov 7 | 7 absolut 8 | 8 abus 9 | 9 ac 10 | 10 accept 11 | 11 access 12 | 12 accord 13 | 13 account 14 | 14 achiev 15 | 15 acquir 16 | 16 across 17 | 17 act 18 | 18 action 19 | 19 activ 20 | 20 actual 21 | 21 ad 22 | 22 adam 23 | 23 add 24 | 24 addit 25 | 25 address 26 | 26 administr 27 | 27 adult 28 | 28 advanc 29 | 29 advantag 30 | 30 advertis 31 | 31 advic 32 | 32 advis 33 | 33 ae 34 | 34 af 35 | 35 affect 36 | 36 affili 37 | 37 afford 38 | 38 africa 39 | 39 after 40 | 40 ag 41 | 41 again 42 | 42 against 43 | 43 agenc 44 | 44 agent 45 | 45 ago 46 | 46 agre 47 | 47 agreement 48 | 48 aid 49 | 49 air 50 | 50 al 51 | 51 alb 52 | 52 align 53 | 53 all 54 | 54 allow 55 | 55 almost 56 | 56 alon 57 | 57 along 58 | 58 alreadi 59 | 59 alsa 60 | 60 also 61 | 61 altern 62 | 62 although 63 | 63 alwai 64 | 64 am 65 | 65 amaz 66 | 66 america 67 | 67 american 68 | 68 among 69 | 69 amount 70 | 70 amp 71 | 71 an 72 | 72 analysi 73 | 73 analyst 74 | 74 and 75 | 75 ani 76 | 76 anim 77 | 77 announc 78 | 78 annual 79 | 79 annuiti 80 | 80 anoth 81 | 81 answer 82 | 82 anti 83 | 83 anumb 84 | 84 anybodi 85 | 85 anymor 86 | 86 anyon 87 | 87 anyth 88 | 88 anywai 89 | 89 anywher 90 | 90 aol 91 | 91 ap 92 | 92 apolog 93 | 93 app 94 | 94 appar 95 | 95 appear 96 | 96 appl 97 | 97 appli 98 | 98 applic 99 | 99 appreci 100 | 100 approach 101 | 101 approv 102 | 102 apt 103 | 103 ar 104 | 104 archiv 105 | 105 area 106 | 106 aren 107 | 107 argument 108 | 108 arial 109 | 109 arm 110 | 110 around 111 | 111 arrai 112 | 112 arriv 113 | 113 art 114 | 114 articl 115 | 115 artist 116 | 116 as 117 | 117 ascii 118 | 118 ask 119 | 119 asset 120 | 120 assist 121 | 121 associ 122 | 122 assum 123 | 123 assur 124 | 124 at 125 | 125 atol 126 | 126 attach 127 | 127 attack 128 | 128 attempt 129 | 129 attent 130 | 130 attornei 131 | 131 attract 132 | 132 audio 133 | 133 aug 134 | 134 august 135 | 135 author 136 | 136 auto 137 | 137 autom 138 | 138 automat 139 | 139 avail 140 | 140 averag 141 | 141 avoid 142 | 142 awai 143 | 143 awar 144 | 144 award 145 | 145 ba 146 | 146 babi 147 | 147 back 148 | 148 background 149 | 149 backup 150 | 150 bad 151 | 151 balanc 152 | 152 ban 153 | 153 bank 154 | 154 bar 155 | 155 base 156 | 156 basenumb 157 | 157 basi 158 | 158 basic 159 | 159 bb 160 | 160 bc 161 | 161 bd 162 | 162 be 163 | 163 beat 164 | 164 beberg 165 | 165 becaus 166 | 166 becom 167 | 167 been 168 | 168 befor 169 | 169 begin 170 | 170 behalf 171 | 171 behavior 172 | 172 behind 173 | 173 believ 174 | 174 below 175 | 175 benefit 176 | 176 best 177 | 177 beta 178 | 178 better 179 | 179 between 180 | 180 bf 181 | 181 big 182 | 182 bill 183 | 183 billion 184 | 184 bin 185 | 185 binari 186 | 186 bit 187 | 187 black 188 | 188 blank 189 | 189 block 190 | 190 blog 191 | 191 blood 192 | 192 blue 193 | 193 bnumber 194 | 194 board 195 | 195 bodi 196 | 196 boi 197 | 197 bonu 198 | 198 book 199 | 199 boot 200 | 200 border 201 | 201 boss 202 | 202 boston 203 | 203 botan 204 | 204 both 205 | 205 bottl 206 | 206 bottom 207 | 207 boundari 208 | 208 box 209 | 209 brain 210 | 210 brand 211 | 211 break 212 | 212 brian 213 | 213 bring 214 | 214 broadcast 215 | 215 broker 216 | 216 browser 217 | 217 bug 218 | 218 bui 219 | 219 build 220 | 220 built 221 | 221 bulk 222 | 222 burn 223 | 223 bush 224 | 224 busi 225 | 225 but 226 | 226 button 227 | 227 by 228 | 228 byte 229 | 229 ca 230 | 230 cabl 231 | 231 cach 232 | 232 calcul 233 | 233 california 234 | 234 call 235 | 235 came 236 | 236 camera 237 | 237 campaign 238 | 238 can 239 | 239 canada 240 | 240 cannot 241 | 241 canon 242 | 242 capabl 243 | 243 capillari 244 | 244 capit 245 | 245 car 246 | 246 card 247 | 247 care 248 | 248 career 249 | 249 carri 250 | 250 cartridg 251 | 251 case 252 | 252 cash 253 | 253 cat 254 | 254 catch 255 | 255 categori 256 | 256 caus 257 | 257 cb 258 | 258 cc 259 | 259 cd 260 | 260 ce 261 | 261 cell 262 | 262 cent 263 | 263 center 264 | 264 central 265 | 265 centuri 266 | 266 ceo 267 | 267 certain 268 | 268 certainli 269 | 269 cf 270 | 270 challeng 271 | 271 chanc 272 | 272 chang 273 | 273 channel 274 | 274 char 275 | 275 charact 276 | 276 charg 277 | 277 charset 278 | 278 chat 279 | 279 cheap 280 | 280 check 281 | 281 cheer 282 | 282 chief 283 | 283 children 284 | 284 china 285 | 285 chip 286 | 286 choic 287 | 287 choos 288 | 288 chri 289 | 289 citi 290 | 290 citizen 291 | 291 civil 292 | 292 claim 293 | 293 class 294 | 294 classifi 295 | 295 clean 296 | 296 clear 297 | 297 clearli 298 | 298 click 299 | 299 client 300 | 300 close 301 | 301 clue 302 | 302 cnet 303 | 303 cnumber 304 | 304 co 305 | 305 code 306 | 306 collect 307 | 307 colleg 308 | 308 color 309 | 309 com 310 | 310 combin 311 | 311 come 312 | 312 comfort 313 | 313 command 314 | 314 comment 315 | 315 commentari 316 | 316 commerci 317 | 317 commiss 318 | 318 commit 319 | 319 common 320 | 320 commun 321 | 321 compani 322 | 322 compar 323 | 323 comparison 324 | 324 compat 325 | 325 compet 326 | 326 competit 327 | 327 compil 328 | 328 complet 329 | 329 comprehens 330 | 330 comput 331 | 331 concentr 332 | 332 concept 333 | 333 concern 334 | 334 condit 335 | 335 conf 336 | 336 confer 337 | 337 confid 338 | 338 confidenti 339 | 339 config 340 | 340 configur 341 | 341 confirm 342 | 342 conflict 343 | 343 confus 344 | 344 congress 345 | 345 connect 346 | 346 consid 347 | 347 consolid 348 | 348 constitut 349 | 349 construct 350 | 350 consult 351 | 351 consum 352 | 352 contact 353 | 353 contain 354 | 354 content 355 | 355 continu 356 | 356 contract 357 | 357 contribut 358 | 358 control 359 | 359 conveni 360 | 360 convers 361 | 361 convert 362 | 362 cool 363 | 363 cooper 364 | 364 copi 365 | 365 copyright 366 | 366 core 367 | 367 corpor 368 | 368 correct 369 | 369 correspond 370 | 370 cost 371 | 371 could 372 | 372 couldn 373 | 373 count 374 | 374 countri 375 | 375 coupl 376 | 376 cours 377 | 377 court 378 | 378 cover 379 | 379 coverag 380 | 380 crash 381 | 381 creat 382 | 382 creativ 383 | 383 credit 384 | 384 critic 385 | 385 cross 386 | 386 cultur 387 | 387 current 388 | 388 custom 389 | 389 cut 390 | 390 cv 391 | 391 da 392 | 392 dagga 393 | 393 dai 394 | 394 daili 395 | 395 dan 396 | 396 danger 397 | 397 dark 398 | 398 data 399 | 399 databas 400 | 400 datapow 401 | 401 date 402 | 402 dave 403 | 403 david 404 | 404 dc 405 | 405 de 406 | 406 dead 407 | 407 deal 408 | 408 dear 409 | 409 death 410 | 410 debt 411 | 411 decad 412 | 412 decid 413 | 413 decis 414 | 414 declar 415 | 415 declin 416 | 416 decor 417 | 417 default 418 | 418 defend 419 | 419 defens 420 | 420 defin 421 | 421 definit 422 | 422 degre 423 | 423 delai 424 | 424 delet 425 | 425 deliv 426 | 426 deliveri 427 | 427 dell 428 | 428 demand 429 | 429 democrat 430 | 430 depart 431 | 431 depend 432 | 432 deposit 433 | 433 describ 434 | 434 descript 435 | 435 deserv 436 | 436 design 437 | 437 desir 438 | 438 desktop 439 | 439 despit 440 | 440 detail 441 | 441 detect 442 | 442 determin 443 | 443 dev 444 | 444 devel 445 | 445 develop 446 | 446 devic 447 | 447 di 448 | 448 dial 449 | 449 did 450 | 450 didn 451 | 451 diet 452 | 452 differ 453 | 453 difficult 454 | 454 digit 455 | 455 direct 456 | 456 directli 457 | 457 director 458 | 458 directori 459 | 459 disabl 460 | 460 discount 461 | 461 discov 462 | 462 discoveri 463 | 463 discuss 464 | 464 disk 465 | 465 displai 466 | 466 disposit 467 | 467 distanc 468 | 468 distribut 469 | 469 dn 470 | 470 dnumber 471 | 471 do 472 | 472 doc 473 | 473 document 474 | 474 doe 475 | 475 doer 476 | 476 doesn 477 | 477 dollar 478 | 478 dollarac 479 | 479 dollarnumb 480 | 480 domain 481 | 481 don 482 | 482 done 483 | 483 dont 484 | 484 doubl 485 | 485 doubt 486 | 486 down 487 | 487 download 488 | 488 dr 489 | 489 draw 490 | 490 dream 491 | 491 drive 492 | 492 driver 493 | 493 drop 494 | 494 drug 495 | 495 due 496 | 496 dure 497 | 497 dvd 498 | 498 dw 499 | 499 dynam 500 | 500 ea 501 | 501 each 502 | 502 earli 503 | 503 earlier 504 | 504 earn 505 | 505 earth 506 | 506 easi 507 | 507 easier 508 | 508 easili 509 | 509 eat 510 | 510 eb 511 | 511 ebai 512 | 512 ec 513 | 513 echo 514 | 514 econom 515 | 515 economi 516 | 516 ed 517 | 517 edg 518 | 518 edit 519 | 519 editor 520 | 520 educ 521 | 521 eff 522 | 522 effect 523 | 523 effici 524 | 524 effort 525 | 525 either 526 | 526 el 527 | 527 electron 528 | 528 elimin 529 | 529 els 530 | 530 email 531 | 531 emailaddr 532 | 532 emerg 533 | 533 empir 534 | 534 employ 535 | 535 employe 536 | 536 en 537 | 537 enabl 538 | 538 encod 539 | 539 encourag 540 | 540 end 541 | 541 enemi 542 | 542 enenkio 543 | 543 energi 544 | 544 engin 545 | 545 english 546 | 546 enhanc 547 | 547 enjoi 548 | 548 enough 549 | 549 ensur 550 | 550 enter 551 | 551 enterpris 552 | 552 entertain 553 | 553 entir 554 | 554 entri 555 | 555 enumb 556 | 556 environ 557 | 557 equal 558 | 558 equip 559 | 559 equival 560 | 560 error 561 | 561 especi 562 | 562 essenti 563 | 563 establish 564 | 564 estat 565 | 565 estim 566 | 566 et 567 | 567 etc 568 | 568 euro 569 | 569 europ 570 | 570 european 571 | 571 even 572 | 572 event 573 | 573 eventu 574 | 574 ever 575 | 575 everi 576 | 576 everyon 577 | 577 everyth 578 | 578 evid 579 | 579 evil 580 | 580 exactli 581 | 581 exampl 582 | 582 excel 583 | 583 except 584 | 584 exchang 585 | 585 excit 586 | 586 exclus 587 | 587 execut 588 | 588 exercis 589 | 589 exist 590 | 590 exmh 591 | 591 expand 592 | 592 expect 593 | 593 expens 594 | 594 experi 595 | 595 expert 596 | 596 expir 597 | 597 explain 598 | 598 explor 599 | 599 express 600 | 600 extend 601 | 601 extens 602 | 602 extra 603 | 603 extract 604 | 604 extrem 605 | 605 ey 606 | 606 fa 607 | 607 face 608 | 608 fact 609 | 609 factor 610 | 610 fail 611 | 611 fair 612 | 612 fall 613 | 613 fals 614 | 614 famili 615 | 615 faq 616 | 616 far 617 | 617 fast 618 | 618 faster 619 | 619 fastest 620 | 620 fat 621 | 621 father 622 | 622 favorit 623 | 623 fax 624 | 624 fb 625 | 625 fd 626 | 626 featur 627 | 627 feder 628 | 628 fee 629 | 629 feed 630 | 630 feedback 631 | 631 feel 632 | 632 femal 633 | 633 few 634 | 634 ffffff 635 | 635 ffnumber 636 | 636 field 637 | 637 fight 638 | 638 figur 639 | 639 file 640 | 640 fill 641 | 641 film 642 | 642 filter 643 | 643 final 644 | 644 financ 645 | 645 financi 646 | 646 find 647 | 647 fine 648 | 648 finish 649 | 649 fire 650 | 650 firewal 651 | 651 firm 652 | 652 first 653 | 653 fit 654 | 654 five 655 | 655 fix 656 | 656 flag 657 | 657 flash 658 | 658 flow 659 | 659 fnumber 660 | 660 focu 661 | 661 folder 662 | 662 folk 663 | 663 follow 664 | 664 font 665 | 665 food 666 | 666 for 667 | 667 forc 668 | 668 foreign 669 | 669 forev 670 | 670 forget 671 | 671 fork 672 | 672 form 673 | 673 format 674 | 674 former 675 | 675 fortun 676 | 676 forward 677 | 677 found 678 | 678 foundat 679 | 679 four 680 | 680 franc 681 | 681 free 682 | 682 freedom 683 | 683 french 684 | 684 freshrpm 685 | 685 fri 686 | 686 fridai 687 | 687 friend 688 | 688 from 689 | 689 front 690 | 690 ftoc 691 | 691 ftp 692 | 692 full 693 | 693 fulli 694 | 694 fun 695 | 695 function 696 | 696 fund 697 | 697 further 698 | 698 futur 699 | 699 ga 700 | 700 gain 701 | 701 game 702 | 702 gari 703 | 703 garrigu 704 | 704 gave 705 | 705 gcc 706 | 706 geek 707 | 707 gener 708 | 708 get 709 | 709 gif 710 | 710 gift 711 | 711 girl 712 | 712 give 713 | 713 given 714 | 714 global 715 | 715 gnome 716 | 716 gnu 717 | 717 gnupg 718 | 718 go 719 | 719 goal 720 | 720 god 721 | 721 goe 722 | 722 gold 723 | 723 gone 724 | 724 good 725 | 725 googl 726 | 726 got 727 | 727 govern 728 | 728 gpl 729 | 729 grand 730 | 730 grant 731 | 731 graphic 732 | 732 great 733 | 733 greater 734 | 734 ground 735 | 735 group 736 | 736 grow 737 | 737 growth 738 | 738 gt 739 | 739 guarante 740 | 740 guess 741 | 741 gui 742 | 742 guid 743 | 743 ha 744 | 744 hack 745 | 745 had 746 | 746 half 747 | 747 ham 748 | 748 hand 749 | 749 handl 750 | 750 happen 751 | 751 happi 752 | 752 hard 753 | 753 hardwar 754 | 754 hat 755 | 755 hate 756 | 756 have 757 | 757 haven 758 | 758 he 759 | 759 head 760 | 760 header 761 | 761 headlin 762 | 762 health 763 | 763 hear 764 | 764 heard 765 | 765 heart 766 | 766 heaven 767 | 767 hei 768 | 768 height 769 | 769 held 770 | 770 hello 771 | 771 help 772 | 772 helvetica 773 | 773 her 774 | 774 herba 775 | 775 here 776 | 776 hermio 777 | 777 hettinga 778 | 778 hi 779 | 779 high 780 | 780 higher 781 | 781 highli 782 | 782 highlight 783 | 783 him 784 | 784 histori 785 | 785 hit 786 | 786 hold 787 | 787 home 788 | 788 honor 789 | 789 hope 790 | 790 host 791 | 791 hot 792 | 792 hour 793 | 793 hous 794 | 794 how 795 | 795 howev 796 | 796 hp 797 | 797 html 798 | 798 http 799 | 799 httpaddr 800 | 800 huge 801 | 801 human 802 | 802 hundr 803 | 803 ibm 804 | 804 id 805 | 805 idea 806 | 806 ident 807 | 807 identifi 808 | 808 idnumb 809 | 809 ie 810 | 810 if 811 | 811 ignor 812 | 812 ii 813 | 813 iii 814 | 814 iiiiiiihnumberjnumberhnumberjnumberhnumb 815 | 815 illeg 816 | 816 im 817 | 817 imag 818 | 818 imagin 819 | 819 immedi 820 | 820 impact 821 | 821 implement 822 | 822 import 823 | 823 impress 824 | 824 improv 825 | 825 in 826 | 826 inc 827 | 827 includ 828 | 828 incom 829 | 829 increas 830 | 830 incred 831 | 831 inde 832 | 832 independ 833 | 833 index 834 | 834 india 835 | 835 indian 836 | 836 indic 837 | 837 individu 838 | 838 industri 839 | 839 info 840 | 840 inform 841 | 841 initi 842 | 842 inlin 843 | 843 innov 844 | 844 input 845 | 845 insert 846 | 846 insid 847 | 847 instal 848 | 848 instanc 849 | 849 instant 850 | 850 instead 851 | 851 institut 852 | 852 instruct 853 | 853 insur 854 | 854 int 855 | 855 integr 856 | 856 intel 857 | 857 intellig 858 | 858 intend 859 | 859 interact 860 | 860 interest 861 | 861 interfac 862 | 862 intern 863 | 863 internet 864 | 864 interview 865 | 865 into 866 | 866 intro 867 | 867 introduc 868 | 868 inumb 869 | 869 invest 870 | 870 investig 871 | 871 investor 872 | 872 invok 873 | 873 involv 874 | 874 ip 875 | 875 ireland 876 | 876 irish 877 | 877 is 878 | 878 island 879 | 879 isn 880 | 880 iso 881 | 881 isp 882 | 882 issu 883 | 883 it 884 | 884 item 885 | 885 itself 886 | 886 jabber 887 | 887 jame 888 | 888 java 889 | 889 jim 890 | 890 jnumberiiiiiiihepihepihf 891 | 891 job 892 | 892 joe 893 | 893 john 894 | 894 join 895 | 895 journal 896 | 896 judg 897 | 897 judgment 898 | 898 jul 899 | 899 juli 900 | 900 jump 901 | 901 june 902 | 902 just 903 | 903 justin 904 | 904 keep 905 | 905 kei 906 | 906 kept 907 | 907 kernel 908 | 908 kevin 909 | 909 keyboard 910 | 910 kid 911 | 911 kill 912 | 912 kind 913 | 913 king 914 | 914 kingdom 915 | 915 knew 916 | 916 know 917 | 917 knowledg 918 | 918 known 919 | 919 la 920 | 920 lack 921 | 921 land 922 | 922 languag 923 | 923 laptop 924 | 924 larg 925 | 925 larger 926 | 926 largest 927 | 927 laser 928 | 928 last 929 | 929 late 930 | 930 later 931 | 931 latest 932 | 932 launch 933 | 933 law 934 | 934 lawrenc 935 | 935 le 936 | 936 lead 937 | 937 leader 938 | 938 learn 939 | 939 least 940 | 940 leav 941 | 941 left 942 | 942 legal 943 | 943 lender 944 | 944 length 945 | 945 less 946 | 946 lesson 947 | 947 let 948 | 948 letter 949 | 949 level 950 | 950 lib 951 | 951 librari 952 | 952 licens 953 | 953 life 954 | 954 lifetim 955 | 955 light 956 | 956 like 957 | 957 limit 958 | 958 line 959 | 959 link 960 | 960 linux 961 | 961 list 962 | 962 listen 963 | 963 littl 964 | 964 live 965 | 965 ll 966 | 966 lo 967 | 967 load 968 | 968 loan 969 | 969 local 970 | 970 locat 971 | 971 lock 972 | 972 lockergnom 973 | 973 log 974 | 974 long 975 | 975 longer 976 | 976 look 977 | 977 lose 978 | 978 loss 979 | 979 lost 980 | 980 lot 981 | 981 love 982 | 982 low 983 | 983 lower 984 | 984 lowest 985 | 985 lt 986 | 986 ma 987 | 987 mac 988 | 988 machin 989 | 989 made 990 | 990 magazin 991 | 991 mai 992 | 992 mail 993 | 993 mailer 994 | 994 main 995 | 995 maintain 996 | 996 major 997 | 997 make 998 | 998 maker 999 | 999 male 1000 | 1000 man 1001 | 1001 manag 1002 | 1002 mani 1003 | 1003 manual 1004 | 1004 manufactur 1005 | 1005 map 1006 | 1006 march 1007 | 1007 margin 1008 | 1008 mark 1009 | 1009 market 1010 | 1010 marshal 1011 | 1011 mass 1012 | 1012 master 1013 | 1013 match 1014 | 1014 materi 1015 | 1015 matter 1016 | 1016 matthia 1017 | 1017 mayb 1018 | 1018 me 1019 | 1019 mean 1020 | 1020 measur 1021 | 1021 mechan 1022 | 1022 media 1023 | 1023 medic 1024 | 1024 meet 1025 | 1025 member 1026 | 1026 membership 1027 | 1027 memori 1028 | 1028 men 1029 | 1029 mention 1030 | 1030 menu 1031 | 1031 merchant 1032 | 1032 messag 1033 | 1033 method 1034 | 1034 mh 1035 | 1035 michael 1036 | 1036 microsoft 1037 | 1037 middl 1038 | 1038 might 1039 | 1039 mike 1040 | 1040 mile 1041 | 1041 militari 1042 | 1042 million 1043 | 1043 mime 1044 | 1044 mind 1045 | 1045 mine 1046 | 1046 mini 1047 | 1047 minimum 1048 | 1048 minut 1049 | 1049 miss 1050 | 1050 mistak 1051 | 1051 mobil 1052 | 1052 mode 1053 | 1053 model 1054 | 1054 modem 1055 | 1055 modifi 1056 | 1056 modul 1057 | 1057 moment 1058 | 1058 mon 1059 | 1059 mondai 1060 | 1060 monei 1061 | 1061 monitor 1062 | 1062 month 1063 | 1063 monthli 1064 | 1064 more 1065 | 1065 morn 1066 | 1066 mortgag 1067 | 1067 most 1068 | 1068 mostli 1069 | 1069 mother 1070 | 1070 motiv 1071 | 1071 move 1072 | 1072 movi 1073 | 1073 mpnumber 1074 | 1074 mr 1075 | 1075 ms 1076 | 1076 msg 1077 | 1077 much 1078 | 1078 multi 1079 | 1079 multipart 1080 | 1080 multipl 1081 | 1081 murphi 1082 | 1082 music 1083 | 1083 must 1084 | 1084 my 1085 | 1085 myself 1086 | 1086 name 1087 | 1087 nation 1088 | 1088 natur 1089 | 1089 nbsp 1090 | 1090 near 1091 | 1091 nearli 1092 | 1092 necessari 1093 | 1093 need 1094 | 1094 neg 1095 | 1095 net 1096 | 1096 netscap 1097 | 1097 network 1098 | 1098 never 1099 | 1099 new 1100 | 1100 newslett 1101 | 1101 next 1102 | 1102 nextpart 1103 | 1103 nice 1104 | 1104 nigeria 1105 | 1105 night 1106 | 1106 no 1107 | 1107 nobodi 1108 | 1108 non 1109 | 1109 none 1110 | 1110 nor 1111 | 1111 normal 1112 | 1112 north 1113 | 1113 not 1114 | 1114 note 1115 | 1115 noth 1116 | 1116 notic 1117 | 1117 now 1118 | 1118 nt 1119 | 1119 null 1120 | 1120 number 1121 | 1121 numbera 1122 | 1122 numberam 1123 | 1123 numberanumb 1124 | 1124 numberb 1125 | 1125 numberbit 1126 | 1126 numberc 1127 | 1127 numbercb 1128 | 1128 numbercbr 1129 | 1129 numbercfont 1130 | 1130 numbercli 1131 | 1131 numbercnumb 1132 | 1132 numbercp 1133 | 1133 numberctd 1134 | 1134 numberd 1135 | 1135 numberdari 1136 | 1136 numberdnumb 1137 | 1137 numberenumb 1138 | 1138 numberf 1139 | 1139 numberfb 1140 | 1140 numberff 1141 | 1141 numberffont 1142 | 1142 numberfp 1143 | 1143 numberftd 1144 | 1144 numberk 1145 | 1145 numberm 1146 | 1146 numbermb 1147 | 1147 numberp 1148 | 1148 numberpd 1149 | 1149 numberpm 1150 | 1150 numberpx 1151 | 1151 numberst 1152 | 1152 numberth 1153 | 1153 numbertnumb 1154 | 1154 numberx 1155 | 1155 object 1156 | 1156 oblig 1157 | 1157 obtain 1158 | 1158 obvious 1159 | 1159 occur 1160 | 1160 oct 1161 | 1161 octob 1162 | 1162 of 1163 | 1163 off 1164 | 1164 offer 1165 | 1165 offic 1166 | 1166 offici 1167 | 1167 often 1168 | 1168 oh 1169 | 1169 ok 1170 | 1170 old 1171 | 1171 on 1172 | 1172 onc 1173 | 1173 onli 1174 | 1174 onlin 1175 | 1175 open 1176 | 1176 oper 1177 | 1177 opinion 1178 | 1178 opportun 1179 | 1179 opt 1180 | 1180 optim 1181 | 1181 option 1182 | 1182 or 1183 | 1183 order 1184 | 1184 org 1185 | 1185 organ 1186 | 1186 origin 1187 | 1187 os 1188 | 1188 osdn 1189 | 1189 other 1190 | 1190 otherwis 1191 | 1191 our 1192 | 1192 out 1193 | 1193 outlook 1194 | 1194 output 1195 | 1195 outsid 1196 | 1196 over 1197 | 1197 own 1198 | 1198 owner 1199 | 1199 oz 1200 | 1200 pacif 1201 | 1201 pack 1202 | 1202 packag 1203 | 1203 page 1204 | 1204 pai 1205 | 1205 paid 1206 | 1206 pain 1207 | 1207 palm 1208 | 1208 panel 1209 | 1209 paper 1210 | 1210 paragraph 1211 | 1211 parent 1212 | 1212 part 1213 | 1213 parti 1214 | 1214 particip 1215 | 1215 particular 1216 | 1216 particularli 1217 | 1217 partit 1218 | 1218 partner 1219 | 1219 pass 1220 | 1220 password 1221 | 1221 past 1222 | 1222 patch 1223 | 1223 patent 1224 | 1224 path 1225 | 1225 pattern 1226 | 1226 paul 1227 | 1227 payment 1228 | 1228 pc 1229 | 1229 peac 1230 | 1230 peopl 1231 | 1231 per 1232 | 1232 percent 1233 | 1233 percentag 1234 | 1234 perfect 1235 | 1235 perfectli 1236 | 1236 perform 1237 | 1237 perhap 1238 | 1238 period 1239 | 1239 perl 1240 | 1240 perman 1241 | 1241 permiss 1242 | 1242 person 1243 | 1243 pgp 1244 | 1244 phone 1245 | 1245 photo 1246 | 1246 php 1247 | 1247 phrase 1248 | 1248 physic 1249 | 1249 pick 1250 | 1250 pictur 1251 | 1251 piec 1252 | 1252 piiiiiiii 1253 | 1253 pipe 1254 | 1254 pjnumber 1255 | 1255 place 1256 | 1256 plai 1257 | 1257 plain 1258 | 1258 plan 1259 | 1259 planet 1260 | 1260 plant 1261 | 1261 planta 1262 | 1262 platform 1263 | 1263 player 1264 | 1264 pleas 1265 | 1265 plu 1266 | 1266 plug 1267 | 1267 pm 1268 | 1268 pocket 1269 | 1269 point 1270 | 1270 polic 1271 | 1271 polici 1272 | 1272 polit 1273 | 1273 poor 1274 | 1274 pop 1275 | 1275 popul 1276 | 1276 popular 1277 | 1277 port 1278 | 1278 posit 1279 | 1279 possibl 1280 | 1280 post 1281 | 1281 potenti 1282 | 1282 pound 1283 | 1283 powel 1284 | 1284 power 1285 | 1285 powershot 1286 | 1286 practic 1287 | 1287 pre 1288 | 1288 predict 1289 | 1289 prefer 1290 | 1290 premium 1291 | 1291 prepar 1292 | 1292 present 1293 | 1293 presid 1294 | 1294 press 1295 | 1295 pretti 1296 | 1296 prevent 1297 | 1297 previou 1298 | 1298 previous 1299 | 1299 price 1300 | 1300 principl 1301 | 1301 print 1302 | 1302 printabl 1303 | 1303 printer 1304 | 1304 privaci 1305 | 1305 privat 1306 | 1306 prize 1307 | 1307 pro 1308 | 1308 probabl 1309 | 1309 problem 1310 | 1310 procedur 1311 | 1311 process 1312 | 1312 processor 1313 | 1313 procmail 1314 | 1314 produc 1315 | 1315 product 1316 | 1316 profession 1317 | 1317 profil 1318 | 1318 profit 1319 | 1319 program 1320 | 1320 programm 1321 | 1321 progress 1322 | 1322 project 1323 | 1323 promis 1324 | 1324 promot 1325 | 1325 prompt 1326 | 1326 properti 1327 | 1327 propos 1328 | 1328 proprietari 1329 | 1329 prospect 1330 | 1330 protect 1331 | 1331 protocol 1332 | 1332 prove 1333 | 1333 proven 1334 | 1334 provid 1335 | 1335 proxi 1336 | 1336 pub 1337 | 1337 public 1338 | 1338 publish 1339 | 1339 pudg 1340 | 1340 pull 1341 | 1341 purchas 1342 | 1342 purpos 1343 | 1343 put 1344 | 1344 python 1345 | 1345 qnumber 1346 | 1346 qualifi 1347 | 1347 qualiti 1348 | 1348 quarter 1349 | 1349 question 1350 | 1350 quick 1351 | 1351 quickli 1352 | 1352 quit 1353 | 1353 quot 1354 | 1354 radio 1355 | 1355 ragga 1356 | 1356 rais 1357 | 1357 random 1358 | 1358 rang 1359 | 1359 rate 1360 | 1360 rather 1361 | 1361 ratio 1362 | 1362 razor 1363 | 1363 razornumb 1364 | 1364 re 1365 | 1365 reach 1366 | 1366 read 1367 | 1367 reader 1368 | 1368 readi 1369 | 1369 real 1370 | 1370 realiz 1371 | 1371 realli 1372 | 1372 reason 1373 | 1373 receiv 1374 | 1374 recent 1375 | 1375 recipi 1376 | 1376 recommend 1377 | 1377 record 1378 | 1378 red 1379 | 1379 redhat 1380 | 1380 reduc 1381 | 1381 refer 1382 | 1382 refin 1383 | 1383 reg 1384 | 1384 regard 1385 | 1385 region 1386 | 1386 regist 1387 | 1387 regul 1388 | 1388 regular 1389 | 1389 rel 1390 | 1390 relat 1391 | 1391 relationship 1392 | 1392 releas 1393 | 1393 relev 1394 | 1394 reliabl 1395 | 1395 remain 1396 | 1396 rememb 1397 | 1397 remot 1398 | 1398 remov 1399 | 1399 replac 1400 | 1400 repli 1401 | 1401 report 1402 | 1402 repositori 1403 | 1403 repres 1404 | 1404 republ 1405 | 1405 request 1406 | 1406 requir 1407 | 1407 research 1408 | 1408 reserv 1409 | 1409 resid 1410 | 1410 resourc 1411 | 1411 respect 1412 | 1412 respond 1413 | 1413 respons 1414 | 1414 rest 1415 | 1415 result 1416 | 1416 retail 1417 | 1417 return 1418 | 1418 reveal 1419 | 1419 revenu 1420 | 1420 revers 1421 | 1421 review 1422 | 1422 revok 1423 | 1423 rh 1424 | 1424 rich 1425 | 1425 right 1426 | 1426 risk 1427 | 1427 road 1428 | 1428 robert 1429 | 1429 rock 1430 | 1430 role 1431 | 1431 roll 1432 | 1432 rom 1433 | 1433 roman 1434 | 1434 room 1435 | 1435 root 1436 | 1436 round 1437 | 1437 rpm 1438 | 1438 rss 1439 | 1439 rule 1440 | 1440 run 1441 | 1441 sa 1442 | 1442 safe 1443 | 1443 sai 1444 | 1444 said 1445 | 1445 sale 1446 | 1446 same 1447 | 1447 sampl 1448 | 1448 san 1449 | 1449 saou 1450 | 1450 sat 1451 | 1451 satellit 1452 | 1452 save 1453 | 1453 saw 1454 | 1454 scan 1455 | 1455 schedul 1456 | 1456 school 1457 | 1457 scienc 1458 | 1458 score 1459 | 1459 screen 1460 | 1460 script 1461 | 1461 se 1462 | 1462 search 1463 | 1463 season 1464 | 1464 second 1465 | 1465 secret 1466 | 1466 section 1467 | 1467 secur 1468 | 1468 see 1469 | 1469 seed 1470 | 1470 seek 1471 | 1471 seem 1472 | 1472 seen 1473 | 1473 select 1474 | 1474 self 1475 | 1475 sell 1476 | 1476 seminar 1477 | 1477 send 1478 | 1478 sender 1479 | 1479 sendmail 1480 | 1480 senior 1481 | 1481 sens 1482 | 1482 sensit 1483 | 1483 sent 1484 | 1484 sep 1485 | 1485 separ 1486 | 1486 septemb 1487 | 1487 sequenc 1488 | 1488 seri 1489 | 1489 serif 1490 | 1490 seriou 1491 | 1491 serv 1492 | 1492 server 1493 | 1493 servic 1494 | 1494 set 1495 | 1495 setup 1496 | 1496 seven 1497 | 1497 seventh 1498 | 1498 sever 1499 | 1499 sex 1500 | 1500 sexual 1501 | 1501 sf 1502 | 1502 shape 1503 | 1503 share 1504 | 1504 she 1505 | 1505 shell 1506 | 1506 ship 1507 | 1507 shop 1508 | 1508 short 1509 | 1509 shot 1510 | 1510 should 1511 | 1511 show 1512 | 1512 side 1513 | 1513 sign 1514 | 1514 signatur 1515 | 1515 signific 1516 | 1516 similar 1517 | 1517 simpl 1518 | 1518 simpli 1519 | 1519 sinc 1520 | 1520 sincer 1521 | 1521 singl 1522 | 1522 sit 1523 | 1523 site 1524 | 1524 situat 1525 | 1525 six 1526 | 1526 size 1527 | 1527 skeptic 1528 | 1528 skill 1529 | 1529 skin 1530 | 1530 skip 1531 | 1531 sleep 1532 | 1532 slow 1533 | 1533 small 1534 | 1534 smart 1535 | 1535 smoke 1536 | 1536 smtp 1537 | 1537 snumber 1538 | 1538 so 1539 | 1539 social 1540 | 1540 societi 1541 | 1541 softwar 1542 | 1542 sold 1543 | 1543 solut 1544 | 1544 solv 1545 | 1545 some 1546 | 1546 someon 1547 | 1547 someth 1548 | 1548 sometim 1549 | 1549 son 1550 | 1550 song 1551 | 1551 soni 1552 | 1552 soon 1553 | 1553 sorri 1554 | 1554 sort 1555 | 1555 sound 1556 | 1556 sourc 1557 | 1557 south 1558 | 1558 space 1559 | 1559 spain 1560 | 1560 spam 1561 | 1561 spamassassin 1562 | 1562 spamd 1563 | 1563 spammer 1564 | 1564 speak 1565 | 1565 spec 1566 | 1566 special 1567 | 1567 specif 1568 | 1568 specifi 1569 | 1569 speech 1570 | 1570 speed 1571 | 1571 spend 1572 | 1572 sponsor 1573 | 1573 sport 1574 | 1574 spot 1575 | 1575 src 1576 | 1576 ssh 1577 | 1577 st 1578 | 1578 stabl 1579 | 1579 staff 1580 | 1580 stai 1581 | 1581 stand 1582 | 1582 standard 1583 | 1583 star 1584 | 1584 start 1585 | 1585 state 1586 | 1586 statement 1587 | 1587 statu 1588 | 1588 step 1589 | 1589 steve 1590 | 1590 still 1591 | 1591 stock 1592 | 1592 stop 1593 | 1593 storag 1594 | 1594 store 1595 | 1595 stori 1596 | 1596 strategi 1597 | 1597 stream 1598 | 1598 street 1599 | 1599 string 1600 | 1600 strip 1601 | 1601 strong 1602 | 1602 structur 1603 | 1603 studi 1604 | 1604 stuff 1605 | 1605 stupid 1606 | 1606 style 1607 | 1607 subject 1608 | 1608 submit 1609 | 1609 subscrib 1610 | 1610 subscript 1611 | 1611 substanti 1612 | 1612 success 1613 | 1613 such 1614 | 1614 suffer 1615 | 1615 suggest 1616 | 1616 suit 1617 | 1617 sum 1618 | 1618 summari 1619 | 1619 summer 1620 | 1620 sun 1621 | 1621 super 1622 | 1622 suppli 1623 | 1623 support 1624 | 1624 suppos 1625 | 1625 sure 1626 | 1626 surpris 1627 | 1627 suse 1628 | 1628 suspect 1629 | 1629 sweet 1630 | 1630 switch 1631 | 1631 system 1632 | 1632 tab 1633 | 1633 tabl 1634 | 1634 tablet 1635 | 1635 tag 1636 | 1636 take 1637 | 1637 taken 1638 | 1638 talk 1639 | 1639 tape 1640 | 1640 target 1641 | 1641 task 1642 | 1642 tax 1643 | 1643 teach 1644 | 1644 team 1645 | 1645 tech 1646 | 1646 technic 1647 | 1647 techniqu 1648 | 1648 technolog 1649 | 1649 tel 1650 | 1650 telecom 1651 | 1651 telephon 1652 | 1652 tell 1653 | 1653 temperatur 1654 | 1654 templ 1655 | 1655 ten 1656 | 1656 term 1657 | 1657 termin 1658 | 1658 terror 1659 | 1659 terrorist 1660 | 1660 test 1661 | 1661 texa 1662 | 1662 text 1663 | 1663 than 1664 | 1664 thank 1665 | 1665 that 1666 | 1666 the 1667 | 1667 thei 1668 | 1668 their 1669 | 1669 them 1670 | 1670 themselv 1671 | 1671 then 1672 | 1672 theori 1673 | 1673 there 1674 | 1674 therefor 1675 | 1675 these 1676 | 1676 thi 1677 | 1677 thing 1678 | 1678 think 1679 | 1679 thinkgeek 1680 | 1680 third 1681 | 1681 those 1682 | 1682 though 1683 | 1683 thought 1684 | 1684 thousand 1685 | 1685 thread 1686 | 1686 threat 1687 | 1687 three 1688 | 1688 through 1689 | 1689 thu 1690 | 1690 thursdai 1691 | 1691 ti 1692 | 1692 ticket 1693 | 1693 tim 1694 | 1694 time 1695 | 1695 tip 1696 | 1696 tire 1697 | 1697 titl 1698 | 1698 tm 1699 | 1699 to 1700 | 1700 todai 1701 | 1701 togeth 1702 | 1702 token 1703 | 1703 told 1704 | 1704 toll 1705 | 1705 tom 1706 | 1706 toner 1707 | 1707 toni 1708 | 1708 too 1709 | 1709 took 1710 | 1710 tool 1711 | 1711 top 1712 | 1712 topic 1713 | 1713 total 1714 | 1714 touch 1715 | 1715 toward 1716 | 1716 track 1717 | 1717 trade 1718 | 1718 tradit 1719 | 1719 traffic 1720 | 1720 train 1721 | 1721 transact 1722 | 1722 transfer 1723 | 1723 travel 1724 | 1724 treat 1725 | 1725 tree 1726 | 1726 tri 1727 | 1727 trial 1728 | 1728 trick 1729 | 1729 trip 1730 | 1730 troubl 1731 | 1731 true 1732 | 1732 truli 1733 | 1733 trust 1734 | 1734 truth 1735 | 1735 try 1736 | 1736 tue 1737 | 1737 tuesdai 1738 | 1738 turn 1739 | 1739 tv 1740 | 1740 two 1741 | 1741 type 1742 | 1742 uk 1743 | 1743 ultim 1744 | 1744 un 1745 | 1745 under 1746 | 1746 understand 1747 | 1747 unfortun 1748 | 1748 uniqu 1749 | 1749 unison 1750 | 1750 unit 1751 | 1751 univers 1752 | 1752 unix 1753 | 1753 unless 1754 | 1754 unlik 1755 | 1755 unlimit 1756 | 1756 unseen 1757 | 1757 unsolicit 1758 | 1758 unsubscrib 1759 | 1759 until 1760 | 1760 up 1761 | 1761 updat 1762 | 1762 upgrad 1763 | 1763 upon 1764 | 1764 urgent 1765 | 1765 url 1766 | 1766 us 1767 | 1767 usa 1768 | 1768 usag 1769 | 1769 usb 1770 | 1770 usd 1771 | 1771 usdollarnumb 1772 | 1772 useless 1773 | 1773 user 1774 | 1774 usr 1775 | 1775 usual 1776 | 1776 util 1777 | 1777 vacat 1778 | 1778 valid 1779 | 1779 valu 1780 | 1780 valuabl 1781 | 1781 var 1782 | 1782 variabl 1783 | 1783 varieti 1784 | 1784 variou 1785 | 1785 ve 1786 | 1786 vendor 1787 | 1787 ventur 1788 | 1788 veri 1789 | 1789 verifi 1790 | 1790 version 1791 | 1791 via 1792 | 1792 video 1793 | 1793 view 1794 | 1794 virtual 1795 | 1795 visa 1796 | 1796 visit 1797 | 1797 visual 1798 | 1798 vnumber 1799 | 1799 voic 1800 | 1800 vote 1801 | 1801 vs 1802 | 1802 vulner 1803 | 1803 wa 1804 | 1804 wai 1805 | 1805 wait 1806 | 1806 wake 1807 | 1807 walk 1808 | 1808 wall 1809 | 1809 want 1810 | 1810 war 1811 | 1811 warm 1812 | 1812 warn 1813 | 1813 warranti 1814 | 1814 washington 1815 | 1815 wasn 1816 | 1816 wast 1817 | 1817 watch 1818 | 1818 water 1819 | 1819 we 1820 | 1820 wealth 1821 | 1821 weapon 1822 | 1822 web 1823 | 1823 weblog 1824 | 1824 websit 1825 | 1825 wed 1826 | 1826 wednesdai 1827 | 1827 week 1828 | 1828 weekli 1829 | 1829 weight 1830 | 1830 welcom 1831 | 1831 well 1832 | 1832 went 1833 | 1833 were 1834 | 1834 west 1835 | 1835 what 1836 | 1836 whatev 1837 | 1837 when 1838 | 1838 where 1839 | 1839 whether 1840 | 1840 which 1841 | 1841 while 1842 | 1842 white 1843 | 1843 whitelist 1844 | 1844 who 1845 | 1845 whole 1846 | 1846 whose 1847 | 1847 why 1848 | 1848 wi 1849 | 1849 wide 1850 | 1850 width 1851 | 1851 wife 1852 | 1852 will 1853 | 1853 william 1854 | 1854 win 1855 | 1855 window 1856 | 1856 wing 1857 | 1857 winner 1858 | 1858 wireless 1859 | 1859 wish 1860 | 1860 with 1861 | 1861 within 1862 | 1862 without 1863 | 1863 wnumberp 1864 | 1864 woman 1865 | 1865 women 1866 | 1866 won 1867 | 1867 wonder 1868 | 1868 word 1869 | 1869 work 1870 | 1870 worker 1871 | 1871 world 1872 | 1872 worldwid 1873 | 1873 worri 1874 | 1874 worst 1875 | 1875 worth 1876 | 1876 would 1877 | 1877 wouldn 1878 | 1878 write 1879 | 1879 written 1880 | 1880 wrong 1881 | 1881 wrote 1882 | 1882 www 1883 | 1883 ximian 1884 | 1884 xml 1885 | 1885 xp 1886 | 1886 yahoo 1887 | 1887 ye 1888 | 1888 yeah 1889 | 1889 year 1890 | 1890 yesterdai 1891 | 1891 yet 1892 | 1892 york 1893 | 1893 you 1894 | 1894 young 1895 | 1895 your 1896 | 1896 yourself 1897 | 1897 zdnet 1898 | 1898 zero 1899 | 1899 zip 1900 | -------------------------------------------------------------------------------- /src/main/resources/ex7/bird_small.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex7/bird_small.mat -------------------------------------------------------------------------------- /src/main/resources/ex7/bird_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex7/bird_small.png -------------------------------------------------------------------------------- /src/main/resources/ex7/ex7data1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex7/ex7data1.mat -------------------------------------------------------------------------------- /src/main/resources/ex7/ex7data2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex7/ex7data2.mat -------------------------------------------------------------------------------- /src/main/resources/ex7/ex7faces.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex7/ex7faces.mat -------------------------------------------------------------------------------- /src/main/resources/ex8/ex8_movieParams.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex8/ex8_movieParams.mat -------------------------------------------------------------------------------- /src/main/resources/ex8/ex8_movies.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex8/ex8_movies.mat -------------------------------------------------------------------------------- /src/main/resources/ex8/ex8data1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex8/ex8data1.mat -------------------------------------------------------------------------------- /src/main/resources/ex8/ex8data2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex8/ex8data2.mat -------------------------------------------------------------------------------- /src/main/resources/ex8/movie_ids.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpuheater/ml-coursera-scala/c2a194bec1aceb802d09e7d897d7a2d5eed710d8/src/main/resources/ex8/movie_ids.txt -------------------------------------------------------------------------------- /src/main/scala/com/cpuheater/ml/Ex1.scala: -------------------------------------------------------------------------------- 1 | package com.cpuheater.ml 2 | 3 | import org.datavec.api.records.reader.impl.csv.CSVRecordReader 4 | import org.datavec.api.split.FileSplit 5 | import org.datavec.api.util.ClassPathResource 6 | import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator 7 | import org.nd4j.linalg.api.buffer.DataBuffer 8 | import org.nd4j.linalg.api.buffer.util.DataTypeUtil 9 | import org.nd4j.linalg.api.ndarray.INDArray 10 | import org.nd4j.linalg.dataset.DataSet 11 | import org.nd4j.linalg.dataset.api.iterator.DataSetIterator 12 | import org.nd4j.linalg.factory.Nd4j 13 | import org.nd4j.linalg.ops.transforms.Transforms._ 14 | import org.nd4s.Implicits._ 15 | import org.nd4s.Evidences.float 16 | 17 | 18 | object Ex1 extends App with Ex1Util{ 19 | 20 | DataTypeUtil.setDTypeForContext(DataBuffer.Type.FLOAT) 21 | 22 | val numLinesToSkip = 0 23 | val delimiter = "," 24 | 25 | 26 | val alpha = 0.01f 27 | val iterations = 1500 28 | 29 | /** 30 | * y = theta1*x + theta0 31 | */ 32 | 33 | def linearRegressionWithOneVariable(): Unit = { 34 | println("linearRegressionWithOneVariable") 35 | val recordReader = new CSVRecordReader(numLinesToSkip, delimiter) 36 | recordReader.initialize(new FileSplit(new ClassPathResource("ex1/ex1data1.txt").getFile)) 37 | 38 | 39 | val iter:DataSetIterator = new RecordReaderDataSetIterator(recordReader, 1000000,1,1, true) 40 | val dataSet: DataSet = iter.next() 41 | 42 | 43 | val features = dataSet.getFeatures() 44 | val labels = dataSet.getLabels() 45 | val bias = Nd4j.onesLike(features) 46 | val featuresWithBias = Nd4j.concat(1, bias, features) 47 | val thetas = Nd4j.create(Array(0d, 0d)).reshape(1, 2) 48 | val computedThetas = computeGradient(featuresWithBias, labels, thetas, alpha, iterations) 49 | println(s"theta0 = ${computedThetas.getColumn(0)} theta1=${computedThetas.getColumn(1)}") 50 | 51 | } 52 | 53 | 54 | def linearRegressionWithMultipleVariables(): Unit = { 55 | println("linearRegressionWithMultipleVariables") 56 | val recordReader = new CSVRecordReader(numLinesToSkip, delimiter) 57 | recordReader.initialize(new FileSplit(new ClassPathResource("ex1/ex1data2.txt").getFile)) 58 | val iter: DataSetIterator = new RecordReaderDataSetIterator(recordReader, 1000000, 2, 2, true) 59 | val dataSet: DataSet = iter.next() 60 | val features = dataSet.getFeatures() 61 | val labels = dataSet.getLabels() 62 | 63 | val featuresNorm = normalize(features.dup()) 64 | val featuresNormWithBias = Nd4j.concat(1, Nd4j.ones(featuresNorm.rows(), 1), featuresNorm) 65 | val thetas = Nd4j.zeros(1, featuresNormWithBias.columns()) 66 | val computedThetas = computeGradient(featuresNormWithBias, labels, thetas, alpha, iterations) 67 | println(s"theta0 = ${computedThetas.getColumn(0)} theta1=${computedThetas.getColumn(1)} theta2=${computedThetas.getColumn(2)}") 68 | 69 | } 70 | 71 | linearRegressionWithOneVariable() 72 | 73 | linearRegressionWithMultipleVariables() 74 | 75 | } 76 | 77 | 78 | 79 | trait Ex1Util { 80 | 81 | def computeCost(features: INDArray, labels: INDArray, theta: INDArray): Float = { 82 | val r = pow((features.mmul(theta.T)) - labels, 2) 83 | val r2 = r.sum(0)/(2*r.length) 84 | r2.getFloat(0) 85 | } 86 | 87 | 88 | def computeGradient(features: INDArray, labels: INDArray, theta: INDArray, alpha: Float, iters: Int): INDArray ={ 89 | val temp = Nd4j.zerosLike(theta) 90 | val params = theta.length() 91 | val nbOfTrainingExamples = features.rows 92 | val updatedTheta = (0 to iters).foldLeft(temp)({ 93 | case (accum, i) => 94 | val error = features.mmul(accum.T) - labels 95 | (0 until params).map{ 96 | p => 97 | val r2 = accum.getFloat(0, p) - (error * features.getColumn(p)).sum(0).mul(alpha/nbOfTrainingExamples).getFloat(0) 98 | accum.put(0, p, r2) 99 | } 100 | println(s"Cost: ${computeCost(features, labels, accum)}") 101 | accum 102 | }) 103 | updatedTheta 104 | 105 | } 106 | 107 | /** 108 | * Feature normalization - subtract mean and divide by standard deviation 109 | * 110 | **/ 111 | 112 | def normalize(features: INDArray): INDArray = { 113 | val mean = features.mean(0) 114 | val std = features.std(0) 115 | val normFeatures = features.subRowVector(mean).divRowVector(std) 116 | normFeatures 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/scala/com/cpuheater/ml/Ex2.scala: -------------------------------------------------------------------------------- 1 | package com.cpuheater.ml 2 | 3 | import org.datavec.api.records.reader.impl.csv.CSVRecordReader 4 | import org.datavec.api.split.FileSplit 5 | import org.datavec.api.util.ClassPathResource 6 | import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator 7 | import org.nd4j.linalg.api.buffer.DataBuffer 8 | import org.nd4j.linalg.api.buffer.util.DataTypeUtil 9 | import org.nd4j.linalg.api.ndarray.INDArray 10 | import org.nd4j.linalg.api.ops.impl.accum.MatchCondition 11 | import org.nd4j.linalg.dataset.DataSet 12 | import org.nd4j.linalg.dataset.api.iterator.DataSetIterator 13 | import org.nd4j.linalg.factory.Nd4j 14 | import org.nd4j.linalg.indexing.conditions.Conditions 15 | import org.nd4j.linalg.ops.transforms.Transforms._ 16 | import org.nd4s.Implicits._ 17 | import org.nd4s.Evidences.float 18 | 19 | 20 | 21 | object Ex2 extends App with Ex2Util{ 22 | 23 | 24 | DataTypeUtil.setDTypeForContext(DataBuffer.Type.FLOAT) 25 | 26 | 27 | val numLinesToSkip = 0 28 | val delimiter = "," 29 | 30 | 31 | /** 32 | * We are not going to use any optimization procedure but we will use 33 | * gradient descent to find parameters thetas 34 | */ 35 | 36 | def logisticRegression(): Unit = { 37 | println("logisticRegression") 38 | val alpha = 0.001f 39 | val iterations = 90000 40 | 41 | val recordReader = new CSVRecordReader(numLinesToSkip, delimiter) 42 | recordReader.initialize(new FileSplit(new ClassPathResource("ex2/ex2data1.txt").getFile)) 43 | 44 | 45 | val iter:DataSetIterator = new RecordReaderDataSetIterator(recordReader, 1000000,2,2, true) 46 | val allData: DataSet = iter.next() 47 | 48 | 49 | val features = allData.getFeatures() 50 | val ones = Nd4j.ones(features.rows(), 1) 51 | val featuresWithBias = Nd4j.concat(1, ones, features) 52 | val labels = allData.getLabels() 53 | 54 | val computedThetas = computeGradient(featuresWithBias, labels, alpha, iterations) 55 | 56 | println(s"Computed thetas ${computedThetas}") 57 | 58 | val positive = filterPositiveOrNegative(featuresWithBias, labels, 1) 59 | val negative = filterPositiveOrNegative(featuresWithBias, labels, 0) 60 | 61 | 62 | 63 | val positivePredicted = Nd4j.getExecutioner().exec(new MatchCondition(hypothesis(positive, computedThetas), Conditions.greaterThan(0.5)),Integer.MAX_VALUE).getInt(0) 64 | 65 | val negativePredicted = Nd4j.getExecutioner().exec(new MatchCondition(hypothesis(negative, computedThetas), Conditions.lessThan(0.5)),Integer.MAX_VALUE).getInt(0) 66 | 67 | println(s"Accuracy: ${(positivePredicted.toDouble + negativePredicted.toDouble)/featuresWithBias.rows()}") 68 | 69 | } 70 | 71 | 72 | 73 | def regularizedLogisticRegression(): Unit = { 74 | println("regularizedLogisticRegression") 75 | val alpha = 15f 76 | val iterations = 100000 77 | println("regularizedLogisticRegression") 78 | val recordReader = new CSVRecordReader(numLinesToSkip, delimiter) 79 | recordReader.initialize(new FileSplit(new ClassPathResource("ex2/ex2data2.txt").getFile)) 80 | val iter:DataSetIterator = new RecordReaderDataSetIterator(recordReader, 1000000,2,2, true) 81 | val allData: DataSet = iter.next() 82 | val features = allData.getFeatures() 83 | val ones = Nd4j.ones(features.rows(), 1) 84 | val featuresWithBias = Nd4j.concat(1, ones, features) 85 | val labels = allData.getLabels() 86 | 87 | val featuresWithBiasMap = mapFeatures(featuresWithBias(->,1),featuresWithBias(->,2)) 88 | 89 | val computedThetas = computeGradient(featuresWithBiasMap, labels, alpha, iterations, lambda = 1) 90 | 91 | 92 | val positive = filterPositiveOrNegative(featuresWithBiasMap, labels, 1) 93 | val negative = filterPositiveOrNegative(featuresWithBiasMap, labels, 0) 94 | 95 | 96 | 97 | val positivePredicted = Nd4j.getExecutioner().exec(new MatchCondition(hypothesis(positive, computedThetas), Conditions.greaterThan(0.5)),Integer.MAX_VALUE).getInt(0) 98 | 99 | val negativePredicted = Nd4j.getExecutioner().exec(new MatchCondition(hypothesis(negative, computedThetas), Conditions.lessThan(0.5)),Integer.MAX_VALUE).getInt(0) 100 | 101 | println(s"Accuracy: ${(positivePredicted.toDouble + negativePredicted.toDouble)/featuresWithBias.rows()}") 102 | 103 | 104 | 105 | } 106 | 107 | logisticRegression() 108 | 109 | regularizedLogisticRegression() 110 | 111 | 112 | } 113 | 114 | 115 | trait Ex2Util { 116 | 117 | def hypothesis(features: INDArray, thetas: INDArray) ={ 118 | sigmoid(features.mmul(thetas.T)) 119 | } 120 | 121 | def computeCost(features: INDArray, labels: INDArray, thetas: INDArray, lambda: Float = 0.0f): Float = { 122 | val output = hypothesis(features, thetas) 123 | val term1 = log(output).mul(-labels) 124 | val term2 = log(output.rsub(1)).mul(labels.rsub(1)) 125 | Nd4j.clearNans(term2) 126 | val regularization = (thetas(1 to term1.rows(), ->).mmul(thetas(1 to term1.rows(), ->).T) * (lambda/2)).getFloat(0) 127 | val crossEntropy = (term1.sub(term2).sumNumber().floatValue() + regularization)/features.shape()(0) 128 | crossEntropy 129 | } 130 | 131 | 132 | def computeGradient(features: INDArray, labels: INDArray, alpha: Float, iters: Int, lambda: Float = 0.0f): INDArray ={ 133 | val thetas = Nd4j.zeros(features.columns(), 1).T 134 | val nbOfTrainingExamples = features.rows() 135 | val updatedTheta = (0 to iters).foldLeft(thetas)({ 136 | case (thetas, i) => 137 | val error = sigmoid(features.mmul(thetas.T)) - labels 138 | 139 | val grad = error.T.dot(features) * alpha/nbOfTrainingExamples 140 | 141 | val regu = thetas(->, 1->) * lambda/nbOfTrainingExamples 142 | grad(->, 1->) = grad(->, 1->) + regu 143 | val updatedThetas = thetas - grad 144 | println(s"Cost: ${computeCost(features, labels, updatedThetas)}") 145 | updatedThetas 146 | }) 147 | updatedTheta 148 | 149 | } 150 | 151 | def filterPositiveOrNegative(features: INDArray, labels: INDArray, condition: Float): INDArray = { 152 | (0 until features.rows()).foldLeft(Option.empty[INDArray]){ 153 | case (maybeINDArray, index) => 154 | val label = labels.getRow(index).getColumn(0).getDouble(0) 155 | if(label == condition){ 156 | val feature = features.getRow(index) 157 | if(maybeINDArray.isEmpty){ 158 | Some(feature) 159 | } 160 | else { 161 | maybeINDArray.map { 162 | array => 163 | Nd4j.concat(0, array, feature) 164 | } 165 | } 166 | } 167 | else 168 | maybeINDArray 169 | }.get 170 | } 171 | 172 | 173 | def mapFeatures(theta1: INDArray, theta2: INDArray): INDArray = { 174 | val degree = 6 175 | var out = Nd4j.ones(theta1.rows(), 1) 176 | (1 to degree).map{ 177 | index1 => 178 | (0 to index1).map{ 179 | index2 => 180 | val r1 = pow(theta1, index1 - index2) 181 | val r2 = pow(theta2, index2) 182 | val r3 = (r1 * r2).reshape( r1.rows(), 1 ) 183 | out = Nd4j.hstack(out, r3) 184 | } 185 | } 186 | out 187 | } 188 | 189 | } 190 | 191 | 192 | -------------------------------------------------------------------------------- /src/main/scala/com/cpuheater/ml/Ex3.scala: -------------------------------------------------------------------------------- 1 | package com.cpuheater.ml 2 | 3 | import com.cpuheater.util.Loader 4 | import org.nd4j.linalg.api.buffer.DataBuffer 5 | import org.nd4j.linalg.api.buffer.util.DataTypeUtil 6 | import org.nd4j.linalg.api.ndarray.INDArray 7 | import org.nd4j.linalg.factory.Nd4j 8 | import org.nd4j.linalg.indexing.BooleanIndexing 9 | import org.nd4j.linalg.indexing.conditions.Conditions 10 | import org.nd4j.linalg.ops.transforms.Transforms._ 11 | import org.nd4s.Implicits._ 12 | import org.nd4s.Evidences.float 13 | 14 | 15 | 16 | object Ex3 extends App with Ex3Util{ 17 | 18 | 19 | DataTypeUtil.setDTypeForContext(DataBuffer.Type.FLOAT) 20 | 21 | 22 | val numLinesToSkip = 0 23 | val delimiter = "," 24 | 25 | /** 26 | * We are not going to use ny optimization procedure but we will use 27 | * gradient descent to find parameters thetas 28 | */ 29 | 30 | 31 | def logisticRegressionMultiClass(): Unit = { 32 | 33 | val alpha = 4f 34 | val iters = 100 35 | 36 | val content = Loader.load("ex3/ex3data1.mat") 37 | val features: INDArray = Nd4j.create(content("X")) 38 | val labels:INDArray = Nd4j.create(content("y")) 39 | 40 | 41 | val ones = Nd4j.ones(features.rows(), 1) 42 | val featuresWithBias = Nd4j.concat(1, ones, features) 43 | 44 | 45 | val allThetas = computeThetasForEachClass(featuresWithBias, labels, alpha, iters) 46 | 47 | 48 | def classPrediction(features: INDArray, thetas: INDArray): Float = { 49 | val predictions = (0 until 10).map{ 50 | index => 51 | val pred = hypothesis(features, thetas(index, ->)) 52 | pred.getFloat(0) 53 | } 54 | val max = Nd4j.argMax(Nd4j.create(predictions.toArray)).getFloat(0) 55 | 56 | if(max == 0) 10.0f else max 57 | } 58 | 59 | val (total, correct) = (0 until featuresWithBias.rows()).foldLeft((0, 0)){ 60 | case ((total, correct), index) => 61 | val pred = classPrediction(featuresWithBias.getRow(index), allThetas) 62 | if(classPrediction(featuresWithBias.getRow(index), allThetas) == labels.getRow(index).getFloat(0)) 63 | (total+1, correct+1) 64 | else 65 | (total+1, correct) 66 | } 67 | 68 | println(s"Logistic Regression Multi Class Accuracy ${correct.toDouble/total}") 69 | 70 | } 71 | 72 | 73 | 74 | 75 | def neuralNetwork() = { 76 | val content = Loader.load("ex3/ex3data1.mat") 77 | val features: INDArray = Nd4j.create(content("X")) 78 | val labels:INDArray = Nd4j.create(content("y").flatten) 79 | 80 | val ones = Nd4j.ones(features.rows(), 1) 81 | val featuresWithBias = Nd4j.concat(1, ones, features) 82 | 83 | val thetas = Loader.load("ex3/ex3weights.mat") 84 | 85 | val (theta1, theta2) = (Nd4j.create(thetas("Theta1")), Nd4j.create(thetas("Theta2"))) 86 | 87 | 88 | def forwardPropagate(features: INDArray, theta1: INDArray, theta2: INDArray) : INDArray= { 89 | val z2 = features.mmul(theta1.T) 90 | val ones = Nd4j.ones(1) 91 | val a2 = Nd4j.concat(1, ones, sigmoid(z2)) 92 | val z3 = a2.mmul(theta2.T) 93 | val output = sigmoid(z3) 94 | output 95 | } 96 | 97 | 98 | val correct = (0 until featuresWithBias.rows()).foldLeft(0){ 99 | case (accu, rowIndex) => 100 | val dataRow = featuresWithBias.getRow(rowIndex) 101 | val output = forwardPropagate(dataRow, theta1, theta2) 102 | val argMax = Nd4j.argMax(output, 1).getInt(0) +1 103 | val label = labels.getDouble(rowIndex).toInt 104 | if(argMax == label) 105 | accu + 1 106 | else 107 | accu 108 | 109 | } 110 | 111 | println(s"Neural network accuracy: ${correct/(featuresWithBias.rows()toDouble)}") 112 | 113 | 114 | } 115 | 116 | neuralNetwork() 117 | 118 | 119 | logisticRegressionMultiClass() 120 | 121 | 122 | } 123 | 124 | 125 | trait Ex3Util { 126 | 127 | 128 | def hypothesis(features: INDArray, thetas: INDArray) ={ 129 | sigmoid(features.mmul(thetas.T)) 130 | } 131 | 132 | def computeCost(features: INDArray, labels: INDArray, thetas: INDArray, lambda: Float = 0.0f): Float = { 133 | val output = hypothesis(features, thetas) 134 | val term1 = log(output).mul(-labels) 135 | val term2 = log(output.rsub(1)).mul(labels.rsub(1)) 136 | Nd4j.clearNans(term2) 137 | val nbOfTrainingExamples = features.rows() 138 | val regularization = (thetas(1 to term1.rows(), ->).mmul(thetas(1 to term1.rows(), ->).T) * (lambda/2*nbOfTrainingExamples)).getFloat(0) 139 | val crossEntropy = term1.sub(term2).sumNumber().floatValue()/nbOfTrainingExamples + regularization 140 | crossEntropy 141 | } 142 | 143 | 144 | def computeGradient(features: INDArray, labels: INDArray, alpha: Float, iters: Int, lambda: Float = 0.0f): INDArray ={ 145 | val thetas = Nd4j.zeros(features.columns(), 1).T 146 | val nbOfTrainingExamples = features.rows() 147 | val updatedTheta = (0 to iters).foldLeft(thetas)({ 148 | case (thetas, i) => 149 | val error = sigmoid(features.mmul(thetas.T)) - labels 150 | val regu = thetas(->, 1->) * lambda/nbOfTrainingExamples 151 | val grad = error.T.dot(features) * alpha/nbOfTrainingExamples 152 | grad(->, 1->) = grad(->, 1->) + regu 153 | val updatedThetas = thetas - grad 154 | println(s"Cost: ${computeCost(features, labels, updatedThetas)}") 155 | updatedThetas 156 | }) 157 | updatedTheta 158 | 159 | } 160 | 161 | 162 | def computeThetasForEachClass(features: INDArray, labels: INDArray, alpha: Float, iters: Int): INDArray = { 163 | val thetas = (0 until 10).foldLeft(Nd4j.zeros(10, features.columns())){ 164 | case (allThetas, index) => 165 | val labelsDuplicate = labels.dup() 166 | val `class` = if(index==0) 10 else index 167 | //TODO Waiting when Conditions.notEquals will be fixed 168 | BooleanIndexing.applyWhere(labelsDuplicate, Conditions.equals(`class`), 100) 169 | BooleanIndexing.applyWhere(labelsDuplicate, Conditions.lessThan(100), 0.0) 170 | BooleanIndexing.applyWhere(labelsDuplicate, Conditions.equals(100), 1.0) 171 | val currentThetas = computeGradient(features, labelsDuplicate, alpha, iters) 172 | allThetas(index, ->) = currentThetas 173 | } 174 | thetas 175 | } 176 | 177 | } 178 | 179 | 180 | -------------------------------------------------------------------------------- /src/main/scala/com/cpuheater/ml/Ex4.scala: -------------------------------------------------------------------------------- 1 | package com.cpuheater.ml 2 | 3 | 4 | import com.cpuheater.util.Loader 5 | import org.nd4j.linalg.api.buffer.DataBuffer 6 | import org.nd4j.linalg.api.buffer.util.DataTypeUtil 7 | import org.nd4j.linalg.api.ndarray.INDArray 8 | import org.nd4j.linalg.factory.Nd4j 9 | import org.nd4j.linalg.ops.transforms.Transforms._ 10 | import org.nd4s.Implicits._ 11 | 12 | import scala.util.Random 13 | 14 | 15 | object Ex4 extends App{ 16 | 17 | DataTypeUtil.setDTypeForContext(DataBuffer.Type.DOUBLE) 18 | 19 | 20 | /** 21 | * Hyperparameters 22 | */ 23 | val inputSize = 400 24 | val hiddenSize = 25 25 | val outputSize = 10 26 | 27 | 28 | 29 | val oneHotMap = Nd4j.eye(10) 30 | 31 | 32 | 33 | def forwardPropagate(feature: INDArray, theta1: INDArray, theta2: INDArray) : (INDArray, INDArray, INDArray, INDArray)= { 34 | val z2 = feature.mmul(theta1.T) 35 | val ones = Nd4j.ones(1) 36 | val a2 = sigmoid(z2) 37 | val z3 = Nd4j.concat(1, ones, a2).mmul(theta2.T) 38 | val a3 = sigmoid(z3) 39 | (z2, a2, z3, a3) 40 | } 41 | 42 | 43 | 44 | 45 | def computeCost(features: INDArray, labels: INDArray, theta1: INDArray, theta2: INDArray, lambda:Double = 0.0) : Double= { 46 | val nbDataExamples = features.rows() 47 | val totalCost = (0 until nbDataExamples).foldLeft(0.0d){ 48 | case (accu, rowIndex) => 49 | val feature = features.getRow(rowIndex) 50 | val (z2, a2, z3, a3) = forwardPropagate(feature, theta1, theta2) 51 | val labelOneHot = oneHotMap.getRow(labels.getRow(rowIndex).getDouble(0).toInt -1) 52 | val term1 = -labelOneHot.mmul(log(a3.T)).getDouble(0) 53 | val term2 = -labelOneHot.rsub(1).mmul(log(a3.rsub(1).T)).getDouble(0) 54 | val cost = term1 + term2 55 | val regular = Nd4j.sum(theta1*theta1).getDouble(0) + Nd4j.sum(theta2* theta2).getDouble(0) 56 | val regular_norm = regular * lambda/(2 * nbDataExamples) 57 | accu + cost + regular_norm 58 | 59 | } 60 | totalCost/nbDataExamples 61 | } 62 | 63 | 64 | 65 | def sigmoidDerivative(x: INDArray): INDArray = { 66 | val result = x*(x.rsub(1)) 67 | result 68 | } 69 | 70 | 71 | def randomThetas() = { 72 | val epsilonInit = 0.12 73 | 74 | val theta1 = Nd4j.rand(hiddenSize, inputSize+1) * 2 * epsilonInit - epsilonInit 75 | val theta2 = Nd4j.rand(outputSize, hiddenSize +1) * 2 * epsilonInit - epsilonInit 76 | 77 | (theta1, theta2) 78 | } 79 | 80 | 81 | 82 | def backpropagation(features: INDArray, labels: INDArray, theta1: INDArray, theta2: INDArray, lambda: Double = 0.0) = { 83 | val nbDataExamples = features.rows() 84 | val (delta1, delta2) = (0 until nbDataExamples).toList.foldLeft((Nd4j.zeros(hiddenSize, inputSize+1), Nd4j.zeros(outputSize, hiddenSize+1))){ 85 | case ((totalDelta1, totalDelta2), rowId) => 86 | val feature = features.getRow(rowId) 87 | val (z2, a2, z3, a3) = forwardPropagate(feature, theta1, theta2) 88 | val labelOneHot = oneHotMap.getRow(labels.getRow(rowId).getDouble(0).toInt -1) 89 | val error3 = a3 - labelOneHot 90 | val error2 = theta2.T(1->, ->).dot(error3.T) * sigmoidDerivative(a2).T 91 | val newTotalDelta1 = totalDelta1 + error2.mmul(feature) 92 | val a2WithOnes = Nd4j.concat(1, Nd4j.ones(1), a2).reshape(1, hiddenSize+1) 93 | val nnewTotalDelta2 = totalDelta2 + error3.T.mmul(a2WithOnes) 94 | (newTotalDelta1, nnewTotalDelta2) 95 | 96 | } 97 | 98 | val delta1Norm = delta1/nbDataExamples.toFloat 99 | val delta2Norm = delta2/nbDataExamples.toFloat 100 | 101 | delta1Norm(->, 1->) = delta1Norm(->, 1->) + theta1(->, 1->)*lambda/nbDataExamples 102 | delta2Norm(->, 1->) = delta2Norm(->, 1->) + theta2(->, 1->)*lambda/nbDataExamples 103 | 104 | 105 | (delta1Norm, delta2Norm) 106 | 107 | 108 | } 109 | 110 | 111 | def gradientChecking(features: INDArray, labels: INDArray, theta1: INDArray, theta2: INDArray, delta1: INDArray, delta2: INDArray) = { 112 | val eps = 0.0001 113 | 114 | val nbOfElements = theta1.length() + theta2.length() 115 | 116 | (0 until 5).foreach{ 117 | _ => 118 | val randomElement = Random.nextInt(nbOfElements) 119 | val epsilonVector = Nd4j.create(nbOfElements, 1) 120 | epsilonVector(randomElement) = eps 121 | val theta1Epsilon = epsilonVector(0 until (inputSize+1)*hiddenSize).reshape(hiddenSize, inputSize+1) 122 | val theta2Epsilon = epsilonVector((inputSize +1)*hiddenSize until (inputSize+1)*hiddenSize + outputSize*(hiddenSize+1)).reshape(outputSize, hiddenSize +1) 123 | val theta1WithEpsilon = theta1 + theta1Epsilon 124 | val theta2WithEpsilon = theta2 + theta2Epsilon 125 | 126 | val costHigh = computeCost(features, labels, theta1WithEpsilon, theta2WithEpsilon) 127 | val costLow = computeCost(features, labels, theta1 - theta1Epsilon, theta2 - theta2Epsilon) 128 | val nG = (costHigh - costLow) / (2 * eps) 129 | println(s"Id: ${randomElement} numerical gradient gradient: ${nG}, backProp gradient = ${Nd4j.toFlattened(delta1, delta2)(randomElement)}") 130 | } 131 | 132 | } 133 | 134 | 135 | def train(features: INDArray, labels: INDArray, theta1: INDArray, theta2: INDArray, iter: Int, lr: Float = 1f, lambda: Float = 0.0f) = { 136 | 137 | (0 until iter).foldLeft((theta1, theta2)){ 138 | case ((theta1, theta2), index) => 139 | val cost = computeCost(features, labels, theta1, theta2, lambda) 140 | println(s"Cost ${cost}") 141 | val (delta1, delta2) = backpropagation( features, labels, theta1, theta2, lambda) 142 | val updatedTheta1 = theta1 - delta1 143 | val updatedTheta2 = theta2 - delta2 144 | (updatedTheta1, updatedTheta2) 145 | } 146 | } 147 | 148 | 149 | 150 | def predict(feature: INDArray, theta1: INDArray, theta2: INDArray): Int = { 151 | val (_, _, _, pred) = forwardPropagate(feature, theta1, theta2) 152 | val value: Int = Nd4j.argMax(pred).getInt(0) +1 153 | value 154 | } 155 | 156 | 157 | 158 | def computeAccuracy(features: INDArray, labels: INDArray, theta1: INDArray, theta2: INDArray): Double = { 159 | val nbDataExamples = features.rows() 160 | val correct = (0 until nbDataExamples).foldLeft(0){ 161 | case (accum, index) => 162 | val pred = predict(features.getRow(index), theta1, theta2) 163 | if(pred == labels(index).toInt) 164 | accum +1 165 | else 166 | accum 167 | } 168 | correct.toDouble/nbDataExamples 169 | } 170 | 171 | 172 | 173 | 174 | def feedforwardNeuralNetwork(): Unit = { 175 | 176 | val content = Loader.load("ex4/ex4data1.mat") 177 | val features: INDArray = Nd4j.create(content("X")) 178 | val labels:INDArray = Nd4j.create(content("y")) 179 | 180 | val ones = Nd4j.ones(features.rows(), 1) 181 | val featuresWithBias = Nd4j.concat(1, ones, features) 182 | 183 | val data = Loader.load("ex4/ex4weights.mat") 184 | 185 | val (theta1, theta2) = (Nd4j.create(data("Theta1")), Nd4j.create(data("Theta2"))) 186 | 187 | 188 | val cost = computeCost(featuresWithBias, labels, theta1, theta2) 189 | 190 | println(s"FeedforwardNeuralNetwork Cost: ${cost} %") 191 | 192 | val regulCost = computeCost(featuresWithBias, labels, theta1, theta2, 1) 193 | 194 | println(s"FeedforwardNeuralNetwork Regularized cost: ${regulCost} %") 195 | 196 | 197 | } 198 | 199 | 200 | def backpropagationNeuralNetwork(): Unit = { 201 | 202 | val alpha = 4 203 | 204 | val iters = 50 205 | 206 | val content = Loader.load("ex4/ex4data1.mat") 207 | val features: INDArray = Nd4j.create(content("X")) 208 | val labels:INDArray = Nd4j.create(content("y")) 209 | 210 | val ones = Nd4j.ones(features.rows(), 1) 211 | val featuresWithBias = Nd4j.concat(1, ones, features) 212 | 213 | 214 | val (theta1, theta2) = randomThetas() 215 | 216 | val (delta1, delta2) = backpropagation(featuresWithBias, labels, theta1, theta2) 217 | 218 | gradientChecking(featuresWithBias, labels, theta1, theta2, delta1, delta2) 219 | 220 | val (trainedTheta1, trainedTheta2) = train(featuresWithBias, labels, theta1, theta2, iters, alpha, 0) 221 | 222 | 223 | 224 | val accuracy = computeAccuracy(featuresWithBias, labels, trainedTheta1, trainedTheta2) 225 | 226 | println(s"Backpropagation neural network accuracy: ${accuracy} %") 227 | 228 | } 229 | 230 | feedforwardNeuralNetwork() 231 | 232 | 233 | backpropagationNeuralNetwork() 234 | 235 | 236 | 237 | 238 | } 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /src/main/scala/com/cpuheater/ml/Ex5.scala: -------------------------------------------------------------------------------- 1 | package com.cpuheater.ml 2 | 3 | import com.cpuheater.util.Loader 4 | import org.nd4j.linalg.api.ndarray.INDArray 5 | import org.nd4j.linalg.factory.Nd4j 6 | import org.nd4j.linalg.ops.transforms.Transforms.pow 7 | import org.nd4s.Implicits._ 8 | import org.nd4s.Evidences.float 9 | 10 | 11 | object Ex5 extends App with Ex5Util { 12 | 13 | 14 | val numLinesToSkip = 0 15 | val delimiter = "," 16 | 17 | 18 | def regularizedLinearRegression(): Unit = { 19 | println("regularizedLinearRegression") 20 | val alpha = 0.001 21 | val iters = 2000 22 | val lambda = 0.0 23 | val content = Loader.load("ex5/ex5data1.mat") 24 | val features: INDArray = Nd4j.create(content("X")) 25 | val labels:INDArray = Nd4j.create(content("y")) 26 | val featuresValidation: INDArray = Nd4j.create(content("Xval")) 27 | val labelsValidation:INDArray = Nd4j.create(content("yval")) 28 | val featuresTest: INDArray = Nd4j.create(content("Xval")) 29 | val labelsTest:INDArray = Nd4j.create(content("yval")) 30 | val featuresWithBias = Nd4j.concat(1, Nd4j.ones(features.rows(), 1), features) 31 | val thetas = Nd4j.ones(Array(2, 1): _*) 32 | 33 | val cost = computeCost(featuresWithBias, labels, thetas, 1.0) 34 | val computedThetas = computeGradient(featuresWithBias, labels, thetas, alpha, iters, lambda) 35 | 36 | 37 | println(s"Computed thetas ${computedThetas}") 38 | 39 | } 40 | 41 | def polynomialLinearRegression(): Unit = { 42 | println("polynomialLinearRegression") 43 | 44 | val alpha = 0.01 45 | val iterations = 20000 46 | val lambda = 0.0001 47 | val content = Loader.load("ex5/ex5data1.mat") 48 | val features: INDArray = Nd4j.create(content("X")) 49 | val labels:INDArray = Nd4j.create(content("y")) 50 | val featuresValidation: INDArray = Nd4j.create(content("Xval")) 51 | val labelsValidation:INDArray = Nd4j.create(content("yval")) 52 | val featuresTest: INDArray = Nd4j.create(content("Xval")) 53 | val labelsTest:INDArray = Nd4j.create(content("yval")) 54 | 55 | val featuresWithBias = Nd4j.concat(1, Nd4j.ones(features.rows(), 1), features) 56 | val newFeatures = createPolynomialFeatures(featuresWithBias, 5) 57 | val newFeaturesNorm = normalize(newFeatures) 58 | val thetas = Nd4j.ones(Array(newFeaturesNorm.columns(), 1): _*) 59 | val computedThetas = computeGradient(newFeaturesNorm, labels, thetas, alpha, iterations, lambda) 60 | println(s"Computed thetas ${computedThetas}") 61 | 62 | } 63 | 64 | 65 | regularizedLinearRegression() 66 | 67 | 68 | polynomialLinearRegression() 69 | 70 | 71 | } 72 | 73 | trait Ex5Util { 74 | 75 | def createPolynomialFeatures(features: INDArray, degree: Int) : INDArray= { 76 | val featuresDuplicate = features.dup() 77 | 78 | (0 until degree).foldLeft(featuresDuplicate){ 79 | case (accum, index) => 80 | val power = index +2 81 | val newFeaturesDuplicate = Nd4j.concat(1, accum, pow(featuresDuplicate(->, 1), power)) 82 | newFeaturesDuplicate 83 | } 84 | } 85 | 86 | 87 | def computeCost(features: INDArray, labels: INDArray, thetas: INDArray, lambda: Double = 0.0): Double = { 88 | val nbTrainingExamples = features.rows() 89 | val r = pow(hypothesis(features, thetas) - labels, 2) 90 | val cost = (r.sum(0)* 1.0/(2*nbTrainingExamples)).getDouble(0) 91 | val regularization = lambda / (2*nbTrainingExamples) * thetas(1->).dot(thetas(1->).T).getDouble(0) 92 | cost + regularization 93 | } 94 | 95 | 96 | def computeGradient(features: INDArray, labels: INDArray, thetas: INDArray, alpha: Double, iters: Int, lambda: Double = 0.0): INDArray ={ 97 | val nbOfTrainingExamples = features.rows 98 | val updatedThetas = (0 to iters).foldLeft(thetas)({ 99 | case (accum, i) => 100 | val error = hypothesis(features, accum) - labels 101 | 102 | val grad = features.T.dot(error) * alpha/nbOfTrainingExamples 103 | val regularization = accum*lambda/nbOfTrainingExamples 104 | regularization(0) = 0 105 | val updatedThetas = accum - grad + regularization 106 | println(s"Cost: ${computeCost(features, labels, updatedThetas)}") 107 | updatedThetas 108 | }) 109 | updatedThetas 110 | 111 | } 112 | 113 | 114 | 115 | 116 | /** 117 | * Feature normalization - subtract mean, divide by standard deviation 118 | * 119 | **/ 120 | 121 | def normalize(features: INDArray): INDArray = { 122 | val mean = features.mean(0) 123 | val std = features.std(0) 124 | val meanBroadcasted = mean.broadcast(Array(features.rows(), mean.columns()): _*) 125 | features(->, 1->) = features(->, 1->) - meanBroadcasted(->, 1->) 126 | val stdBroadcasted = mean.broadcast(Array(features.rows(), std.columns()): _*) 127 | features(->, 1->) = features(->, 1->) / stdBroadcasted(->, 1->) 128 | features 129 | } 130 | 131 | 132 | 133 | 134 | 135 | /** 136 | * y = theta1*x + theta0 137 | */ 138 | 139 | 140 | def hypothesis(features: INDArray, thetas: INDArray) ={ 141 | features.mmul(thetas) 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /src/main/scala/com/cpuheater/ml/Ex6.scala: -------------------------------------------------------------------------------- 1 | package com.cpuheater.ml 2 | 3 | import com.cpuheater.util.Loader 4 | import org.nd4j.linalg.api.buffer.DataBuffer 5 | import org.nd4j.linalg.api.buffer.util.DataTypeUtil 6 | import org.nd4j.linalg.api.ndarray.INDArray 7 | import org.nd4j.linalg.factory.Nd4j 8 | import org.nd4j.linalg.indexing.BooleanIndexing 9 | import org.nd4j.linalg.indexing.conditions.Conditions 10 | import org.nd4s.Evidences.float 11 | import org.nd4s.Implicits._ 12 | 13 | import scala.util.Random 14 | 15 | object Ex6 extends App{ 16 | 17 | DataTypeUtil.setDTypeForContext(DataBuffer.Type.FLOAT) 18 | 19 | 20 | def accuracy(pred: INDArray, labels: INDArray): Float = { 21 | val sum = (0 until pred.rows()).map{ 22 | index => 23 | if(pred.getRow(index).getFloat(0) == labels.getRow(index).getFloat(0)) 24 | 1 25 | else 26 | 0 27 | }.sum 28 | sum.toFloat / pred.rows() 29 | } 30 | 31 | 32 | def linearSVM(): Unit = { 33 | val content = Loader.load("ex6/ex6data1.mat") 34 | val features: INDArray = Nd4j.create(content("X")) 35 | val labels:INDArray = Nd4j.create(content("y")) 36 | BooleanIndexing.applyWhere(labels, Conditions.lessThan(1), -1) 37 | val svm = new SVM(10, 0.001f) 38 | svm.fit(features, labels) 39 | val pred = svm.predict(features) 40 | 41 | println(s"Accuracy: ${accuracy(pred.T, labels)}") 42 | } 43 | 44 | linearSVM() 45 | } 46 | 47 | 48 | class SVM(iter: Int, epsilon: Float = 0.001f) { 49 | 50 | 51 | val c: Float = 1.0f 52 | 53 | var w = Nd4j.zeros(1) 54 | var b = 0f 55 | 56 | def fit(features: INDArray, labels: INDArray) : Unit = { 57 | val Array(n, d) = features.shape() 58 | val alpha = Nd4j.zeros(n) 59 | var count = 0 60 | var continue = true 61 | while(continue) { 62 | count = count +1 63 | val alpha_prev = alpha.dup() 64 | (0 until n).map{ 65 | j => 66 | val i = randi(0, n-1, j) 67 | val (x_i, x_j, y_i, y_j) = (features(i,->), features(j,->), labels(i).toInt, labels(j).toInt) 68 | val k_ij = kernel(x_i, x_i) + kernel(x_j, x_j) - 2 * kernel(x_i, x_j) 69 | 70 | if(k_ij != 0) { 71 | val (alpha_prime_j, alpha_prime_i) = (alpha(j), alpha.apply(i)) 72 | val (l, h) = computeMinMax(c, alpha_prime_j, alpha_prime_i, y_j, y_i) 73 | 74 | w = calcW(alpha, labels, features) 75 | b = calcB(features, labels, w) 76 | 77 | val e_i = e(x_i, y_i, w, b) 78 | val e_j = e(x_j, y_j, w, b) 79 | 80 | 81 | alpha(j) = alpha_prime_j + (y_j * (e_i - e_j))/k_ij 82 | alpha(j) = Math.max(alpha(j), l) 83 | alpha(j) = Math.min(alpha(j), h) 84 | 85 | alpha(i) = alpha_prime_i + y_i*y_j * (alpha_prime_j - alpha(j)) 86 | 87 | } 88 | 89 | } 90 | 91 | 92 | 93 | val diff = Nd4j.norm1(alpha - alpha_prev) 94 | if(diff < epsilon) 95 | continue = false 96 | 97 | if(count >= iter) 98 | println(s"Iteration max ${iter}") 99 | continue = false 100 | } 101 | 102 | b = calcB(features, labels, w) 103 | w = calcW(alpha, labels, features) 104 | } 105 | 106 | 107 | private def h(x: INDArray, w: INDArray, b: Float): INDArray = { 108 | val result = (w.dot(x.T) + b) 109 | BooleanIndexing.applyWhere(result, Conditions.lessThan(0), -1) 110 | BooleanIndexing.applyWhere(result, Conditions.greaterThanOrEqual(0), 1) 111 | result 112 | } 113 | 114 | 115 | def predict(features: INDArray): INDArray = { 116 | h(features, w, b) 117 | } 118 | 119 | private def e(x_k: INDArray, y_k: Int, w: INDArray, b: Float): Float = { 120 | h(x_k, w, b).getFloat(0).toInt - y_k 121 | } 122 | 123 | 124 | private def calcB(x: INDArray, y: INDArray, w: INDArray): Float ={ 125 | val b_tmp = y - w.dot(x.T) 126 | Nd4j.mean(b_tmp).getFloat(0) 127 | } 128 | 129 | private def calcW(alpha: INDArray, y: INDArray, x: INDArray): INDArray = { 130 | (alpha * y.T).dot(x) 131 | } 132 | 133 | 134 | 135 | private def computeMinMax(c: Float, alpha_prime_j: Float, alpha_prime_i: Float, y_j: Float, y_i: Float): (Float, Float) = { 136 | if(y_i != y_j) 137 | (Math.max(0, alpha_prime_j - alpha_prime_i), Math.min(c, c - alpha_prime_i + alpha_prime_j)) 138 | else 139 | (Math.max(0, alpha_prime_i + alpha_prime_j - c), Math.min(c, alpha_prime_i + alpha_prime_j)) 140 | } 141 | 142 | private def kernel(x1: INDArray, x2: INDArray): Float ={ 143 | x1.dot(x2.T).getFloat(0) 144 | } 145 | 146 | 147 | private def randi(a: Int,b: Int,z:Int) : Int = { 148 | var i = z 149 | while (i == z) 150 | i = a + Random.nextInt(a+b) 151 | i 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /src/main/scala/com/cpuheater/ml/Ex7.scala: -------------------------------------------------------------------------------- 1 | package com.cpuheater.ml 2 | 3 | import com.cpuheater.util.Loader 4 | import org.nd4j.linalg.api.buffer.DataBuffer 5 | import org.nd4j.linalg.api.buffer.util.DataTypeUtil 6 | import org.nd4j.linalg.api.ndarray.INDArray 7 | import org.nd4j.linalg.factory.Nd4j 8 | import org.nd4j.linalg.ops.transforms.Transforms._ 9 | import org.nd4s.Implicits._ 10 | import scala.collection.JavaConversions._ 11 | import scala.collection.SortedSet 12 | import scala.util.Random 13 | import org.nd4s.Evidences.float 14 | 15 | 16 | object Ex7 extends App with Ex7Util { 17 | 18 | DataTypeUtil.setDTypeForContext(DataBuffer.Type.FLOAT) 19 | 20 | 21 | def kMeansClustering() { 22 | 23 | val data = Loader.load("ex7/ex7data2.mat") 24 | val features: INDArray = Nd4j.create(data("X")) 25 | 26 | val K = 3 27 | 28 | val centroids = Nd4j.create(Array(Array(3.0, 3), Array(6.0,2), Array(8.0,5))) 29 | 30 | val newCentroids = runKMeans(features, centroids , 3, 10) 31 | println(s"Centroids: ${newCentroids}") 32 | } 33 | 34 | def imageCompressionKMeans() { 35 | 36 | val data = Loader.load("ex7/bird_small.mat") 37 | val features: INDArray = (Nd4j.create(data("A")) / 255).reshape(-1, 3) 38 | 39 | 40 | val K = 16 41 | val randomCentroids = chooseKRandomCentroids(features,K) 42 | val newCentroids = runKMeans(features,randomCentroids, K, 10) 43 | 44 | println(s"Image compression centroids : ${newCentroids}") 45 | } 46 | 47 | def projectData(features: INDArray, u: INDArray, k: Int) : INDArray = { 48 | val uReduced = u(->, 0 -> k) 49 | features.dot(uReduced) 50 | } 51 | 52 | def recoverData(z: INDArray, u: INDArray, k: Int) = { 53 | val uReduced = u(->, 0 -> k) 54 | z.dot(uReduced.T) 55 | } 56 | 57 | def pca(): Unit = { 58 | 59 | val data = Loader.load("ex7/ex7data1.mat") 60 | val features: INDArray = (Nd4j.create(data("X"))) 61 | 62 | val (means, std, featuresNorm) = featureNormalize(features) 63 | 64 | 65 | val (u, s, v) = getUSV(featuresNorm) 66 | println(s"Matrix U ${u}") 67 | println(s"Matrix S ${s}") 68 | println(s"Matrix V ${v}") 69 | 70 | 71 | val z = projectData(featuresNorm, u, 1) 72 | println(s"Projections of first components ${z(0)}") 73 | 74 | 75 | val recovered = recoverData(z, u, 1) 76 | println(s"Recovered data ${recovered}") 77 | } 78 | 79 | 80 | 81 | def faces(): Unit = { 82 | 83 | val data = Loader.load("ex7/ex7faces.mat") 84 | val features: INDArray = (Nd4j.create(data("X"))) 85 | 86 | val (means, std, featuresNorm) = featureNormalize(features) 87 | 88 | 89 | val (u, s, v) = getUSV(featuresNorm) 90 | 91 | 92 | val z = projectData(featuresNorm, u, 1) 93 | println(s"Projections of first components ${z(0)}") 94 | 95 | 96 | val recovered = recoverData(z, u, 1) 97 | println(s"Recovered data ${recovered.getRow(0)}") 98 | } 99 | 100 | kMeansClustering() 101 | 102 | imageCompressionKMeans() 103 | 104 | pca() 105 | 106 | faces() 107 | 108 | } 109 | 110 | 111 | trait Ex7Util { 112 | 113 | def distSquared(p1: INDArray, p2: INDArray): Float = { 114 | val power = pow(p1-p2, 2) 115 | val dist = Nd4j.sum(power).getFloat(0) 116 | dist 117 | } 118 | 119 | 120 | def findClosestCentroids(features: INDArray, centroids: INDArray): INDArray = { 121 | val centroidIndexes = (0 until features.rows()).map{ 122 | index => 123 | val feature = features.getRow(index) 124 | val (_, centroidIndex) = (0 until centroids.rows()).foldLeft((Float.MaxValue, 0)){ 125 | case ((min, minCentroidIndex), centroidIndex) => 126 | val centroid = centroids.getRow(centroidIndex) 127 | val dist = distSquared(feature, centroid) 128 | if(dist < min) 129 | (dist, centroidIndex) 130 | else 131 | (min, minCentroidIndex) 132 | } 133 | centroidIndex 134 | }.toNDArray 135 | centroidIndexes 136 | } 137 | 138 | def computeCentroids(features: INDArray, featuresCenIds: INDArray) : INDArray= { 139 | 140 | val uniqueCentroidIds = SortedSet(featuresCenIds.data().asInt(): _*) 141 | 142 | val featuresByCentroid = uniqueCentroidIds.foldLeft(Seq.empty[INDArray]){ 143 | case (accum, cenId) => 144 | val featureByCentroid = (0 until features.rows()).foldLeft(Seq.empty[INDArray]){ 145 | case (featureByCentroid, index) => 146 | val currentCenId = featuresCenIds.getColumn(index).getInt(0) 147 | val feature = features.getRow(index) 148 | if(cenId == currentCenId) { 149 | featureByCentroid :+ feature 150 | } 151 | else 152 | featureByCentroid 153 | } 154 | accum :+ Nd4j.create(featureByCentroid, Array(featureByCentroid.size, featureByCentroid(0).columns())) 155 | } 156 | 157 | featuresByCentroid.zipWithIndex.foldLeft(Nd4j.create(uniqueCentroidIds.size, features.getRow(0).length())) { 158 | case (accum, (features, index)) => 159 | val ndMean = features.mean(0) 160 | accum.putRow(index, ndMean) 161 | accum 162 | } 163 | } 164 | 165 | def runKMeans(features: INDArray, centroids: INDArray, k: Int, iter: Int) : INDArray= { 166 | (0 until iter).foldLeft(centroids){ 167 | case (currentCentroid, _) => 168 | val newCenIds = findClosestCentroids(features, currentCentroid) 169 | val newCentroids = computeCentroids(features, newCenIds) 170 | newCentroids 171 | } 172 | } 173 | 174 | 175 | 176 | def chooseKRandomCentroids(features: INDArray, k: Int): INDArray = { 177 | val tmp = Nd4j.zeros(Array(k, features.getRow(0).columns()): _*) 178 | (0 until tmp.rows()).foreach{ 179 | index => 180 | val random = Random.nextInt(features.rows()) 181 | tmp.putRow(index, features.getRow(random)) 182 | } 183 | tmp 184 | 185 | } 186 | 187 | def featureNormalize(features: INDArray): (INDArray, INDArray, INDArray) = { 188 | val mean = Nd4j.mean(features, 0) 189 | val norm = features.subRowVector(mean) 190 | val std = Nd4j.std(norm, 0) 191 | val features_normalize = norm.divRowVector(std) 192 | (mean, std, features_normalize) 193 | } 194 | 195 | def getUSV(features: INDArray): (INDArray, INDArray, INDArray) = { 196 | val covMatrix = features.T.dot(features)/features.rows() 197 | 198 | val m = features.rows 199 | val n = features.columns 200 | 201 | 202 | val s = Nd4j.create(if (m < n) m else n) 203 | val u = if (m < n) Nd4j.create(n, n) else Nd4j.create(n, n) 204 | val v = Nd4j.create(n, n) 205 | 206 | Nd4j.getBlasWrapper.lapack.gesvd(covMatrix, s, u, v) 207 | 208 | 209 | (u, s, v) 210 | } 211 | 212 | } 213 | 214 | 215 | 216 | -------------------------------------------------------------------------------- /src/main/scala/com/cpuheater/ml/Ex8.scala: -------------------------------------------------------------------------------- 1 | package com.cpuheater.ml 2 | 3 | import com.cpuheater.util.Loader 4 | import org.nd4s.Implicits._ 5 | import org.nd4j.linalg.inverse.InvertMatrix 6 | import org.nd4j.linalg.ops.transforms.Transforms._ 7 | import org.nd4j.linalg.indexing.BooleanIndexing 8 | import org.nd4j.linalg.factory.Nd4j 9 | import org.nd4j.linalg.indexing.conditions.Conditions 10 | import org.datavec.api.records.reader.impl.regex.RegexLineRecordReader 11 | import org.datavec.api.split.FileSplit 12 | import org.datavec.api.util.ClassPathResource 13 | import org.nd4j.linalg.api.buffer.DataBuffer 14 | import org.nd4j.linalg.api.buffer.util.DataTypeUtil 15 | import org.nd4j.linalg.api.ndarray.INDArray 16 | import scala.collection.JavaConversions._ 17 | 18 | 19 | object Ex8 extends App with Ex8Util{ 20 | 21 | DataTypeUtil.setDTypeForContext(DataBuffer.Type.FLOAT) 22 | 23 | val numLinesToSkip = 0 24 | val delimiter = "," 25 | 26 | def anomalyDetection() = { 27 | val data = Loader.load("ex8/ex8data1.mat") 28 | val features = Nd4j.create(data("X")) 29 | val featureValidation = Nd4j.create(data("Xval")) 30 | val labelsValidation = Nd4j.create(data("yval")) 31 | val probs = Nd4j.zerosLike(features) 32 | val probsValidation = Nd4j.zeros(featureValidation.rows(), 1) 33 | val (mu, sigma) = estMultivariateGauss(features) 34 | probsValidation(->,->) = calcPDF(featureValidation, mu, sigma) 35 | val (bestF1, bestEps) = selectThreshold(labelsValidation, probsValidation) 36 | println(s"Best epsilon: ${bestEps}, best F1: ${bestF1}") 37 | 38 | } 39 | 40 | def recommendation(): Unit = { 41 | val data = Loader.load("ex8/ex8_movies.mat") 42 | val y = Nd4j.create(data("Y")) 43 | val r = Nd4j.create(data("R")) 44 | val params = Loader.load("ex8/ex8_movieParams.mat") 45 | val regex = "(\\d+) (.*)" 46 | val regexLineRecordReader = new RegexLineRecordReader(regex, 0) 47 | regexLineRecordReader.initialize(new FileSplit(new ClassPathResource("ex8/movie_ids.txt").getFile)) 48 | val movies = scala.collection.mutable.Map[Int, String]() 49 | while(regexLineRecordReader.hasNext) { 50 | val List(id, name) = regexLineRecordReader.next().toList 51 | movies(id.toInt) = name.toString 52 | } 53 | 54 | val ratings = Nd4j.zeros(1682,1) 55 | ratings(0) = 4 56 | ratings(97) = 2 57 | ratings(6) = 3 58 | ratings(11) = 5 59 | ratings(53) = 4 60 | ratings(63) = 5 61 | ratings(65) = 3 62 | ratings(68) = 5 63 | ratings(182) = 4 64 | ratings(225) = 5 65 | ratings(354) = 5 66 | 67 | val yWithNewRatings = Nd4j.concat(1, y, ratings) 68 | BooleanIndexing.applyWhere(ratings, Conditions.greaterThan(0), 1) 69 | val rWithNewRatings = Nd4j.concat(1,r, ratings) 70 | val Array(numOfMovies, numOfUsers) = rWithNewRatings.shape() 71 | val numOfFeatures = 10 72 | val features = Nd4j.rand(numOfMovies, numOfFeatures) 73 | val thetas = Nd4j.rand(numOfUsers, numOfFeatures) 74 | val (computedFeatures, computedThetas) = computeGradient(features, thetas, yWithNewRatings, rWithNewRatings, numOfUsers, numOfMovies, numOfFeatures, 0, 0.001f, 100) 75 | 76 | val predictions = computedFeatures.dot(computedThetas.T) 77 | val lastPredictions = predictions(->, predictions.columns()-1) 78 | val Array(indices, newHala) = Nd4j.sortWithIndices(lastPredictions.dup(), 0, false) 79 | 80 | println("Top 10 movies") 81 | 82 | (0 until 10).map{ 83 | i => 84 | val index = indices(i).toInt 85 | println(s" movie ${lastPredictions(index)}, ${movies(index)}") 86 | } 87 | 88 | } 89 | anomalyDetection() 90 | recommendation() 91 | 92 | } 93 | 94 | 95 | trait Ex8Util { 96 | 97 | def calcGauss(features: INDArray): (INDArray, INDArray) = { 98 | val mu = features.mean(0) 99 | val sigma = features.`var`(0) 100 | (mu, sigma) 101 | } 102 | 103 | def estGauss(features:INDArray): (INDArray, INDArray) = { 104 | val mu = features.mean(0) 105 | val variance = features.`var`(0) 106 | (mu, variance) 107 | } 108 | 109 | def estMultivariateGauss(features: INDArray) : (INDArray, INDArray) = { 110 | val mu = features.mean(0) 111 | val nbExamples = features.rows() 112 | val mubroadcast = mu.broadcast(Array(features.rows(), mu.columns()): _*) 113 | val sigma2 = ((features-mubroadcast).T.dot(features-mubroadcast))/nbExamples 114 | (mu, sigma2) 115 | } 116 | 117 | def calcPDF(features: INDArray, mu: INDArray, sigma: INDArray): INDArray = { 118 | val det = sigma.getFloat(0,0)*sigma.getFloat(1,1) - sigma.getFloat(0,1)*sigma.getFloat(1,0) 119 | val n = features.columns() 120 | if(sigma.isVector()) 121 | Nd4j.diag(sigma) 122 | val norm = 1.0/(Math.sqrt(det) * (Math.pow(2*Math.PI, n/2))) 123 | val density = Nd4j.zeros(features.rows(), 1) 124 | val inv = InvertMatrix.invert(sigma, false) 125 | (0 until features.rows()).map{ 126 | index => 127 | val feature = features.getRow(index) 128 | val term = (feature-mu).dot(inv).dot((feature-mu).T) * (-0.5) 129 | density(index, 0) = exp( term) * norm 130 | } 131 | density 132 | } 133 | 134 | 135 | 136 | def computeF1(predictions: INDArray, labels: INDArray) : Float= { 137 | val P = if(predictions.sum(0).getFloat(0) > 0) { 138 | (0 until predictions.rows()).foldLeft(0) { 139 | case (p, index) => 140 | val pred = predictions.getRow(index).getFloat(0) 141 | val label = labels.getRow(index).getFloat(0) 142 | if (label == 1.0 && label == pred) 143 | p + 1 144 | else 145 | p 146 | 147 | } / predictions.sum(0).getFloat(0) 148 | } else { 149 | 0 150 | } 151 | 152 | val R = if(predictions.sum(0).getFloat(0) > 0) { 153 | (0 until predictions.rows()).foldLeft(0) { 154 | case (r, index) => 155 | val pred = predictions.getRow(index).getFloat(0) 156 | val label = labels.getRow(index).getFloat(0) 157 | if (label == 1.0 && label == pred) 158 | r + 1 159 | else 160 | r 161 | 162 | } / labels.sum(0).getFloat(0) 163 | } else { 164 | 0 165 | } 166 | 167 | if(P > 0 && R > 0) 168 | 2*P*R/(P+R) 169 | else 170 | 0 171 | } 172 | 173 | 174 | def selectThreshold(labelsVal: INDArray, predictions: INDArray) = { 175 | val steps = 1000 176 | 177 | val epses: INDArray = Nd4j.linspace(predictions.min(0).getFloat(0), 178 | predictions.max(0).getFloat(0), steps) 179 | 180 | (0 until epses.columns()).foldLeft((0.0, 0.0)){ 181 | case ((bestF1, bestEPs), i) => 182 | val eps = epses.getColumn(i).getFloat(0) 183 | val predictionsDuplicate = predictions.dup() 184 | BooleanIndexing.applyWhere(predictionsDuplicate, Conditions.lessThan(eps), 1.0d) 185 | BooleanIndexing.applyWhere(predictionsDuplicate, Conditions.lessThan(1.0d), 0.0d) 186 | val tempF1 = computeF1(predictionsDuplicate, labelsVal) 187 | if(tempF1 > bestF1) { 188 | (tempF1, eps) 189 | } 190 | else { 191 | (bestF1, bestEPs) 192 | } 193 | } 194 | 195 | } 196 | 197 | 198 | def computeCost(features: INDArray, thetas: INDArray, y: INDArray, r: INDArray, numOfUsers: Int, numOfMovies: Int, numOfFeatures: Int, lambda: Float = 0.0f) = { 199 | val r = features.dot(thetas.T) 200 | val r2 = r.mul(r) 201 | val cost =Nd4j.sum(pow(r2 - y, 2)) * 0.5 202 | val reguCost1 = Nd4j.sum(pow(thetas, 2)) * lambda/2.0 203 | val reguCost2 = Nd4j.sum(pow(features, 2)) * lambda/2.0 204 | val totalCost = cost + reguCost1 + reguCost2 205 | totalCost 206 | } 207 | 208 | def computeGradient(features: INDArray, thetas: INDArray, y: INDArray, r: INDArray, numOfUsers: Int, numOfMovies: Int, 209 | numOfFeatures: Int, lambda: Float = 0.0f, alpha: Float = 1 ,iters: Int = 1) :( INDArray, INDArray) = { 210 | 211 | val (updatedFeatures, updatedThetas) = (0 until iters).foldLeft((features, thetas)){ 212 | case ((features, thetas), i) => 213 | val r1 = features.dot(thetas.T) 214 | val r2 = r1 * r 215 | val r3 = r2 - y 216 | val grad = r3.dot(thetas) 217 | val thetaGrad = r3.T.dot(features) 218 | val regGrad = grad + features * lambda 219 | val regThetaGrad = thetaGrad + thetas * lambda 220 | val updatedFeatures = features - regGrad * alpha 221 | val updatedThetas = thetas - regThetaGrad * alpha 222 | (updatedFeatures, updatedThetas) 223 | } 224 | 225 | (updatedFeatures, updatedThetas) 226 | 227 | } 228 | 229 | 230 | def normalizeRatings(y: INDArray, r: INDArray) = { 231 | val mean = Nd4j.sum(y, 1) / Nd4j.sum(r, 1) 232 | val result = y.subColumnVector(mean) 233 | (result, mean) 234 | } 235 | 236 | 237 | 238 | } 239 | -------------------------------------------------------------------------------- /src/main/scala/com/cpuheater/util/Loader.scala: -------------------------------------------------------------------------------- 1 | package com.cpuheater.util 2 | 3 | import java.io.File 4 | 5 | import com.jmatio.io.MatFileReader 6 | import com.jmatio.types._ 7 | 8 | import scala.collection.JavaConversions._ 9 | 10 | 11 | 12 | 13 | object Loader { 14 | /** 15 | * Helper function to load matlab files 16 | * @param fileName 17 | * @return 18 | */ 19 | def load(fileName: String): Map[String, Array[Array[Double]]] = { 20 | val classLoader = getClass.getClassLoader 21 | val file = new File(classLoader.getResource(fileName).getFile) 22 | val mfr = new MatFileReader(file) 23 | mfr.getContent.map{ 24 | case (key, array: MLDouble) => (key, array.asInstanceOf[MLDouble].getArray) 25 | case (key, array: MLUInt8) => (key, array.asInstanceOf[MLUInt8].getArray.map(_.map(_.toDouble))) 26 | }.toMap 27 | } 28 | 29 | } 30 | --------------------------------------------------------------------------------