- use expectations
- improved gibbs sampling - LayerArray is template class git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@18 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+25
-17
@@ -10,27 +10,29 @@
|
||||
|
||||
#ifndef LAYERARRAY_HPP
|
||||
#define LAYERARRAY_HPP
|
||||
#include <cstdint>
|
||||
#include "VisibleLayer.hpp"
|
||||
#include <stdint.h>
|
||||
|
||||
class VisibleLayerArray;
|
||||
template <class T>
|
||||
class LayerArray;
|
||||
|
||||
class VisibleLayerArrayListener
|
||||
template <class T>
|
||||
class LayerArrayListener
|
||||
{
|
||||
public:
|
||||
VisibleLayerArrayListener() {}
|
||||
virtual~VisibleLayerArrayListener() {}
|
||||
LayerArrayListener() {}
|
||||
virtual~LayerArrayListener() {}
|
||||
|
||||
virtual void onChanged(const VisibleLayerArray &obj) = 0;
|
||||
virtual void onChanged(const LayerArray<T> &obj) = 0;
|
||||
};
|
||||
|
||||
class VisibleLayerArray
|
||||
template <class T>
|
||||
class LayerArray
|
||||
{
|
||||
class Entry : public VisibleLayer
|
||||
class Entry : public T
|
||||
{
|
||||
public:
|
||||
Entry(uint32_t numUnits, const double *pInit)
|
||||
: VisibleLayer(numUnits, pInit)
|
||||
: T(numUnits, pInit)
|
||||
, pPrev(nullptr)
|
||||
, pNext(nullptr)
|
||||
{
|
||||
@@ -41,10 +43,11 @@ class VisibleLayerArray
|
||||
Entry *pPrev;
|
||||
Entry *pNext;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
VisibleLayerArray(VisibleLayerArrayListener *pListener = nullptr)
|
||||
LayerArray(LayerArrayListener<T> *pListener = nullptr)
|
||||
: m_size(0)
|
||||
, m_pRoot(nullptr)
|
||||
, m_ppIndex(nullptr)
|
||||
@@ -52,8 +55,9 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~VisibleLayerArray()
|
||||
virtual ~LayerArray()
|
||||
{
|
||||
m_pListener = nullptr;
|
||||
clear();
|
||||
}
|
||||
|
||||
@@ -82,7 +86,6 @@ public:
|
||||
|
||||
void clear()
|
||||
{
|
||||
// rebuildIndex();
|
||||
if (m_ppIndex)
|
||||
{
|
||||
for (int i=0; i < m_size; i++)
|
||||
@@ -101,11 +104,16 @@ public:
|
||||
m_pListener->onChanged(*this);
|
||||
}
|
||||
|
||||
VisibleLayer& getAt(uint32_t index)
|
||||
T& getAt(uint32_t index)
|
||||
{
|
||||
return *m_ppIndex[index];
|
||||
}
|
||||
|
||||
T& operator[](uint32_t index)
|
||||
{
|
||||
return getAt(index);
|
||||
}
|
||||
|
||||
void removeAt(uint32_t index)
|
||||
{
|
||||
if (m_ppIndex[index]->pPrev)
|
||||
@@ -145,12 +153,12 @@ public:
|
||||
|
||||
for (i=0; i < m_size; i++)
|
||||
{
|
||||
uint32_t numUnits = ((VisibleLayer*)m_ppIndex[i])->getNumUnits();
|
||||
uint32_t numUnits = m_ppIndex[i]->getNumUnits();
|
||||
fprintf(pFile, "%d\n", numUnits);
|
||||
|
||||
for (j=0; j < numUnits; j++)
|
||||
{
|
||||
fprintf(pFile, "%3.6f\n", ((VisibleLayer*)m_ppIndex[i])->getStates()[j]);
|
||||
fprintf(pFile, "%3.6f\n", m_ppIndex[i]->getStates()[j]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +202,7 @@ private:
|
||||
uint32_t m_size;
|
||||
Entry *m_pRoot;
|
||||
Entry **m_ppIndex;
|
||||
VisibleLayerArrayListener *m_pListener;
|
||||
LayerArrayListener<T> *m_pListener;
|
||||
void allocIndex(size_t size)
|
||||
{
|
||||
if (m_ppIndex)
|
||||
|
||||
Reference in New Issue
Block a user