![]() |
Blitz Support : |
From: roger.grant (roger.grant_at_[hidden])
Date: 2003-10-13 16:30:09
Todd,
I have enclosd an example, sorry for the formatting problem :)
Regards,
Roger
//
class rgGRNN : public doubleObjFunction
{
private:
// passed arrays
DoubleVec actualOUTCOME;
DoubleArray actualINPUTS;
DoubleVec predictedOUTCOME;
// some good stuff to only build once
int numROWS, numCOLS;
public:
virtual double objFunc(const DoubleVec &) const;
virtual DoubleVec rgGRNN::objGrad(const DoubleVec &);
virtual DoubleSymMatrix objHess(const DoubleVec &);
rgGRNN(const DoubleArray &, const DoubleVec &, DoubleVec &);
DoubleVec rgGRNN::getOUTCOME();
};
rgGRNN::rgGRNN(const DoubleArray &x, const DoubleVec &y, DoubleVec &z)
: actualINPUTS(x),actualOUTCOME(y),predictedOUTCOME(z)
{
numROWS = rows(actualINPUTS);
numCOLS = cols(actualINPUTS);
}
DoubleVec rgGRNN::getOUTCOME()
{
return predictedOUTCOME;
}
double rgGRNN::objFunc(const DoubleVec & inSIGMA) const
{
// DoubleArray rowSIGMA = inSIGMA;
// rowSIGMA = rowSIGMA.Transpose();
int i,j,k;
double holdROWS;
double sumDENOM;
double sumNUMER;
double partialERROR;
double retERROR = 0;
Index oneELEMENT = 0;
Index oneCOLUMN = 0;
Index allCOLS(0,numCOLS,1);
int * includeINDEX = new int [numROWS-1];
double *dptr;
double temp;
for (i=0; i<numROWS; i++)
{
partialERROR = 0;
sumDENOM = 0;
sumNUMER = 0;
k=0;
// This is the section where it builds the index using numROWS -1
for (j=0; j<numROWS; j++)
{
if (j != i)
{
includeINDEX[k] = j;
k++;
}
}
Index testROWS(includeINDEX, numROWS-1);
// As you can see the Index is built from an array
oneCOLUMN = 0;
dptr = &inSIGMA(0);
for (j=0; j< numCOLS; j++)
{
temp = *dptr;
if (temp == 0) {}
else {
DoubleArray tempX = actualINPUTS(testROWS, oneCOLUMN) -
actualINPUTS(oneELEMENT, oneCOLUMN);
tempX /= inSIGMA(j);
tempX *= tempX;
tempX += 1;
tempX = 1 / tempX;
sumDENOM += sum(tempX);
tempX *= actualOUTCOME(testROWS);
sumNUMER += sum(tempX);
}
oneCOLUMN++;
dptr++;
}
if (sumDENOM == 0)
{
sumDENOM = 1e-40;
}
partialERROR = sumNUMER / sumDENOM;
predictedOUTCOME(oneELEMENT) = partialERROR;
DoubleVec trialOUTCOME = actualOUTCOME(oneELEMENT);
partialERROR -= trialOUTCOME(0);
partialERROR *= partialERROR;
//
holdROWS = (i / (numROWS - 1));
holdROWS *= 4;
holdROWS++;
holdROWS /= 5;
partialERROR *= holdROWS;
//
retERROR += partialERROR;
oneELEMENT++;
}
delete [] includeINDEX;
retERROR /= numROWS;
return retERROR;
}
----- Original Message -----
From: "Todd Veldhuizen" <tveldhui_at_[hidden]>
To: "roger.grant" <roger.grant_at_[hidden]>
Cc: <blitz-support_at_[hidden]>
Sent: Sunday, October 12, 2003 10:49 AM
Subject: Re: [Blitz-support] question
> Hi Roger,
>
> Could you post an example of the kind of iteration you'd like to do,
> (i.e. an excerpt of M++ code)?
>
> Regarding BLAS, does your code spend a substantial amount of time in an
> array operation that corresponds to a BLAS routine? Blitz++ is designed to
> get decent performance for any array expression, whereas BLAS provides a
> selected set of fast implementations of common expressions in linear
> algebra. The idea of invoking BLAS from blitz when possible has been
> kicked around, but so far it seems like nobody has had their code run
> unacceptably slow because BLAS isn't used (or, they've been willing
> to grab pointers and invoke blas themselves.) I guess it just hasn't
> seemed worth the effort to anyone to write the BLAS hooks.
>
> Cheers,
> Todd
>
>
> On Fri, 10 Oct 2003, roger.grant wrote:
> > I am currently using the M++ package on Windows. I am transferring my
work to FreeBSD and the M++ is not easily changeable to go to a UNIX
environment and is also of very old technology as compared to Bltz++.
Anyway, M++ defines an Index as a class and I am able to define a special
index which I will call a Leave-One-Out index. I can then transverse my
array iteratively leaving one out.
> > Example:
> > Define a Vector of 100 items.
> > define a leave-one-out index which will be of size 99.
> > pass thru the Vector 100 times; each time leaving out a different point
( from 0 to 99)
> > This is VERY useful for working to develope pattern matching algorithms
as you never use the point that you are trying to predict within the
algorithm. My software may make 1000's of passes on the Vector/Array working
to optimize the algorithm, to minimize the "error". The Vector/Array is only
created once and only the "view" of the data is changed.
> > How can I accomplish this with Blitz++???
> > Thank You!
> > Roger Grant
> > PS: I am surprised that you do not use the blas libraries. Wouldn't this
lead to a severe performance hit as most architectures have optimized
assembler coded blas?
> >
>
>
> --
> Todd Veldhuizen / tveldhui_at_[hidden] / Indiana University Computer
Science
>