00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00041
#include "RegularGridVMatrix.h"
00042
00043
namespace PLearn {
00044
using namespace std;
00045
00046
00047 RegularGridVMatrix::RegularGridVMatrix()
00048 {
00049
00050
00051
00052
00053 }
00054
00055 RegularGridVMatrix::RegularGridVMatrix(
TVec<int> the_dimensions,
TVec< pair<real,real> > the_range)
00056 :dimensions(the_dimensions.
copy()), range(the_range.
copy())
00057 {
00058
build_();
00059 }
00060
00061
00062
PLEARN_IMPLEMENT_OBJECT(
RegularGridVMatrix,
"ONE LINE DESCR",
00063
"RegularGridVMatrix represents the list of coordinates along a regularly spaced grid.");
00064
00065 void RegularGridVMatrix::getNewRow(
int i,
const Vec& v)
const
00066
{
00067
int d =
width();
00068
if(v.
length()!=d)
00069
PLERROR(
"In RegularGridVMatrix::getNewRow, size of v (%d) differs from vmat width (%d)",v.
length(), d);
00070
if(i<0 || i>=
length())
00071
PLERROR(
"In RegularGridVMatrix::getNewRow, row %d out of range [0,%d]",i,
length()-1);
00072
int idx = i;
00073
for(
int k=d-1;
k>=0;
k--)
00074 {
00075
int idx_k = idx%
dimensions[
k];
00076 idx = idx/
dimensions[
k];
00077 v[
k] =
range[
k].
first + (range[
k].second-range[
k].first)/(
dimensions[
k]-1)*idx_k;
00078 }
00079 }
00080
00081 void RegularGridVMatrix::declareOptions(
OptionList& ol)
00082 {
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
declareOption(ol,
"dimensions", &RegularGridVMatrix::dimensions, OptionBase::buildoption,
00094
"A vector of integers giving the number of sample coordinates\n"
00095
"for each dimension of the grid. Ex for a 100x100 2D grid: [ 100 100 ]\n");
00096
declareOption(ol,
"range", &RegularGridVMatrix::range, OptionBase::buildoption,
00097
"A vector of low:high pairs with as many dimensions as the grid\n"
00098
"ex for 2D: [ -10:10 -3:4 ] \n");
00099
00100
00101 inherited::declareOptions(ol);
00102 }
00103
00104 void RegularGridVMatrix::build_()
00105 {
00106 width_ =
dimensions.
length();
00107 length_ = (width_ ?
product(
dimensions) : 0);
00108
if(inputsize_<0)
00109 {
00110 inputsize_ = width_;
00111 targetsize_ = 0;
00112 weightsize_ = 0;
00113 }
00114 }
00115
00116
00117 void RegularGridVMatrix::build()
00118 {
00119 inherited::build();
00120
build_();
00121 }
00122
00123 void RegularGridVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00124 {
00125 inherited::makeDeepCopyFromShallowCopy(copies);
00126
deepCopyField(
dimensions, copies);
00127
deepCopyField(
range, copies);
00128 }
00129
00130 }
00131