PLearn 0.1
PentaTest.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PentaTest.cc
00004 //
00005 // Copyright (C) 2005 Nicolas Chapados
00006 // Copyright (C) 2005 Olivier Delalleau 
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions are met:
00010 // 
00011 //  1. Redistributions of source code must retain the above copyright
00012 //     notice, this list of conditions and the following disclaimer.
00013 // 
00014 //  2. Redistributions in binary form must reproduce the above copyright
00015 //     notice, this list of conditions and the following disclaimer in the
00016 //     documentation and/or other materials provided with the distribution.
00017 // 
00018 //  3. The name of the authors may not be used to endorse or promote
00019 //     products derived from this software without specific prior written
00020 //     permission.
00021 // 
00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 // 
00033 // This file is part of the PLearn library. For more information on the PLearn
00034 // library, go to the PLearn Web site at www.plearn.org
00035 
00036 /* *******************************************************      
00037    * $Id: .pyskeleton_header 544 2003-09-01 00:05:31Z plearner $ 
00038    ******************************************************* */
00039 
00040 // Authors: Nicolas Chapados, Olivier Delalleau
00041 
00045 #include "PentaTest.h"
00046 #include <plearn/math/TMat_maths.h>
00047 #include <plearn/math/BandedSolvers.h>
00048 
00049 namespace PLearn {
00050 using namespace std;
00051 
00052 PLEARN_IMPLEMENT_OBJECT(
00053     PentaTest,
00054     "PentadiagonalSolveInPlace test.",
00055     ""
00056 );
00057 
00059 // PentaTest //
00061 PentaTest::PentaTest() 
00062     /* ### Initialize all fields to their default value */
00063 {
00064     // ...
00065 
00066     // ### You may (or not) want to call build_() to finish building the object
00067     // ### (doing so assumes the parent classes' build_() have been called too
00068     // ### in the parent classes' constructors, something that you must ensure)
00069 }
00070 
00072 // build //
00074 void PentaTest::build()
00075 {
00076     inherited::build();
00077     build_();
00078 }
00079 
00081 // makeDeepCopyFromShallowCopy //
00083 void PentaTest::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00084 {
00085     inherited::makeDeepCopyFromShallowCopy(copies);
00086 
00087     // ### Call deepCopyField on all "pointer-like" fields 
00088     // ### that you wish to be deepCopied rather than 
00089     // ### shallow-copied.
00090     // ### ex:
00091     // deepCopyField(trainvec, copies);
00092 
00093     // ### Remove this line when you have fully implemented this method.
00094     PLERROR("PentaTest::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00095 }
00096 
00098 // declareOptions //
00100 void PentaTest::declareOptions(OptionList& ol)
00101 {
00102     // ### Declare all of this object's options here
00103     // ### For the "flags" of each option, you should typically specify  
00104     // ### one of OptionBase::buildoption, OptionBase::learntoption or 
00105     // ### OptionBase::tuningoption. Another possible flag to be combined with
00106     // ### is OptionBase::nosave
00107 
00108     // ### ex:
00109     // declareOption(ol, "myoption", &PentaTest::myoption, OptionBase::buildoption,
00110     //               "Help text describing this option");
00111     // ...
00112 
00113     // Now call the parent class' declareOptions
00114     inherited::declareOptions(ol);
00115 }
00116 
00118 // build_ //
00120 void PentaTest::build_()
00121 {
00122     // ### This method should do the real building of the object,
00123     // ### according to set 'options', in *any* situation. 
00124     // ### Typical situations include:
00125     // ###  - Initial building of an object from a few user-specified options
00126     // ###  - Building of a "reloaded" object: i.e. from the complete set of all serialised options.
00127     // ###  - Updating or "re-building" of an object after a few "tuning" options have been modified.
00128     // ### You should assume that the parent class' build_() has already been called.
00129 }
00130 
00132 // perform //
00134 void PentaTest::perform()
00135 {
00136     try {
00137         const int n = 10;
00138         Mat A(n,n);
00139         Vec a(n),b(n),c(n),y(n);
00140         for (int i=0; i<n; ++i) {
00141             A(i,i) = 50+1.5*i;
00142             a[i] = 50+1.5*i;
00143             if (i+1<n) {
00144                 A(i,i+1) = 4+2*i;
00145                 A(i+1,i) = 4+2*i;
00146                 b[i] = 4+2*i;
00147             }
00148             if (i+2<n) {
00149                 A(i,i+2) = i;
00150                 A(i+2,i) = i;
00151                 c[i] = i;
00152             }
00153             y[i] = 2*i+1;
00154         }
00155 
00156         cout << "A matrix is" << endl;
00157         cout << A << endl;
00158         cout << "y vector is " << endl;
00159         cout << y << endl;
00160         cout << "Solution found by Cholesky" << endl;
00161         Vec x = choleskySolve(A, y);
00162         cout << x << endl;
00163 
00164         cout << "Solution found by Pentadiagonal solver" << endl;
00165         PentadiagonalSolveInPlace(y, a, b, c);
00166         cout << y << endl;
00167     }
00168     catch (PLearnError e) {
00169         cout << "PLearnError: " << e.message() << endl;
00170     }
00171 }
00172 
00173 } // end of namespace PLearn
00174 
00175 
00176 /*
00177   Local Variables:
00178   mode:c++
00179   c-basic-offset:4
00180   c-file-style:"stroustrup"
00181   c-file-offsets:((innamespace . 0)(inline-open . 0))
00182   indent-tabs-mode:nil
00183   fill-column:79
00184   End:
00185 */
00186 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines