- use Matrix, linear algebra library Eigen 3.2.2

git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@23 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2014-10-12 14:30:40 +00:00
parent 7b1a713adc
commit 19c69ac02a
13 changed files with 246 additions and 359 deletions
+16 -7
View File
@@ -11,6 +11,9 @@
#ifndef LAYERARRAY_HPP
#define LAYERARRAY_HPP
#include <stdint.h>
#include <Eigen/Dense>
using namespace Eigen;
template <class T>
class LayerArray;
@@ -31,7 +34,7 @@ class LayerArray
class Entry : public T
{
public:
Entry(uint32_t numUnits, const double *pInit)
Entry(uint32_t numUnits, const VectorXd *pInit)
: T(numUnits, pInit)
, pPrev(nullptr)
, pNext(nullptr)
@@ -75,13 +78,15 @@ public:
clear();
}
void add(const double *pData, uint32_t size)
T* add(const VectorXd *pData, uint32_t size)
{
Entry *pNew;
Entry *pL = m_pRoot;
pNew = new Entry(size, pData);
if (!m_pRoot)
{
m_pRoot = new Entry(size, pData);
m_pRoot = pNew;
}
else
{
@@ -90,12 +95,14 @@ public:
{
pL = pL->pNext;
}
pL->pNext = new Entry(size, pData);
pL->pNext = pNew;
pL->pNext->pPrev = pL;
}
rebuildIndex();
if (m_pListener)
m_pListener->onChanged(*this);
return (T*)pNew;
}
void clear()
@@ -172,7 +179,7 @@ public:
for (j=0; j < numUnits; j++)
{
fprintf(pFile, "%3.6f\n", m_ppIndex[i]->getStates()[j]);
fprintf(pFile, "%3.6f\n", m_ppIndex[i]->states()(j));
}
}
@@ -199,13 +206,15 @@ public:
uint32_t numUnits;
fscanf(pFile, "%d\n", &numUnits);
pData = new double[numUnits];
T* data = add(nullptr, numUnits);
for (j=0; j < numUnits; j++)
{
fscanf(pFile, "%f", &v);
pData[j] = v;
data->states()(j) = v;
}
add(pData, numUnits);
delete [] pData;
}