<commit_before>package neuroflow.playground

import neuroflow.core.Activator.Tanh
import neuroflow.core._
import neuroflow.core.WeightProvider.randomWeights
import neuroflow.nets.DynamicNetwork.constructor

import scala.annotation.tailrec

/**
  * @author bogdanski
  * @since 22.01.16
  */
object Sinusoidal {

  /**
    * Here the goal is to predict the shape of sin(10*x).
    * The net will be trained with the exact values from the interval [0.0 : 0.8]
    * and the task is to continue (or predict) the next values ]0.8 : 4.0] based on learned history.
    */
  def apply = {
    val fn = Tanh.apply
    val group = 4
    val sets = Settings(true, 10.0, 0.0000001, 500, None, None, Some(Map("t" -> 0.25, "c" -> 0.25)))
    val net = Network(Input(3) :: Hidden(5, fn) :: Hidden(3, fn) :: Output(1, fn) :: Nil, sets)
    val sinusoidal = Range.Double(0.0, 0.8, 0.05).grouped(group).toList.map(i => i.map(k => (k, Math.sin(10 * k))))
    val xsys = sinusoidal.map(s => (s.dropRight(1).map(_._2), s.takeRight(1).map(_._2)))
    val xs = xsys.map(_._1)
    val ys = xsys.map(_._2)
    net.train(xs, ys)
    val initial = Range.Double(0.0, 0.15, 0.05).zipWithIndex.map(p => (p._1, xs.head(p._2)))
    val result = predict(net, xs.head, 0.15, initial)
    result.foreach { r =>
      println(s"${r._1}, ${r._2}")
    }
  }

  @tailrec def predict(net: Network, last: Seq[Double], i: Double, results: Seq[(Double, Double)]): Seq[(Double, Double)] = {
    if (i < 4.0) {
      val score = net.evaluate(last).head
      predict(net, last.drop(1) :+ score, i + 0.05, results :+ (i, score))
    } else results
  }

}
<commit_msg>Better explanation<commit_after>package neuroflow.playground

import neuroflow.core.Activator.Tanh
import neuroflow.core._
import neuroflow.core.WeightProvider.randomWeights
import neuroflow.nets.DynamicNetwork.constructor

import scala.annotation.tailrec

/**
  * @author bogdanski
  * @since 22.01.16
  */
object Sinusoidal {

  /**
    * Here the goal is to predict the shape of sin(10*x).
    * The net will be trained with the exact function values drawn from the interval [0.0 : 0.8],
    * and the task is to continue (or predict) the next values from the interval ]0.8 : 4.0]
    * based solely on learned history.
    */
  def apply = {
    val fn = Tanh.apply
    val group = 4
    val sets = Settings(true, 10.0, 0.0000001, 500, None, None, Some(Map("t" -> 0.25, "c" -> 0.25)))
    val net = Network(Input(3) :: Hidden(5, fn) :: Hidden(3, fn) :: Output(1, fn) :: Nil, sets)
    val sinusoidal = Range.Double(0.0, 0.8, 0.05).grouped(group).toList.map(i => i.map(k => (k, Math.sin(10 * k))))
    val xsys = sinusoidal.map(s => (s.dropRight(1).map(_._2), s.takeRight(1).map(_._2)))
    val xs = xsys.map(_._1)
    val ys = xsys.map(_._2)
    net.train(xs, ys)
    val initial = Range.Double(0.0, 0.15, 0.05).zipWithIndex.map(p => (p._1, xs.head(p._2)))
    val result = predict(net, xs.head, 0.15, initial)
    result.foreach { r =>
      println(s"${r._1}, ${r._2}")
    }
  }

  @tailrec def predict(net: Network, last: Seq[Double], i: Double, results: Seq[(Double, Double)]): Seq[(Double, Double)] = {
    if (i < 4.0) {
      val score = net.evaluate(last).head
      predict(net, last.drop(1) :+ score, i + 0.05, results :+ (i, score))
    } else results
  }

}

{'fraction_non_alphanumeric': 0.17040630685263797, 'fraction_numerical': 0.046694966646452396, 'mean_word_length': 3.0879801734820322, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4440701', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1218, 'n_words': 323}