forked from yuhonglin/Lbfgsb.jl
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make into standard folder structure, not usable yet
- Loading branch information
Showing
5 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Created by http://www.gitignore.io | ||
|
||
### Emacs ### | ||
# -*- mode: gitignore; -*- | ||
*~ | ||
\#*\# | ||
/.emacs.desktop | ||
/.emacs.desktop.lock | ||
*.elc | ||
auto-save-list | ||
tramp | ||
.\#* | ||
|
||
# Org-mode | ||
.org-id-locations | ||
*_archive | ||
|
||
# flymake-mode | ||
*_flymake.* | ||
|
||
# eshell files | ||
/eshell/history | ||
/eshell/lastdir | ||
|
||
# elpa packages | ||
/elpa/ | ||
|
||
# reftex files | ||
*.rel | ||
|
||
# AUCTeX auto folder | ||
/auto/ | ||
|
||
|
||
### C++ ### | ||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
|
||
|
||
### CMake ### | ||
CMakeCache.txt | ||
CMakeFiles | ||
Makefile | ||
cmake_install.cmake | ||
install_manifest.txt | ||
|
||
### build ### | ||
/build/* | ||
/bin/* | ||
/emacs-build/* | ||
/output/* | ||
/viewer.py | ||
# /python/* | ||
/test/* | ||
libpysegfit.so | ||
segfit |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: cpp | ||
compiler: | ||
- clang | ||
notifications: | ||
email: false | ||
env: | ||
matrix: | ||
- JULIAVERSION="juliareleases" | ||
- JULIAVERSION="julianightlies" | ||
before_install: | ||
- sudo add-apt-repository ppa:staticfloat/julia-deps -y | ||
- sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y | ||
- sudo apt-get update -qq -y | ||
- sudo apt-get install libpcre3-dev julia -y | ||
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi | ||
script: | ||
- julia -e 'Pkg.init(); Pkg.clone(pwd()); Pkg.test("Lbfgsb")' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
The Lbfgsb.jl package is licensed under the Simplified "2-clause" BSD License: | ||
|
||
> Copyright (c) 2014: Honglin Yu. | ||
> | ||
> Redistribution and use in source and binary forms, with or without | ||
> modification, are permitted provided that the following conditions are | ||
> met: | ||
> | ||
> 1. Redistributions of source code must retain the above copyright | ||
> notice, this list of conditions and the following disclaimer. | ||
> 2. Redistributions in binary form must reproduce the above copyright | ||
> notice, this list of conditions and the following disclaimer in the | ||
> documentation and/or other materials provided with the distribution. | ||
> | ||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
> A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
> OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
> SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
> LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
> DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
> THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
> OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
module Lbfgsb | ||
|
||
# package code goes here | ||
macro callLBFGS(cmd) | ||
quote | ||
if length($cmd) != 0 | ||
@simd for i = 1:length($cmd) | ||
task[i] = ($cmd)[i]; | ||
end | ||
@simd for i = length($cmd)+1:60 | ||
task[i] = ' '; | ||
end | ||
end | ||
|
||
ccall((:setulb_, "./liblbfgsb.so"), | ||
Void, | ||
(Ptr{Int32}, | ||
Ptr{Int32}, | ||
Ptr{Float64}, | ||
Ptr{Float64}, | ||
Ptr{Float64}, | ||
Ptr{Int32}, | ||
Ptr{Float64}, | ||
Ptr{Float64}, | ||
Ptr{Float64}, | ||
Ptr{Float64}, | ||
Ptr{Float64}, | ||
Ptr{Int32}, | ||
Ptr{Uint8}, | ||
Ptr{Int32}, | ||
Ptr{Uint8}, | ||
Ptr{Bool}, | ||
Ptr{Int32}, | ||
Ptr{Float64} ), | ||
n, | ||
m, | ||
x, | ||
lb, | ||
ub, | ||
btype, | ||
f, | ||
g, | ||
factr, | ||
pgtol, | ||
wa, | ||
iwa, | ||
task, | ||
iprint, | ||
csave, | ||
lsave, | ||
isave, | ||
dsave ); | ||
end | ||
end | ||
|
||
function lbfgsb (ogFunc, | ||
x; | ||
lb = [], | ||
ub = [], | ||
btype = [], | ||
m::Int64 = 5, | ||
maxiter::Int64 = 100, | ||
factr::Float64 = 1e7, | ||
pgtol::Float64 = 1e-5, | ||
iprint::Int64 = -1 # does not print | ||
) | ||
m = [convert(Int32, m)] | ||
factr = [convert(Float64, factr)]; | ||
pgtol = [convert(Float64, pgtol)]; | ||
iprint = [convert(Int32, iprint)]; | ||
|
||
n = [convert(Int32, length(x))]; # number of variables | ||
f = [convert(Float64, 0.0)]; # The value of the objective. | ||
g = [convert(Float64, 0.0) for i=1:(n[1])]; # The value of the gradient. | ||
|
||
if length(lb) == 0 | ||
lb = [-Inf for i=1:(n[1])]; | ||
else | ||
lb = [convert(Float64, i) for i in lb] | ||
end | ||
|
||
if length(ub) == 0 | ||
ub = [Inf for i=1:(n[1])]; | ||
else | ||
ub = [convert(Float64, i) for i in ub] | ||
end | ||
|
||
if length(btype) == 0 | ||
btype = [convert(Int32, 2) for i=1:(n[1])]; | ||
else | ||
btype = [convert(Int32, i) for i in btype]; | ||
end | ||
|
||
# structures used by the L-BFGS-B routine. | ||
wa = [convert(Float64, 0.0) for i = 1:(2*m[1] + 5)*n[1] + 12*m[1]*(m[1] + 1)]; | ||
iwa = [convert(Int32, 0) for i = 1:3*n[1]]; | ||
task = [convert(Uint8, 0) for i =1:60]; | ||
csave = [convert(Uint8, 0) for i =1:60]; | ||
lsave = [convert(Bool, 0) for i=1:4]; | ||
isave = [convert(Int32, 0) for i=1:44]; | ||
dsave = [convert(Float64, 0.0) for i=1:29]; | ||
|
||
@callLBFGS "START" | ||
|
||
status = "success"; | ||
|
||
t = 0; | ||
|
||
while true | ||
|
||
if task[1] == 'F' | ||
tf, g = ogFunc(x); | ||
f[1] = convert(Float64, tf); | ||
|
||
elseif task[1] == 'N' | ||
t += 1; | ||
if t >= maxiter # exceed maximum number of iteration | ||
@callLBFGS "STOP" | ||
break; | ||
end | ||
elseif task[1] == 'C' # convergence | ||
break; | ||
elseif task[1] == 'A' | ||
status = "abnormal"; | ||
break; | ||
elseif task[1] == 'E' | ||
status = "error"; | ||
break; | ||
end | ||
|
||
@callLBFGS "" | ||
end | ||
|
||
return (f, x, status, t); | ||
end | ||
|
||
end # module |