Skip to content

Commit

Permalink
Everything made public
Browse files Browse the repository at this point in the history
All variables and functions in the EpsilonGreedy struct is now public.
  • Loading branch information
crenwick committed Apr 12, 2016
1 parent c3b3ee2 commit bf1eb92
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Sources/EpsilonGreedy.swift
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
import Foundation

struct EpsilonGreedy {
let epsilon: Float
let counts: [Int]
let values: [Float]
public struct EpsilonGreedy {
public let epsilon: Float
public let counts: [Int]
public let values: [Float]

init(epsilon: Float, counts: [Int], values: [Float]) {
public init(epsilon: Float, counts: [Int], values: [Float]) {
self.epsilon = epsilon
self.counts = counts
self.values = values
}

init(epsilon: Float, nArms: Int) {
public init(epsilon: Float, nArms: Int) {
self = EpsilonGreedy(epsilon: epsilon, counts: [], values: [])
.initialize(nArms: nArms)
}

func initialize(nArms nArms: Int) -> EpsilonGreedy {
public func initialize(nArms nArms: Int) -> EpsilonGreedy {
return EpsilonGreedy(
epsilon: epsilon,
counts: (0..<nArms).map({ _ in 0 }),
values: (0..<nArms).map({ _ in 0 })
)
}

func newEpsilon(epsilon: Float) -> EpsilonGreedy {
public func newEpsilon(epsilon: Float) -> EpsilonGreedy {
return EpsilonGreedy(epsilon: epsilon, counts: counts, values: values)
}

func indMax(values: [Float]) -> Int? {
public func indMax(values: [Float]) -> Int? {
guard
let max = values.maxElement(),
let index = values.indexOf(max) else { return nil }
return Int(index)
}

func selectArm() -> Int? {
public func selectArm() -> Int? {
if Float(arc4random())/Float(UInt32.max) > epsilon {
return indMax(values)
}
return Int(arc4random_uniform(UInt32(values.count)) + 1)
}

func update(chosenArm: Int, reward: Float) -> EpsilonGreedy {
public func update(chosenArm: Int, reward: Float) -> EpsilonGreedy {
var newCounts = counts
newCounts[chosenArm] = counts[chosenArm] + 1

Expand Down

0 comments on commit bf1eb92

Please sign in to comment.