Bernd Gutmann's lbfgs interface
This commit is contained in:
parent
f1cbc7f3be
commit
7e1f3009e6
@ -2530,6 +2530,7 @@ mkdir -p packages/real
|
|||||||
mkdir -p packages/semweb
|
mkdir -p packages/semweb
|
||||||
mkdir -p packages/sgml
|
mkdir -p packages/sgml
|
||||||
mkdir -p packages/xml
|
mkdir -p packages/xml
|
||||||
|
mkdir -p packages/yap-lbfgs
|
||||||
mkdir -p packages/zlib
|
mkdir -p packages/zlib
|
||||||
mkdir -p packages/archive
|
mkdir -p packages/archive
|
||||||
mkdir -p swi
|
mkdir -p swi
|
||||||
@ -2654,5 +2655,7 @@ AC_CONFIG_FILES([packages/prism/src/c/Makefile])
|
|||||||
AC_CONFIG_FILES([packages/prism/src/prolog/Makefile])
|
AC_CONFIG_FILES([packages/prism/src/prolog/Makefile])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_CONFIG_FILES([packages/yap-lbfgs/Makefile])
|
||||||
|
|
||||||
AC_OUTPUT()
|
AC_OUTPUT()
|
||||||
|
|
||||||
|
674
packages/yap-lbfgs/LICENSE.txt
Normal file
674
packages/yap-lbfgs/LICENSE.txt
Normal file
@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
64
packages/yap-lbfgs/Makefile.in
Normal file
64
packages/yap-lbfgs/Makefile.in
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#
|
||||||
|
# default base directory for YAP installation
|
||||||
|
# (EROOT for architecture-dependent files)
|
||||||
|
#
|
||||||
|
prefix = @prefix@
|
||||||
|
exec_prefix = @exec_prefix@
|
||||||
|
ROOTDIR = $(prefix)
|
||||||
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
|
#
|
||||||
|
# where the binary should be
|
||||||
|
#
|
||||||
|
BINDIR = $(EROOTDIR)/bin
|
||||||
|
#
|
||||||
|
# where YAP should look for libraries
|
||||||
|
#
|
||||||
|
LIBDIR=@libdir@
|
||||||
|
SHAREDIR=$(ROOTDIR)/share/Yap
|
||||||
|
YAPLIBDIR=@libdir@/Yap
|
||||||
|
#
|
||||||
|
#
|
||||||
|
CC=@CC@
|
||||||
|
CFLAGS= @SHLIB_CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../include -I$(srcdir)/liblbfgs-1.7/include
|
||||||
|
LDFLAGS=@LDFLAGS@
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# You shouldn't need to change what follows.
|
||||||
|
#
|
||||||
|
INSTALL=@INSTALL@
|
||||||
|
INSTALL_DATA=@INSTALL_DATA@
|
||||||
|
INSTALL_PROGRAM=@INSTALL_PROGRAM@
|
||||||
|
SHELL=/bin/sh
|
||||||
|
RANLIB=@RANLIB@
|
||||||
|
srcdir=@srcdir@
|
||||||
|
SO=@SO@
|
||||||
|
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
|
||||||
|
CWD=$(PWD)
|
||||||
|
#
|
||||||
|
|
||||||
|
OBJS=yap_lbfgs.o lbfgs.o
|
||||||
|
SOBJS=yap_lbfgs.@SO@
|
||||||
|
PLLIB=$(srcdir)/lbfgs.pl
|
||||||
|
|
||||||
|
#in some systems we just create a single object, in others we need to
|
||||||
|
# create a libray
|
||||||
|
|
||||||
|
all: $(SOBJS)
|
||||||
|
|
||||||
|
yap_lbfgs.o: $(srcdir)/yap_lbfgs.c
|
||||||
|
$(CC) -c $(CFLAGS) $(srcdir)/yap_lbfgs.c -o yap_lbfgs.o
|
||||||
|
|
||||||
|
lbfgs.o: $(srcdir)/liblbfgs-1.7/lib/lbfgs.c
|
||||||
|
$(CC) -c $(CFLAGS) -I $(srcdir)/liblbfgs-1.7/lib $(srcdir)/liblbfgs-1.7/lib/lbfgs.c -o lbfgs.o
|
||||||
|
|
||||||
|
@DO_SECOND_LD@yap_lbfgs.@SO@: yap_lbfgs.o lbfgs.o
|
||||||
|
@DO_SECOND_LD@ @SHLIB_LD@ $(LDFLAGS) -o yap_lbfgs.@SO@ yap_lbfgs.o lbfgs.o @EXTRA_LIBS_FOR_DLLS@
|
||||||
|
|
||||||
|
install: all
|
||||||
|
$(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(YAPLIBDIR)
|
||||||
|
for h in $(PLLIB); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR); done
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o *~ $(OBJS) $(SOBJS) *.BAK
|
||||||
|
|
215
packages/yap-lbfgs/doc/index.html
Normal file
215
packages/yap-lbfgs/doc/index.html
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
|
<head profile="http://www.w3.org/2005/10/profile">
|
||||||
|
<title>YAP-LBFGS</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
|
||||||
|
<meta http-equiv="language" content="english,en" />
|
||||||
|
<meta name="robots" content="index,follow" />
|
||||||
|
<meta name="revisit-after" content="14 days" />
|
||||||
|
<link rel="stylesheet" title="Main" type="text/css" href="style.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>YAP-LBFGS</h1>
|
||||||
|
|
||||||
|
<h2>What is YAP-LBFGS</h2>
|
||||||
|
<p>YAP-LBFGS is an interface to call <a href="http://www.chokkan.org/software/liblbfgs/">libLBFGS</a> from within
|
||||||
|
YAP. libLBFGS is a C library for Limited-memory
|
||||||
|
Broyden-Fletcher-Goldfarb-Shanno (L-BFGS) solving the under-constrained
|
||||||
|
minimization problem:</p>
|
||||||
|
<p> minimize <span class="math">F(X), X=(x1,x2,..., xN)</span></p>
|
||||||
|
<p><a href="http://www.dcc.fc.up.pt/~vsc/Yap/">YAP</a> (Yet Another
|
||||||
|
Prolog) is a Prolog interpreter</p>
|
||||||
|
<h2>Contact</h2>
|
||||||
|
<p>YAP-LBFGS has been developed by Bernd Gutmann (<a
|
||||||
|
href="http://www.cs.kuleuven.be/cgi-bin/e-post.pl?epost=bernd.gutmann">email</a>,
|
||||||
|
<a href="http://www.cs.kuleuven.be/~bernd/">homepage</a>). In case you publish something using YAP-LBFGS, please give credit to me and to libLBFGS. And if you find YAP-LBFGS useful, or if you find a bug, or if you
|
||||||
|
port it to another system, ... please send me an email.</p>
|
||||||
|
|
||||||
|
<h2>Download</h2>
|
||||||
|
<p>Latest version (25.04.2009) <a href="yap-lbfgs.tgz">yap-lbfgs.tgz</a></p>
|
||||||
|
|
||||||
|
<h2>Installation</h2>
|
||||||
|
<p>Note: The Make file is currently only working under Mac OS, but with little
|
||||||
|
effort it is possible to adapt it to your needs.<br />
|
||||||
|
And in case you are a C expert and can produce a better/more general Make file, please let me know.</p>
|
||||||
|
<ol>
|
||||||
|
<li>Download and compile <a
|
||||||
|
href="http://www.chokkan.org/software/liblbfgs/">libLBFGS</a>.</li>
|
||||||
|
<li>Download and unpack YAP-LBFGS</li>
|
||||||
|
<li>Edit the Makefile of
|
||||||
|
YAP-LBFGS and change the line <span class="code">LIBS= ../lib/lbfgs.o</span> to wherever the
|
||||||
|
lbfgs.o file can be found.</li>
|
||||||
|
<li>Execute Make in the YAP-LBFGS folder</li>
|
||||||
|
<li>Run <span class="code">yap -l ex1.pl</span> and run the query
|
||||||
|
<span class="code">:-demo.</span> to see whether everything works fine.</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>License</h2>
|
||||||
|
<p> YAP-LBFGS is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.</p>
|
||||||
|
<p> YAP-LBFGS is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.</p>
|
||||||
|
|
||||||
|
<h2>Usage</h2>
|
||||||
|
<p>The module lbfgs provides the following predicates after you loaded
|
||||||
|
it by <span class="code">:-use_module(lbfgs).</span></p>
|
||||||
|
<h3>optimizer_initialize(+N,+Module,+Evaluate,+Progress)</h3>
|
||||||
|
<p>Create space to optimize a function with N variables (N has to be
|
||||||
|
integer). <span class="code">Module</span> is the name of the module where the call back
|
||||||
|
predicates can be found, <span class="code">Evaluate</span> is the call back predicate (arity 3)
|
||||||
|
to evaluate the function math <span class="math">F</span>, <span class="code">Progress</span> is the call back predicate invoked
|
||||||
|
(arity 8) after every iteration</p>
|
||||||
|
<p>Example <span class="code">
|
||||||
|
optimizer_initialize(1,user,evaluate,progress)</span></p>
|
||||||
|
|
||||||
|
<p>The evaluate call back predicate has to be of the type <span class="code">evaluate(-F,+N,+Step)</span>. It has to calculate the current function value <span class="code">F</span>. <span class="code">N</span> is the size of the parameter vector (the value which was used to initialize LBFGS) and <span class="code">Step</span> is the current state of the line search. The call back predicate can access the current values of <span class="math">x[i]</span> by calling <span class="code">optimizer_get_x(+I,-Xi)</span>. Finally, the call back predicate has to calculate the gradient of <span class="math">F</span> and set its value by calling <span class="code">optimizer_set_g(+I,+Gi)</span> for every <span class="math">1<=I<=N</span>.</p>
|
||||||
|
|
||||||
|
<p>The progress call back predicate has to be of the type <span class="code">progress(+F,+X_Norm,+G_Norm,+Step,+N,+Iteration,+LS,-Continue)</span>. It is called after every iteration. The call back predicate can access the current values of X and of the gradient by calling <span class="code">optimizer_get_x(+I,-Xi)</span> and <span class="code">optimizer_get_g(+I,-Gi)</span> respectively. Howver, it must not call the setter predicates for <span class="code">X</span> or <span class="code">G</span>. If it tries to do so, the optimizer will terminate with an error. If <span class="code">Continue</span> is set to 0 (int) the optimization process will continue for one more iteration, any other value will terminate the optimization process.</p>
|
||||||
|
|
||||||
|
<h3>optimizer_initialize(+N,+Evaluate,+Progress)</h3>
|
||||||
|
<p>The same as before, except that the user module is the default
|
||||||
|
value.</p>
|
||||||
|
<p>Example <span class="code">
|
||||||
|
optimizer_initialize(1,evaluate,progress)</span></p>
|
||||||
|
|
||||||
|
<h3>optimizer_run(-F,-Status)</h3>
|
||||||
|
<p>Runs the optimization, <span class="code">F</span> is the best (minimal) function value and
|
||||||
|
Status (int) is the status code returned by libLBFGS. Anything except
|
||||||
|
0 indicates an error, see the <a href="http://www.chokkan.org/software/liblbfgs/group__liblbfgs__api.html#g06fc87d81c62e9abb8790b6e5713c55b">documentation of libLBFGS</a> for the
|
||||||
|
meaning.</p>
|
||||||
|
|
||||||
|
<h3>optimizer_get_x(+I,-X)</h3>
|
||||||
|
<p>Get the current value for <span class="math">x[I]</span>. Only possible when the optimizer is
|
||||||
|
initialized or running.</p>
|
||||||
|
|
||||||
|
<h3>optimizer_set_x(+I,+X)</h3>
|
||||||
|
<p>Set the current value for <span class="math">x[I]</span>. Only possible when the optimizer is
|
||||||
|
initialized but not running.</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h3>optimizer_get_g(+I,-G)</h3>
|
||||||
|
<p>Get the current value for <span class="math">g[I]</span> (the partial derivative of <span class="math">F</span> with respect to <span class="math">x[I]</span>). Only possible when the optimizer is
|
||||||
|
initialized or running.</p>
|
||||||
|
|
||||||
|
<h3>optimizer_set_g(+I,+G)</h3>
|
||||||
|
<p>Set the current value for <span class="math">g[I]</span> (the partial derivative of <span class="math">F</span> with
|
||||||
|
respect to <span class="math">x[I]</span>). Can only be called from the evaluate call back predicate.</p>
|
||||||
|
|
||||||
|
<h3> optimizer_finalize/0</h3>
|
||||||
|
<p>Clean up the memory.</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h3> optimizer_parameters/0</h3>
|
||||||
|
<p>Prints a table with the current parameters. See the <a href="http://www.chokkan.org/software/liblbfgs/structlbfgs__parameter__t.html#_details">documentation
|
||||||
|
of libLBFGS</a> for the meaning of each parameter.</p>
|
||||||
|
<pre>
|
||||||
|
?- optimizer_parameters.
|
||||||
|
==========================================================================================
|
||||||
|
Type Name Value Description
|
||||||
|
==========================================================================================
|
||||||
|
int m 6 The number of corrections to approximate the inverse hessian matrix.
|
||||||
|
float epsilon 1e-05 Epsilon for convergence test.
|
||||||
|
int past 0 Distance for delta-based convergence test.
|
||||||
|
float delta 1e-05 Delta for convergence test.
|
||||||
|
int max_iterations 0 The maximum number of iterations
|
||||||
|
int linesearch 0 The line search algorithm.
|
||||||
|
int max_linesearch 40 The maximum number of trials for the line search.
|
||||||
|
float min_step 1e-20 The minimum step of the line search routine.
|
||||||
|
float max_step 1e+20 The maximum step of the line search.
|
||||||
|
float ftol 0.0001 A parameter to control the accuracy of the line search routine.
|
||||||
|
float gtol 0.9 A parameter to control the accuracy of the line search routine.
|
||||||
|
float xtol 1e-16 The machine precision for floating-point values.
|
||||||
|
float orthantwise_c 0.0 Coefficient for the L1 norm of variables
|
||||||
|
int orthantwise_start 0 Start index for computing the L1 norm of the variables.
|
||||||
|
int orthantwise_end -1 End index for computing the L1 norm of the variables.
|
||||||
|
==========================================================================================
|
||||||
|
use optimizer_set_paramater(Name,Value) to change parameters
|
||||||
|
use optimizer_get_parameter(Name,Value) to see current parameters
|
||||||
|
use optimizer_parameters to print this overview
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<h3> optimizer_set_parameter(+Name,+Value)</h3>
|
||||||
|
<p>Set the parameter Name to Value. Only possible while the optimizer
|
||||||
|
is not running.</p>
|
||||||
|
|
||||||
|
<h3> optimizer_get_parameter(+Name,-Value)</h3>
|
||||||
|
<p>Get the current Value for Name</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Demo</h2>
|
||||||
|
|
||||||
|
<p>The following Prolog program (<span class="code">ex1.pl</span>) searches for minimas of the function
|
||||||
|
<span class="math">f(x0)=sin(x0)</span>. In order to do so, it provides the call back
|
||||||
|
predicate <span class="code">evaluate</span> which calculates <span class="math">f(x0)</span> and the gradient <span class="math">d/dx0 f=cos(x0)</span>.</p>
|
||||||
|
<pre>
|
||||||
|
:- use_module(lbfgs).
|
||||||
|
|
||||||
|
% This is the call back function which evaluates F and the gradient of F
|
||||||
|
evaluate(FX,_N,_Step) :-
|
||||||
|
optimizer_get_x(0,X0),
|
||||||
|
FX is sin(X0),
|
||||||
|
G0 is cos(X0),
|
||||||
|
optimizer_set_g(0,G0).
|
||||||
|
|
||||||
|
% This is the call back function which is invoked to report the progress
|
||||||
|
% if the last argument is set to anything else than 0, the optimizer will
|
||||||
|
% stop right now
|
||||||
|
progress(FX,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :-
|
||||||
|
optimizer_get_x(0,X0),
|
||||||
|
format('~d. Iteration : x0=~4f f(X)=~4f |X|=~4f
|
||||||
|
|X\'|=~4f Step=~4f Ls=~4f~n',
|
||||||
|
[Iteration,X0,FX,X_Norm,G_Norm,Step,Ls]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
demo :-
|
||||||
|
format('Optimizing the function f(x0) = sin(x0)~n',[]),
|
||||||
|
optimizer_initialize(1,evaluate,progress),
|
||||||
|
|
||||||
|
|
||||||
|
StartX is random*10,
|
||||||
|
format('We start the search at the random position x0=~5f~2n',[StartX]),
|
||||||
|
optimizer_set_x(0,StartX),
|
||||||
|
|
||||||
|
optimizer_run(BestF,Status),
|
||||||
|
optimizer_get_x(0,BestX0),
|
||||||
|
optimizer_finalize,
|
||||||
|
format('~2nOptimization done~nWe found a minimum at
|
||||||
|
f(~f)=~f~2nLBFGS Status=~w~n',[BestX0,BestF,Status]).
|
||||||
|
</pre>
|
||||||
|
<p>The output of this program is something like:</p>
|
||||||
|
<pre>
|
||||||
|
?- demo.
|
||||||
|
Optimizing the function f(x0) = sin(x0)
|
||||||
|
We start the search at the random position x0=7.24639
|
||||||
|
|
||||||
|
1. Iteration : x0=5.0167 f(X)=-0.9541 |X|=5.0167 |X'|=0.2996 Step=3.9057 Ls=3.0000
|
||||||
|
2. Iteration : x0=4.7708 f(X)=-0.9983 |X|=4.7708 |X'|=0.0584 Step=0.0998 Ls=2.0000
|
||||||
|
3. Iteration : x0=4.7113 f(X)=-1.0000 |X|=4.7113 |X'|=0.0011 Step=1.0000 Ls=1.0000
|
||||||
|
4. Iteration : x0=4.7124 f(X)=-1.0000 |X|=4.7124 |X'|=0.0000 Step=1.0000 Ls=1.0000
|
||||||
|
|
||||||
|
|
||||||
|
Optimization done
|
||||||
|
We found a minimum at f(4.712390)=-1.000000
|
||||||
|
|
||||||
|
LBFGS Status=0
|
||||||
|
yes
|
||||||
|
?-
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><a href="http://www.validome.org/referer">
|
||||||
|
<img id="valimg"
|
||||||
|
src="http://www.validome.org/images/set3/valid_xhtml_1_0.gif"
|
||||||
|
alt="Valid XHTML 1.0" width="80" height="15" /></a>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
43
packages/yap-lbfgs/doc/style.css
Normal file
43
packages/yap-lbfgs/doc/style.css
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
body {
|
||||||
|
margin:20pt;
|
||||||
|
background-color : #DDDDDD;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
text-align : center;
|
||||||
|
background-color : #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-left:22pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
border : 1pt;
|
||||||
|
border-style : dashed;
|
||||||
|
background-color : #EEEEEE;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-left : 11pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.code {
|
||||||
|
background-color : #EEEEEE;
|
||||||
|
font-family: courier;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.math {
|
||||||
|
background-color : #EEEEEE;
|
||||||
|
font-family: courier;
|
||||||
|
padding: 1pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background-color: #EEEEEE;
|
||||||
|
margin:22pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
#valimg {
|
||||||
|
border: none;
|
||||||
|
}
|
53
packages/yap-lbfgs/ex1.pl
Normal file
53
packages/yap-lbfgs/ex1.pl
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
%%% -*- Mode: Prolog; -*-
|
||||||
|
|
||||||
|
|
||||||
|
% This file is part of YAP-LBFGS.
|
||||||
|
% Copyright (C) 2009 Bernd Gutmann
|
||||||
|
%
|
||||||
|
% YAP-LBFGS is free software: you can redistribute it and/or modify
|
||||||
|
% it under the terms of the GNU General Public License as published by
|
||||||
|
% the Free Software Foundation, either version 3 of the License, or
|
||||||
|
% (at your option) any later version.
|
||||||
|
%
|
||||||
|
% YAP-LBFGS is distributed in the hope that it will be useful,
|
||||||
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
% GNU General Public License for more details.
|
||||||
|
%
|
||||||
|
% You should have received a copy of the GNU General Public License
|
||||||
|
% along with YAP-LBFGS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
:- use_module(library(lbfgs)).
|
||||||
|
|
||||||
|
|
||||||
|
% This is the call back function which evaluates F and the gradient of F
|
||||||
|
evaluate(FX,_N,_Step) :-
|
||||||
|
optimizer_get_x(0,X0),
|
||||||
|
FX is sin(X0),
|
||||||
|
G0 is cos(X0),
|
||||||
|
optimizer_set_g(0,G0).
|
||||||
|
|
||||||
|
% This is the call back function which is invoked to report the progress
|
||||||
|
% if the last argument is set to anywhting else than 0, the optimizer will
|
||||||
|
% stop right now
|
||||||
|
progress(FX,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :-
|
||||||
|
optimizer_get_x(0,X0),
|
||||||
|
format('~d. Iteration : x0=~4f f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f~n',[Iteration,X0,FX,X_Norm,G_Norm,Step,Ls]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
demo :-
|
||||||
|
format('Optimizing the function f(x0) = sin(x0)~n',[]),
|
||||||
|
optimizer_initialize(1,evaluate,progress),
|
||||||
|
|
||||||
|
|
||||||
|
StartX is random*10,
|
||||||
|
format('We start the search at the random position x0=~5f~2n',[StartX]),
|
||||||
|
optimizer_set_x(0,StartX),
|
||||||
|
|
||||||
|
optimizer_run(BestF,Status),
|
||||||
|
optimizer_get_x(0,BestX0),
|
||||||
|
optimizer_finalize,
|
||||||
|
format('~2nOptimization done~nWe found a minimum at f(~f)=~f~2nLBFGS Status=~w~n',[BestX0,BestF,Status]).
|
||||||
|
|
||||||
|
|
64
packages/yap-lbfgs/ex2.pl
Normal file
64
packages/yap-lbfgs/ex2.pl
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
%%% -*- Mode: Prolog; -*-
|
||||||
|
|
||||||
|
|
||||||
|
% This file is part of YAP-LBFGS.
|
||||||
|
% Copyright (C) 2009 Bernd Gutmann
|
||||||
|
%
|
||||||
|
% YAP-LBFGS is free software: you can redistribute it and/or modify
|
||||||
|
% it under the terms of the GNU General Public License as published by
|
||||||
|
% the Free Software Foundation, either version 3 of the License, or
|
||||||
|
% (at your option) any later version.
|
||||||
|
%
|
||||||
|
% YAP-LBFGS is distributed in the hope that it will be useful,
|
||||||
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
% GNU General Public License for more details.
|
||||||
|
%
|
||||||
|
% You should have received a copy of the GNU General Public License
|
||||||
|
% along with YAP-LBFGS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
:- use_module(library(lbfgs)).
|
||||||
|
|
||||||
|
|
||||||
|
% This is the call back function which evaluates F and the gradient of F
|
||||||
|
evaluate(FX,_N,_Step) :-
|
||||||
|
optimizer_get_x(0,X0),
|
||||||
|
optimizer_get_x(1,X1),
|
||||||
|
|
||||||
|
FX is (X0-2)*(X0-2) + (X1-1)*(X1-1),
|
||||||
|
G0 is 2*(X0-2),
|
||||||
|
G1 is 2*(X1-1),
|
||||||
|
|
||||||
|
optimizer_set_g(0,G0),
|
||||||
|
optimizer_set_g(1,G1).
|
||||||
|
|
||||||
|
% This is the call back function which is invoked to report the progress
|
||||||
|
% if the last argument is set to anywhting else than 0, the optimizer will
|
||||||
|
% stop right now
|
||||||
|
progress(FX,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :-
|
||||||
|
optimizer_get_x(0,X0),
|
||||||
|
optimizer_get_x(1,X1),
|
||||||
|
format('~d. Iteration : (x0,x1)=(~4f,~4f) f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f~n',[Iteration,X0,X1,FX,X_Norm,G_Norm,Step,Ls]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
demo :-
|
||||||
|
format('Optimizing the function f(x0,x1) = (x0-2)^2 + (x1-1)^2~n',[]),
|
||||||
|
optimizer_initialize(2,evaluate,progress),
|
||||||
|
|
||||||
|
|
||||||
|
StartX0 is random*1000-500,
|
||||||
|
StartX1 is random*1000-500,
|
||||||
|
|
||||||
|
format('We start the search at the random position (x0,x1)=(~5f,~5f)~2n',[StartX0,StartX1]),
|
||||||
|
optimizer_set_x(0,StartX0),
|
||||||
|
optimizer_set_x(1,StartX1),
|
||||||
|
|
||||||
|
optimizer_run(BestF,Status),
|
||||||
|
optimizer_get_x(0,BestX0),
|
||||||
|
optimizer_get_x(1,BestX1),
|
||||||
|
|
||||||
|
optimizer_finalize,
|
||||||
|
format('~2nOptimization done~nWe found a minimum at f(~f,~f)=~f~2nLBFGS Status=~w~n',[BestX0,BestX1,BestF,Status]).
|
||||||
|
|
||||||
|
|
122
packages/yap-lbfgs/lbfgs.pl
Normal file
122
packages/yap-lbfgs/lbfgs.pl
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
%%% -*- Mode: Prolog; -*-
|
||||||
|
|
||||||
|
% This file is part of YAP-LBFGS.
|
||||||
|
% Copyright (C) 2009 Bernd Gutmann
|
||||||
|
%
|
||||||
|
% YAP-LBFGS is free software: you can redistribute it and/or modify
|
||||||
|
% it under the terms of the GNU General Public License as published by
|
||||||
|
% the Free Software Foundation, either version 3 of the License, or
|
||||||
|
% (at your option) any later version.
|
||||||
|
%
|
||||||
|
% YAP-LBFGS is distributed in the hope that it will be useful,
|
||||||
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
% GNU General Public License for more details.
|
||||||
|
%
|
||||||
|
% You should have received a copy of the GNU General Public License
|
||||||
|
% along with YAP-LBFGS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:- module(lbfgs,[optimizer_initialize/3,
|
||||||
|
optimizer_initialize/4,
|
||||||
|
optimizer_run/2,
|
||||||
|
optimizer_get_x/2,
|
||||||
|
optimizer_set_x/2,
|
||||||
|
|
||||||
|
optimizer_get_g/2,
|
||||||
|
optimizer_set_g/2,
|
||||||
|
|
||||||
|
optimizer_finalize/0,
|
||||||
|
|
||||||
|
optimizer_set_parameter/2,
|
||||||
|
optimizer_get_parameter/2,
|
||||||
|
optimizer_parameters/0]).
|
||||||
|
|
||||||
|
% switch on all the checks to reduce bug searching time
|
||||||
|
% :- yap_flag(unknown,error).
|
||||||
|
% :- style_check(single_var).
|
||||||
|
|
||||||
|
:- dynamic initialized/0.
|
||||||
|
:- dynamic user:'$lbfgs_callback_evaluate'/3.
|
||||||
|
:- dynamic user:'$lbfgs_callback_progress'/8.
|
||||||
|
|
||||||
|
:- load_foreign_files(['yap_lbfgs'],[],'init_lbfgs_predicates').
|
||||||
|
|
||||||
|
|
||||||
|
optimizer_initialize(N,Call_Evaluate,Call_Progress) :-
|
||||||
|
optimizer_initialize(N,user,Call_Evaluate,Call_Progress).
|
||||||
|
optimizer_initialize(N,Module,Call_Evaluate,Call_Progress) :-
|
||||||
|
\+ initialized,
|
||||||
|
|
||||||
|
integer(N),
|
||||||
|
N>0,
|
||||||
|
|
||||||
|
% check whether there are such call back functions
|
||||||
|
current_module(Module),
|
||||||
|
current_predicate(Module:Call_Evaluate/3),
|
||||||
|
current_predicate(Module:Call_Progress/8),
|
||||||
|
|
||||||
|
optimizer_reserve_memory(N),
|
||||||
|
|
||||||
|
% install call back predicates in the user module which call
|
||||||
|
% the predicates given by the arguments
|
||||||
|
EvalGoal =.. [Call_Evaluate,E1,E2,E3],
|
||||||
|
ProgressGoal =.. [Call_Progress,P1,P2,P3,P4,P5,P6,P7,P8],
|
||||||
|
assert( (user:'$lbfgs_callback_evaluate'(E1,E2,E3) :- once(call(Module:EvalGoal))) ),
|
||||||
|
assert( (user:'$lbfgs_callback_progress'(P1,P2,P3,P4,P5,P6,P7,P8) :- once(call(Module:ProgressGoal))) ),
|
||||||
|
|
||||||
|
assert(initialized).
|
||||||
|
|
||||||
|
optimizer_finalize :-
|
||||||
|
initialized,
|
||||||
|
optimizer_free_memory,
|
||||||
|
retractall(user:'$lbfgs_callback_evaluate'(_,_,_)),
|
||||||
|
retractall(user:'$lbfgs_callback_progress'(_,_,_,_,_,_,_,_)),
|
||||||
|
retractall(initialized).
|
||||||
|
|
||||||
|
optimizer_parameters :-
|
||||||
|
optimizer_get_parameter(m,M),
|
||||||
|
optimizer_get_parameter(epsilon,Epsilon),
|
||||||
|
optimizer_get_parameter(past,Past),
|
||||||
|
optimizer_get_parameter(delta,Delta),
|
||||||
|
optimizer_get_parameter(max_iterations,Max_Iterations),
|
||||||
|
optimizer_get_parameter(linesearch,Linesearch),
|
||||||
|
optimizer_get_parameter(max_linesearch,Max_Linesearch),
|
||||||
|
optimizer_get_parameter(min_step,Min_Step),
|
||||||
|
optimizer_get_parameter(max_step,Max_Step),
|
||||||
|
optimizer_get_parameter(ftol,Ftol),
|
||||||
|
optimizer_get_parameter(gtol,Gtol),
|
||||||
|
optimizer_get_parameter(xtol,Xtol),
|
||||||
|
optimizer_get_parameter(orthantwise_c,Orthantwise_C),
|
||||||
|
optimizer_get_parameter(orthantwise_start,Orthantwise_Start),
|
||||||
|
optimizer_get_parameter(orthantwise_end,Orthantwise_End),
|
||||||
|
|
||||||
|
format('==========================================================================================~n',[]),
|
||||||
|
print_param('Name','Value','Description','Type'),
|
||||||
|
format('==========================================================================================~n',[]),
|
||||||
|
print_param(m,M,'The number of corrections to approximate the inverse hessian matrix.',int),
|
||||||
|
print_param(epsilon,Epsilon,'Epsilon for convergence test.',float),
|
||||||
|
print_param(past,Past,'Distance for delta-based convergence test.',int),
|
||||||
|
print_param(delta,Delta,'Delta for convergence test.',float),
|
||||||
|
print_param(max_iterations,Max_Iterations,'The maximum number of iterations',int),
|
||||||
|
print_param(linesearch,Linesearch,'The line search algorithm.',int),
|
||||||
|
print_param(max_linesearch,Max_Linesearch,'The maximum number of trials for the line search.',int),
|
||||||
|
print_param(min_step,Min_Step,'The minimum step of the line search routine.',float),
|
||||||
|
print_param(max_step,Max_Step,'The maximum step of the line search.',float),
|
||||||
|
print_param(ftol,Ftol,'A parameter to control the accuracy of the line search routine.',float),
|
||||||
|
print_param(gtol,Gtol,'A parameter to control the accuracy of the line search routine.',float),
|
||||||
|
print_param(xtol,Xtol,'The machine precision for floating-point values.',float),
|
||||||
|
print_param(orthantwise_c,Orthantwise_C,'Coefficient for the L1 norm of variables',float),
|
||||||
|
print_param(orthantwise_start,Orthantwise_Start,'Start index for computing the L1 norm of the variables.',int),
|
||||||
|
print_param(orthantwise_end,Orthantwise_End,'End index for computing the L1 norm of the variables.',int),
|
||||||
|
format('==========================================================================================~n',[]),
|
||||||
|
format(' use optimizer_set_paramater(Name,Value) to change parameters~n',[]),
|
||||||
|
format(' use optimizer_get_parameter(Name,Value) to see current parameters~n',[]),
|
||||||
|
format(' use optimizer_parameters to print this overview~2n',[]).
|
||||||
|
|
||||||
|
|
||||||
|
print_param(Name,Value,Text,Dom) :-
|
||||||
|
format(user,'~w~10+~w~19+~w~15+~w~30+~n',[Dom,Name,Value,Text]).
|
||||||
|
|
||||||
|
|
1
packages/yap-lbfgs/liblbfgs-1.7/AUTHORS
vendored
Normal file
1
packages/yap-lbfgs/liblbfgs-1.7/AUTHORS
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Naoaki Okazaki <okazaki at chokkan org>
|
22
packages/yap-lbfgs/liblbfgs-1.7/COPYING
vendored
Normal file
22
packages/yap-lbfgs/liblbfgs-1.7/COPYING
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
The MIT License
|
||||||
|
|
||||||
|
Copyright (c) 1990 Jorge Nocedal
|
||||||
|
Copyright (c) 2007-2009 Naoaki Okazaki
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
to deal in the Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
100
packages/yap-lbfgs/liblbfgs-1.7/ChangeLog
vendored
Normal file
100
packages/yap-lbfgs/liblbfgs-1.7/ChangeLog
vendored
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
2009-02-28 Naoaki Okazaki <okazaki at chokkan org>
|
||||||
|
|
||||||
|
* libLBFGS 1.7:
|
||||||
|
- Improved OWL-QN routines for stability.
|
||||||
|
- Removed the support of OWL-QN method in MoreThuente algorithm
|
||||||
|
because it accidentally fails in early stages of iterations for some
|
||||||
|
objectives. Because of this change, the OW-LQN method must be used
|
||||||
|
with the backtracking algorithm (LBFGS_LINESEARCH_BACKTRACKING), or
|
||||||
|
the library returns LBFGSERR_INVALID_LINESEARCH.
|
||||||
|
- Renamed line search algorithms as follows:
|
||||||
|
- LBFGS_LINESEARCH_BACKTRACKING: regular Wolfe condition.
|
||||||
|
- LBFGS_LINESEARCH_BACKTRACKING_LOOSE: regular Wolfe condition.
|
||||||
|
- LBFGS_LINESEARCH_BACKTRACKING_STRONG: strong Wolfe condition.
|
||||||
|
- Source code clean-up.
|
||||||
|
|
||||||
|
|
||||||
|
2008-11-02 Naoaki Okazaki <okazaki at chokkan org>
|
||||||
|
|
||||||
|
* libLBFGS 1.6:
|
||||||
|
- Improved line-search algorithm with strong Wolfe condition, which
|
||||||
|
was contributed by Takashi Imamichi. This routine is now default for
|
||||||
|
LBFGS_LINESEARCH_BACKTRACKING. The previous line search algorithm
|
||||||
|
with regular Wolfe condition is still available as
|
||||||
|
LBFGS_LINESEARCH_BACKTRACKING_LOOSE.
|
||||||
|
- Configurable stop index for L1-norm computation. A member variable
|
||||||
|
lbfgs_parameter_t::orthantwise_end was added to specify the index
|
||||||
|
number at which the library stops computing the L1 norm of the
|
||||||
|
variables. This is useful to prevent some variables from being
|
||||||
|
regularized by the OW-LQN method.
|
||||||
|
- A sample program written in C++ (sample/sample.cpp).
|
||||||
|
|
||||||
|
|
||||||
|
2008-07-10 Naoaki Okazaki <okazaki at chokkan org>
|
||||||
|
|
||||||
|
* libLBFGS 1.5:
|
||||||
|
- Configurable starting index for L1-norm computation. A member
|
||||||
|
variable lbfgs_parameter_t::orthantwise_start was added to specify
|
||||||
|
the index number from which the library computes the L1 norm of the
|
||||||
|
variables.
|
||||||
|
- Fixed a zero-division error when the initial variables have already
|
||||||
|
been a minimizer (reported by Takashi Imamichi). In this case, the
|
||||||
|
library returns LBFGS_ALREADY_MINIMIZED status code.
|
||||||
|
- Defined LBFGS_SUCCESS status code as zero; removed unused constants,
|
||||||
|
LBFGSFALSE and LBFGSTRUE.
|
||||||
|
- Fixed a compile error in an implicit down-cast.
|
||||||
|
|
||||||
|
|
||||||
|
2008-04-25 Naoaki Okazaki <okazaki at chokkan org>
|
||||||
|
|
||||||
|
* libLBFGS 1.4:
|
||||||
|
- Configurable line search algorithms. A member variable
|
||||||
|
lbfgs_parameter_t::linesearch was added to choose either MoreThuente
|
||||||
|
method (LBFGS_LINESEARCH_MORETHUENTE) or backtracking algorithm
|
||||||
|
(LBFGS_LINESEARCH_BACKTRACKING).
|
||||||
|
- Fixed a bug: the previous version did not compute psuedo-gradients
|
||||||
|
properly in the line search routines for OW-LQN. This bug might quit
|
||||||
|
an iteration process too early when the OW-LQN routine was activated
|
||||||
|
(0 < lbfgs_parameter_t::orthantwise_c).
|
||||||
|
- Configure script for POSIX environments.
|
||||||
|
- SSE/SSE2 optimizations with GCC.
|
||||||
|
- New functions lbfgs_malloc and lbfgs_free to use SSE/SSE2 routines
|
||||||
|
transparently. It is uncessary to use these functions for libLBFGS
|
||||||
|
built without SSE/SSE2 routines; you can still use any memory
|
||||||
|
allocators if SSE/SSE2 routines are disabled in libLBFGS.
|
||||||
|
|
||||||
|
|
||||||
|
2007-12-16 Naoaki Okazaki <okazaki at chokkan org>
|
||||||
|
|
||||||
|
* libLBFGS 1.3:
|
||||||
|
- An API change. An argument was added to lbfgs() function to receive
|
||||||
|
the final value of the objective function. This argument can be set
|
||||||
|
to NULL if the final value is unnecessary.
|
||||||
|
- Fixed a null-pointer bug in the sample code (reported by Takashi
|
||||||
|
Imamichi).
|
||||||
|
- Added build scripts for Microsoft Visual Studio 2005 and GCC.
|
||||||
|
- Added README file.
|
||||||
|
|
||||||
|
|
||||||
|
2007-12-13 Naoaki Okazaki <okazaki at chokkan org>
|
||||||
|
|
||||||
|
* libLBFGS 1.2:
|
||||||
|
- Fixed a serious bug in orthant-wise L-BFGS. An important variable
|
||||||
|
was used without initialization.
|
||||||
|
- Configurable L-BFGS parameters (number of limited memories, epsilon).
|
||||||
|
|
||||||
|
|
||||||
|
2007-12-01 Naoaki Okazaki <okazaki at chokkan org>
|
||||||
|
|
||||||
|
* libLBFGS 1.1:
|
||||||
|
- Implemented orthant-wise L-BFGS.
|
||||||
|
- Implemented lbfgs_parameter_init() function.
|
||||||
|
- Fixed several bugs.
|
||||||
|
- API documentation.
|
||||||
|
|
||||||
|
|
||||||
|
2007-09-20 Naoaki Okazaki <okazaki at chokkan org>
|
||||||
|
|
||||||
|
* libLBFGS 1.0
|
||||||
|
- Initial release.
|
||||||
|
|
231
packages/yap-lbfgs/liblbfgs-1.7/INSTALL
vendored
Normal file
231
packages/yap-lbfgs/liblbfgs-1.7/INSTALL
vendored
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
Installation Instructions
|
||||||
|
*************************
|
||||||
|
|
||||||
|
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004 Free
|
||||||
|
Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free documentation; the Free Software Foundation gives
|
||||||
|
unlimited permission to copy, distribute and modify it.
|
||||||
|
|
||||||
|
Basic Installation
|
||||||
|
==================
|
||||||
|
|
||||||
|
These are generic installation instructions.
|
||||||
|
|
||||||
|
The `configure' shell script attempts to guess correct values for
|
||||||
|
various system-dependent variables used during compilation. It uses
|
||||||
|
those values to create a `Makefile' in each directory of the package.
|
||||||
|
It may also create one or more `.h' files containing system-dependent
|
||||||
|
definitions. Finally, it creates a shell script `config.status' that
|
||||||
|
you can run in the future to recreate the current configuration, and a
|
||||||
|
file `config.log' containing compiler output (useful mainly for
|
||||||
|
debugging `configure').
|
||||||
|
|
||||||
|
It can also use an optional file (typically called `config.cache'
|
||||||
|
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||||
|
the results of its tests to speed up reconfiguring. (Caching is
|
||||||
|
disabled by default to prevent problems with accidental use of stale
|
||||||
|
cache files.)
|
||||||
|
|
||||||
|
If you need to do unusual things to compile the package, please try
|
||||||
|
to figure out how `configure' could check whether to do them, and mail
|
||||||
|
diffs or instructions to the address given in the `README' so they can
|
||||||
|
be considered for the next release. If you are using the cache, and at
|
||||||
|
some point `config.cache' contains results you don't want to keep, you
|
||||||
|
may remove or edit it.
|
||||||
|
|
||||||
|
The file `configure.ac' (or `configure.in') is used to create
|
||||||
|
`configure' by a program called `autoconf'. You only need
|
||||||
|
`configure.ac' if you want to change it or regenerate `configure' using
|
||||||
|
a newer version of `autoconf'.
|
||||||
|
|
||||||
|
The simplest way to compile this package is:
|
||||||
|
|
||||||
|
1. `cd' to the directory containing the package's source code and type
|
||||||
|
`./configure' to configure the package for your system. If you're
|
||||||
|
using `csh' on an old version of System V, you might need to type
|
||||||
|
`sh ./configure' instead to prevent `csh' from trying to execute
|
||||||
|
`configure' itself.
|
||||||
|
|
||||||
|
Running `configure' takes awhile. While running, it prints some
|
||||||
|
messages telling which features it is checking for.
|
||||||
|
|
||||||
|
2. Type `make' to compile the package.
|
||||||
|
|
||||||
|
3. Optionally, type `make check' to run any self-tests that come with
|
||||||
|
the package.
|
||||||
|
|
||||||
|
4. Type `make install' to install the programs and any data files and
|
||||||
|
documentation.
|
||||||
|
|
||||||
|
5. You can remove the program binaries and object files from the
|
||||||
|
source code directory by typing `make clean'. To also remove the
|
||||||
|
files that `configure' created (so you can compile the package for
|
||||||
|
a different kind of computer), type `make distclean'. There is
|
||||||
|
also a `make maintainer-clean' target, but that is intended mainly
|
||||||
|
for the package's developers. If you use it, you may have to get
|
||||||
|
all sorts of other programs in order to regenerate files that came
|
||||||
|
with the distribution.
|
||||||
|
|
||||||
|
Compilers and Options
|
||||||
|
=====================
|
||||||
|
|
||||||
|
Some systems require unusual options for compilation or linking that the
|
||||||
|
`configure' script does not know about. Run `./configure --help' for
|
||||||
|
details on some of the pertinent environment variables.
|
||||||
|
|
||||||
|
You can give `configure' initial values for configuration parameters
|
||||||
|
by setting variables in the command line or in the environment. Here
|
||||||
|
is an example:
|
||||||
|
|
||||||
|
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
|
||||||
|
|
||||||
|
*Note Defining Variables::, for more details.
|
||||||
|
|
||||||
|
Compiling For Multiple Architectures
|
||||||
|
====================================
|
||||||
|
|
||||||
|
You can compile the package for more than one kind of computer at the
|
||||||
|
same time, by placing the object files for each architecture in their
|
||||||
|
own directory. To do this, you must use a version of `make' that
|
||||||
|
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
||||||
|
directory where you want the object files and executables to go and run
|
||||||
|
the `configure' script. `configure' automatically checks for the
|
||||||
|
source code in the directory that `configure' is in and in `..'.
|
||||||
|
|
||||||
|
If you have to use a `make' that does not support the `VPATH'
|
||||||
|
variable, you have to compile the package for one architecture at a
|
||||||
|
time in the source code directory. After you have installed the
|
||||||
|
package for one architecture, use `make distclean' before reconfiguring
|
||||||
|
for another architecture.
|
||||||
|
|
||||||
|
Installation Names
|
||||||
|
==================
|
||||||
|
|
||||||
|
By default, `make install' will install the package's files in
|
||||||
|
`/usr/local/bin', `/usr/local/man', etc. You can specify an
|
||||||
|
installation prefix other than `/usr/local' by giving `configure' the
|
||||||
|
option `--prefix=PREFIX'.
|
||||||
|
|
||||||
|
You can specify separate installation prefixes for
|
||||||
|
architecture-specific files and architecture-independent files. If you
|
||||||
|
give `configure' the option `--exec-prefix=PREFIX', the package will
|
||||||
|
use PREFIX as the prefix for installing programs and libraries.
|
||||||
|
Documentation and other data files will still use the regular prefix.
|
||||||
|
|
||||||
|
In addition, if you use an unusual directory layout you can give
|
||||||
|
options like `--bindir=DIR' to specify different values for particular
|
||||||
|
kinds of files. Run `configure --help' for a list of the directories
|
||||||
|
you can set and what kinds of files go in them.
|
||||||
|
|
||||||
|
If the package supports it, you can cause programs to be installed
|
||||||
|
with an extra prefix or suffix on their names by giving `configure' the
|
||||||
|
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||||
|
|
||||||
|
Optional Features
|
||||||
|
=================
|
||||||
|
|
||||||
|
Some packages pay attention to `--enable-FEATURE' options to
|
||||||
|
`configure', where FEATURE indicates an optional part of the package.
|
||||||
|
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||||
|
is something like `gnu-as' or `x' (for the X Window System). The
|
||||||
|
`README' should mention any `--enable-' and `--with-' options that the
|
||||||
|
package recognizes.
|
||||||
|
|
||||||
|
For packages that use the X Window System, `configure' can usually
|
||||||
|
find the X include and library files automatically, but if it doesn't,
|
||||||
|
you can use the `configure' options `--x-includes=DIR' and
|
||||||
|
`--x-libraries=DIR' to specify their locations.
|
||||||
|
|
||||||
|
Specifying the System Type
|
||||||
|
==========================
|
||||||
|
|
||||||
|
There may be some features `configure' cannot figure out automatically,
|
||||||
|
but needs to determine by the type of machine the package will run on.
|
||||||
|
Usually, assuming the package is built to be run on the _same_
|
||||||
|
architectures, `configure' can figure that out, but if it prints a
|
||||||
|
message saying it cannot guess the machine type, give it the
|
||||||
|
`--build=TYPE' option. TYPE can either be a short name for the system
|
||||||
|
type, such as `sun4', or a canonical name which has the form:
|
||||||
|
|
||||||
|
CPU-COMPANY-SYSTEM
|
||||||
|
|
||||||
|
where SYSTEM can have one of these forms:
|
||||||
|
|
||||||
|
OS KERNEL-OS
|
||||||
|
|
||||||
|
See the file `config.sub' for the possible values of each field. If
|
||||||
|
`config.sub' isn't included in this package, then this package doesn't
|
||||||
|
need to know the machine type.
|
||||||
|
|
||||||
|
If you are _building_ compiler tools for cross-compiling, you should
|
||||||
|
use the `--target=TYPE' option to select the type of system they will
|
||||||
|
produce code for.
|
||||||
|
|
||||||
|
If you want to _use_ a cross compiler, that generates code for a
|
||||||
|
platform different from the build platform, you should specify the
|
||||||
|
"host" platform (i.e., that on which the generated programs will
|
||||||
|
eventually be run) with `--host=TYPE'.
|
||||||
|
|
||||||
|
Sharing Defaults
|
||||||
|
================
|
||||||
|
|
||||||
|
If you want to set default values for `configure' scripts to share, you
|
||||||
|
can create a site shell script called `config.site' that gives default
|
||||||
|
values for variables like `CC', `cache_file', and `prefix'.
|
||||||
|
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||||
|
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||||
|
`CONFIG_SITE' environment variable to the location of the site script.
|
||||||
|
A warning: not all `configure' scripts look for a site script.
|
||||||
|
|
||||||
|
Defining Variables
|
||||||
|
==================
|
||||||
|
|
||||||
|
Variables not defined in a site shell script can be set in the
|
||||||
|
environment passed to `configure'. However, some packages may run
|
||||||
|
configure again during the build, and the customized values of these
|
||||||
|
variables may be lost. In order to avoid this problem, you should set
|
||||||
|
them in the `configure' command line, using `VAR=value'. For example:
|
||||||
|
|
||||||
|
./configure CC=/usr/local2/bin/gcc
|
||||||
|
|
||||||
|
will cause the specified gcc to be used as the C compiler (unless it is
|
||||||
|
overridden in the site shell script).
|
||||||
|
|
||||||
|
`configure' Invocation
|
||||||
|
======================
|
||||||
|
|
||||||
|
`configure' recognizes the following options to control how it operates.
|
||||||
|
|
||||||
|
`--help'
|
||||||
|
`-h'
|
||||||
|
Print a summary of the options to `configure', and exit.
|
||||||
|
|
||||||
|
`--version'
|
||||||
|
`-V'
|
||||||
|
Print the version of Autoconf used to generate the `configure'
|
||||||
|
script, and exit.
|
||||||
|
|
||||||
|
`--cache-file=FILE'
|
||||||
|
Enable the cache: use and save the results of the tests in FILE,
|
||||||
|
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
||||||
|
disable caching.
|
||||||
|
|
||||||
|
`--config-cache'
|
||||||
|
`-C'
|
||||||
|
Alias for `--cache-file=config.cache'.
|
||||||
|
|
||||||
|
`--quiet'
|
||||||
|
`--silent'
|
||||||
|
`-q'
|
||||||
|
Do not print messages saying which checks are being made. To
|
||||||
|
suppress all normal output, redirect it to `/dev/null' (any error
|
||||||
|
messages will still be shown).
|
||||||
|
|
||||||
|
`--srcdir=DIR'
|
||||||
|
Look for the package's source code in directory DIR. Usually
|
||||||
|
`configure' can determine that directory automatically.
|
||||||
|
|
||||||
|
`configure' also accepts some other, not widely useful, options. Run
|
||||||
|
`configure --help' for more details.
|
||||||
|
|
71
packages/yap-lbfgs/liblbfgs-1.7/README
vendored
Normal file
71
packages/yap-lbfgs/liblbfgs-1.7/README
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
libLBFGS: C library of limited-memory BFGS (L-BFGS)
|
||||||
|
|
||||||
|
Copyright (c) 1990, Jorge Nocedal
|
||||||
|
Copyright (c) 2007-2009, Naoaki Okazaki
|
||||||
|
|
||||||
|
=========================================================================
|
||||||
|
1. Introduction
|
||||||
|
=========================================================================
|
||||||
|
libLBFGS is a C port of the implementation of Limited-memory
|
||||||
|
Broyden-Fletcher-Goldfarb-Shanno (L-BFGS) method written by Jorge Nocedal.
|
||||||
|
The original FORTRAN source code is available at:
|
||||||
|
http://www.ece.northwestern.edu/~nocedal/lbfgs.html
|
||||||
|
|
||||||
|
The L-BFGS method solves the unconstrainted minimization problem:
|
||||||
|
minimize F(x), x = (x1, x2, ..., xN),
|
||||||
|
only if the objective function F(x) and its gradient G(x) are computable.
|
||||||
|
|
||||||
|
Refer to the libLBFGS web site for more information.
|
||||||
|
http://www.chokkan.org/software/liblbfgs/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
=========================================================================
|
||||||
|
2. How to build
|
||||||
|
=========================================================================
|
||||||
|
[Microsoft Visual Studio 2008]
|
||||||
|
Open the solution file "lbfgs.sln" and build it.
|
||||||
|
|
||||||
|
[GCC]
|
||||||
|
$ ./configure
|
||||||
|
$ make
|
||||||
|
$ make install # To install libLBFGS library and header.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
=========================================================================
|
||||||
|
3. Note on SSE/SSE2 optimization
|
||||||
|
=========================================================================
|
||||||
|
This library has SSE/SSE2 optimization routines for vector arithmetic
|
||||||
|
operations on Intel/AMD processors. The SSE2 routine is for 64 bit double
|
||||||
|
values, and the SSE routine is for 32 bit float values. Since the default
|
||||||
|
parameters in libLBFGS are tuned for double precision values, it may need
|
||||||
|
to modify these parameters to use the SSE optimization routines.
|
||||||
|
|
||||||
|
To use the SSE2 optimization routine, specify --enable-sse2 option to the
|
||||||
|
configure script.
|
||||||
|
|
||||||
|
$ ./configure --enable-sse2
|
||||||
|
|
||||||
|
To build libLBFGS with SSE2 optimization enabled on Microsoft Visual
|
||||||
|
Studio 2005, define USE_SSE and __SSE2__ symbols.
|
||||||
|
|
||||||
|
Make sure to run libLBFGS on processors where SSE2 instrunctions are
|
||||||
|
available. The library does not check the existence of SSE2 instructions.
|
||||||
|
|
||||||
|
To package maintainers,
|
||||||
|
|
||||||
|
Please do not enable SSE/SSE2 optimization routine. The library built
|
||||||
|
with SSE/SSE2 optimization will crash without any notice when necessary
|
||||||
|
SSE/SSE2 instructions are unavailable on CPUs.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
=========================================================================
|
||||||
|
4. License
|
||||||
|
=========================================================================
|
||||||
|
libLBFGS is distributed under the term of the MIT license.
|
||||||
|
Please refer to COPYING file in the distribution.
|
||||||
|
|
||||||
|
$Id: README 56 2009-02-28 09:41:21Z naoaki $
|
678
packages/yap-lbfgs/liblbfgs-1.7/include/lbfgs.h
vendored
Normal file
678
packages/yap-lbfgs/liblbfgs-1.7/include/lbfgs.h
vendored
Normal file
@ -0,0 +1,678 @@
|
|||||||
|
/*
|
||||||
|
* C library of Limited memory BFGS (L-BFGS).
|
||||||
|
*
|
||||||
|
* Copyright (c) 1990, Jorge Nocedal
|
||||||
|
* Copyright (c) 2007,2008,2009 Naoaki Okazaki
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* $Id: lbfgs.h 56 2009-02-28 09:41:21Z naoaki $ */
|
||||||
|
|
||||||
|
#ifndef __LBFGS_H__
|
||||||
|
#define __LBFGS_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif/*__cplusplus*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The default precision of floating point values is 64bit (double).
|
||||||
|
*/
|
||||||
|
#ifndef LBFGS_FLOAT
|
||||||
|
#define LBFGS_FLOAT 64
|
||||||
|
#endif/*LBFGS_FLOAT*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Activate optimization routines for IEEE754 floating point values.
|
||||||
|
*/
|
||||||
|
#ifndef LBFGS_IEEE_FLOAT
|
||||||
|
#define LBFGS_IEEE_FLOAT 1
|
||||||
|
#endif/*LBFGS_IEEE_FLOAT*/
|
||||||
|
|
||||||
|
#if LBFGS_FLOAT == 32
|
||||||
|
typedef float lbfgsfloatval_t;
|
||||||
|
|
||||||
|
#elif LBFGS_FLOAT == 64
|
||||||
|
typedef double lbfgsfloatval_t;
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "libLBFGS supports single (float; LBFGS_FLOAT = 32) or double (double; LBFGS_FLOAT=64) precision only."
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup liblbfgs_api libLBFGS API
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* The libLBFGS API.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return values of lbfgs().
|
||||||
|
*
|
||||||
|
* Roughly speaking, a negative value indicates an error.
|
||||||
|
*/
|
||||||
|
enum {
|
||||||
|
/** L-BFGS reaches convergence. */
|
||||||
|
LBFGS_SUCCESS = 0,
|
||||||
|
LBFGS_CONVERGENCE = 0,
|
||||||
|
LBFGS_STOP,
|
||||||
|
/** The initial variables already minimize the objective function. */
|
||||||
|
LBFGS_ALREADY_MINIMIZED,
|
||||||
|
|
||||||
|
/** Unknown error. */
|
||||||
|
LBFGSERR_UNKNOWNERROR = -1024,
|
||||||
|
/** Logic error. */
|
||||||
|
LBFGSERR_LOGICERROR,
|
||||||
|
/** Insufficient memory. */
|
||||||
|
LBFGSERR_OUTOFMEMORY,
|
||||||
|
/** The minimization process has been canceled. */
|
||||||
|
LBFGSERR_CANCELED,
|
||||||
|
/** Invalid number of variables specified. */
|
||||||
|
LBFGSERR_INVALID_N,
|
||||||
|
/** Invalid number of variables (for SSE) specified. */
|
||||||
|
LBFGSERR_INVALID_N_SSE,
|
||||||
|
/** The array x must be aligned to 16 (for SSE). */
|
||||||
|
LBFGSERR_INVALID_X_SSE,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::epsilon specified. */
|
||||||
|
LBFGSERR_INVALID_EPSILON,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::past specified. */
|
||||||
|
LBFGSERR_INVALID_TESTPERIOD,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::delta specified. */
|
||||||
|
LBFGSERR_INVALID_DELTA,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::linesearch specified. */
|
||||||
|
LBFGSERR_INVALID_LINESEARCH,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::max_step specified. */
|
||||||
|
LBFGSERR_INVALID_MINSTEP,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::max_step specified. */
|
||||||
|
LBFGSERR_INVALID_MAXSTEP,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::ftol specified. */
|
||||||
|
LBFGSERR_INVALID_FTOL,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::gtol specified. */
|
||||||
|
LBFGSERR_INVALID_GTOL,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::xtol specified. */
|
||||||
|
LBFGSERR_INVALID_XTOL,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::max_linesearch specified. */
|
||||||
|
LBFGSERR_INVALID_MAXLINESEARCH,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::orthantwise_c specified. */
|
||||||
|
LBFGSERR_INVALID_ORTHANTWISE,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::orthantwise_start specified. */
|
||||||
|
LBFGSERR_INVALID_ORTHANTWISE_START,
|
||||||
|
/** Invalid parameter lbfgs_parameter_t::orthantwise_end specified. */
|
||||||
|
LBFGSERR_INVALID_ORTHANTWISE_END,
|
||||||
|
/** The line-search step went out of the interval of uncertainty. */
|
||||||
|
LBFGSERR_OUTOFINTERVAL,
|
||||||
|
/** A logic error occurred; alternatively, the interval of uncertainty
|
||||||
|
became too small. */
|
||||||
|
LBFGSERR_INCORRECT_TMINMAX,
|
||||||
|
/** A rounding error occurred; alternatively, no line-search step
|
||||||
|
satisfies the sufficient decrease and curvature conditions. */
|
||||||
|
LBFGSERR_ROUNDING_ERROR,
|
||||||
|
/** The line-search step became smaller than lbfgs_parameter_t::min_step. */
|
||||||
|
LBFGSERR_MINIMUMSTEP,
|
||||||
|
/** The line-search step became larger than lbfgs_parameter_t::max_step. */
|
||||||
|
LBFGSERR_MAXIMUMSTEP,
|
||||||
|
/** The line-search routine reaches the maximum number of evaluations. */
|
||||||
|
LBFGSERR_MAXIMUMLINESEARCH,
|
||||||
|
/** The algorithm routine reaches the maximum number of iterations. */
|
||||||
|
LBFGSERR_MAXIMUMITERATION,
|
||||||
|
/** Relative width of the interval of uncertainty is at most
|
||||||
|
lbfgs_parameter_t::xtol. */
|
||||||
|
LBFGSERR_WIDTHTOOSMALL,
|
||||||
|
/** A logic error (negative line-search step) occurred. */
|
||||||
|
LBFGSERR_INVALIDPARAMETERS,
|
||||||
|
/** The current search direction increases the objective function value. */
|
||||||
|
LBFGSERR_INCREASEGRADIENT,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Line search algorithms.
|
||||||
|
*/
|
||||||
|
enum {
|
||||||
|
/** The default algorithm (MoreThuente method). */
|
||||||
|
LBFGS_LINESEARCH_DEFAULT = 0,
|
||||||
|
/** MoreThuente method proposd by More and Thuente. */
|
||||||
|
LBFGS_LINESEARCH_MORETHUENTE = 0,
|
||||||
|
/** Backtracking method with strong Wolfe condition. */
|
||||||
|
LBFGS_LINESEARCH_BACKTRACKING_STRONG = 1,
|
||||||
|
/** Backtracking method with regular Wolfe condition. */
|
||||||
|
LBFGS_LINESEARCH_BACKTRACKING = 2,
|
||||||
|
/** Backtracking method with regular Wolfe condition. */
|
||||||
|
LBFGS_LINESEARCH_BACKTRACKING_LOOSE = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* L-BFGS optimization parameters.
|
||||||
|
* Call lbfgs_parameter_init() function to initialize parameters to the
|
||||||
|
* default values.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
/**
|
||||||
|
* The number of corrections to approximate the inverse hessian matrix.
|
||||||
|
* The L-BFGS routine stores the computation results of previous \ref m
|
||||||
|
* iterations to approximate the inverse hessian matrix of the current
|
||||||
|
* iteration. This parameter controls the size of the limited memories
|
||||||
|
* (corrections). The default value is \c 6. Values less than \c 3 are
|
||||||
|
* not recommended. Large values will result in excessive computing time.
|
||||||
|
*/
|
||||||
|
int m;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Epsilon for convergence test.
|
||||||
|
* This parameter determines the accuracy with which the solution is to
|
||||||
|
* be found. A minimization terminates when
|
||||||
|
* ||g|| < \ref epsilon * max(1, ||x||),
|
||||||
|
* where ||.|| denotes the Euclidean (L2) norm. The default value is
|
||||||
|
* \c 1e-5.
|
||||||
|
*/
|
||||||
|
lbfgsfloatval_t epsilon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distance for delta-based convergence test.
|
||||||
|
* This parameter determines the distance, in iterations, to compute
|
||||||
|
* the rate of decrease of the objective function. If the value of this
|
||||||
|
* parameter is zero, the library does not perform the delta-based
|
||||||
|
* convergence test. The default value is \c 0.
|
||||||
|
*/
|
||||||
|
int past;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delta for convergence test.
|
||||||
|
* This parameter determines the minimum rate of decrease of the
|
||||||
|
* objective function. The library stops iterations when the
|
||||||
|
* following condition is met:
|
||||||
|
* (f' - f) / f < \ref delta,
|
||||||
|
* where f' is the objective value of \ref past iterations ago, and f is
|
||||||
|
* the objective value of the current iteration.
|
||||||
|
* The default value is \c 0.
|
||||||
|
*/
|
||||||
|
lbfgsfloatval_t delta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum number of iterations.
|
||||||
|
* The lbfgs() function terminates an optimization process with
|
||||||
|
* ::LBFGSERR_MAXIMUMITERATION status code when the iteration count
|
||||||
|
* exceedes this parameter. Setting this parameter to zero continues an
|
||||||
|
* optimization process until a convergence or error. The default value
|
||||||
|
* is \c 0.
|
||||||
|
*/
|
||||||
|
int max_iterations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The line search algorithm.
|
||||||
|
* This parameter specifies a line search algorithm to be used by the
|
||||||
|
* L-BFGS routine.
|
||||||
|
*/
|
||||||
|
int linesearch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum number of trials for the line search.
|
||||||
|
* This parameter controls the number of function and gradients evaluations
|
||||||
|
* per iteration for the line search routine. The default value is \c 20.
|
||||||
|
*/
|
||||||
|
int max_linesearch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minimum step of the line search routine.
|
||||||
|
* The default value is \c 1e-20. This value need not be modified unless
|
||||||
|
* the exponents are too large for the machine being used, or unless the
|
||||||
|
* problem is extremely badly scaled (in which case the exponents should
|
||||||
|
* be increased).
|
||||||
|
*/
|
||||||
|
lbfgsfloatval_t min_step;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum step of the line search.
|
||||||
|
* The default value is \c 1e+20. This value need not be modified unless
|
||||||
|
* the exponents are too large for the machine being used, or unless the
|
||||||
|
* problem is extremely badly scaled (in which case the exponents should
|
||||||
|
* be increased).
|
||||||
|
*/
|
||||||
|
lbfgsfloatval_t max_step;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A parameter to control the accuracy of the line search routine.
|
||||||
|
* The default value is \c 1e-4. This parameter should be greater
|
||||||
|
* than zero and smaller than \c 0.5.
|
||||||
|
*/
|
||||||
|
lbfgsfloatval_t ftol;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A parameter to control the accuracy of the line search routine.
|
||||||
|
* The default value is \c 0.9. If the function and gradient
|
||||||
|
* evaluations are inexpensive with respect to the cost of the
|
||||||
|
* iteration (which is sometimes the case when solving very large
|
||||||
|
* problems) it may be advantageous to set this parameter to a small
|
||||||
|
* value. A typical small value is \c 0.1. This parameter shuold be
|
||||||
|
* greater than the \ref ftol parameter (\c 1e-4) and smaller than
|
||||||
|
* \c 1.0.
|
||||||
|
*/
|
||||||
|
lbfgsfloatval_t gtol;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The machine precision for floating-point values.
|
||||||
|
* This parameter must be a positive value set by a client program to
|
||||||
|
* estimate the machine precision. The line search routine will terminate
|
||||||
|
* with the status code (::LBFGSERR_ROUNDING_ERROR) if the relative width
|
||||||
|
* of the interval of uncertainty is less than this parameter.
|
||||||
|
*/
|
||||||
|
lbfgsfloatval_t xtol;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coeefficient for the L1 norm of variables.
|
||||||
|
* This parameter should be set to zero for standard minimization
|
||||||
|
* problems. Setting this parameter to a positive value activates
|
||||||
|
* Orthant-Wise Limited-memory Quasi-Newton (OWL-QN) method, which
|
||||||
|
* minimizes the objective function F(x) combined with the L1 norm |x|
|
||||||
|
* of the variables, {F(x) + C |x|}. This parameter is the coeefficient
|
||||||
|
* for the |x|, i.e., C. As the L1 norm |x| is not differentiable at
|
||||||
|
* zero, the library modifies function and gradient evaluations from
|
||||||
|
* a client program suitably; a client program thus have only to return
|
||||||
|
* the function value F(x) and gradients G(x) as usual. The default value
|
||||||
|
* is zero.
|
||||||
|
*/
|
||||||
|
lbfgsfloatval_t orthantwise_c;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start index for computing L1 norm of the variables.
|
||||||
|
* This parameter is valid only for OWL-QN method
|
||||||
|
* (i.e., \ref orthantwise_c != 0). This parameter b (0 <= b < N)
|
||||||
|
* specifies the index number from which the library computes the
|
||||||
|
* L1 norm of the variables x,
|
||||||
|
* |x| := |x_{b}| + |x_{b+1}| + ... + |x_{N}| .
|
||||||
|
* In other words, variables x_1, ..., x_{b-1} are not used for
|
||||||
|
* computing the L1 norm. Setting b (0 < b < N), one can protect
|
||||||
|
* variables, x_1, ..., x_{b-1} (e.g., a bias term of logistic
|
||||||
|
* regression) from being regularized. The default value is zero.
|
||||||
|
*/
|
||||||
|
int orthantwise_start;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End index for computing L1 norm of the variables.
|
||||||
|
* This parameter is valid only for OWL-QN method
|
||||||
|
* (i.e., \ref orthantwise_c != 0). This parameter e (0 < e <= N)
|
||||||
|
* specifies the index number at which the library stops computing the
|
||||||
|
* L1 norm of the variables x,
|
||||||
|
*/
|
||||||
|
int orthantwise_end;
|
||||||
|
} lbfgs_parameter_t;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback interface to provide objective function and gradient evaluations.
|
||||||
|
*
|
||||||
|
* The lbfgs() function call this function to obtain the values of objective
|
||||||
|
* function and its gradients when needed. A client program must implement
|
||||||
|
* this function to evaluate the values of the objective function and its
|
||||||
|
* gradients, given current values of variables.
|
||||||
|
*
|
||||||
|
* @param instance The user data sent for lbfgs() function by the client.
|
||||||
|
* @param x The current values of variables.
|
||||||
|
* @param g The gradient vector. The callback function must compute
|
||||||
|
* the gradient values for the current variables.
|
||||||
|
* @param n The number of variables.
|
||||||
|
* @param step The current step of the line search routine.
|
||||||
|
* @retval lbfgsfloatval_t The value of the objective function for the current
|
||||||
|
* variables.
|
||||||
|
*/
|
||||||
|
typedef lbfgsfloatval_t (*lbfgs_evaluate_t)(
|
||||||
|
void *instance,
|
||||||
|
const lbfgsfloatval_t *x,
|
||||||
|
lbfgsfloatval_t *g,
|
||||||
|
const int n,
|
||||||
|
const lbfgsfloatval_t step
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback interface to receive the progress of the optimization process.
|
||||||
|
*
|
||||||
|
* The lbfgs() function call this function for each iteration. Implementing
|
||||||
|
* this function, a client program can store or display the current progress
|
||||||
|
* of the optimization process.
|
||||||
|
*
|
||||||
|
* @param instance The user data sent for lbfgs() function by the client.
|
||||||
|
* @param x The current values of variables.
|
||||||
|
* @param g The current gradient values of variables.
|
||||||
|
* @param fx The current value of the objective function.
|
||||||
|
* @param xnorm The Euclidean norm of the variables.
|
||||||
|
* @param gnorm The Euclidean norm of the gradients.
|
||||||
|
* @param step The line-search step used for this iteration.
|
||||||
|
* @param n The number of variables.
|
||||||
|
* @param k The iteration count.
|
||||||
|
* @param ls The number of evaluations called for this iteration.
|
||||||
|
* @retval int Zero to continue the optimization process. Returning a
|
||||||
|
* non-zero value will cancel the optimization process.
|
||||||
|
*/
|
||||||
|
typedef int (*lbfgs_progress_t)(
|
||||||
|
void *instance,
|
||||||
|
const lbfgsfloatval_t *x,
|
||||||
|
const lbfgsfloatval_t *g,
|
||||||
|
const lbfgsfloatval_t fx,
|
||||||
|
const lbfgsfloatval_t xnorm,
|
||||||
|
const lbfgsfloatval_t gnorm,
|
||||||
|
const lbfgsfloatval_t step,
|
||||||
|
int n,
|
||||||
|
int k,
|
||||||
|
int ls
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
A user must implement a function compatible with ::lbfgs_evaluate_t (evaluation
|
||||||
|
callback) and pass the pointer to the callback function to lbfgs() arguments.
|
||||||
|
Similarly, a user can implement a function compatible with ::lbfgs_progress_t
|
||||||
|
(progress callback) to obtain the current progress (e.g., variables, function
|
||||||
|
value, ||G||, etc) and to cancel the iteration process if necessary.
|
||||||
|
Implementation of a progress callback is optional: a user can pass \c NULL if
|
||||||
|
progress notification is not necessary.
|
||||||
|
|
||||||
|
In addition, a user must preserve two requirements:
|
||||||
|
- The number of variables must be multiples of 16 (this is not 4).
|
||||||
|
- The memory block of variable array ::x must be aligned to 16.
|
||||||
|
|
||||||
|
This algorithm terminates an optimization
|
||||||
|
when:
|
||||||
|
|
||||||
|
||G|| < \epsilon \cdot \max(1, ||x||) .
|
||||||
|
|
||||||
|
In this formula, ||.|| denotes the Euclidean norm.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start a L-BFGS optimization.
|
||||||
|
*
|
||||||
|
* @param n The number of variables.
|
||||||
|
* @param x The array of variables. A client program can set
|
||||||
|
* default values for the optimization and receive the
|
||||||
|
* optimization result through this array. This array
|
||||||
|
* must be allocated by ::lbfgs_malloc function
|
||||||
|
* for libLBFGS built with SSE/SSE2 optimization routine
|
||||||
|
* enabled. The library built without SSE/SSE2
|
||||||
|
* optimization does not have such a requirement.
|
||||||
|
* @param ptr_fx The pointer to the variable that receives the final
|
||||||
|
* value of the objective function for the variables.
|
||||||
|
* This argument can be set to \c NULL if the final
|
||||||
|
* value of the objective function is unnecessary.
|
||||||
|
* @param proc_evaluate The callback function to provide function and
|
||||||
|
* gradient evaluations given a current values of
|
||||||
|
* variables. A client program must implement a
|
||||||
|
* callback function compatible with \ref
|
||||||
|
* lbfgs_evaluate_t and pass the pointer to the
|
||||||
|
* callback function.
|
||||||
|
* @param proc_progress The callback function to receive the progress
|
||||||
|
* (the number of iterations, the current value of
|
||||||
|
* the objective function) of the minimization
|
||||||
|
* process. This argument can be set to \c NULL if
|
||||||
|
* a progress report is unnecessary.
|
||||||
|
* @param instance A user data for the client program. The callback
|
||||||
|
* functions will receive the value of this argument.
|
||||||
|
* @param param The pointer to a structure representing parameters for
|
||||||
|
* L-BFGS optimization. A client program can set this
|
||||||
|
* parameter to \c NULL to use the default parameters.
|
||||||
|
* Call lbfgs_parameter_init() function to fill a
|
||||||
|
* structure with the default values.
|
||||||
|
* @retval int The status code. This function returns zero if the
|
||||||
|
* minimization process terminates without an error. A
|
||||||
|
* non-zero value indicates an error.
|
||||||
|
*/
|
||||||
|
int lbfgs(
|
||||||
|
int n,
|
||||||
|
lbfgsfloatval_t *x,
|
||||||
|
lbfgsfloatval_t *ptr_fx,
|
||||||
|
lbfgs_evaluate_t proc_evaluate,
|
||||||
|
lbfgs_progress_t proc_progress,
|
||||||
|
void *instance,
|
||||||
|
lbfgs_parameter_t *param
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize L-BFGS parameters to the default values.
|
||||||
|
*
|
||||||
|
* Call this function to fill a parameter structure with the default values
|
||||||
|
* and overwrite parameter values if necessary.
|
||||||
|
*
|
||||||
|
* @param param The pointer to the parameter structure.
|
||||||
|
*/
|
||||||
|
void lbfgs_parameter_init(lbfgs_parameter_t *param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate an array for variables.
|
||||||
|
*
|
||||||
|
* This function allocates an array of variables for the convenience of
|
||||||
|
* ::lbfgs function; the function has a requreiemt for a variable array
|
||||||
|
* when libLBFGS is built with SSE/SSE2 optimization routines. A user does
|
||||||
|
* not have to use this function for libLBFGS built without SSE/SSE2
|
||||||
|
* optimization.
|
||||||
|
*
|
||||||
|
* @param n The number of variables.
|
||||||
|
*/
|
||||||
|
lbfgsfloatval_t* lbfgs_malloc(int n);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free an array of variables.
|
||||||
|
*
|
||||||
|
* @param x The array of variables allocated by ::lbfgs_malloc
|
||||||
|
* function.
|
||||||
|
*/
|
||||||
|
void lbfgs_free(lbfgsfloatval_t *x);
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif/*__cplusplus*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
@mainpage libLBFGS: a library of Limited-memory Broyden-Fletcher-Goldfarb-Shanno (L-BFGS)
|
||||||
|
|
||||||
|
@section intro Introduction
|
||||||
|
|
||||||
|
This library is a C port of the implementation of Limited-memory
|
||||||
|
Broyden-Fletcher-Goldfarb-Shanno (L-BFGS) method written by Jorge Nocedal.
|
||||||
|
The original FORTRAN source code is available at:
|
||||||
|
http://www.ece.northwestern.edu/~nocedal/lbfgs.html
|
||||||
|
|
||||||
|
The L-BFGS method solves the unconstrainted minimization problem,
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
minimize F(x), x = (x1, x2, ..., xN),
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
only if the objective function F(x) and its gradient G(x) are computable. The
|
||||||
|
well-known Newton's method requires computation of the inverse of the hessian
|
||||||
|
matrix of the objective function. However, the computational cost for the
|
||||||
|
inverse hessian matrix is expensive especially when the objective function
|
||||||
|
takes a large number of variables. The L-BFGS method iteratively finds a
|
||||||
|
minimizer by approximating the inverse hessian matrix by information from last
|
||||||
|
m iterations. This innovation saves the memory storage and computational time
|
||||||
|
drastically for large-scaled problems.
|
||||||
|
|
||||||
|
Among the various ports of L-BFGS, this library provides several features:
|
||||||
|
- <b>Optimization with L1-norm (Orthant-Wise Limited-memory Quasi-Newton
|
||||||
|
(OWL-QN) method)</b>:
|
||||||
|
In addition to standard minimization problems, the library can minimize
|
||||||
|
a function F(x) combined with L1-norm |x| of the variables,
|
||||||
|
{F(x) + C |x|}, where C is a constant scalar parameter. This feature is
|
||||||
|
useful for estimating parameters of sparse log-linear models (e.g.,
|
||||||
|
logistic regression and maximum entropy) with L1-regularization (or
|
||||||
|
Laplacian prior).
|
||||||
|
- <b>Clean C code</b>:
|
||||||
|
Unlike C codes generated automatically by f2c (Fortran 77 into C converter),
|
||||||
|
this port includes changes based on my interpretations, improvements,
|
||||||
|
optimizations, and clean-ups so that the ported code would be well-suited
|
||||||
|
for a C code. In addition to comments inherited from the original code,
|
||||||
|
a number of comments were added through my interpretations.
|
||||||
|
- <b>Callback interface</b>:
|
||||||
|
The library receives function and gradient values via a callback interface.
|
||||||
|
The library also notifies the progress of the optimization by invoking a
|
||||||
|
callback function. In the original implementation, a user had to set
|
||||||
|
function and gradient values every time the function returns for obtaining
|
||||||
|
updated values.
|
||||||
|
- <b>Thread safe</b>:
|
||||||
|
The library is thread-safe, which is the secondary gain from the callback
|
||||||
|
interface.
|
||||||
|
- <b>Cross platform.</b> The source code can be compiled on Microsoft Visual
|
||||||
|
Studio 2005, GNU C Compiler (gcc), etc.
|
||||||
|
- <b>Configurable precision</b>: A user can choose single-precision (float)
|
||||||
|
or double-precision (double) accuracy by changing ::LBFGS_FLOAT macro.
|
||||||
|
- <b>SSE/SSE2 optimization</b>:
|
||||||
|
This library includes SSE/SSE2 optimization (written in compiler intrinsics)
|
||||||
|
for vector arithmetic operations on Intel/AMD processors. The library uses
|
||||||
|
SSE for float values and SSE2 for double values. The SSE/SSE2 optimization
|
||||||
|
routine is disabled by default.
|
||||||
|
|
||||||
|
This library is used by:
|
||||||
|
- <a href="http://www.chokkan.org/software/crfsuite/">CRFsuite: A fast implementation of Conditional Random Fields (CRFs)</a>
|
||||||
|
- <a href="http://www.public.iastate.edu/~gdancik/mlegp/">mlegp: an R package for maximum likelihood estimates for Gaussian processes</a>
|
||||||
|
- <a href="http://infmath.uibk.ac.at/~matthiasf/imaging2/">imaging2: the imaging2 class library</a>
|
||||||
|
- <a href="http://search.cpan.org/~laye/Algorithm-LBFGS-0.16/">Algorithm::LBFGS - Perl extension for L-BFGS</a>
|
||||||
|
|
||||||
|
@section download Download
|
||||||
|
|
||||||
|
- <a href="http://www.chokkan.org/software/dist/liblbfgs-1.7.tar.gz">Source code</a>
|
||||||
|
|
||||||
|
libLBFGS is distributed under the term of the
|
||||||
|
<a href="http://opensource.org/licenses/mit-license.php">MIT license</a>.
|
||||||
|
|
||||||
|
@section changelog History
|
||||||
|
- Version 1.7 (2009-02-28):
|
||||||
|
- Improved OWL-QN routines for stability.
|
||||||
|
- Removed the support of OWL-QN method in MoreThuente algorithm because
|
||||||
|
it accidentally fails in early stages of iterations for some objectives.
|
||||||
|
Because of this change, <b>the OW-LQN method must be used with the
|
||||||
|
backtracking algorithm (::LBFGS_LINESEARCH_BACKTRACKING)</b>, or the
|
||||||
|
library returns ::LBFGSERR_INVALID_LINESEARCH.
|
||||||
|
- Renamed line search algorithms as follows:
|
||||||
|
- ::LBFGS_LINESEARCH_BACKTRACKING: regular Wolfe condition.
|
||||||
|
- ::LBFGS_LINESEARCH_BACKTRACKING_LOOSE: regular Wolfe condition.
|
||||||
|
- ::LBFGS_LINESEARCH_BACKTRACKING_STRONG: strong Wolfe condition.
|
||||||
|
- Source code clean-up.
|
||||||
|
- Version 1.6 (2008-11-02):
|
||||||
|
- Improved line-search algorithm with strong Wolfe condition, which was
|
||||||
|
contributed by Takashi Imamichi. This routine is now default for
|
||||||
|
::LBFGS_LINESEARCH_BACKTRACKING. The previous line search algorithm
|
||||||
|
with regular Wolfe condition is still available as
|
||||||
|
::LBFGS_LINESEARCH_BACKTRACKING_LOOSE.
|
||||||
|
- Configurable stop index for L1-norm computation. A member variable
|
||||||
|
::lbfgs_parameter_t::orthantwise_end was added to specify the index
|
||||||
|
number at which the library stops computing the L1 norm of the
|
||||||
|
variables. This is useful to prevent some variables from being
|
||||||
|
regularized by the OW-LQN method.
|
||||||
|
- A sample program written in C++ (sample/sample.cpp).
|
||||||
|
- Version 1.5 (2008-07-10):
|
||||||
|
- Configurable starting index for L1-norm computation. A member variable
|
||||||
|
::lbfgs_parameter_t::orthantwise_start was added to specify the index
|
||||||
|
number from which the library computes the L1 norm of the variables.
|
||||||
|
This is useful to prevent some variables from being regularized by the
|
||||||
|
OWL-QN method.
|
||||||
|
- Fixed a zero-division error when the initial variables have already
|
||||||
|
been a minimizer (reported by Takashi Imamichi). In this case, the
|
||||||
|
library returns ::LBFGS_ALREADY_MINIMIZED status code.
|
||||||
|
- Defined ::LBFGS_SUCCESS status code as zero; removed unused constants,
|
||||||
|
LBFGSFALSE and LBFGSTRUE.
|
||||||
|
- Fixed a compile error in an implicit down-cast.
|
||||||
|
- Version 1.4 (2008-04-25):
|
||||||
|
- Configurable line search algorithms. A member variable
|
||||||
|
::lbfgs_parameter_t::linesearch was added to choose either MoreThuente
|
||||||
|
method (::LBFGS_LINESEARCH_MORETHUENTE) or backtracking algorithm
|
||||||
|
(::LBFGS_LINESEARCH_BACKTRACKING).
|
||||||
|
- Fixed a bug: the previous version did not compute psuedo-gradients
|
||||||
|
properly in the line search routines for OWL-QN. This bug might quit
|
||||||
|
an iteration process too early when the OWL-QN routine was activated
|
||||||
|
(0 < ::lbfgs_parameter_t::orthantwise_c).
|
||||||
|
- Configure script for POSIX environments.
|
||||||
|
- SSE/SSE2 optimizations with GCC.
|
||||||
|
- New functions ::lbfgs_malloc and ::lbfgs_free to use SSE/SSE2 routines
|
||||||
|
transparently. It is uncessary to use these functions for libLBFGS built
|
||||||
|
without SSE/SSE2 routines; you can still use any memory allocators if
|
||||||
|
SSE/SSE2 routines are disabled in libLBFGS.
|
||||||
|
- Version 1.3 (2007-12-16):
|
||||||
|
- An API change. An argument was added to lbfgs() function to receive the
|
||||||
|
final value of the objective function. This argument can be set to
|
||||||
|
\c NULL if the final value is unnecessary.
|
||||||
|
- Fixed a null-pointer bug in the sample code (reported by Takashi Imamichi).
|
||||||
|
- Added build scripts for Microsoft Visual Studio 2005 and GCC.
|
||||||
|
- Added README file.
|
||||||
|
- Version 1.2 (2007-12-13):
|
||||||
|
- Fixed a serious bug in orthant-wise L-BFGS.
|
||||||
|
An important variable was used without initialization.
|
||||||
|
- Version 1.1 (2007-12-01):
|
||||||
|
- Implemented orthant-wise L-BFGS.
|
||||||
|
- Implemented lbfgs_parameter_init() function.
|
||||||
|
- Fixed several bugs.
|
||||||
|
- API documentation.
|
||||||
|
- Version 1.0 (2007-09-20):
|
||||||
|
- Initial release.
|
||||||
|
|
||||||
|
@section api Documentation
|
||||||
|
|
||||||
|
- @ref liblbfgs_api "libLBFGS API"
|
||||||
|
|
||||||
|
@section sample Sample code
|
||||||
|
|
||||||
|
@include sample.c
|
||||||
|
|
||||||
|
@section ack Acknowledgements
|
||||||
|
|
||||||
|
The L-BFGS algorithm is described in:
|
||||||
|
- Jorge Nocedal.
|
||||||
|
Updating Quasi-Newton Matrices with Limited Storage.
|
||||||
|
<i>Mathematics of Computation</i>, Vol. 35, No. 151, pp. 773--782, 1980.
|
||||||
|
- Dong C. Liu and Jorge Nocedal.
|
||||||
|
On the limited memory BFGS method for large scale optimization.
|
||||||
|
<i>Mathematical Programming</i> B, Vol. 45, No. 3, pp. 503-528, 1989.
|
||||||
|
|
||||||
|
The line search algorithms used in this implementation are described in:
|
||||||
|
- John E. Dennis and Robert B. Schnabel.
|
||||||
|
<i>Numerical Methods for Unconstrained Optimization and Nonlinear
|
||||||
|
Equations</i>, Englewood Cliffs, 1983.
|
||||||
|
- Jorge J. More and David J. Thuente.
|
||||||
|
Line search algorithm with guaranteed sufficient decrease.
|
||||||
|
<i>ACM Transactions on Mathematical Software (TOMS)</i>, Vol. 20, No. 3,
|
||||||
|
pp. 286-307, 1994.
|
||||||
|
|
||||||
|
This library also implements Orthant-Wise Limited-memory Quasi-Newton (OWL-QN)
|
||||||
|
method presented in:
|
||||||
|
- Galen Andrew and Jianfeng Gao.
|
||||||
|
Scalable training of L1-regularized log-linear models.
|
||||||
|
In <i>Proceedings of the 24th International Conference on Machine
|
||||||
|
Learning (ICML 2007)</i>, pp. 33-40, 2007.
|
||||||
|
|
||||||
|
Special thanks go to Yoshimasa Tsuruoka and Daisuke Okanohara for technical
|
||||||
|
information about OWL-QN.
|
||||||
|
|
||||||
|
Finally I would like to thank the original author, Jorge Nocedal, who has been
|
||||||
|
distributing the effieicnt and explanatory implementation in an open source
|
||||||
|
licence.
|
||||||
|
|
||||||
|
@section reference Reference
|
||||||
|
|
||||||
|
- <a href="http://www.ece.northwestern.edu/~nocedal/lbfgs.html">L-BFGS</a> by Jorge Nocedal.
|
||||||
|
- <a href="http://research.microsoft.com/en-us/downloads/b1eb1016-1738-4bd5-83a9-370c9d498a03/default.aspx">Orthant-Wise Limited-memory Quasi-Newton Optimizer for L1-regularized Objectives</a> by Galen Andrew.
|
||||||
|
- <a href="http://chasen.org/~taku/software/misc/lbfgs/">C port (via f2c)</a> by Taku Kudo.
|
||||||
|
- <a href="http://www.alglib.net/optimization/lbfgs.php">C#/C++/Delphi/VisualBasic6 port</a> in ALGLIB.
|
||||||
|
- <a href="http://cctbx.sourceforge.net/">Computational Crystallography Toolbox</a> includes
|
||||||
|
<a href="http://cctbx.sourceforge.net/current_cvs/c_plus_plus/namespacescitbx_1_1lbfgs.html">scitbx::lbfgs</a>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif/*__LBFGS_H__*/
|
133
packages/yap-lbfgs/liblbfgs-1.7/lib/arithmetic_ansi.h
vendored
Normal file
133
packages/yap-lbfgs/liblbfgs-1.7/lib/arithmetic_ansi.h
vendored
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* ANSI C implementation of vector operations.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2007,2008,2009 Naoaki Okazaki
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* $Id: arithmetic_ansi.h 50 2009-02-16 15:14:23Z naoaki $ */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
|
#if LBFGS_FLOAT == 32 && LBFGS_IEEE_FLOAT
|
||||||
|
#define fsigndiff(x, y) (((*(uint32_t*)(x)) ^ (*(uint32_t*)(y))) & 0x80000000U)
|
||||||
|
#else
|
||||||
|
#define fsigndiff(x, y) (*(x) * (*(y) / fabs(*(y))) < 0.)
|
||||||
|
#endif/*LBFGS_IEEE_FLOAT*/
|
||||||
|
|
||||||
|
inline static void* vecalloc(size_t size)
|
||||||
|
{
|
||||||
|
void *memblock = malloc(size);
|
||||||
|
if (memblock) {
|
||||||
|
memset(memblock, 0, size);
|
||||||
|
}
|
||||||
|
return memblock;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecfree(void *memblock)
|
||||||
|
{
|
||||||
|
free(memblock);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecset(lbfgsfloatval_t *x, const lbfgsfloatval_t c, const int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0;i < n;++i) {
|
||||||
|
x[i] = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void veccpy(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0;i < n;++i) {
|
||||||
|
y[i] = x[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecncpy(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0;i < n;++i) {
|
||||||
|
y[i] = -x[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecadd(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const lbfgsfloatval_t c, const int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0;i < n;++i) {
|
||||||
|
y[i] += c * x[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecdiff(lbfgsfloatval_t *z, const lbfgsfloatval_t *x, const lbfgsfloatval_t *y, const int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0;i < n;++i) {
|
||||||
|
z[i] = x[i] - y[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecscale(lbfgsfloatval_t *y, const lbfgsfloatval_t c, const int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0;i < n;++i) {
|
||||||
|
y[i] *= c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecmul(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0;i < n;++i) {
|
||||||
|
y[i] *= x[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecdot(lbfgsfloatval_t* s, const lbfgsfloatval_t *x, const lbfgsfloatval_t *y, const int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
*s = 0.;
|
||||||
|
for (i = 0;i < n;++i) {
|
||||||
|
*s += x[i] * y[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vec2norm(lbfgsfloatval_t* s, const lbfgsfloatval_t *x, const int n)
|
||||||
|
{
|
||||||
|
vecdot(s, x, x, n);
|
||||||
|
*s = (lbfgsfloatval_t)sqrt(*s);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vec2norminv(lbfgsfloatval_t* s, const lbfgsfloatval_t *x, const int n)
|
||||||
|
{
|
||||||
|
vec2norm(s, x, n);
|
||||||
|
*s = (lbfgsfloatval_t)(1.0 / *s);
|
||||||
|
}
|
287
packages/yap-lbfgs/liblbfgs-1.7/lib/arithmetic_sse_double.h
vendored
Normal file
287
packages/yap-lbfgs/liblbfgs-1.7/lib/arithmetic_sse_double.h
vendored
Normal file
@ -0,0 +1,287 @@
|
|||||||
|
/*
|
||||||
|
* SSE2 implementation of vector oprations (64bit double).
|
||||||
|
*
|
||||||
|
* Copyright (c) 2007,2008,2009 Naoaki Okazaki
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* $Id: arithmetic_sse_double.h 50 2009-02-16 15:14:23Z naoaki $ */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
|
#if 1400 <= _MSC_VER
|
||||||
|
#include <intrin.h>
|
||||||
|
#endif/*1400 <= _MSC_VER*/
|
||||||
|
|
||||||
|
#if HAVE_EMMINTRIN_H
|
||||||
|
#include <emmintrin.h>
|
||||||
|
#endif/*HAVE_EMMINTRIN_H*/
|
||||||
|
|
||||||
|
inline static void* vecalloc(size_t size)
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
void *memblock = _aligned_malloc(size, 16);
|
||||||
|
#else
|
||||||
|
void *memblock = memalign(16, size);
|
||||||
|
#endif
|
||||||
|
if (memblock != NULL) {
|
||||||
|
memset(memblock, 0, size);
|
||||||
|
}
|
||||||
|
return memblock;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecfree(void *memblock)
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
_aligned_free(memblock);
|
||||||
|
#else
|
||||||
|
free(memblock);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#define fsigndiff(x, y) \
|
||||||
|
((_mm_movemask_pd(_mm_set_pd(*(x), *(y))) + 1) & 0x002)
|
||||||
|
|
||||||
|
#define vecset(x, c, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128d XMM0 = _mm_set1_pd(c); \
|
||||||
|
for (i = 0;i < (n);i += 8) { \
|
||||||
|
_mm_store_pd((x)+i , XMM0); \
|
||||||
|
_mm_store_pd((x)+i+2, XMM0); \
|
||||||
|
_mm_store_pd((x)+i+4, XMM0); \
|
||||||
|
_mm_store_pd((x)+i+6, XMM0); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define veccpy(y, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for (i = 0;i < (n);i += 8) { \
|
||||||
|
__m128d XMM0 = _mm_load_pd((x)+i ); \
|
||||||
|
__m128d XMM1 = _mm_load_pd((x)+i+2); \
|
||||||
|
__m128d XMM2 = _mm_load_pd((x)+i+4); \
|
||||||
|
__m128d XMM3 = _mm_load_pd((x)+i+6); \
|
||||||
|
_mm_store_pd((y)+i , XMM0); \
|
||||||
|
_mm_store_pd((y)+i+2, XMM1); \
|
||||||
|
_mm_store_pd((y)+i+4, XMM2); \
|
||||||
|
_mm_store_pd((y)+i+6, XMM3); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecncpy(y, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for (i = 0;i < (n);i += 8) { \
|
||||||
|
__m128d XMM0 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM1 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM2 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM3 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM4 = _mm_load_pd((x)+i ); \
|
||||||
|
__m128d XMM5 = _mm_load_pd((x)+i+2); \
|
||||||
|
__m128d XMM6 = _mm_load_pd((x)+i+4); \
|
||||||
|
__m128d XMM7 = _mm_load_pd((x)+i+6); \
|
||||||
|
XMM0 = _mm_sub_pd(XMM0, XMM4); \
|
||||||
|
XMM1 = _mm_sub_pd(XMM1, XMM5); \
|
||||||
|
XMM2 = _mm_sub_pd(XMM2, XMM6); \
|
||||||
|
XMM3 = _mm_sub_pd(XMM3, XMM7); \
|
||||||
|
_mm_store_pd((y)+i , XMM0); \
|
||||||
|
_mm_store_pd((y)+i+2, XMM1); \
|
||||||
|
_mm_store_pd((y)+i+4, XMM2); \
|
||||||
|
_mm_store_pd((y)+i+6, XMM3); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecadd(y, x, c, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128d XMM7 = _mm_set1_pd(c); \
|
||||||
|
for (i = 0;i < (n);i += 4) { \
|
||||||
|
__m128d XMM0 = _mm_load_pd((x)+i ); \
|
||||||
|
__m128d XMM1 = _mm_load_pd((x)+i+2); \
|
||||||
|
__m128d XMM2 = _mm_load_pd((y)+i ); \
|
||||||
|
__m128d XMM3 = _mm_load_pd((y)+i+2); \
|
||||||
|
XMM0 = _mm_mul_pd(XMM0, XMM7); \
|
||||||
|
XMM1 = _mm_mul_pd(XMM1, XMM7); \
|
||||||
|
XMM2 = _mm_add_pd(XMM2, XMM0); \
|
||||||
|
XMM3 = _mm_add_pd(XMM3, XMM1); \
|
||||||
|
_mm_store_pd((y)+i , XMM2); \
|
||||||
|
_mm_store_pd((y)+i+2, XMM3); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecdiff(z, x, y, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for (i = 0;i < (n);i += 8) { \
|
||||||
|
__m128d XMM0 = _mm_load_pd((x)+i ); \
|
||||||
|
__m128d XMM1 = _mm_load_pd((x)+i+2); \
|
||||||
|
__m128d XMM2 = _mm_load_pd((x)+i+4); \
|
||||||
|
__m128d XMM3 = _mm_load_pd((x)+i+6); \
|
||||||
|
__m128d XMM4 = _mm_load_pd((y)+i ); \
|
||||||
|
__m128d XMM5 = _mm_load_pd((y)+i+2); \
|
||||||
|
__m128d XMM6 = _mm_load_pd((y)+i+4); \
|
||||||
|
__m128d XMM7 = _mm_load_pd((y)+i+6); \
|
||||||
|
XMM0 = _mm_sub_pd(XMM0, XMM4); \
|
||||||
|
XMM1 = _mm_sub_pd(XMM1, XMM5); \
|
||||||
|
XMM2 = _mm_sub_pd(XMM2, XMM6); \
|
||||||
|
XMM3 = _mm_sub_pd(XMM3, XMM7); \
|
||||||
|
_mm_store_pd((z)+i , XMM0); \
|
||||||
|
_mm_store_pd((z)+i+2, XMM1); \
|
||||||
|
_mm_store_pd((z)+i+4, XMM2); \
|
||||||
|
_mm_store_pd((z)+i+6, XMM3); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecscale(y, c, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128d XMM7 = _mm_set1_pd(c); \
|
||||||
|
for (i = 0;i < (n);i += 4) { \
|
||||||
|
__m128d XMM0 = _mm_load_pd((y)+i ); \
|
||||||
|
__m128d XMM1 = _mm_load_pd((y)+i+2); \
|
||||||
|
XMM0 = _mm_mul_pd(XMM0, XMM7); \
|
||||||
|
XMM1 = _mm_mul_pd(XMM1, XMM7); \
|
||||||
|
_mm_store_pd((y)+i , XMM0); \
|
||||||
|
_mm_store_pd((y)+i+2, XMM1); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecmul(y, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for (i = 0;i < (n);i += 8) { \
|
||||||
|
__m128d XMM0 = _mm_load_pd((x)+i ); \
|
||||||
|
__m128d XMM1 = _mm_load_pd((x)+i+2); \
|
||||||
|
__m128d XMM2 = _mm_load_pd((x)+i+4); \
|
||||||
|
__m128d XMM3 = _mm_load_pd((x)+i+6); \
|
||||||
|
__m128d XMM4 = _mm_load_pd((y)+i ); \
|
||||||
|
__m128d XMM5 = _mm_load_pd((y)+i+2); \
|
||||||
|
__m128d XMM6 = _mm_load_pd((y)+i+4); \
|
||||||
|
__m128d XMM7 = _mm_load_pd((y)+i+6); \
|
||||||
|
XMM4 = _mm_mul_pd(XMM4, XMM0); \
|
||||||
|
XMM5 = _mm_mul_pd(XMM5, XMM1); \
|
||||||
|
XMM6 = _mm_mul_pd(XMM6, XMM2); \
|
||||||
|
XMM7 = _mm_mul_pd(XMM7, XMM3); \
|
||||||
|
_mm_store_pd((y)+i , XMM4); \
|
||||||
|
_mm_store_pd((y)+i+2, XMM5); \
|
||||||
|
_mm_store_pd((y)+i+4, XMM6); \
|
||||||
|
_mm_store_pd((y)+i+6, XMM7); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if 3 <= __SSE__
|
||||||
|
/*
|
||||||
|
Horizontal add with haddps SSE3 instruction. The work register (rw)
|
||||||
|
is unused.
|
||||||
|
*/
|
||||||
|
#define __horizontal_sum(r, rw) \
|
||||||
|
r = _mm_hadd_ps(r, r); \
|
||||||
|
r = _mm_hadd_ps(r, r);
|
||||||
|
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
Horizontal add with SSE instruction. The work register (rw) is used.
|
||||||
|
*/
|
||||||
|
#define __horizontal_sum(r, rw) \
|
||||||
|
rw = r; \
|
||||||
|
r = _mm_shuffle_ps(r, rw, _MM_SHUFFLE(1, 0, 3, 2)); \
|
||||||
|
r = _mm_add_ps(r, rw); \
|
||||||
|
rw = r; \
|
||||||
|
r = _mm_shuffle_ps(r, rw, _MM_SHUFFLE(2, 3, 0, 1)); \
|
||||||
|
r = _mm_add_ps(r, rw);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define vecdot(s, x, y, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128d XMM0 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM1 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM2, XMM3, XMM4, XMM5; \
|
||||||
|
for (i = 0;i < (n);i += 4) { \
|
||||||
|
XMM2 = _mm_load_pd((x)+i ); \
|
||||||
|
XMM3 = _mm_load_pd((x)+i+2); \
|
||||||
|
XMM4 = _mm_load_pd((y)+i ); \
|
||||||
|
XMM5 = _mm_load_pd((y)+i+2); \
|
||||||
|
XMM2 = _mm_mul_pd(XMM2, XMM4); \
|
||||||
|
XMM3 = _mm_mul_pd(XMM3, XMM5); \
|
||||||
|
XMM0 = _mm_add_pd(XMM0, XMM2); \
|
||||||
|
XMM1 = _mm_add_pd(XMM1, XMM3); \
|
||||||
|
} \
|
||||||
|
XMM0 = _mm_add_pd(XMM0, XMM1); \
|
||||||
|
XMM1 = _mm_shuffle_pd(XMM0, XMM0, _MM_SHUFFLE2(1, 1)); \
|
||||||
|
XMM0 = _mm_add_pd(XMM0, XMM1); \
|
||||||
|
_mm_store_sd((s), XMM0); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vec2norm(s, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128d XMM0 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM1 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM2, XMM3, XMM4, XMM5; \
|
||||||
|
for (i = 0;i < (n);i += 4) { \
|
||||||
|
XMM2 = _mm_load_pd((x)+i ); \
|
||||||
|
XMM3 = _mm_load_pd((x)+i+2); \
|
||||||
|
XMM4 = XMM2; \
|
||||||
|
XMM5 = XMM3; \
|
||||||
|
XMM2 = _mm_mul_pd(XMM2, XMM4); \
|
||||||
|
XMM3 = _mm_mul_pd(XMM3, XMM5); \
|
||||||
|
XMM0 = _mm_add_pd(XMM0, XMM2); \
|
||||||
|
XMM1 = _mm_add_pd(XMM1, XMM3); \
|
||||||
|
} \
|
||||||
|
XMM0 = _mm_add_pd(XMM0, XMM1); \
|
||||||
|
XMM1 = _mm_shuffle_pd(XMM0, XMM0, _MM_SHUFFLE2(1, 1)); \
|
||||||
|
XMM0 = _mm_add_pd(XMM0, XMM1); \
|
||||||
|
XMM0 = _mm_sqrt_pd(XMM0); \
|
||||||
|
_mm_store_sd((s), XMM0); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define vec2norminv(s, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128d XMM0 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM1 = _mm_setzero_pd(); \
|
||||||
|
__m128d XMM2, XMM3, XMM4, XMM5; \
|
||||||
|
for (i = 0;i < (n);i += 4) { \
|
||||||
|
XMM2 = _mm_load_pd((x)+i ); \
|
||||||
|
XMM3 = _mm_load_pd((x)+i+2); \
|
||||||
|
XMM4 = XMM2; \
|
||||||
|
XMM5 = XMM3; \
|
||||||
|
XMM2 = _mm_mul_pd(XMM2, XMM4); \
|
||||||
|
XMM3 = _mm_mul_pd(XMM3, XMM5); \
|
||||||
|
XMM0 = _mm_add_pd(XMM0, XMM2); \
|
||||||
|
XMM1 = _mm_add_pd(XMM1, XMM3); \
|
||||||
|
} \
|
||||||
|
XMM2 = _mm_set1_pd(1.0); \
|
||||||
|
XMM0 = _mm_add_pd(XMM0, XMM1); \
|
||||||
|
XMM1 = _mm_shuffle_pd(XMM0, XMM0, _MM_SHUFFLE2(1, 1)); \
|
||||||
|
XMM0 = _mm_add_pd(XMM0, XMM1); \
|
||||||
|
XMM0 = _mm_sqrt_pd(XMM0); \
|
||||||
|
XMM2 = _mm_div_pd(XMM2, XMM0); \
|
||||||
|
_mm_store_sd((s), XMM2); \
|
||||||
|
}
|
287
packages/yap-lbfgs/liblbfgs-1.7/lib/arithmetic_sse_float.h
vendored
Normal file
287
packages/yap-lbfgs/liblbfgs-1.7/lib/arithmetic_sse_float.h
vendored
Normal file
@ -0,0 +1,287 @@
|
|||||||
|
/*
|
||||||
|
* SSE/SSE3 implementation of vector oprations (32bit float).
|
||||||
|
*
|
||||||
|
* Copyright (c) 2007,2008,2009 Naoaki Okazaki
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* $Id: arithmetic_sse_float.h 50 2009-02-16 15:14:23Z naoaki $ */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
|
#if 1400 <= _MSC_VER
|
||||||
|
#include <intrin.h>
|
||||||
|
#endif/*_MSC_VER*/
|
||||||
|
|
||||||
|
#if HAVE_XMMINTRIN_H
|
||||||
|
#include <xmmintrin.h>
|
||||||
|
#endif/*HAVE_XMMINTRIN_H*/
|
||||||
|
|
||||||
|
#if LBFGS_FLOAT == 32 && LBFGS_IEEE_FLOAT
|
||||||
|
#define fsigndiff(x, y) (((*(uint32_t*)(x)) ^ (*(uint32_t*)(y))) & 0x80000000U)
|
||||||
|
#else
|
||||||
|
#define fsigndiff(x, y) (*(x) * (*(y) / fabs(*(y))) < 0.)
|
||||||
|
#endif/*LBFGS_IEEE_FLOAT*/
|
||||||
|
|
||||||
|
inline static void* vecalloc(size_t size)
|
||||||
|
{
|
||||||
|
void *memblock = _aligned_malloc(size, 16);
|
||||||
|
if (memblock != NULL) {
|
||||||
|
memset(memblock, 0, size);
|
||||||
|
}
|
||||||
|
return memblock;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void vecfree(void *memblock)
|
||||||
|
{
|
||||||
|
_aligned_free(memblock);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecset(x, c, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128 XMM0 = _mm_set_ps1(c); \
|
||||||
|
for (i = 0;i < (n);i += 16) { \
|
||||||
|
_mm_store_ps((x)+i , XMM0); \
|
||||||
|
_mm_store_ps((x)+i+ 4, XMM0); \
|
||||||
|
_mm_store_ps((x)+i+ 8, XMM0); \
|
||||||
|
_mm_store_ps((x)+i+12, XMM0); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define veccpy(y, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for (i = 0;i < (n);i += 16) { \
|
||||||
|
__m128 XMM0 = _mm_load_ps((x)+i ); \
|
||||||
|
__m128 XMM1 = _mm_load_ps((x)+i+ 4); \
|
||||||
|
__m128 XMM2 = _mm_load_ps((x)+i+ 8); \
|
||||||
|
__m128 XMM3 = _mm_load_ps((x)+i+12); \
|
||||||
|
_mm_store_ps((y)+i , XMM0); \
|
||||||
|
_mm_store_ps((y)+i+ 4, XMM1); \
|
||||||
|
_mm_store_ps((y)+i+ 8, XMM2); \
|
||||||
|
_mm_store_ps((y)+i+12, XMM3); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecncpy(y, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
const uint32_t mask = 0x80000000; \
|
||||||
|
__m128 XMM4 = _mm_load_ps1((float*)&mask); \
|
||||||
|
for (i = 0;i < (n);i += 16) { \
|
||||||
|
__m128 XMM0 = _mm_load_ps((x)+i ); \
|
||||||
|
__m128 XMM1 = _mm_load_ps((x)+i+ 4); \
|
||||||
|
__m128 XMM2 = _mm_load_ps((x)+i+ 8); \
|
||||||
|
__m128 XMM3 = _mm_load_ps((x)+i+12); \
|
||||||
|
XMM0 = _mm_xor_ps(XMM0, XMM4); \
|
||||||
|
XMM1 = _mm_xor_ps(XMM1, XMM4); \
|
||||||
|
XMM2 = _mm_xor_ps(XMM2, XMM4); \
|
||||||
|
XMM3 = _mm_xor_ps(XMM3, XMM4); \
|
||||||
|
_mm_store_ps((y)+i , XMM0); \
|
||||||
|
_mm_store_ps((y)+i+ 4, XMM1); \
|
||||||
|
_mm_store_ps((y)+i+ 8, XMM2); \
|
||||||
|
_mm_store_ps((y)+i+12, XMM3); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecadd(y, x, c, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128 XMM7 = _mm_set_ps1(c); \
|
||||||
|
for (i = 0;i < (n);i += 8) { \
|
||||||
|
__m128 XMM0 = _mm_load_ps((x)+i ); \
|
||||||
|
__m128 XMM1 = _mm_load_ps((x)+i+4); \
|
||||||
|
__m128 XMM2 = _mm_load_ps((y)+i ); \
|
||||||
|
__m128 XMM3 = _mm_load_ps((y)+i+4); \
|
||||||
|
XMM0 = _mm_mul_ps(XMM0, XMM7); \
|
||||||
|
XMM1 = _mm_mul_ps(XMM1, XMM7); \
|
||||||
|
XMM2 = _mm_add_ps(XMM2, XMM0); \
|
||||||
|
XMM3 = _mm_add_ps(XMM3, XMM1); \
|
||||||
|
_mm_store_ps((y)+i , XMM2); \
|
||||||
|
_mm_store_ps((y)+i+4, XMM3); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecdiff(z, x, y, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for (i = 0;i < (n);i += 16) { \
|
||||||
|
__m128 XMM0 = _mm_load_ps((x)+i ); \
|
||||||
|
__m128 XMM1 = _mm_load_ps((x)+i+ 4); \
|
||||||
|
__m128 XMM2 = _mm_load_ps((x)+i+ 8); \
|
||||||
|
__m128 XMM3 = _mm_load_ps((x)+i+12); \
|
||||||
|
__m128 XMM4 = _mm_load_ps((y)+i ); \
|
||||||
|
__m128 XMM5 = _mm_load_ps((y)+i+ 4); \
|
||||||
|
__m128 XMM6 = _mm_load_ps((y)+i+ 8); \
|
||||||
|
__m128 XMM7 = _mm_load_ps((y)+i+12); \
|
||||||
|
XMM0 = _mm_sub_ps(XMM0, XMM4); \
|
||||||
|
XMM1 = _mm_sub_ps(XMM1, XMM5); \
|
||||||
|
XMM2 = _mm_sub_ps(XMM2, XMM6); \
|
||||||
|
XMM3 = _mm_sub_ps(XMM3, XMM7); \
|
||||||
|
_mm_store_ps((z)+i , XMM0); \
|
||||||
|
_mm_store_ps((z)+i+ 4, XMM1); \
|
||||||
|
_mm_store_ps((z)+i+ 8, XMM2); \
|
||||||
|
_mm_store_ps((z)+i+12, XMM3); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecscale(y, c, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128 XMM7 = _mm_set_ps1(c); \
|
||||||
|
for (i = 0;i < (n);i += 8) { \
|
||||||
|
__m128 XMM0 = _mm_load_ps((y)+i ); \
|
||||||
|
__m128 XMM1 = _mm_load_ps((y)+i+4); \
|
||||||
|
XMM0 = _mm_mul_ps(XMM0, XMM7); \
|
||||||
|
XMM1 = _mm_mul_ps(XMM1, XMM7); \
|
||||||
|
_mm_store_ps((y)+i , XMM0); \
|
||||||
|
_mm_store_ps((y)+i+4, XMM1); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vecmul(y, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for (i = 0;i < (n);i += 16) { \
|
||||||
|
__m128 XMM0 = _mm_load_ps((x)+i ); \
|
||||||
|
__m128 XMM1 = _mm_load_ps((x)+i+ 4); \
|
||||||
|
__m128 XMM2 = _mm_load_ps((x)+i+ 8); \
|
||||||
|
__m128 XMM3 = _mm_load_ps((x)+i+12); \
|
||||||
|
__m128 XMM4 = _mm_load_ps((y)+i ); \
|
||||||
|
__m128 XMM5 = _mm_load_ps((y)+i+ 4); \
|
||||||
|
__m128 XMM6 = _mm_load_ps((y)+i+ 8); \
|
||||||
|
__m128 XMM7 = _mm_load_ps((y)+i+12); \
|
||||||
|
XMM4 = _mm_mul_ps(XMM4, XMM0); \
|
||||||
|
XMM5 = _mm_mul_ps(XMM5, XMM1); \
|
||||||
|
XMM6 = _mm_mul_ps(XMM6, XMM2); \
|
||||||
|
XMM7 = _mm_mul_ps(XMM7, XMM3); \
|
||||||
|
_mm_store_ps((y)+i , XMM4); \
|
||||||
|
_mm_store_ps((y)+i+ 4, XMM5); \
|
||||||
|
_mm_store_ps((y)+i+ 8, XMM6); \
|
||||||
|
_mm_store_ps((y)+i+12, XMM7); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if 3 <= __SSE__
|
||||||
|
/*
|
||||||
|
Horizontal add with haddps SSE3 instruction. The work register (rw)
|
||||||
|
is unused.
|
||||||
|
*/
|
||||||
|
#define __horizontal_sum(r, rw) \
|
||||||
|
r = _mm_hadd_ps(r, r); \
|
||||||
|
r = _mm_hadd_ps(r, r);
|
||||||
|
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
Horizontal add with SSE instruction. The work register (rw) is used.
|
||||||
|
*/
|
||||||
|
#define __horizontal_sum(r, rw) \
|
||||||
|
rw = r; \
|
||||||
|
r = _mm_shuffle_ps(r, rw, _MM_SHUFFLE(1, 0, 3, 2)); \
|
||||||
|
r = _mm_add_ps(r, rw); \
|
||||||
|
rw = r; \
|
||||||
|
r = _mm_shuffle_ps(r, rw, _MM_SHUFFLE(2, 3, 0, 1)); \
|
||||||
|
r = _mm_add_ps(r, rw);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define vecdot(s, x, y, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128 XMM0 = _mm_setzero_ps(); \
|
||||||
|
__m128 XMM1 = _mm_setzero_ps(); \
|
||||||
|
__m128 XMM2, XMM3, XMM4, XMM5; \
|
||||||
|
for (i = 0;i < (n);i += 8) { \
|
||||||
|
XMM2 = _mm_load_ps((x)+i ); \
|
||||||
|
XMM3 = _mm_load_ps((x)+i+4); \
|
||||||
|
XMM4 = _mm_load_ps((y)+i ); \
|
||||||
|
XMM5 = _mm_load_ps((y)+i+4); \
|
||||||
|
XMM2 = _mm_mul_ps(XMM2, XMM4); \
|
||||||
|
XMM3 = _mm_mul_ps(XMM3, XMM5); \
|
||||||
|
XMM0 = _mm_add_ps(XMM0, XMM2); \
|
||||||
|
XMM1 = _mm_add_ps(XMM1, XMM3); \
|
||||||
|
} \
|
||||||
|
XMM0 = _mm_add_ps(XMM0, XMM1); \
|
||||||
|
__horizontal_sum(XMM0, XMM1); \
|
||||||
|
_mm_store_ss((s), XMM0); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vec2norm(s, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128 XMM0 = _mm_setzero_ps(); \
|
||||||
|
__m128 XMM1 = _mm_setzero_ps(); \
|
||||||
|
__m128 XMM2, XMM3; \
|
||||||
|
for (i = 0;i < (n);i += 8) { \
|
||||||
|
XMM2 = _mm_load_ps((x)+i ); \
|
||||||
|
XMM3 = _mm_load_ps((x)+i+4); \
|
||||||
|
XMM2 = _mm_mul_ps(XMM2, XMM2); \
|
||||||
|
XMM3 = _mm_mul_ps(XMM3, XMM3); \
|
||||||
|
XMM0 = _mm_add_ps(XMM0, XMM2); \
|
||||||
|
XMM1 = _mm_add_ps(XMM1, XMM3); \
|
||||||
|
} \
|
||||||
|
XMM0 = _mm_add_ps(XMM0, XMM1); \
|
||||||
|
__horizontal_sum(XMM0, XMM1); \
|
||||||
|
XMM2 = XMM0; \
|
||||||
|
XMM1 = _mm_rsqrt_ss(XMM0); \
|
||||||
|
XMM3 = XMM1; \
|
||||||
|
XMM1 = _mm_mul_ss(XMM1, XMM1); \
|
||||||
|
XMM1 = _mm_mul_ss(XMM1, XMM3); \
|
||||||
|
XMM1 = _mm_mul_ss(XMM1, XMM0); \
|
||||||
|
XMM1 = _mm_mul_ss(XMM1, _mm_set_ss(-0.5f)); \
|
||||||
|
XMM3 = _mm_mul_ss(XMM3, _mm_set_ss(1.5f)); \
|
||||||
|
XMM3 = _mm_add_ss(XMM3, XMM1); \
|
||||||
|
XMM3 = _mm_mul_ss(XMM3, XMM2); \
|
||||||
|
_mm_store_ss((s), XMM3); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vec2norminv(s, x, n) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
__m128 XMM0 = _mm_setzero_ps(); \
|
||||||
|
__m128 XMM1 = _mm_setzero_ps(); \
|
||||||
|
__m128 XMM2, XMM3; \
|
||||||
|
for (i = 0;i < (n);i += 16) { \
|
||||||
|
XMM2 = _mm_load_ps((x)+i ); \
|
||||||
|
XMM3 = _mm_load_ps((x)+i+4); \
|
||||||
|
XMM2 = _mm_mul_ps(XMM2, XMM2); \
|
||||||
|
XMM3 = _mm_mul_ps(XMM3, XMM3); \
|
||||||
|
XMM0 = _mm_add_ps(XMM0, XMM2); \
|
||||||
|
XMM1 = _mm_add_ps(XMM1, XMM3); \
|
||||||
|
} \
|
||||||
|
XMM0 = _mm_add_ps(XMM0, XMM1); \
|
||||||
|
__horizontal_sum(XMM0, XMM1); \
|
||||||
|
XMM2 = XMM0; \
|
||||||
|
XMM1 = _mm_rsqrt_ss(XMM0); \
|
||||||
|
XMM3 = XMM1; \
|
||||||
|
XMM1 = _mm_mul_ss(XMM1, XMM1); \
|
||||||
|
XMM1 = _mm_mul_ss(XMM1, XMM3); \
|
||||||
|
XMM1 = _mm_mul_ss(XMM1, XMM0); \
|
||||||
|
XMM1 = _mm_mul_ss(XMM1, _mm_set_ss(-0.5f)); \
|
||||||
|
XMM3 = _mm_mul_ss(XMM3, _mm_set_ss(1.5f)); \
|
||||||
|
XMM3 = _mm_add_ss(XMM3, XMM1); \
|
||||||
|
_mm_store_ss((s), XMM3); \
|
||||||
|
}
|
1357
packages/yap-lbfgs/liblbfgs-1.7/lib/lbfgs.c
vendored
Normal file
1357
packages/yap-lbfgs/liblbfgs-1.7/lib/lbfgs.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
557
packages/yap-lbfgs/yap_lbfgs.c
Normal file
557
packages/yap-lbfgs/yap_lbfgs.c
Normal file
@ -0,0 +1,557 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "YapInterface.h"
|
||||||
|
#include <lbfgs.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of YAP-LBFGS.
|
||||||
|
Copyright (C) 2009 Bernd Gutmann
|
||||||
|
|
||||||
|
YAP-LBFGS is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
YAP-LBFGS is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with YAP-LBFGS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// These constants describe the internal state
|
||||||
|
#define OPTIMIZER_STATUS_NONE 0
|
||||||
|
#define OPTIMIZER_STATUS_INITIALIZED 1
|
||||||
|
#define OPTIMIZER_STATUS_RUNNING 2
|
||||||
|
#define OPTIMIZER_STATUS_CB_EVAL 3
|
||||||
|
#define OPTIMIZER_STATUS_CB_PROGRESS 4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int optimizer_status=OPTIMIZER_STATUS_NONE; // the internal state
|
||||||
|
int n; // the size of the parameter vector
|
||||||
|
lbfgsfloatval_t *x; // pointer to the parameter vector x[0],...,x[n-1]
|
||||||
|
lbfgsfloatval_t *g; // pointer to the gradient vector g[0],...,g[n-1]
|
||||||
|
lbfgs_parameter_t param; // the parameters used for lbfgs
|
||||||
|
char buffer [2048]; // this buffer is used for creating the atoms to call
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static lbfgsfloatval_t evaluate(
|
||||||
|
void *instance,
|
||||||
|
const lbfgsfloatval_t *x,
|
||||||
|
lbfgsfloatval_t *g_tmp,
|
||||||
|
const int n,
|
||||||
|
const lbfgsfloatval_t step
|
||||||
|
)
|
||||||
|
{
|
||||||
|
YAP_Term error;
|
||||||
|
YAP_Term call;
|
||||||
|
YAP_Bool result;
|
||||||
|
|
||||||
|
if (sprintf(buffer,"'$lbfgs_callback_evaluate'(FX,%i,%f)",n,step)<0) {
|
||||||
|
printf("ERROR: Creating call atom at evaluate function.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
g=g_tmp;
|
||||||
|
call=YAP_ReadBuffer(buffer,&error);
|
||||||
|
|
||||||
|
optimizer_status=OPTIMIZER_STATUS_CB_EVAL;
|
||||||
|
result=YAP_CallProlog(call);
|
||||||
|
optimizer_status=OPTIMIZER_STATUS_RUNNING;
|
||||||
|
|
||||||
|
if (result==FALSE) {
|
||||||
|
printf("ERROR: Calling the evaluate call back function in YAP.\n");
|
||||||
|
// Goal did not succeed
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(YAP_ArgOfTerm(1,call))) {
|
||||||
|
return (lbfgsfloatval_t) YAP_FloatOfTerm(YAP_ArgOfTerm(1,call));
|
||||||
|
} else if (YAP_IsIntTerm(YAP_ArgOfTerm(1,call))) {
|
||||||
|
return (lbfgsfloatval_t) YAP_IntOfTerm(YAP_ArgOfTerm(1,call));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("ERROR: The evaluate call back function did not return a number as first argument.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int progress(
|
||||||
|
void *instance,
|
||||||
|
const lbfgsfloatval_t *local_x,
|
||||||
|
const lbfgsfloatval_t *local_g,
|
||||||
|
const lbfgsfloatval_t fx,
|
||||||
|
const lbfgsfloatval_t xnorm,
|
||||||
|
const lbfgsfloatval_t gnorm,
|
||||||
|
const lbfgsfloatval_t step,
|
||||||
|
int n,
|
||||||
|
int k,
|
||||||
|
int ls
|
||||||
|
)
|
||||||
|
{
|
||||||
|
YAP_Term error;
|
||||||
|
YAP_Term call;
|
||||||
|
YAP_Bool result;
|
||||||
|
|
||||||
|
if (sprintf(buffer,"'$lbfgs_callback_progress'(%f,%f,%f,%f,%i,%i,%i,STOP)",fx,xnorm,gnorm,step,n,k,ls)<0) {
|
||||||
|
printf("ERROR: Creating atom at progress call back.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
call=YAP_ReadBuffer(buffer,&error);
|
||||||
|
optimizer_status=OPTIMIZER_STATUS_CB_PROGRESS;
|
||||||
|
result=YAP_CallProlog(call);
|
||||||
|
optimizer_status=OPTIMIZER_STATUS_RUNNING;
|
||||||
|
|
||||||
|
if (result==FALSE) {
|
||||||
|
printf("ERROR: Calling the progress call back function in YAP.\n");
|
||||||
|
// Goal did not succeed
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (YAP_IsIntTerm(YAP_ArgOfTerm(8,call))) {
|
||||||
|
return YAP_IntOfTerm(YAP_ArgOfTerm(8,call));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("ERROR: The progress call back function did not return an integer as last argument\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int set_x_value(void) {
|
||||||
|
YAP_Term t1=YAP_ARG1;
|
||||||
|
YAP_Term t2=YAP_ARG2;
|
||||||
|
int i=0;
|
||||||
|
|
||||||
|
if (optimizer_status!=OPTIMIZER_STATUS_INITIALIZED) {
|
||||||
|
printf("ERROR: set_x_value/2 can be called only when the optimizer is initialized and not running.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (YAP_IsIntTerm(t1)) {
|
||||||
|
i=YAP_IntOfTerm(t1);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i<0 || i>=n) {
|
||||||
|
printf("ERROR: invalid index for set_x_value/2.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
x[i]=(lbfgsfloatval_t) YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
x[i]=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int get_x_value(void) {
|
||||||
|
YAP_Term t1=YAP_ARG1;
|
||||||
|
YAP_Term t2=YAP_ARG2;
|
||||||
|
int i=0;
|
||||||
|
|
||||||
|
if (optimizer_status==OPTIMIZER_STATUS_NONE) {
|
||||||
|
printf("ERROR: set_x_value/2 can be called only when the optimizer is initialized.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (YAP_IsIntTerm(t1)) {
|
||||||
|
i=YAP_IntOfTerm(t1);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i<0 || i>=n) {
|
||||||
|
printf("ERROR: invalid index for set_x_value/2.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(x[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int set_g_value(void) {
|
||||||
|
YAP_Term t1=YAP_ARG1;
|
||||||
|
YAP_Term t2=YAP_ARG2;
|
||||||
|
int i=0;
|
||||||
|
|
||||||
|
if (optimizer_status != OPTIMIZER_STATUS_CB_EVAL) {
|
||||||
|
printf("ERROR: optimizer_set_g/2 can only be called by the evaluation call back function.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (YAP_IsIntTerm(t1)) {
|
||||||
|
i=YAP_IntOfTerm(t1);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i<0 || i>=n) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
g[i]=(lbfgsfloatval_t) YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
g[i]=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int get_g_value(void) {
|
||||||
|
YAP_Term t1=YAP_ARG1;
|
||||||
|
YAP_Term t2=YAP_ARG2;
|
||||||
|
int i=0;
|
||||||
|
|
||||||
|
if (optimizer_status != OPTIMIZER_STATUS_RUNNING && optimizer_status != OPTIMIZER_STATUS_CB_EVAL && optimizer_status != OPTIMIZER_STATUS_CB_PROGRESS) {
|
||||||
|
printf("ERROR: optimizer_get_g/2 can only be called while the optimizer is running.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (YAP_IsIntTerm(t1)) {
|
||||||
|
i=YAP_IntOfTerm(t1);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i<0 || i>=n) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(g[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int optimizer_initialize(void) {
|
||||||
|
YAP_Term t1 = YAP_ARG1;
|
||||||
|
int temp_n=0;
|
||||||
|
|
||||||
|
if (optimizer_status!=OPTIMIZER_STATUS_NONE) {
|
||||||
|
printf("ERROR: Optimizer has already been initialized. Please call optimizer_finalize/0 first.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (! YAP_IsIntTerm(t1)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp_n=YAP_IntOfTerm(t1);
|
||||||
|
|
||||||
|
if (temp_n<1) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = lbfgs_malloc(temp_n);
|
||||||
|
|
||||||
|
if (x == NULL) {
|
||||||
|
printf("ERROR: Failed to allocate a memory block for variables.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
n=temp_n;
|
||||||
|
|
||||||
|
optimizer_status=OPTIMIZER_STATUS_INITIALIZED;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int optimizer_run(void) {
|
||||||
|
YAP_Term t1 = YAP_ARG1;
|
||||||
|
YAP_Term t2 = YAP_ARG2;
|
||||||
|
int ret = 0;
|
||||||
|
lbfgsfloatval_t fx;
|
||||||
|
lbfgsfloatval_t * tmp_x=x;
|
||||||
|
|
||||||
|
if (optimizer_status == OPTIMIZER_STATUS_NONE) {
|
||||||
|
printf("ERROR: Memory for parameter vector not initialized, please call optimizer_initialize/1 first.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optimizer_status != OPTIMIZER_STATUS_INITIALIZED) {
|
||||||
|
printf("ERROR: Optimizer is running right now. Please wait till it is finished.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// both arguments have to be variables
|
||||||
|
if (! YAP_IsVarTerm(t1) || ! YAP_IsVarTerm(t2)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
optimizer_status = OPTIMIZER_STATUS_RUNNING;
|
||||||
|
ret = lbfgs(n, x, &fx, evaluate, progress, NULL, ¶m);
|
||||||
|
x=tmp_x;
|
||||||
|
optimizer_status = OPTIMIZER_STATUS_INITIALIZED;
|
||||||
|
|
||||||
|
YAP_Unify(t1,YAP_MkFloatTerm(fx));
|
||||||
|
YAP_Unify(t2,YAP_MkIntTerm(ret));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int optimizer_finalize( void ) {
|
||||||
|
if (optimizer_status == OPTIMIZER_STATUS_NONE) {
|
||||||
|
printf("Error: Optimizer is not initialized.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optimizer_status == OPTIMIZER_STATUS_INITIALIZED) {
|
||||||
|
lbfgs_free(x);
|
||||||
|
x=NULL;
|
||||||
|
n=0;
|
||||||
|
optimizer_status = OPTIMIZER_STATUS_NONE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("ERROR: Optimizer is running right now. Please wait till it is finished.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int optimizer_set_parameter( void ) {
|
||||||
|
YAP_Term t1 = YAP_ARG1;
|
||||||
|
YAP_Term t2 = YAP_ARG2;
|
||||||
|
|
||||||
|
if (optimizer_status != OPTIMIZER_STATUS_NONE && optimizer_status != OPTIMIZER_STATUS_INITIALIZED){
|
||||||
|
printf("ERROR: Optimizer is running right now. Please wait till it is finished.\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (! YAP_IsAtomTerm(t1)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* name=YAP_AtomName(YAP_AtomOfTerm(t1));
|
||||||
|
|
||||||
|
if ((strcmp(name, "m") == 0)) {
|
||||||
|
if (! YAP_IsIntTerm(t2)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
param.m = YAP_IntOfTerm(t2);
|
||||||
|
} else if ((strcmp(name, "epsilon") == 0)) {
|
||||||
|
lbfgsfloatval_t v;
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
v=YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
param.epsilon=v;
|
||||||
|
} else if ((strcmp(name, "past") == 0)) {
|
||||||
|
if (! YAP_IsIntTerm(t2)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
param.past = YAP_IntOfTerm(t2);
|
||||||
|
} else if ((strcmp(name, "delta") == 0)) {
|
||||||
|
lbfgsfloatval_t v;
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
v=YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
param.delta=v;
|
||||||
|
} else if ((strcmp(name, "max_iterations") == 0)) {
|
||||||
|
if (! YAP_IsIntTerm(t2)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
param.max_iterations = YAP_IntOfTerm(t2);
|
||||||
|
} else if ((strcmp(name, "linesearch") == 0)) {
|
||||||
|
if (! YAP_IsIntTerm(t2)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
param.linesearch = YAP_IntOfTerm(t2);
|
||||||
|
} else if ((strcmp(name, "max_linesearch") == 0)) {
|
||||||
|
if (! YAP_IsIntTerm(t2)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
param.max_linesearch = YAP_IntOfTerm(t2);
|
||||||
|
} else if ((strcmp(name, "min_step") == 0)) {
|
||||||
|
lbfgsfloatval_t v;
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
v=YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
param.min_step=v;
|
||||||
|
} else if ((strcmp(name, "max_step") == 0)) {
|
||||||
|
lbfgsfloatval_t v;
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
v=YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
param.max_step=v;
|
||||||
|
} else if ((strcmp(name, "ftol") == 0)) {
|
||||||
|
lbfgsfloatval_t v;
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
v=YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
param.ftol=v;
|
||||||
|
} else if ((strcmp(name, "gtol") == 0)) {
|
||||||
|
lbfgsfloatval_t v;
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
v=YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
param.gtol=v;
|
||||||
|
} else if ((strcmp(name, "xtol") == 0)) {
|
||||||
|
lbfgsfloatval_t v;
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
v=YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
param.xtol=v;
|
||||||
|
} else if ((strcmp(name, "orthantwise_c") == 0)) {
|
||||||
|
lbfgsfloatval_t v;
|
||||||
|
|
||||||
|
if (YAP_IsFloatTerm(t2)) {
|
||||||
|
v=YAP_FloatOfTerm(t2);
|
||||||
|
} else if (YAP_IsIntTerm(t2)) {
|
||||||
|
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
param.orthantwise_c=v;
|
||||||
|
} else if ((strcmp(name, "orthantwise_start") == 0)) {
|
||||||
|
if (! YAP_IsIntTerm(t2)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
param.orthantwise_start = YAP_IntOfTerm(t2);
|
||||||
|
} else if ((strcmp(name, "orthantwise_end") == 0)) {
|
||||||
|
if (! YAP_IsIntTerm(t2)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
param.orthantwise_end = YAP_IntOfTerm(t2);
|
||||||
|
} else {
|
||||||
|
printf("ERROR: The parameter %s is unknown.\n",name);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int optimizer_get_parameter( void ) {
|
||||||
|
YAP_Term t1 = YAP_ARG1;
|
||||||
|
YAP_Term t2 = YAP_ARG2;
|
||||||
|
|
||||||
|
if (! YAP_IsAtomTerm(t1)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* name=YAP_AtomName(YAP_AtomOfTerm(t1));
|
||||||
|
|
||||||
|
if ((strcmp(name, "m") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkIntTerm(param.m));
|
||||||
|
} else if ((strcmp(name, "epsilon") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(param.epsilon));
|
||||||
|
} else if ((strcmp(name, "past") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkIntTerm(param.past));
|
||||||
|
} else if ((strcmp(name, "delta") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(param.delta));
|
||||||
|
} else if ((strcmp(name, "max_iterations") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkIntTerm(param.max_iterations));
|
||||||
|
} else if ((strcmp(name, "linesearch") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkIntTerm(param.linesearch));
|
||||||
|
} else if ((strcmp(name, "max_linesearch") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkIntTerm(param.max_linesearch));
|
||||||
|
} else if ((strcmp(name, "min_step") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(param.min_step));
|
||||||
|
} else if ((strcmp(name, "max_step") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(param.max_step));
|
||||||
|
} else if ((strcmp(name, "ftol") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(param.ftol));
|
||||||
|
} else if ((strcmp(name, "gtol") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(param.gtol));
|
||||||
|
} else if ((strcmp(name, "xtol") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(param.xtol));
|
||||||
|
} else if ((strcmp(name, "orthantwise_c") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkFloatTerm(param.orthantwise_c));
|
||||||
|
} else if ((strcmp(name, "orthantwise_start") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkIntTerm(param.orthantwise_start));
|
||||||
|
} else if ((strcmp(name, "orthantwise_end") == 0)) {
|
||||||
|
return YAP_Unify(t2,YAP_MkIntTerm(param.orthantwise_end));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("ERROR: The parameter %s is unknown.\n",name);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void init_lbfgs_predicates( void )
|
||||||
|
{
|
||||||
|
//Initialize the parameters for the L-BFGS optimization.
|
||||||
|
lbfgs_parameter_init(¶m);
|
||||||
|
|
||||||
|
|
||||||
|
YAP_UserCPredicate("optimizer_reserve_memory",optimizer_initialize,1);
|
||||||
|
YAP_UserCPredicate("optimizer_run",optimizer_run,2);
|
||||||
|
YAP_UserCPredicate("optimizer_free_memory",optimizer_finalize,0);
|
||||||
|
|
||||||
|
YAP_UserCPredicate("optimizer_set_x",set_x_value,2);
|
||||||
|
YAP_UserCPredicate("optimizer_get_x",get_x_value,2);
|
||||||
|
YAP_UserCPredicate("optimizer_set_g",set_g_value,2);
|
||||||
|
YAP_UserCPredicate("optimizer_get_g",get_g_value,2);
|
||||||
|
|
||||||
|
YAP_UserCPredicate("optimizer_set_parameter",optimizer_set_parameter,2);
|
||||||
|
YAP_UserCPredicate("optimizer_get_parameter",optimizer_get_parameter,2);
|
||||||
|
}
|
Reference in New Issue
Block a user