Ejemplo n.º 1
0
        public void read_test()
        {
            string basePath = NUnit.Framework.TestContext.CurrentContext.TestDirectory;

            MemoryStream file   = new MemoryStream(Encoding.Default.GetBytes(Resources.L1R_LR_a9a));
            TextReader   reader = new StreamReader(file);

            File.WriteAllText(Path.Combine(basePath, "svm.txt"), reader.ReadToEnd());

            #region doc_read
            // Let's say we have used LIBLINEAR to learn a linear SVM model that has
            // been stored in a text file named "svm.txt". We would like to load this
            // same model in .NET and use it to make predictions using C#.
            //
            // First, we use LibSvmModel.Load to load the LIBLINEAR model from disk:
            LibSvmModel model = LibSvmModel.Load(Path.Combine(basePath, "svm.txt"));

            // Now, we can use the model class to create the equivalent Accord.NET SVM:
            SupportVectorMachine svm = model.CreateMachine();

            // Now, we can use this machine normally, like as shown in the
            // examples in the Support Vector Machine documentation page.
            #endregion

            Assert.AreEqual(2, svm.NumberOfClasses);
            Assert.AreEqual(122, svm.NumberOfInputs);
            Assert.AreEqual(1, svm.Weights.Length);
            Assert.AreEqual(1, svm.SupportVectors.Length);
        }
Ejemplo n.º 2
0
        public void ReadLinearMachineTest()
        {
            MemoryStream file = new MemoryStream(
                Encoding.Default.GetBytes(Resources.L1R_LR_a9a));

            LibSvmModel reader = LibSvmModel.Load(file);

            Assert.AreEqual(-1, reader.Bias);
            Assert.AreEqual(2, reader.Classes);
            Assert.AreEqual(123, reader.Dimension);
            Assert.AreEqual(2, reader.Labels.Length);
            Assert.AreEqual(+1, reader.Labels[0]);
            Assert.AreEqual(-1, reader.Labels[1]);
            Assert.AreEqual(LibSvmSolverType.L1RegularizedLogisticRegression, reader.Solver);
            Assert.AreEqual(null, reader.Vectors);
            Assert.AreEqual(123, reader.Weights.Length);



            for (int i = 0; i < a9a_weights.Length; i++)
            {
                Assert.AreEqual(a9a_weights[i], reader.Weights[i]);
            }


            var machine = reader.CreateMachine();

            Assert.IsNull(machine.SupportVectors);
            Assert.AreEqual(machine.Threshold, a9a_weights[0]);

            for (int i = 0; i < machine.Weights.Length; i++)
            {
                Assert.AreEqual(machine.Weights[i], a9a_weights[i + 1]);
            }
        }
