' This is an example script file to demonstrate how MemBrain scripts
' can be used to train and validate a net.


'Adjust the view
VIEW_SETTING BLACK_BG YES SHOW_GRID NO UPDATE_TEACH YES UPDATE_THINK YES SHOW_FIRE NO SHOW_ACT_SPIKES NO SHOW_LINKS YES

OPEN_NET 4x4.mbn	' Open the net to be trained and validated
RANDOMIZE_NET			' Randomize all link weights and activation thresholds.
RESET_THINK_STEPS		' Reset the think step counter
LESSON_COUNT 1			' Clear all lessons except for #1
LESSON_COUNT 3			' This script uses four lessons in the Lesson Editor (create
				' them now) As a net is already loaded the new lessons will be
				' created in sync with the net (same I/O names).
SET_LESSON 1			' First operate on Lesson #1

IMPORT_LESSON training.csv	' Load training lesson
HIDE_LESSONEDITOR		' Hide the lesson editor again to fully view the net

' Set the teacher to be used. This script uses the currently active teacher of MemBrain, thus, the line 
' is commented out. Use the name of the teacher you want to set as the active one instead here if you want to 
' ensure that a certain teacher is used.
SET_TEACHER  RPROP		' Use the teacher with the name 'BP'

' Adjust the teacher
TEACHER_SETTING LEARNRATE 0.001	' The learning rate

TEACHER_SETTING TARGET_ERR 0.09	' The target net error

' Lesson repetitions per teach step,
' Pattern repetitions per teach step,
' The pattern selection method
TEACHER_SETTING LESSON_REPS 1	PATTERN_REPS 1	PATTERN_SELECT	RAND_ORDER 

TEACH_SPEED 0			' Set maximum teach speed

SHOW_ERRORVIEWER		' Show the net error viewer and reset it
RESET_ERRORVIEWER		

START_TEACH			' Start teaching and wait for stop (target error reached)
SLEEP TEACH_END
HIDE_ERRORVIEWER		' Hide the error viewer again
RESET_THINK_STEPS		' Reset think step counter

SET_LESSON 2			' Load lesson #2 with the validation data
LESSON_OUTPUTS NO		' Don't need any output data, this lesson is only input

IMPORT_LESSON validation.csv
'Could also import a lesson (see line above but the imported file has to use country
'specific characters for list separation (; or ,) and for decimal point (. or ,)
'LOAD_LESSON validation.mbl
'LESSON_OUTPUTS NO		' Don't need any output data, this lesson is only input

RECORDING_TYPE OUT		' Record output signals of output neurons
START_RECORDING 3		' Enable recording of data to lesson #3

'HIDE_LESSONEDITOR		' Hide the lesson editor

RESET_THINK_STEPS		' Reset the think step counter

'THINK_LESSON		' Think on every pattern in lesson #2 (and record to #4)
SLEEP 8000			' Wait until 'Think on Lesson' is finished

STOP_RECORDING			' Deactivate recording again

' Now export lesson #3 and 4 to csv
SET_LESSON 3
EXPORT_LESSON_RAW ValidateResult.csv


' Adjust for maximum speed again 
THINK_SPEED 0

' Uncomment the following line if you want MemBrain to terminate after the script execution
' EXIT











