Simplified structure

This commit is contained in:
Chris Watson 2019-09-10 19:06:36 -07:00
parent 9f599230da
commit b11731a824
9 changed files with 15 additions and 47 deletions

View File

@ -1,6 +1,5 @@
require "./apatite/core_ext/array" require "./apatite/core_ext/*"
require "./apatite/*"
require "./apatite/linear_algebra"
# Apatite is a fundimental package for scientific computing in Crystal. If that # Apatite is a fundimental package for scientific computing in Crystal. If that
# sounds like a modified version of the first line from the NumPy homepage, # sounds like a modified version of the first line from the NumPy homepage,
@ -8,6 +7,5 @@ require "./apatite/linear_algebra"
# of NumPy sitting atop the blazing speed and beautiful syntax # of NumPy sitting atop the blazing speed and beautiful syntax
# of Crystal. # of Crystal.
module Apatite module Apatite
extend self
include Apatite::LinearAlgebra
end end

7
src/apatite/error.cr Normal file
View File

@ -0,0 +1,7 @@
module Apatite
class Error < Exception; end
class ErrDimensionMismatch < Error; end
class ZeroVectorError < Error; end
class ErrNotRegular < Error; end
class ErrOperationNotDefined < Error; end
end

View File

@ -1,28 +0,0 @@
require "./linear_algebra/error"
# require "./linear_algebra/ndarray"
require "./linear_algebra/matrix"
require "./linear_algebra/vector"
module Apatite
module LinearAlgebra
extend self
# Calculates the sigmoid curve for a numeric input.
#
# `f(x) = 1/(1 + e^-x)`
#
# See also: [Sigmoid function (WikiWand)](https://www.wikiwand.com/en/Sigmoid_function)
def sigmoid(input : Number)
num = input.to_f64
1 / (1 + Math.exp(-num))
end
# Calculates the derivative sigmoid curve for a numeric input.
#
# `f'(x) = f(x)(1 - f(x)),`
def sigmoid_d(input : Number)
num = input.to_f64
num * (1 - num)
end
end
end

View File

@ -1,9 +0,0 @@
module Apatite
module LinearAlgebra
class Error < Exception; end
class ErrDimensionMismatch < Error; end
class ZeroVectorError < Error; end
class ErrNotRegular < Error; end
class ErrOperationNotDefined < Error; end
end
end

View File

@ -2,7 +2,7 @@ require "./vector"
require "./matrix/eigenvalue_decomposition" require "./matrix/eigenvalue_decomposition"
require "./matrix/lup_decomposition" require "./matrix/lup_decomposition"
module Apatite::LinearAlgebra module Apatite
class Matrix(T) class Matrix(T)
include Enumerable(Vector) include Enumerable(Vector)
include Indexable(Vector) include Indexable(Vector)

View File

@ -1,4 +1,4 @@
module Apatite::LinearAlgebra module Apatite
class Matrix(T) class Matrix(T)
# Eigenvalues and eigenvectors of a real matrix. # Eigenvalues and eigenvectors of a real matrix.
# #

View File

@ -1,4 +1,4 @@
module Apatite::LinearAlgebra module Apatite
class Matrix(T) class Matrix(T)
# For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n # For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n
# unit lower triangular matrix L, an n-by-n upper triangular matrix U, # unit lower triangular matrix L, an n-by-n upper triangular matrix U,

View File

@ -1,4 +1,4 @@
module Apatite::LinearAlgebra module Apatite
class NDArray class NDArray
# include Enumerable(Float64) # include Enumerable(Float64)
# include Indexable(Float64) # include Indexable(Float64)

View File

@ -2,7 +2,7 @@ require "complex"
require "big" require "big"
require "json" require "json"
module Apatite::LinearAlgebra module Apatite
# Represents a mathematical vector, and also constitutes a row or column # Represents a mathematical vector, and also constitutes a row or column
# of a `Matrix` # of a `Matrix`
class Vector(T) class Vector(T)