Ejemplo n.º 3
0
        public void test_s3()
        {
            var train = prepare(3);

            LibSvmModel model = train.Model;
            Assert.AreEqual(LibSvmSolverType.L2RegularizedL1LossSvcDual, model.Solver);
            // string str = model.Weights.ToCSharp();
            double[] expected = new double[] { -0.401629598520185, -0.773692686460867, -0.312335214627432, 0.106848014589882, 0.296745504093646, 0.280804783884593, 0.21021590349813, -0.101137961719607, 0.495334138592479, 0.477317757881286, 0.0657758292278433, -0.0651672937733189, -0.288411874610754, 0, -0.181019257723421, -0.0680152700236748, -0.0661676771714488, -0.0380062865518476, -0.0484211070497921, -0.129083523731551, -0.0735363957707153, 0.106819833694668, -0.236558408497104, 0.352491492414635, 0.0290482334017427, -0.0322153530423156, -0.244087074776336, -0.288411874610754, 0.107229023942626, 0.00308051893375935, 0.0421908594410488, -0.00790251872382717, 0.425534535239457, -0.167817071824762, -0.288411874610754, -0.740390697468092, -0.236558408497104, -0.0735363957707153, -0.0031671196405721, 0.652023022856298, 0.713663493859524, -0.416362049843629, -0.520583325833811, -0.378035368261245, -0.0335263941526525, -0.376226795521769, 0.609440841233395, 0.637217622238635, -0.0543349830534787, -0.396783151507348, 0.383083257789943, 0.722724047607922, 0.550617601506356, -0.327001175612184, -0.241745452425932, 0.185575222960543, -0.478821483978426, -0.132412425831108, -0.404669649893571, 0.500145178858346, -0.149668109563638, 0.826658732621267, -0.374766720805368, 0.0401701464755676, -0.0835455064778577, -0.619468889565957, -0.190677360767839, 0.0677256354134698, 0.093206559864874, -0.40031600645515, -0.22411586109885, 0.0618700737554764, -0.44142323440156, 0.0397936358813781, -0.817754699472699, 0.416125100952518, -0.607878191385389, 0.206248592865198, -0.765676341984267, -0.121518520859692, 0.0146734875332432, 0.205079297819953, 0.265812478970579, 0.201415806107914, 0.288411874610754, 0.153218673646929, -0.160453127113863, 0.588019337231132, 0.446009429789949, -2.77555756156289E-17, -0.157261230804335, 0.123914113655308, -0.576823749221507, -0.348510612465221, -0.288411874610753, 0.183444744474292, 0.169671275146074, -5.20417042793042E-18, 0.484516101138739, 0.330602734051802, 0.0424778472473847, -0.345954210465833, -0.576823749221508, -0.0537838457373276, 0.0287365977898098, 0.576979482790363, 0.61633825164591, -0.576823749221507, 0, 0.0398814950623403, 0.0151109587266906, 0.242846018917985, -0.746063286902218, 0.0235389972341098, -0.28201296387134, 1.38777878078145E-17, -0.0380071556910028, 0.0862240661884463, 0.134568555571055, -0.0444222025263786, -0.288411874610754, -0.296648036337198, 0.174431528417172, 0 };
            Assert.IsTrue(model.Weights.IsEqual(expected, 1e-10));
            check(train, model);
        }
Ejemplo n.º 4
0
        public void test_s1()
        {
            var train = prepare(1);

            LibSvmModel model = train.Model;
            Assert.AreEqual(LibSvmSolverType.L2RegularizedL2LossSvcDual, model.Solver);
            // string str = model.Weights.ToCSharp();
            double[] expected = new double[] { -0.187002350839077, -0.372888673818314, -0.173357250924836, 0.0460061306863742, 0.159432235050686, 0.153805208167014, 0.102280655364794, -0.0399791292433845, 0.22887110689633, 0.249699503488536, 0.0145478303618283, -0.023883724996344, -0.449871257963284, 0, -0.0958590593405079, -0.0272292388805825, -0.033334768137011, -0.0173823549276472, -0.0131969295533334, -0.105180205573265, -0.0194718215279722, 0.085315958226414, -0.0859046378808536, 0.21043089145851, 0.0112064936060971, 0.00349206877157435, -0.108970664758944, -0.0997423577909522, 0.163203008994957, -0.0130443283659992, -0.0573780292106573, 0.00277802392862691, 0.245132553222642, -0.0908327191938414, -0.328036584745414, -0.433663364549813, -0.0859046378808536, -0.0194718215279722, 0.0146985623776712, 0.337338910741885, 0.368184238724315, -0.241895478441348, -0.267330264569461, -0.256214195052238, -0.072326089026487, -0.169882306963936, 0.452461744490078, 0.259321393457042, 0.0398475344105853, -0.184653976176208, 0.164098787141844, 0.306373565792976, 0.234268730131852, -0.202490944065139, -0.113615464557767, 0.0807820000188813, -0.280402909344066, -0.00479408170714506, -0.340275919151371, 0.274133229827586, -0.150926961870586, 0.381153555925809, -0.196795847822892, -0.0636900281416252, -0.0313036428203732, -0.203275792071456, -0.0730905959085381, 0.024278357530068, 0.0548212332914942, -0.130389802707576, -0.124779660013882, -0.0109324789391815, -0.221739138341446, 0.0347367875023654, -0.379836317286808, 0.19283396644772, -0.29283784131755, 0.105835490478467, -0.349478285940799, -0.076814900489791, -0.0121075470121231, 0.0970441396590154, 0.154354242944623, 0.10733004579722, 0.258817529621069, 0.08691176694377, -0.148671631787905, 0.238558848358923, 0.215938565641395, -0.209791248020613, -0.0811678661712386, 0.199816035240309, -0.34989098521102, -0.188994871017643, -0.197672501645266, 0.102161398092268, 0.0920984821714616, -0.0700726392792897, 0.224548403332015, 0.282920742042534, 0.0323108035772194, -0.0331970097274, -0.287892388521086, -0.0831699561226539, 0.12033750074312, 0.421368403976953, 0.29302432542685, -0.373886665293191, -0.0799840697019076, 0.06332981582091, 0.0808506496073297, 0.0820943265217946, -0.586678861595612, -0.0168931559449453, -0.100453547477385, -0.0969937132859026, -0.0775245667562146, -0.0508634252247505, 0.18550658652016, -0.101291607856744, -0.0545868086411493, -0.357727276179065, -0.00899044404008111, 0 };
            Assert.IsTrue(model.Weights.IsEqual(expected, 1e-10));
            check(train, model);
        }
