This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::f64; | |
// sigmoid activation function | |
fn sigmoid(x: f64) -> f64 { | |
1.0 / (1.0 + (-x).exp()) | |
} | |
// derivative of the sigmoid function | |
fn sigmoid_prime(x: f64) -> f64 { | |
sigmoid(x) * (1.0 - sigmoid(x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type complex = {re: float; im: float} | |
let complex_add a b = {re = a.re +. b.re; im = a.im +. b.im} | |
let complex_sub a b = {re = a.re -. b.re; im = a.im -. b.im} | |
let complex_mul a b = {re = a.re *. b.re -. a.im *. b.im; im = a.re *. b.im +. a.im *. b.re} | |
let complex_exp theta = {re = cos theta; im = sin theta} | |
let rec fft x = | |
let n = Array.length x in | |
if n <= 1 then x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type complex = {re: float; im: float} | |
let complex_add a b = {re = a.re +. b.re; im = a.im +. b.im} | |
let complex_mul a b = {re = a.re *. b.re -. a.im *. b.im; im = a.re *. b.im +. a.im *. b.re} | |
let complex_exp theta = {re = cos theta; im = sin theta} | |
let idft x = | |
let n_total = Array.length x in | |
let x_n n = | |
let sum = ref {re = 0.0; im = 0.0} in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* complex num ops*) | |
type complex = {re: float; im: float} | |
let complex_add a b = {re = a.re +. b.re; im = a.im +. b.im} | |
let complex_sub a b = {re = a.re -. b.re; im = a.im -. b.im} | |
let complex_mul a b = {re = a.re *. b.re -. a.im *. b.im; im = a.re *. b.im +. a.im *. b.re} | |
(* exponential of a complex number given angle in radians*) | |
let complex_exp theta = {re = cos theta; im = sin theta} | |
(* discrete fourier transform*) |