learning scala Function Recursive Tail Call】的更多相关文章

可以使用scala库,可以从字面上看出是在调用 递归函数: code import scala.util.control.TailCalls._ val arrayDonuts: Array[String] = Array("Vanilla Donut", "Strawberry Donut", "Plain Donut", "Glazed Donut") println("\nStep : How to defin…
Ordering using andThen: f(x) andThen g(x) = g(f(x)) Ordering using compose: f(x) compose g(x) = f(g(x)) println("Step 1: Assume a pre-calculated total cost amount") val totalCost: Double = println("\nStep 2: How to define a val function to…
[machine learning] Loss Function view 有关Loss Function(LF),只想说,终于写了 一.Loss Function 什么是Loss Function?wiki上有一句解释我觉得很到位,引用一下:The loss function quantifies the amount by which the prediction deviates from the actual values.Loss Function中文损失函数,适用于用于统计,经济,机…
Scala collection such as List or Sequence or even an Array to variable argument function using the syntax :_ *. code : def printReport(names: String*) { println(s"""Donut Report = ${names.mkString(" - ")}""") } prin…
println("Step 1: How to create a wrapper String class which will extend the String type") class DonutString(s: String) { def isFavoriteDonut: Boolean = s == "Glazed Donut" } println("\nStep 2: How to create an implicit function to…
Partial函数的定义 scala> val isVeryTasty: PartialFunction[String, String] = { case "Glazed Donut" | "Strawberry Donut" => "Very Tasty"}isVeryTasty: PartialFunction[String,String] = <function1> scala> isVeryTasty(&qu…
package com.aura.scala.day01 object genericClasses { def main(args: Array[String]): Unit = { val stack = new Stack[Int] stack.push() stack.push() println(stack.pop()) println(stack.pop()) } } class Stack[A] { private var elements: List[A] = Nil def p…
package com.aura.scala.day01 import scala.util.Random object extractorObject { def main(args: Array[String]): Unit = { // val customer1ID = CustomerID("Sukyoung") // Sukyoung--23098234908 // customer1ID match { // case CustomerID(name) => pri…
Sigmoid Function ReLU Function Tanh Function…
为什么需要值函数近似? 之前我们提到过各种计算值函数的方法,比如对于 MDP 已知的问题可以使用 Bellman 期望方程求得值函数:对于 MDP 未知的情况,可以通过 MC 以及 TD 方法来获得值函数,为什么需要再进行值函数近似呢? 其实到目前为止,我们介绍的值函数计算方法都是通过查表的方式获取的: 表中每一个状态 \(s\) 均对应一个 \(V(s)\) 或者每一个状态-动作 <\(s, a\)> 但是对于大型 MDP 问题,上述方法会遇到瓶颈: 太多的 MDP 状态.动作需要存储 单独…
数组:可变的,可索引的,元素具有相同类型的数据集合 一维数组 scala> val intValueArr = new Array[Int](3)intValueArr: Array[Int] = Array(0, 0, 0) scala> val myStrArr = Array("BigData","hadoop","spark")myStrArr: Array[String] = Array(BigData, hadoop, s…
1 .if satement 与其它语言不同的是,scala if statement 返回的是一个值 scala> val a = if ( 6 > 0 ) 1 else -1a: Int = 1 2. while statement 3. do.. while statement 4 for statement for ( 变量 <-  表达式 ) { 语句块}: scala> for ( i <- 1 to 3 ) println(i)123 scala> for…
scala读文件:   example: scala> import scala.io.Sourceimport scala.io.Source scala> var inputFile = Source.fromFile("text.txt")inputFile: scala.io.BufferedSource = non-empty iterator scala> for ( line <- inputFile.getLines()) println(lin…
scala 写文件功能: scala> import java.io.PrintWriterimport java.io.PrintWriter scala> val outputFile = new PrintWriter("text.txt")outputFile: java.io.PrintWriter = java.io.PrintWriter@213c812a scala> outputFile.println("hello panzidong&q…
控制台输出语句: print println example: scala> print("i=");print(i)i=345scala> println("hello ");println("world")hello world…
控制台输入语句: readInt, readDouble, readByte, readShort, readLong, readChar, readBoolean, readLine example:scala> import io.StdIn._import io.StdIn._ scala> var i=readInt()2i: Int = 2 scala> var f=readFloat()2.2f: Float = 2.2 scala> var b=readBoolean…
scala 变量: val : 声明时,必须被初始化,不能再重新赋值. scala> test = "only1"<console>:11: error: not found: value test test = "only1" ^<console>:12: error: not found: value test val $ires0 = test ^    var :可被多次赋值. scala> var test2 = &qu…
scala 操作符: 算术运算符:  +  - *  / % 关系统运算符: > , < ,= ,!= ,>=,<=, 逻辑运算符: && . || , ! 位运算符:&, |, ^,~,<<,>>,>>>(无符号右移) 赋值运算符: = 优先及由上及下…
1. Arbitrary multi parameters funcs sum(1,2,3,4,5) = sum(1 to 5: _*)the equal '=' can be ignored if there is none  return val def sum(args: Int*) = { var result = 0 for(arg <- args) result += arg result }   scala Array Buffer to Java List: import sca…
package com.example import akka.actor._ import akka.util.Timeout object Tutorial_03_Ask_Pattern extends App { val system = ActorSystem("DonutStoreActorySystem") val donutInfoActor = system.actorOf(Props[DonutInfoActor], name="DonutInfoActor…
package com.example import akka.actor.ActorSystem import scala.util.{Failure, Success} import scala.concurrent.ExecutionContext.Implicits.global object Tutorial_01_ActorSystem_Introduction extends App { println("Step1 : Create an actor system")…
collect will apply a partial function to all elements of a Traversable and return a different collection…
The Scala collections library provides specialised implementations for Sets of fewer than 5 values (see the source). The iterators for these implementations return elements in the order in which they were added, rather than the consistent, hash-based…
code: package com.aura.scala.day01 object forComprehensions { def main(args: Array[String]): Unit = { val userBase = List(User(), User(), User(), User()) val twentySomethins = && userYonger.age < ) yield userYonger.name twentySomethins.foreach(…
package com.aura.scala.day01 import scala.util.matching.Regex object regularExpressionPatterns { def main(args: Array[String]): Unit = { // example 1 // .r 方法可便任意字符串变成一个正则表达式 val numberPatter: Regex = "[0-9]".r numberPatter.findFirstMatchIn(&quo…
(1)Scala中创建多行字符串使用Scala的Multiline String. 在Scala中,利用三个双引号包围多行字符串就可以实现. 代码实例如: val foo = """a bc d""" 运行结果为: a bc d (2) 上述方法存在一个缺陷问题,输入的内容,带有空格.\t之类,导致每一行的开始位置不能整洁对齐. 而在实际应用场景下,有时候我们就是确实需要在scala创建多少字符串,但是每一行需要固定对齐. 解决该问题的方法就是应…
package com.aura.scala.day01 object sealedClassed { def findPlaceToSit(piece: Furniture) = piece match { case a: Couch => "Lie on the couch" case b: Chair => "Sit on the chair" } } //sealed定义密封类 sealed abstract class Furniture ca…
code: package com.aura.scala.day01 object patternMatching03 { //当不同类型对象需要调用不同方法时,仅匹配类型的模式非常有用. def goIDLE(device : Device) = device match { case p: Phone => p.screenOff case c:Computer => c.screenSaverOn } } abstract class Device case class Phone(mo…
code package com.aura.scala.day01 object patternMatching02 { def main(args: Array[String]): Unit = { def showNotifacation(notification: Notification):String = { notification match { case Email(sender, title, _) => s"You got an email from $sender w…
code: package com.aura.scala.day01 import scala.util.Random object patternMatching01 { def main(args: Array[String]): Unit = { val x:Int = Random.nextInt() // 一个模式匹配语句包括一个待匹配的值,match关键字,以及至少一个case 语句. x match { => "zero" => "one"…