Skip to content

Commit

Permalink
Fix: normals default sigma is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
t-ae committed Apr 28, 2017
1 parent d452190 commit 2c06a4a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/numsw/Matrix/MatrixRandom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension Matrix where T: FloatingPointFunctions & FloatingPoint {

extension Matrix where T: FloatingPoint & FloatingPointFunctions & Arithmetic {

public static func normal(mu: T = 0, sigma: T = 0, rows: Int, columns: Int) -> Matrix<T> {
public static func normal(mu: T = 0, sigma: T = 1, rows: Int, columns: Int) -> Matrix<T> {
// Box-Muller's method
let u1 = uniform(low: T(0), high: T(1), rows: rows, columns: columns)
let u2 = uniform(low: T(0), high: T(1), rows: rows, columns: columns)
Expand Down
2 changes: 1 addition & 1 deletion Sources/numsw/NDArray/NDArrayRandom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension NDArray where T: FloatingPointFunctions & FloatingPoint {

extension NDArray where T: FloatingPoint & FloatingPointFunctions & Arithmetic {

public static func normal(mu: T = 0, sigma: T = 0, shape: [Int]) -> NDArray<T> {
public static func normal(mu: T = 0, sigma: T = 1, shape: [Int]) -> NDArray<T> {
let u1 = uniform(low: T(0), high: T(1), shape: shape)
let u2 = uniform(low: T(0), high: T(1), shape: shape)

Expand Down
5 changes: 5 additions & 0 deletions Tests/numswTests/NDArrayTests/NDArrayRandomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class NDArrayRandomTests: XCTestCase {
}
}

func testNormal() {
let a = NDArray<Double>.normal(mu: 0, sigma: 1, shape: [1000])
print(a.elements)
}

static var allTests: [(String, (NDArrayRandomTests) -> () throws -> Void)] {
return [
("testUniform", testUniform)
Expand Down

0 comments on commit 2c06a4a

Please sign in to comment.