Ejemplo n.º 5
0
        public void test_s2()
        {
            var train = prepare(2);

            LibSvmModel model = train.Model;
            Assert.AreEqual(LibSvmSolverType.L2RegularizedL2LossSvc, model.Solver);
            string str = model.Weights.ToCSharp();
            //#if DEBUG
            double[] expected = new double[] { -0.187488643204109, -0.373136497040337, -0.168596301812443, 0.0451521813591027, 0.157154532897231, 0.151937441392535, 0.104843234216973, -0.0407496210011012, 0.230627674025567, 0.251448948904186, 0.0135428679089929, -0.02227322036464, -0.450015219699401, 1.55567658030135E-07, -0.0952819033820788, -0.0300774932724827, -0.0343337732410459, -0.0156920402206682, -0.0121034330877106, -0.106903401705997, -0.0181793655497043, 0.0853496931341161, -0.0868039864022859, 0.209832779335181, 0.0122401477633454, 0.00194323530710603, -0.111417438728785, -0.0969894151640031, 0.165850217966184, -0.0127391870484018, -0.0569999343345307, 0.00324607565297792, 0.243185323331783, -0.0890270787770432, -0.330076307983963, -0.430064188235043, -0.0868039864022859, -0.0181793655497043, 0.0141833830704617, 0.333375513912553, 0.366967735914914, -0.240073321212837, -0.269871250399526, -0.259150148036756, -0.0681802361966292, -0.168295007891941, 0.451113584618734, 0.260850594802921, 0.0365592239584133, -0.184725821022451, 0.164721216620745, 0.310051242456444, 0.236333432692522, -0.200080870448996, -0.115979073970556, 0.0803217030777578, -0.278875863241091, -0.00415381843091501, -0.340830028558683, 0.273195694522959, -0.149962968468448, 0.381974545217254, -0.197410873781337, -0.0655370867335718, -0.0313931719423322, -0.20674671693062, -0.0683753390334389, 0.0244039447956699, 0.0566754317405574, -0.130629134898303, -0.124681081753469, -0.0132578030884981, -0.219911872243387, 0.0324232290392954, -0.377134635298919, 0.18964599209494, -0.292652650651508, 0.105164007447436, -0.349429026170129, -0.0758627041764055, -0.0109266689154976, 0.0947919154889142, 0.153937840569, 0.107111789654718, 0.257897774071562, 0.0857333928025374, -0.146980660963761, 0.237451375255384, 0.212351028197568, -0.211457594949358, -0.0819757493882409, 0.199304913307405, -0.349739659624966, -0.190015573708603, -0.20216859674772, 0.102384502181668, 0.0909173081352463, -0.0685254780872241, 0.225005648134243, 0.284696897812626, 0.0309696439559705, -0.0341233048939117, -0.285523796575142, -0.0839428976156166, 0.119330850958298, 0.421711442694419, 0.293845599109487, -0.372609566010577, -0.0796039339198295, 0.0622752858389034, 0.0795779904821594, 0.0819649245653717, -0.587624329159858, -0.017941306571887, -0.101942218979906, -0.0961266251941682, -0.0787327889007127, -0.0503197252725044, 0.187890906555972, -0.099453269658236, -0.0576271277200639, -0.35885871690453, -0.00724823533973023, 2.80613693735061E-07 };
            //#else
            //            double[] expected = new double[] { -0.187488684683379, -0.373136487138834, -0.168596297827493, 0.0451521846830595, 0.157154535635041, 0.151937442367844, 0.104843216339796, -0.0407496404691985, 0.230627661950133, 0.251448927969665, 0.0135428465544977, -0.0222732365318683, -0.45001517816874, 1.18359959264837E-07, -0.0952818987910206, -0.0300774895097418, -0.0343337692522382, -0.0156920361762693, -0.0121034285510775, -0.106903403675511, -0.0181793619237928, 0.0853497076222055, -0.0868039821127823, 0.20983279079475, 0.0122401516611134, 0.0019432371412759, -0.111417430606487, -0.0969894135371026, 0.165850206643491, -0.0127391880660181, -0.0569998925382195, 0.00324608115445964, 0.243185324068444, -0.0890270290518889, -0.330076419854405, -0.430064190167946, -0.0868039821127823, -0.0181793619237928, 0.0141833888023809, 0.333375523121628, 0.366967727278737, -0.240073297162667, -0.269871229633974, -0.259150143545648, -0.0681802040735845, -0.168294996426294, 0.451113521282955, 0.260850592207594, 0.0365592298076514, -0.184725824270251, 0.164721222886, 0.310051246074565, 0.236333434359015, -0.20008087099189, -0.115979076249734, 0.0803217049947406, -0.278875862818475, -0.00415381064275821, -0.340830125196113, 0.273195700088985, -0.149962962605033, 0.381974569219595, -0.19741088793074, -0.0655370663375542, -0.0313931803316783, -0.206746704058553, -0.0683753528415963, 0.0244039493222803, 0.0566754286498214, -0.130629130866142, -0.12468107250134, -0.0132577968850348, -0.219911861224717, 0.032423238944097, -0.377134625488273, 0.189646003207757, -0.292652641026957, 0.105164018746521, -0.349429028990722, -0.0758626978823985, -0.0109266633784906, 0.0947919231011283, 0.153937844869923, 0.107111779163649, 0.257897794062107, 0.0857333608630217, -0.14698066784591, 0.237451344698826, 0.212351002622261, -0.211457780819405, -0.081975722103927, 0.199304907430013, -0.349739620147625, -0.190015597100508, -0.202168584601848, 0.102384508137795, 0.090917282924455, -0.0685260968157893, 0.225005654849588, 0.284696889782371, 0.0309696485382446, -0.0341233101589734, -0.285523826478739, -0.083942927459638, 0.119330816533167, 0.421711422706037, 0.293845614531373, -0.372609589321001, -0.0796039532633266, 0.0622752947768166, 0.0795780383249316, 0.0819649149261612, -0.587624370921401, -0.0179413154714611, -0.101942215921912, -0.0961266191331531, -0.078732798490904, -0.0503197271601607, 0.187890926560842, -0.09945328709214, -0.0576271350838896, -0.35885875658865, -0.00724823688139036 };
            //#endif
            Assert.IsTrue(model.Weights.IsEqual(expected, 1e-10));
            check(train, model);
        }
