<commit_before>package io.github.mandar2812.dynaml.examples

import java.io.File

import breeze.linalg.DenseVector
import com.github.tototoshi.csv.CSVWriter
import io.github.mandar2812.dynaml.utils
import scala.collection.mutable.{MutableList => ML}

/**
 * @author mandar2812 on 3/8/15.
 * Carry out experiment with the FS-LSSVM
 * on three possible data sets.
 * 1. Forest Cover type : Class 2 vs rest
 * 2. Adult Data set
 * 3. Magic Gamma Telescope Data set.
 *
 * Conduct a number of trials and average out
 * the performance results and store it in a file
 */
object FSExperiment {
  def apply(nCores: Int = 4, trials: Int,
            data: String = "ForestCover",
            root: String = "data/",
            factor: Int = 2,
            kernels: List[String] = List("RationalQuadratic", "Cauchy",
              "Laplacian", "RBF", "Linear")): Unit = {
    val writer = CSVWriter.open(new File(root+data+"Res.csv"), append = true)

    def Experiment(kern: String, prototypes: Int = 100):Unit = {

      List("gs", "csa").foreach((globalOpt) => {

        List((2, 0.55), (3, 0.45)).foreach((gridSize) => {
          val perfs: ML[DenseVector[Double]] = ML()
          var times: ML[Double] = ML()
          (1 to trials).toList.foreach((trial) => {
            data match {
              case "ForestCover" => {
                val t0 = System.currentTimeMillis().toDouble/1000.0
                perfs += TestForestCover(nCores,
                  prototypes, kern, globalOpt,
                  grid = gridSize._1, step = gridSize._2,
                  frac = 1.0, dataRoot = root, local = true,
                  logscale = true, paraFactor = factor)
                times += System.currentTimeMillis().toDouble/1000.0 - t0
              }
              case "HiggsSUSY" => {
                val t0 = System.currentTimeMillis().toDouble/1000.0
                perfs += TestSUSY(nCores,
                  prototypes, kern, globalOpt,
                  grid = gridSize._1, step = gridSize._2,
                  frac = 1.0, dataRoot = root, local = true,
                  logscale = true, paraFactor = factor)
                times += System.currentTimeMillis().toDouble/1000.0 - t0
              }
              case "Adult" => {
                val t0 = System.currentTimeMillis().toDouble/1000.0
                perfs += TestAdult(nCores, prototypes, kern,
                  globalOpt, grid = gridSize._1, step = gridSize._2,
                  frac = 1.0, logscale = true, paraFactor = factor)
                times += System.currentTimeMillis().toDouble/1000.0 - t0
              }
              case "MagicGamma" => {
                val t0 = System.currentTimeMillis().toDouble/1000.0
                perfs += TestMagicGamma(nCores,<commit_msg>Added Delve to FSExp<commit_after>package io.github.mandar2812.dynaml.examples

import java.io.File

import breeze.linalg.DenseVector
import com.github.tototoshi.csv.CSVWriter
import io.github.mandar2812.dynaml.utils
import scala.collection.mutable.{MutableList => ML}

/**
 * @author mandar2812 on 3/8/15.
 * Carry out experiment with the FS-LSSVM
 * on three possible data sets.
 * 1. Forest Cover type : Class 2 vs rest
 * 2. Adult Data set
 * 3. Magic Gamma Telescope Data set.
 *
 * Conduct a number of trials and average out
 * the performance results and store it in a file
 */
object FSExperiment {
  def apply(nCores: Int = 4, trials: Int,
            data: String = "ForestCover",
            root: String = "data/",
            factor: Int = 2,
            kernels: List[String] = List("RationalQuadratic", "Cauchy",
              "Laplacian", "RBF", "Linear")): Unit = {
    val writer = CSVWriter.open(new File(root+data+"Res.csv"), append = true)

    def Experiment(kern: String, prototypes: Int = 100):Unit = {

      List("gs", "csa").foreach((globalOpt) => {

        List((2, 0.55), (3, 0.45)).foreach((gridSize) => {
          val perfs: ML[DenseVector[Double]] = ML()
          var times: ML[Double] = ML()
          (1 to trials).toList.foreach((trial) => {
            data match {
              case "Delve" => {
                val t0 = System.currentTimeMillis().toDouble/1000.0
                perfs += TestDelve(nCores,
                  prototypes, kern, globalOpt,
                  grid = gridSize._1, step = gridSize._2,
                  frac = 1.0, logscale = true, paraFactor = factor)
                times += System.currentTimeMillis().toDouble/1000.0 - t0
              }

              case "ForestCover" => {
                val t0 = System.currentTimeMillis().toDouble/1000.0
                perfs += TestForestCover(nCores,
                  prototypes, kern, globalOpt,
                  grid = gridSize._1, step = gridSize._2,
                  frac = 1.0, dataRoot = root, local = true,
                  logscale = true, paraFactor = factor)
                times += System.currentTimeMillis().toDouble/1000.0 - t0
              }
              case "HiggsSUSY" => {
                val t0 = System.currentTimeMillis().toDouble/1000.0
                perfs += TestSUSY(nCores,
                  prototypes, kern, globalOpt,
                  grid = gridSize._1, step = gridSize._2,
                  frac = 1.0, dataRoot = root, local = true,
                  logscale = true, paraFactor = factor)
                times += System.currentTimeMillis().toDouble/1000.0 - t0
              }
              case "Adult" => {
                val t0 = System.currentTimeMillis().toDouble/1000.0
                perfs += TestAdult(nCores, prototypes, kern,
                  globalOpt, grid = gridSize._1, step = gridSize._2,
                  frac = 1.0, logscale = true, paraFactor = factor)
                times += System.currentTimeMillis().toDouble/1000.0 - t0
              }
              case "MagicGamma" => {
                val t0 = System.currentTimeMillis().toDouble/1000.0
                perfs += TestMagicGamma(nCores,
{'fraction_non_alphanumeric': 0.11663576605427271, 'fraction_numerical': 0.032361368616214393, 'mean_word_length': 1.8284080076263107, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2562633', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1709, 'n_words': 431}