sbasis.h revision 04d58df841d9eb087eb99074f5c99235b801189b
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * \brief Defines S-power basis function class
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * Authors:
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk * Nathan Hurst <njh@mail.csse.monash.edu.au>
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk * Michael Sloan <mgsloan@gmail.com>
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * Copyright (C) 2006-2007 authors
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * This library is free software; you can redistribute it and/or
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * modify it either under the terms of the GNU Lesser General Public
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * License version 2.1 as published by the Free Software Foundation
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * (the "LGPL") or, at your option, under the terms of the Mozilla
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * Public License Version 1.1 (the "MPL"). If you do not alter this
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * notice, a recipient may use your version of this file under either
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * the MPL or the LGPL.
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * You should have received a copy of the LGPL along with this library
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * in the file COPYING-LGPL-2.1; if not, write to the Free Software
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * You should have received a copy of the MPL along with this library
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk * in the file COPYING-MPL-1.1
ae22ad7adc4a7a418e71f5dbab8c1f0f7f464562johanengelen * The contents of this file are subject to the Mozilla Public License
ae22ad7adc4a7a418e71f5dbab8c1f0f7f464562johanengelen * Version 1.1 (the "License"); you may not use this file except in
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * compliance with the License. You may obtain a copy of the License at
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * OF ANY KIND, either express or implied. See the LGPL or the MPL for
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * the specific language governing rights and limitations.
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm//#define USE_SBASISN 1
963f23115db07f460bdd862b957f8bd9dba88b9bgustav_b/*** An empty SBasis is identically 0. */
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm* \brief S-power basis function class
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm* An empty SBasis is identically 0. */
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm // As part of our migration away from SBasis isa vector we provide this minimal set of vector interface methods.
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm return d[i];
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm Linear const* begin() const { return (Linear const*)&*d.begin();}
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm Linear const* end() const { return (Linear const*)&*d.end();}
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm void resize(unsigned n, Linear const& l) { d.resize(n, l);}
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen void insert(Linear* before, const Linear* src_begin, const Linear* src_end) { d.insert(std::vector<Linear>::iterator(before), src_begin, src_end);}
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm //void insert(Linear* aa, Linear* bb, Linear* cc} { d.insert(aa, bb, cc);}
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm //void insert(Linear* before, int& n, Linear const &l) { d.insert(std::vector<Linear>::iterator(before), n, l);}
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm bool operator==(SBasis const&B) const { return d == B.d;}
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm bool operator!=(SBasis const&B) const { return d != B.d;}
c5526a2c3001be486990d816757dd5ac028b3c3fjohanengelen explicit SBasis(size_t n, Linear const&l) : d(n, l) {}
c5526a2c3001be486990d816757dd5ac028b3c3fjohanengelen //IMPL: FragmentConcept
c5526a2c3001be486990d816757dd5ac028b3c3fjohanengelen typedef double output_type;
c5526a2c3001be486990d816757dd5ac028b3c3fjohanengelen if(empty()) return true;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm for(unsigned i = 0; i < size(); i++) {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm return true;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm if (empty()) return true;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm return true;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm bool isFinite() const;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm inline double at0() const {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm inline double at1() const{
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm double valueAt(double t) const {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm double s = t*(1-t);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm for(unsigned k = size(); k > 0; k--) {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm //double valueAndDerivative(double t, double &der) const {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm double operator()(double t) const {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm std::vector<double> valueAndDerivatives(double t, unsigned n) const;
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk// compute f(g)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm//MUTATOR PRISON
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm //remove extra zeros
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm void truncate(unsigned k) { if(k < size()) resize(k); }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm//TODO: figure out how to stick this in linear, while not adding an sbasis dep
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrminline SBasis Linear::toSBasis() const { return SBasis(*this); }
1e7c268648bcbae15fc13b8c94dee677b401d9b3gustav_b//implemented in sbasis-roots.cpp
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrmOptInterval bounds_fast(SBasis const &a, int order = 0);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrmOptInterval bounds_local(SBasis const &a, const OptInterval &t, int order = 0);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm/** Returns a function which reverses the domain of a.
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm \param a sbasis function
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm \relates SBasis
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrmuseful for reversing a parameteric curve.
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm for(unsigned k = 0; k < a.size(); k++)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm//IMPL: ScalableConcept
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm for(unsigned i = 0; i < p.size(); i++) {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm result[i] = -p[i];
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrminline SBasis operator*(double k, SBasis const &a) { return a*k; }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrminline SBasis operator/(SBasis const &a, double k) { return a*(1./k); }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrminline SBasis& operator/=(SBasis& a, double b) { return (a*=(1./b)); }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm//IMPL: AddableConcept
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm//TODO: remove?
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm/*inline SBasis operator+(const SBasis & a, Linear const & b) {
ae22ad7adc4a7a418e71f5dbab8c1f0f7f464562johanengelen if(b.isZero()) return a;
ae22ad7adc4a7a418e71f5dbab8c1f0f7f464562johanengelen if(a.isZero()) return b;
ae22ad7adc4a7a418e71f5dbab8c1f0f7f464562johanengelen SBasis result(a);
ae22ad7adc4a7a418e71f5dbab8c1f0f7f464562johanengelen result[0] += b;
ae22ad7adc4a7a418e71f5dbab8c1f0f7f464562johanengelen return result;
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgkinline SBasis operator-(const SBasis & a, Linear const & b) {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm if(b.isZero()) return a;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm SBasis result(a);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm result[0] -= b;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm return result;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrminline SBasis& operator+=(SBasis& a, const Linear& b) {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm if(a.isZero())
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm a.push_back(b);
6dee13f1978edf532e28b55de684694f0b2e9449bgk a[0] += b;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrminline SBasis& operator-=(SBasis& a, const Linear& b) {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm if(a.isZero())
3ae3dd4eb0191cc986a035c790b8b97e6c6e4ee4johanengelen a.push_back(-b);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm a[0] -= b;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm//IMPL: OffsetableConcept
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm a[0] += b;
SBasis c;
// This performs a multiply and accumulate operation in about the same time as multiply. return a*b + c
return multiply(a, b);
a = multiply(a, b);
unsigned val=0;
val++;
return val;
inline SBasis portion(const SBasis &t, double from, double to) { return compose(t, Linear(from, to)); }
inline SBasis portion(const SBasis &t, Interval ivl) { return compose(t, Linear(ivl.min(), ivl.max())); }
inline SBasis
return out_file;
for(unsigned i = 0; i < p.size(); i++) {
return out_file;
// These are deprecated, use sbasis-math.h versions if possible
double level,