- added ready of armadillo dat-file (Quick and dirty)
- added stack training for DeepStack
This commit is contained in:
+35
-1
@@ -1,8 +1,10 @@
|
||||
import numpy as np
|
||||
from layer import Layer
|
||||
from stack import Stack, StackType, StackException
|
||||
from stack_factory import StackFactory
|
||||
from params import RbmParams
|
||||
|
||||
if __name__ == "__main__":
|
||||
def test():
|
||||
params = RbmParams()
|
||||
stack = Stack(StackType.Deep, "Stack")
|
||||
dims = [(2, 3), (3, 4), (4, 5)]
|
||||
@@ -21,4 +23,36 @@ if __name__ == "__main__":
|
||||
stack.remove(lay1)
|
||||
stack.remove(lay0)
|
||||
|
||||
def read_armadillo(filename: str) -> np.ndarray:
|
||||
result = None
|
||||
with open(filename) as fp:
|
||||
identifier = fp.readline().replace("\n", '')
|
||||
if "ARMA_MAT_TXT_FN008" not in identifier:
|
||||
raise Exception("Not a armadillo data file!")
|
||||
|
||||
line = fp.readline().replace("\n", '').split(' ')
|
||||
shape = [int(s) for s in line]
|
||||
print(f"shape: {shape}")
|
||||
|
||||
result = np.zeros(shape=shape, dtype=np.float64)
|
||||
line = fp.readline().replace("\n", '').split(' ')
|
||||
line = line[1:]
|
||||
data = [float(s) for s in line]
|
||||
for row in range(shape[0]):
|
||||
result[row, :] = data
|
||||
|
||||
return result
|
||||
|
||||
def main():
|
||||
# Create stack from project file
|
||||
stack = StackFactory.from_file("/home/jens/work/repos/Rbm/test.prj")
|
||||
|
||||
# Load train data
|
||||
batch = read_armadillo("/home/jens/work/repos/Rbm/test.training.dat")
|
||||
|
||||
# Train
|
||||
stack.train(batch)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
print("Test: [passed]")
|
||||
|
||||
Reference in New Issue
Block a user