{"id":52,"date":"2016-03-29T15:49:18","date_gmt":"2016-03-29T15:49:18","guid":{"rendered":"http:\/\/kelp.unidevel.it\/?page_id=52"},"modified":"2017-02-15T19:03:58","modified_gmt":"2017-02-15T19:03:58","slug":"using-a-cache","status":"publish","type":"page","link":"http:\/\/www.kelp-ml.org\/?page_id=52","title":{"rendered":"Using a Cache"},"content":{"rendered":"<p>Caching is an important feature of KeLP. In most of the cases, kernel computation between two examples are useful in different step of the learning process. If one caches this computation, the learning algorithm can be quicker, as computation already done can be accessed directly from a cache.<\/p>\n<p>For this reason, KeLP implements two types of caching. One is the <em>norm<\/em> cache, that is useful to cache the values of the norm in the kernel space. The other is a <em>kernel<\/em> cache, that is the storage of the kernel computations.<\/p>\n<p>In the following snippet, an example on how to use these two caches is provided. It refers to the <a title=\"Tree Kernels\" href=\"http:\/\/sag.art.uniroma2.it\/demo-software\/kelp\/kebal-tree-kernels\/\">Tree Kernels <\/a>dataset.<\/p>\n<pre>Kernel linear = new LinearKernel(\"bow\");\r\nFixIndexSquaredNormCache ncache = new FixIndexSquaredNormCache(6000);\r\nlinear.setNormCache(ncache);\r\nlinear = new NormalizationKernel(linear);\r\n\r\nKernel ptk = new PartialTreeKernel(\"tree\");\r\nFixIndexSquaredNormCache ncache1 = new FixIndexSquaredNormCache(6000);\r\nptk.setNormCache(ncache1);\r\nptk = new NormalizationKernel(ptk);\r\n\r\nLinearKernelCombination linearCombination = new LinearKernelCombination();\r\nlinearCombination.addKernel(1.0f, linear);\r\nlinearCombination.addKernel(1.0f, ptk);\r\nlinearCombination.normalizeWeights();\r\n\r\nKernelCache cache = new FixIndexKernelCache(6000);\r\nlinearCombination.setKernelCache(cache);<\/pre>\n<p>There are some general guidelines when using caches in KeLP.<br \/>\nWhen using kernel combination, the kernel cache is useful only on the outer kernels, that is the combination.<br \/>\nNorm cache are useful only when the norm in the kernel space is necessary. There are two cases when the norm cache can be beneficial. The first is when using a <em>RBF kernel<\/em>.<br \/>\nThe other case is when one wants to normalize a kernel function, that is when using a <em>NormalizationKernel<\/em>. In this case, the norm cache must be assigned to the inner kernel of a <em>NormalizationKernel<\/em>, as reported in the previous snippet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Caching is an important feature of KeLP. In most of the cases, kernel computation between two examples are useful in different step of the learning process. If one caches this computation, the learning algorithm can be quicker, as computation already done can be accessed directly from a cache. For this reason, KeLP implements two types <a href=\"http:\/\/www.kelp-ml.org\/?page_id=52\" rel=\"nofollow\"><span class=\"sr-only\">Read more about Using a Cache<\/span>[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":27,"menu_order":14,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/52"}],"collection":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=52"}],"version-history":[{"count":2,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/52\/revisions"}],"predecessor-version":[{"id":352,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/52\/revisions\/352"}],"up":[{"embeddable":true,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/27"}],"wp:attachment":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}