sbasis.h revision 07bda0b13ae048815f53f21ad1edbe3cc1b7e4e8
/**
* \file
* \brief Defines S-power basis function class
*
* Authors:
* Nathan Hurst <njh@mail.csse.monash.edu.au>
* Michael Sloan <mgsloan@gmail.com>
*
* Copyright (C) 2006-2007 authors
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*/
#ifndef SEEN_SBASIS_H
#define SEEN_SBASIS_H
#include <vector>
#include <cassert>
#include <iostream>
//#define USE_SBASISN 1
#if defined(USE_SBASIS_OF)
#include "sbasis-of.h"
#elif defined(USE_SBASISN)
#include "sbasisN.h"
/*** An empty SBasis is identically 0. */
};
#else
/**
* \brief S-power basis function class
*
* An empty SBasis is identically 0. */
// As part of our migration away from SBasis isa vector we provide this minimal set of vector interface methods.
return d[i];
}
void insert(Linear* before, const Linear* src_begin, const Linear* src_end) { d.insert(std::vector<Linear>::iterator(before), src_begin, src_end);}
//void insert(Linear* aa, Linear* bb, Linear* cc} { d.insert(aa, bb, cc);}
//void insert(Linear* before, int& n, Linear const &l) { d.insert(std::vector<Linear>::iterator(before), n, l);}
SBasis() {}
}
}
d(a.d)
{}
d(ls)
{}
}
}
//IMPL: FragmentConcept
typedef double output_type;
inline bool isZero() const {
if(empty()) return true;
for(unsigned i = 0; i < size(); i++) {
}
return true;
}
inline bool isConstant() const {
if (empty()) return true;
if(!(*this)[0].isConstant()) return false;
for (unsigned i = 1; i < size(); i++) {
}
return true;
}
bool isFinite() const;
inline double at0() const {
}
inline double at1() const{
}
double valueAt(double t) const {
double s = t*(1-t);
for(unsigned k = size(); k > 0; k--) {
}
}
//double valueAndDerivative(double t, double &der) const {
//}
double operator()(double t) const {
return valueAt(t);
}
// compute f(g)
//MUTATOR PRISON
//remove extra zeros
void normalize() {
pop_back();
}
void derive(); // in place version
};
//TODO: figure out how to stick this in linear, while not adding an sbasis dep
//implemented in sbasis-roots.cpp
/** Returns a function which reverses the domain of a.
\param a sbasis function
\relates SBasis
useful for reversing a parameteric curve.
*/
for(unsigned k = 0; k < a.size(); k++)
return result;
}
//IMPL: ScalableConcept
for(unsigned i = 0; i < p.size(); i++) {
result[i] = -p[i];
}
return result;
}
//IMPL: AddableConcept
//TODO: remove?
/*inline SBasis operator+(const SBasis & a, Linear const & b) {
if(b.isZero()) return a;
if(a.isZero()) return b;
SBasis result(a);
result[0] += b;
return result;
}
inline SBasis operator-(const SBasis & a, Linear const & b) {
if(b.isZero()) return a;
SBasis result(a);
result[0] -= b;
return result;
}
inline SBasis& operator+=(SBasis& a, const Linear& b) {
if(a.isZero())
a.push_back(b);
else
a[0] += b;
return a;
}
inline SBasis& operator-=(SBasis& a, const Linear& b) {
if(a.isZero())
a.push_back(-b);
else
a[0] -= b;
return a;
}*/
//IMPL: OffsetableConcept
result[0] += b;
return result;
}
result[0] -= b;
return result;
}
if(a.isZero())
else
a[0] += b;
return a;
}
if(a.isZero())
else
a[0] -= b;
return a;
}
SBasis c;
return c;
}
// This performs a multiply and accumulate operation in about the same time as multiply. return a*b + c
// return a kth order approx to 1/a)
return multiply(a, b);
}
a = multiply(a, b);
return a;
}
/** Returns the degree of the first non zero coefficient.
\param a sbasis function
\param tol largest abs val considered 0
\return first non zero coefficient
\relates SBasis
*/
inline unsigned
unsigned val=0;
val++;
return val;
}
// a(b(t))
//compose_inverse(f,g)=compose(f,inverse(g)), but is numerically more stable in some good cases...
//TODO: requires g(0)=0 & g(1)=1 atm. generalization should be obvious.
/** Returns the sbasis on domain [0,1] that was t on [from, to]
\param t sbasis function
\param from,to interval
\return sbasis
\relates SBasis
*/
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())); }
// compute f(g)
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 htol=1e-7,
double vtol=1e-7,
double a=0,
double b=1);
//--------- Levelset like functions -----------------------------------------------------
/** Solve f(t) = v +/- tolerance. The collection of intervals where
* v - vtol <= f(t) <= v+vtol
* is returned (with a precision tol on the boundaries).
\param f sbasis function
\param level the value of v.
\param vtol: error tolerance on v.
\param a, b limit search on domain [a,b]
\param tol: tolerance on the result bounds.
\returns a vector of intervals.
*/
double level,
double vtol = 1e-5,
double a=0.,
double b=1.,
double tol = 1e-5);
/** Solve f(t)\in I=[u,v], which defines a collection of intervals (J_k). More precisely,
* a collection (J'_k) is returned with J'_k = J_k up to a given tolerance.
\param f sbasis function
\param level: the given interval of deisred values for f.
\param a, b limit search on domain [a,b]
\param tol: tolerance on the bounds of the result.
\returns a vector of intervals.
*/
double a=0.,
double b=1.,
double tol = 1e-5);
/** 'Solve' f(t) = v +/- tolerance for several values of v at once.
\param f sbasis function
\param levels vector of values, that should be sorted.
\param vtol: error tolerance on v.
\param a, b limit search on domain [a,b]
\param tol: the bounds of the returned intervals are exact up to that tolerance.
\returns a vector of vectors of intervals.
*/
double a=0.,
double b=1.,
double vtol = 1e-5,
double tol = 1e-5);
/** 'Solve' f(t)\in I=[u,v] for several intervals I at once.
\param f sbasis function
\param levels vector of 'y' intervals, that should be disjoints and sorted.
\param a, b limit search on domain [a,b]
\param tol: the bounds of the returned intervals are exact up to that tolerance.
\returns a vector of vectors of intervals.
*/
double a=0.,
double b=1.,
double tol = 1e-5);
}
#endif
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
#endif