protected virtual void SinglePixelRLEvaluateStep() { SchoolWorld.ActionInput.SafeCopyToHost(); bool wasTargetDetected = SchoolWorld.ActionInput.Host[ControlMapper.Idx("forward")] != 0; bool wasTargetPresent = m_previousObjectType == ObjectType.Target; if (wasTargetDetected && wasTargetPresent) { m_targetsDetected++; WrappedWorld.Reward.Host[0] = 1f; } else if (m_previousObjectType != ObjectType.None) { if (wasTargetDetected && !wasTargetPresent) { m_targetsMisdetected++; WrappedWorld.Reward.Host[0] = -1f; } else if (wasTargetPresent && !wasTargetDetected) { WrappedWorld.Reward.Host[0] = -1f; } else { WrappedWorld.Reward.Host[0] = 0f; } } else { WrappedWorld.Reward.Host[0] = 0; } }
public void MapWorldInputs() { // Copy data from wrapper to world (inputs) - SchoolWorld validation ensures that we have something connected School.ActionInput.SafeCopyToHost(); ControlsAdapterTemp.Host[0] = School.ActionInput.Host[ControlMapper.Idx("left")]; // A ControlsAdapterTemp.Host[1] = School.ActionInput.Host[ControlMapper.Idx("backward")]; // S ControlsAdapterTemp.Host[2] = School.ActionInput.Host[ControlMapper.Idx("right")]; // D ControlsAdapterTemp.SafeCopyToDevice(); }
public void EvaluateSinglePixelRLStep() { SchoolWorld.ActionInput.SafeCopyToHost(); int action = 0; if (SchoolWorld.ActionInput.Host[ControlMapper.Idx("forward")] != 0) { action = 1; } else if (SchoolWorld.ActionInput.Host[ControlMapper.Idx("backward")] != 0) { action = 2; } else if (SchoolWorld.ActionInput.Host[ControlMapper.Idx("left")] != 0) { action = 3; } else if (SchoolWorld.ActionInput.Host[ControlMapper.Idx("right")] != 0) { action = 4; } int expectedAction = 0; if (m_lastTransition != null) { expectedAction = m_lastTransition.action; //MyLog.WARNING.WriteLine("Action taken: " + action+" expected action: "+expectedAction); } if (m_lastTransition == null) { m_stepIsCorrect = true; WrappedWorld.Reward.Host[0] = 0f; } else if (action == expectedAction) { m_stepIsCorrect = true; if (m_importantActions.Contains(action)) { m_importantActionsTaken++; WrappedWorld.Reward.Host[0] = 1f; } else { WrappedWorld.Reward.Host[0] = 0f; } } else { m_stepIsCorrect = false; WrappedWorld.Reward.Host[0] = -1f; } }
public override void Execute() { // Process FOF controls Owner.ActionInput.SafeCopyToHost(); float fof_up = Owner.ActionInput.Host[ControlMapper.Idx("fof_up")]; // I float fof_left = Owner.ActionInput.Host[ControlMapper.Idx("fof_left")]; // J float fof_down = Owner.ActionInput.Host[ControlMapper.Idx("fof_down")]; // K float fof_right = Owner.ActionInput.Host[ControlMapper.Idx("fof_right")]; // L FofX = ConvertBiControlToUniControl(fof_left, fof_right); FofY = ConvertBiControlToUniControl(fof_down, fof_up); Owner.CurrentWorld.MapWorldInputs(); }
protected override bool DidTrainingUnitComplete(ref bool wasUnitSuccessful) { int correction = m_currentObjectType == ObjectType.Target ? 1 : 0; wasUnitSuccessful = (m_targetsShown - correction == m_targetsDetected && m_targetsMisdetected == 0); bool acted = SchoolWorld.ActionInput.Host[ControlMapper.Idx("forward")] != 0; MyLog.Writer.WriteLine(MyLogLevel.WARNING, "did act: " + acted + ", wasTarget: " + (m_previousObjectType == ObjectType.Target) + ", was allowed to act: " + m_previousTargetWithAction); MyLog.Writer.WriteLine(MyLogLevel.WARNING, "m_targetsShown:" + m_targetsShown + ", m_targetsDetected: " + m_targetsDetected + "correction: " + correction + ", targetsMisdetected: " + m_targetsMisdetected); return(m_targetsShown - correction == m_targetsPerTU); // - correction, because when ending, ExecuteStep is done before the last EvaluateStep - the ExecuteStep may prepare a new state which should be ignored by EvaluateStep }