Ejemplo n.º 6
0
        private static void check(Liblinear.Train train, LibSvmModel model)
        {
            var svm = train.Machine;
            //Assert.IsTrue(svm.SupportVectors.Length > 1);

            svm.Compress();

            Assert.AreEqual(svm.Threshold, model.Weights[0]);
            Assert.AreEqual(svm.SupportVectors.Length, 1);
            double[] expected = model.Weights.Get(1, 0);
            double[] actual = svm.SupportVectors[0].ToDense(model.Dimension);
            if (expected.Length < actual.Length)
                expected = Vector.Create(actual.Length, expected);
            Assert.IsTrue(expected.IsEqual(actual, 1e-10));
        }
Ejemplo n.º 7
0
        public void test_s6()
        {
            var train = prepare(6);

            LibSvmModel model = train.Model;
            Assert.AreEqual(LibSvmSolverType.L1RegularizedLogisticRegression, model.Solver);
            string str = model.Weights.ToCSharp();
            //#if DEBUG
            double[] expected = new double[] { -0.00193216355810173, -1.52731426685158, -0.599776711650451, -0.00319564089166846, 0.289527791149864, 0.272364988108588, 0.246704120354527, -0.129625236613622, 0.559784132997766, 0.665288912239086, 0.00082130247355937, -0.068685525408862, 0, 0, -0.184148089259529, -0.00303543635838481, -0.0129520891189136, 0.0144814543999521, 0.0304744789897905, -0.255252153444507, -0.00174662277901463, 0.209977934175585, -0.256132564072238, 0.563586870298957, 0.0072239412440491, 0, -0.23771432070953, -0.205558283623123, 0.397834193197151, 0, 0, 0, 0.664122274013464, 0, 0, -1.24531058191161, -0.106190729454989, -0.0018559838697592, 0.144472769418946, 1.00783329636676, 1.35202802007435, -0.423233984488684, -0.572197179894806, -0.496787925326737, 0, -0.12436408113766, 0.624902459817089, 0.659030417868679, 0.088965500604939, -0.681518377882409, 0.37301023405541, 0.782781914475685, 0.603519596026014, -0.631412190730473, -0.343158925421728, 0.0800638946866124, -0.824172381850303, 0, 0, 0.676962549507195, 0, 1.372607551119, -0.770481643706557, 0, 0.132198824325896, -0.475314987731171, -0.0741577066926857, 0.118463108590901, 0, -0.193221047885999, -0.245050084471318, 0, -0.80376848156524, 0, -1.61247672654214, 0, -1.11080844516924, 0, -1.03033583361617, -0.220817871657321, -0.00276707775003049, 0.291414096665174, 0.456261126214769, 0.239380035634766, 0, 0, -0.101248803601272, 0.259891352073587, 0.345707368384023, 0, 0, 0.095523716357443, 0, 0, -0.0998613789796218, 0, 0, 0, 0.59747953609938, 0.322817116322095, 0, 0, 0, -0.370867372403255, 0, 0, 0, 0, 0, 0, 0, 0, -0.32374708199723, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            //#else
            //            double[] expected = new double[] { 0, -1.52411930888346, -0.596583111817898, 0, 0.292727759023382, 0.275575366462407, 0.24676095743599, -0.129572201230956, 0.559844892231062, 0.66534521821825, 0.000879164230483986, -0.0686330886172225, 0, 0, -0.181111397622509, 0, -0.00991428352063406, 0.0175209904561796, 0.0335134989297192, -0.255248789526732, -0.00176502791555098, 0.209984782120422, -0.367448607497345, 0.563593171185714, 0.00722090309758671, 0, -0.237718621468823, -0.205548471968789, 0.39784021510125, 0, 0, 0, 0.664127260363579, 0, 0, -1.25044015241842, 0, -0.00696263268540241, 0.13934699307474, 1.0027042612194, 1.37706274399545, -0.399190697412508, -0.548129185552888, -0.472742183132691, 0.0239080067826225, -0.100301587442094, 0.649939683214092, 0.659022287123922, 0.0889535736703365, -0.681529198102947, 0.372998740354973, 0.782770361970399, 0.603509699549445, -0.63141768284789, -0.343165978301099, 0.0800517084939236, -0.824178452698112, 0, 0, 0.67695344281223, 0, 1.37261423836496, -0.769604742726835, 0, 0.133193714506675, -0.474719179756764, -0.0731460851858957, 0.118470294170168, 0, -0.193218228858021, -0.24504663547359, 0, -0.803766963049391, 0, -1.6124656118763, 0, -1.11078701834284, 0, -1.05850565047486, -0.248995040148162, -0.0309462280753098, 0.263232619254183, 0.428081745732971, 0.239394878623662, 0, 0, -0.101230987414069, 0.259900887582786, 0.345724852074213, 0, 0, 0.0955162313021578, 0, 0, -0.0998563602922507, 0, 0, 0, 0.597462627643535, 0.32283415080533, 0, 0, 0, -0.370870419527936, 0, 0, 0, 0, 0, 0, 0, 0, -0.323785935489522, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            //#endif
            Assert.IsTrue(model.Weights.IsEqual(expected, 1e-10));
            check(train, model);
        }
Ejemplo n.º 8
0
        public void WriteLinearMachineTest()
        {
            MemoryStream destination = new MemoryStream();

            var model = new LibSvmModel()
            {
                Bias      = -1,
                Classes   = 2,
                Dimension = 123,
                Labels    = new[] { +1, -1 },
                Solver    = LibSvmSolverType.L1RegularizedLogisticRegression,
                Weights   = a9a_weights
            };

            model.Save(destination);

            destination.Seek(0, SeekOrigin.Begin);
            TextReader textReader = new StreamReader(destination);

            string[] actual = textReader.ReadToEnd()
                              .Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            string[] expected = Resources.L1R_LR_a9a
                                .Split(new[] { "\r\n" }, StringSplitOptions.None);

            Assert.AreEqual(expected.Length, actual.Length);

            for (int i = 0; i < 7; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }

            for (int i = 6; i < expected.Length; i++)
            {
                if (expected[i] == actual[i])
                {
                    continue;
                }

                double a = Double.Parse(expected[i], CultureInfo.InvariantCulture);
                double b = Double.Parse(actual[i], CultureInfo.InvariantCulture);

                Assert.AreEqual(a, b);
            }

            Assert.AreEqual(expected[expected.Length - 1], String.Empty);
        }
Ejemplo n.º 9
0
        public void ReadWriteTest_a9a()
        {
            string basePath = NUnit.Framework.TestContext.CurrentContext.TestDirectory;

            MemoryStream file = new MemoryStream(Encoding.Default.GetBytes(Resources.L1R_LR_a9a));

            LibSvmModel model1   = LibSvmModel.Load(file);
            string      savePath = Path.Combine(basePath, "svm.txt");

            var svm1 = model1.CreateMachine();

            model1.Save(savePath);

            LibSvmModel model2 = LibSvmModel.Load(savePath);
            var         svm2   = model2.CreateMachine();

            LibSvmModel model3 = LibSvmModel.FromMachine(svm1);
            var         svm3   = model3.CreateMachine();

            model3.Solver = LibSvmSolverType.L1RegularizedLogisticRegression;

            string aPath = Path.Combine(basePath, "a.txt");
            string bPath = Path.Combine(basePath, "b.txt");
            string cPath = Path.Combine(basePath, "c.txt");

            model1.Save(aPath);
            model2.Save(bPath);
            model3.Save(cPath);

            string a = File.ReadAllText(aPath);
            string b = File.ReadAllText(bPath);
            string c = File.ReadAllText(cPath);

            Assert.AreEqual(a, b);
            Assert.AreEqual(a, c);


            Assert.AreEqual(svm1.Weights, svm2.Weights);
            Assert.AreEqual(svm1.SupportVectors, svm2.SupportVectors);
            Assert.AreEqual(svm1.Threshold, svm2.Threshold);

            Assert.AreEqual(svm1.Weights, svm3.Weights);
            Assert.AreEqual(svm1.SupportVectors, svm3.SupportVectors);
            Assert.AreEqual(svm1.Threshold, svm3.Threshold);
        }
Ejemplo n.º 10
0
        public void WriteLinearMachineTest_ExactCopy()
        {
            MemoryStream file = new MemoryStream(
                Encoding.Default.GetBytes(Resources.L1R_LR_a9a));

            LibSvmModel reader = LibSvmModel.Load(file);

            MemoryStream destination = new MemoryStream();

            reader.Save(destination);

            destination.Seek(0, SeekOrigin.Begin);

            TextReader textReader = new StreamReader(destination);

            string[] actual = textReader.ReadToEnd()
                              .Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            string[] expected = Resources.L1R_LR_a9a
                                .Split(new[] { "\r\n" }, StringSplitOptions.None);

            Assert.AreEqual(expected.Length, actual.Length);

            for (int i = 0; i < 7; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }

            for (int i = 6; i < expected.Length; i++)
            {
                if (expected[i] == actual[i])
                {
                    continue;
                }

                double a = Double.Parse(expected[i], CultureInfo.InvariantCulture);
                double b = Double.Parse(actual[i], CultureInfo.InvariantCulture);

                Assert.AreEqual(a, b);
            }

            Assert.AreEqual(expected[expected.Length - 1], String.Empty);
        }
Ejemplo n.º 11
0
        static void Main()
        {
            // Path to the folder with classifiers models
            var jarRoot = @"\Users\devir\OneDrive\Documents\Visual Studio 2015\Projects\ner";
            var classifiersDirecrory = jarRoot + @"\classifiers";

            // Loading 3 class classifier model
            var classifier = CRFClassifier.getClassifierNoExceptions(
                classifiersDirecrory + @"\english.muc.7class.distsim.crf.ser.gz");

            var s1 = " She got up this morning at 9:00 am and went to a shop to spend five dollars to buy a 50% off toothbrush.";


            var s2 = "Tell the latest on olympics from the New York.";

            Console.WriteLine("{0}\n", classifier.classifyToCharacterOffsets(s1));
            Console.WriteLine("{0}\n", classifier.classifyWithInlineXML(s1));

            //MUNCULIN NER SATU SATU
            string result = classifier.classifyWithInlineXML(s1);
            String substr1 = "TIME";
            String substr2 = "LOCATION";
            String substr3 = "PERSON";
            String substr4 = "ORGANIZATION";
            String substr5 = "MONEY";
            String substr6 = "Percent";
            String substr7 = "Date";
            string total1, total2, total3, total4, total5, total6, total7;

            //if (result.Contains(substr1))
            //{
            //    string[] hasiltime = GetStringInBetween("<TIME>", "</TIME>", result, false, false);
            //    string output_time = hasiltime[0];
            //    string next_time = hasiltime[1];
            //    total1 = output_time;
            //   // Console.WriteLine(output_time);
            //}
            //if (result.Contains(substr2))
            //{
            //    string[] hasillocation = GetStringInBetween("<LOCATION>", "</LOCATION>", result, false, false);
            //    string output_location = hasillocation[0];
            //    string next_loc = hasillocation[1];
            //    //Console.WriteLine(output_location);
            //    total2 = output_location;
            //}
            //if (result.Contains(substr3))
            //{
            //    string[] hasilperson = GetStringInBetween("<PERSON>", "</PERSON>", result, false, false);
            //    string output_person = hasilperson[0];
            //    string next_person = hasilperson[1];
            //    //Console.WriteLine(hasilperson);
            //    total3 = output_person;
            //}
            //if (result.Contains(substr4))
            //{
            //    string[] hasilORGANIZATION = GetStringInBetween("<ORGANIZATION>", "</ORGANIZATION>", result, false, false);
            //    string output_ORGANIZATION = hasilORGANIZATION[0];
            //    string next_ORGANIZATION = hasilORGANIZATION[1];
            //    //Console.WriteLine(output_ORGANIZATION);
            //    total4 = output_ORGANIZATION;
            //}
            //if (result.Contains(substr5))
            //{
            //    string[] hasilMONEY = GetStringInBetween("<MONEY>", "</MONEY>", result, false, false);
            //    string output_MONEY = hasilMONEY[0];
            //    string next_MONEY = hasilMONEY[1];
            //    // Console.WriteLine(output_MONEY);
            //    total5 = output_MONEY;
            //}
            //if (result.Contains(substr6))
            //{
            //    string[] hasilPercent = GetStringInBetween("<Percent>", "</Percent>", result, false, false);
            //    string output_Percent = hasilPercent[0];
            //    string next_Percent = hasilPercent[1];
            //    //Console.WriteLine(output_Percent);
            //    total6 = output_Percent;
            //}
            //if (result.Contains(substr7))
            //{
            //    string[] hasilDate = GetStringInBetween("<Date>", "</Date>", result, false, false);
            //    string output_Date = hasilDate[0];
            //    string next_Date = hasilDate[1];
            //    //Console.WriteLine(output_Date);
            //    total7 = output_Date;

            //}

            string[] hasiltime   = GetStringInBetween("<TIME>", "</TIME>", result, false, false);
            string   output_time = hasiltime[0];
            string   next_time   = hasiltime[1];

            total1 = output_time;
            //Console.WriteLine(output_time);

            string[] hasillocation   = GetStringInBetween("<LOCATION>", "</LOCATION>", result, false, false);
            string   output_location = hasillocation[0];
            string   next_loc        = hasillocation[1];

            //Console.WriteLine(output_location);
            total2 = output_location;

            string[] hasilperson   = GetStringInBetween("<PERSON>", "</PERSON>", result, false, false);
            string   output_person = hasilperson[0];
            string   next_person   = hasilperson[1];

            //Console.WriteLine(hasilperson);
            total3 = output_person;

            string[] hasilORGANIZATION   = GetStringInBetween("<ORGANIZATION>", "</ORGANIZATION>", result, false, false);
            string   output_ORGANIZATION = hasilORGANIZATION[0];
            string   next_ORGANIZATION   = hasilORGANIZATION[1];

            //Console.WriteLine(output_ORGANIZATION);
            total4 = output_ORGANIZATION;

            string[] hasilMONEY   = GetStringInBetween("<MONEY>", "</MONEY>", result, false, false);
            string   output_MONEY = hasilMONEY[0];
            string   next_MONEY   = hasilMONEY[1];

            // Console.WriteLine(output_MONEY);
            total5 = output_MONEY;

            string[] hasilPercent   = GetStringInBetween("<Percent>", "</Percent>", result, false, false);
            string   output_Percent = hasilPercent[0];
            string   next_Percent   = hasilPercent[1];

            //Console.WriteLine(output_Percent);
            total6 = output_Percent;

            string[] hasilDate   = GetStringInBetween("<Date>", "</Date>", result, false, false);
            string   output_Date = hasilDate[0];
            string   next_Date   = hasilDate[1];

            //Console.WriteLine(output_Date);
            total7 = output_Date;


            //BOW
            string semua = total1 + ";" + total2 + ";" + total3 + ";" + total4 + ";" + total5 + ";" + total6 + ";" + total7 + ";";

            Console.WriteLine(semua);
            string[] gabungan = { total1, total2, total3, total4, total5, total6, total7 };

            foreach (var a in gabungan)
            {
                Console.WriteLine(a);
            }
            string[][] words = gabungan.Tokenize();
            //var codebook = new TFIDF()
            //{
            //    Tf = TermFrequency.Log,
            //    Idf = InverseDocumentFrequency.Default
            //};
            var codebook = new BagOfWords()
            {
                MaximumOccurance = 1 // the resulting vector will have only 0's and 1's
            };

            codebook.Learn(words);
            double[]   bow1            = codebook.Transform(words[0]);
            double[]   bow2            = codebook.Transform(words[1]);
            double[]   bow3            = codebook.Transform(words[2]);
            double[]   bow4            = codebook.Transform(words[3]);
            double[]   bow5            = codebook.Transform(words[4]);
            double[]   bow6            = codebook.Transform(words[5]);
            double[]   bow7            = codebook.Transform(words[6]);
            double[][] keseluruhanBOW1 = { bow1, bow2, bow3, bow4, bow5, bow6, bow7 };

            //coba
            bool quitNow = false;

            while (!quitNow)
            {
                string val;
                Console.Write("Enter question: ");
                val = Console.ReadLine();
                string[] textss =
                {
                    val,
                };



                string[][] wordss = textss.Tokenize();
                //var codebook2 = new TFIDF()
                //{
                //    Tf = TermFrequency.Log,
                //    Idf = InverseDocumentFrequency.Default
                //};
                var codebook2 = new BagOfWords()
                {
                    MaximumOccurance = 1 // the resulting vector will have only 0's and 1's
                };
                codebook2.Learn(wordss);
                double[] c1   = codebook2.Transform(wordss[0]);
                string   path = @"C:\Users\devir\OneDrive\Documents\Visual Studio 2015\Projects\ner";
                //var load_svm_model = Serializer.Load<MulticlassClassifierBase>(Path.Combine(path, "pelatihanSVMbayardanpergi.bin"));


                //LibSvmModel modela = LibSvmModel.Load(Path.Combine(path, "pelatihanSVMbayardanpergi.bint"));
                //int jawaban = load_svm_model.Decide( c1); // answer will be 2.
                // Now, we can use the model class to create the equivalent Accord.NET SVM:

                //Console.WriteLine(jawaban);
                LibSvmModel model = LibSvmModel.Load(Path.Combine(path, "pelatihanSVMbayardanpergi.txt"));

                // Now, we can use the model class to create the equivalent Accord.NET SVM:
                SupportVectorMachine svm = model.CreateMachine();

                // Compute classification error
                bool predicted = svm.Decide(c1);

                // var machine = teacher.Learn(inputs, outputs);

                if (predicted == false)
                {
                    Console.WriteLine("BAYAR");
                }
                ;
                if (predicted == true)
                {
                    Console.WriteLine("PERGI");
                }
                ;
                Console.ReadLine();
            }

            // In order to convert any 2d array to jagged one
            // let's use a generic implementation
        }